Currently I'm learning Processing using the Sparkfun Guide to Processing. Great book so far! But now I'm stuck with a tutorial in chapter 11: recording audio using the Minim library.
Using the code below, as explained in the book, I get a Null Pointer Exception when trying to record a sample by pressing left or right. I would love to know what's wrong here. I'm having trouble working it out. I'm sure it's something totally simple, but I just can't see it. There is some sample code to download for this chapter, but this particular sketch is not included.
Thanks for your help!
Here's the null pointer code (edited to include some lines that I did not include prior as they didn't seem to be causing the sketch to crash):
==== JavaSound Minim Error ====
==== Error obtaining new output stream:/Users/*edited full path*/soundboard/data/right.wav (No such file or directory)
==== JavaSound Minim Error ====
==== Error obtaining new output stream: /Users/*edited full path*/soundboard/data/left.wav (No such file or directory)
java.lang.NullPointerException
at ddf.minim.javasound.JSStreamingSampleRecorder.samples(JSStreamingSampleRecorder.java:177)
at ddf.minim.SignalSplitter.samples(SignalSplitter.java:112)
at ddf.minim.javasound.JSAudioOutput.run(JSAudioOutput.java:84)
And here's the code I'm using for the sketch:
import ddf.minim.*;
Minim minim;
AudioInput mic;
AudioRecorder left;
AudioRecorder right;
AudioSample Pright;
AudioSample Pleft;
void setup(){
size(800,900);
minim = new Minim(this);
mic = minim.getLineIn();
right = minim.createRecorder(mic,"data/right.wav");
left = minim.createRecorder(mic, "data/left.wav");
};
void draw(){
};
void keyPressed(){
//begin left record
if(keyCode == LEFT){
if(left.isRecording()){
left.endRecord();
left.save();
}
else{
left.beginRecord();
};
};
//begin right record
if(keyCode == RIGHT){
if(right.isRecording()){
right.endRecord();
right.save();
}
else{
right.beginRecord();
};
};
//play the right sample
if(keyCode == UP){
Pright = minim.loadSample("right.wav");
Pright.trigger();
};
//play the left sample
if(keyCode == DOWN){
Pleft = minim.loadSample("left.wav");
Pleft.trigger();
};
};