Hi,
Here's what I ended up writing.
Here's what I ended up writing.
- import ddf.minim.*;
import ddf.minim.analysis.*;
Minim minim;
AudioInput audioIn;
AudioRecorder recorder;
BeatDetect beat;
int savedTime;
int silenceTime = 5000;
void setup()
{
size(512, 200);
background(0);
int bufferSize = 4096;
float sampleRate = 44100;
minim = new Minim(this);
audioIn = minim.getLineIn(Minim.STEREO, bufferSize, sampleRate);
recorder = minim.createRecorder(audioIn, "myrecording.wav", true);
beat = new BeatDetect(bufferSize, sampleRate);
beat.setSensitivity(200); //in milliseconds
beat.detectMode(BeatDetect.SOUND_ENERGY);
}
void draw()
{
beat.detect(audioIn.mix);
if (beat.isOnset()){
println( "Beat detected..." );
if ( recorder.isRecording() == false ){
recorder.beginRecord();
println( "Recording started" );
}
savedTime = millis(); //reset counter to now
}
else {
int passedTime = millis() - savedTime;
println( passedTime );
if (passedTime > silenceTime) {
println( "5 seconds have passed" );
savedTime = millis(); // Save the current time to restart the timer!
recorder.endRecord();
println( "Stop recording" );
recorder.save();
println("Done saving");
exit();
}
}
}