[英]problems with minim and processing
嘗試創建一個聲音采樣器,使其可以以不同的頻率/速率播放錄制的樣本,並且正在使用TickRate更改播放速率,類似於TickRate示例。 當我運行時,我在這里得到NullPointerException player.patch(rateControl).patch(out);
但不知道為什么,為什么有任何想法?
import ddf.minim.*;
import ddf.minim.analysis.*;
import ddf.minim.signals.*;
import ddf.minim.ugens.*;
import ddf.minim.spi.*;
Minim minim;
AudioOutput out;
AudioSample sample1;
AudioInput in;
AudioRecorder recorder;
boolean recorded;
FilePlayer player;
TickRate rateControl;
void setup()
{
size(512, 200, P3D);
minim = new Minim(this);
in = minim.getLineIn(Minim.STEREO, 512);
recorder = minim.createRecorder(in, "myrecording2.wav");
rateControl = new TickRate(1.f);
out = minim.getLineOut(Minim.STEREO, 512);
player.patch(rateControl).patch(out);
textFont(createFont("Arial", 12));
}
void draw()
{
if ( recorder.isRecording() )
{
fill(255,255,255);
text("Now recording, press the r key to stop recording.", 5, 310);
}
else if ( !recorded )
{
fill(255,255,255);
text("Press the r key to start recording.", 5, 315);
}
else
{
fill(255,255,255);
text("Press the q key to save the recording to disk as a sample.", 5, 315);
}
for(int i = 0; i < out.bufferSize() - 1; i++)
{
float x1 = map(i, 0, out.bufferSize(), 0, width);
float x2 = map(i+1, 0, out.bufferSize(), 0, width);
line(x1, 50 + out.left.get(i)*50, x2, 50 + out.left.get(i+1)*50);
line(x1, 150 + out.right.get(i)*50, x2, 150 + out.right.get(i+1)*50);
}
}
void keyReleased()
{
if ( !recorded && key == 'r' )
{
if ( recorder.isRecording() )
{
recorder.endRecord();
recorded = true;
}
else
{
recorder.beginRecord();
}
}
if ( recorded && key == 'q' )
{
player = new FilePlayer( recorder.save() );
sample1 = minim.loadSample( "myrecording.wav" , 512 );
if ( sample1 == null ) println("didn't get sample");
}
}
void keyPressed()
{
if ( key == 's' )
{
sample1.trigger();
}
else if ( key == 'd' )
{
rateControl.value.setLastValue(3.0f);
sample1.trigger();
}
}
您只能在keyReleased()
函數中將player
設置為等於某個值。 因此,運行setup()
時, player
仍具有默認的null
值。
退后一步,您應該養成調試代碼的習慣。 當您收到NullPointerException
,請嘗試打印出該行上每個變量的值。 您會發現哪個為null
,然后可以找出原因。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.