Sound recorder: prevent from adding new record to the end of the previous
in
Core Library Questions
•
1 year ago
Hi there. I am making a sound recorder with processing, and have a problem with the recorder that adds new recording to the end of my main recorder file ("rec.wav"). I can copy it to a new file, but I need to find a way to start every time a new recording from scratch when 'r' is pressed. I looked at the library but couldn't find any solution. Anyone knows how to reset the bytes?
here's my code:
//minim
import ddf.minim.*;
//declare
Minim minim;
AudioInput in;
AudioRecorder recorder;
byte b[];
void setup()
{
size(512, 200);
}
minim = new Minim(this);
in = minim.getLineIn(Minim.STEREO, 512);
recorder = minim.createRecorder(in, "rec.wav", true);
textFont(createFont("Arial", 12));
}
void draw()
{
background(0);
stroke(255);
for (int i = 0; i < in.left.size()-1; i++)
{
line(i, 50 + in.left.get(i)*50, i+1, 50 + in.left.get(i+1)*50);
line(i, 150 + in.right.get(i)*50, i+1, 150 + in.right.get(i+1)*50);
}
if ( recorder.isRecording() )
{
text("Currently recording...", 5, 15);
}
else
{
text("Not recording.", 5, 15);
}
if (key=='s')
// text("Button"+x+".", 40, 40);
recorder.save();
b = loadBytes("rec.wav");
saveBytes("conv.wav",b);
//println("Done saving "+x+" pin");
}
void keyReleased()
{
if (key=='r')
{
if ( recorder.isRecording() )
{
recorder.endRecord();
}
else
{
recorder.beginRecord();
}
}
}
void stop()
{
// always close Minim audio classes when you are done with them
in.close();
// always stop Minim before exiting
minim.stop();
super.stop();
}
1