We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › add timer or delay into my recorder
Page Index Toggle Pages: 1
add timer or delay into my recorder (Read 1726 times)
add timer or delay into my recorder
May 13th, 2010, 7:39pm
 
i hope it will be easy for you guys, i have a sound recorder now, press "r" to record, press "f" to end record, and press "s" to save the file.
I want to change to press "r" to start record, then after 10seconds will end record, and than save. how?

below is my coding now:
import ddf.minim.*;



Minim minim;
AudioInput in;
AudioRecorder recorder;

/*##########################*/
int countname; //change the name
int name = 000000; //set the number in key's' function

// change the file name
void newFile()
{      
 countname =( name + 1);
 //recorder = minim.createRecorder(in, "file/A08May" + countname + ".wav", true);
 recorder = minim.createRecorder(in, countname + ".wav", true);
 // println("file/" + countname + ".wav");
}
/*###############################*/


void setup()
{
 size(512, 200, P2D);
 textMode(SCREEN);
 
 minim = new Minim(this);

 // get a stereo line-in: sample buffer length of 2048
 // default sample rate is 44100, default bit depth is 16
 in = minim.getLineIn(Minim.STEREO, 2048);
 // create a recorder that  will record from the input to the filename specified, using buffered recording
 // buffered recording means that all captured audio will be written into a sample buffer
 // then when save() is called, the contents of the buffer will actually be written to a file
 // the file will be located in the sketch's root folder.
 
 newFile();//go to change file name
 textFont(createFont("SanSerif", 12));
}

void draw()
{
 background(0);
 stroke(255);
 // draw the waveforms
 // the values returned by left.get() and right.get() will be between -1 and 1,
 // so we need to scale them up to see the waveform
 for(int i = 0; i < in.bufferSize() - 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);
 }
}

void keyReleased()
{
 if ( key == 'r' )
 {
   // to indicate that you want to start or stop capturing audio data, you must call
   // beginRecord() and endRecord() on the AudioRecorder object. You can start and stop
   // as many times as you like, the audio data will be appended to the end of the buffer
   // (in the case of buffered recording) or to the end of the file (in the case of streamed recording).
   if ( recorder.isRecording() )
   {
     recorder.endRecord();
   }
   else
   {
     /*#######################################*/
     newFile();
     /*#######################################*/
     recorder.beginRecord();
   }
 }
 if (key == 'f'){
   recorder.endRecord();
   
 }
 if ( key == 's' )
 {
   // we've filled the file out buffer,
   // now write it to the file we specified in createRecorder
   // in the case of buffered recording, if the buffer is large,
   // this will appear to freeze the sketch for sometime
   // in the case of streamed recording,
   // it will not freeze as the data is already in the file and all that is being done
   // is closing the file.
   // the method returns the recorded audio as an AudioRecording,
   // see the example  AudioRecorder >> RecordAndPlayback for more about that
   
   name++; //change the file name, everytime +1
   recorder.save();
   println("Done saving.");
   println(name);//check the name
 }
}

void stop()
{
 // always close Minim audio classes when you are done with them
 in.close();
 minim.stop();
 
 super.stop();
}


Thanks
Re: add timer or delay into my recorder
Reply #1 - May 13th, 2010, 11:22pm
 
Use the millis() function to check than 10,000ms has been spend since start of recording: store the current value at start, check diff of current value and start value against wanted time.
Plenty of examples in the forum.
Re: add timer or delay into my recorder
Reply #2 - May 13th, 2010, 11:26pm
 
yah, i find this:
http://processing.org/discourse/yabb2/num_1265681408.html#4

but i dont understand :
When you have established this class you can create an instance of the class Timer:

     Timer timer;

and it give me error Sad
Re: add timer or delay into my recorder
Reply #3 - May 13th, 2010, 11:41pm
 
The code of the Timer class is given in that thread...
Re: add timer or delay into my recorder
Reply #4 - May 13th, 2010, 11:58pm
 
sorry for im just a beginer
it just give make a class, never apply to other code, dont know how to apply it
Re: add timer or delay into my recorder
Reply #5 - May 14th, 2010, 12:34am
 
Well, I gave there a quite extensive answer with example code just one hour or two ago...
Re: add timer or delay into my recorder
Reply #6 - May 17th, 2010, 9:20pm
 
finally add the timer, and connect to flash also, below is my code, hope it will be help:

[color=#0000ff]//this is for connection to flash
/**
* oscP5sendreceive by andreas schlegel
* example shows how to send and receive osc messages.
* oscP5 website at http://www.sojamo.de/oscP5
*/

import oscP5.*;
import netP5.*;
 
OscP5 oscP5;
NetAddress myRemoteLocation;






//this is for my recorder coding
import ddf.minim.*;

Minim minim;
AudioInput in;
AudioRecorder recorder;

/*##########################*/
int countname; //change the name
int name = 0; //set the number in key's' function

boolean finishedrec=false;
boolean pressed=false;
//about timer
class Timer{
 int savedTime; //when timer started
 int totalTime; // how long timer should last
 boolean finished;
 Timer (int tempTotalTime){
   totalTime = tempTotalTime;
   finished=false;
 }
 
 //Starting the timer
 void start(){
   if(  finishedrec==false)
   savedTime = millis(); //when the timer starts it stores the current time in milliseconds
 }
 void reset()
 {
    savedTime=0;
 }
 
 boolean isFinished(){
   //Check how much time has passed
   int passedTime = millis() - savedTime;
   if(passedTime > totalTime){
     finished=true;

     return true;
   }else{
       finished=false;
     return false;
   }
 }
}





// change the file name
void newFile()
{      
 countname =( name + 1);
 //recorder = minim.createRecorder(in, "file/A08May" + countname + ".wav", true);
 recorder = minim.createRecorder(in, "file/" + countname + ".wav", true);
 // println("file/" + countname + ".wav");
}
/*###############################*/

Timer timer;
void setup()
{
 size(512, 200, P2D);
 textMode(SCREEN);
 timer= new Timer(10000);
 minim = new Minim(this);

 // get a stereo line-in: sample buffer length of 2048
 // default sample rate is 44100, default bit depth is 16
 in = minim.getLineIn(Minim.STEREO, 2048);
 // create a recorder that  will record from the input to the filename specified, using buffered recording
 // buffered recording means that all captured audio will be written into a sample buffer
 // then when save() is called, the contents of the buffer will actually be written to a file
 // the file will be located in the sketch's root folder.
 
 newFile();//go to change file name
 textFont(createFont("SanSerif", 12));
 
 //start oscP5, listening for incoming messages at port 12000
 oscP5 = new OscP5(this,12000);
 /* myRemoteLocation is a NetAddress. a NetAddress takes 2 parameters,
  * an ip address and a port number. myRemoteLocation is used as parameter in
  * oscP5.send() when sending osc packets to another computer, device,
  * application. usage see below. for testing purposes the listening port
  * and the port of the remote location address are the same, hence you will
  * send messages back to this sketch.
  */
 myRemoteLocation = new NetAddress("127.0.0.1",12000);
}

void draw()
{
 
 background(0);
 stroke(255);
 // draw the waveforms
 // the values returned by left.get() and right.get() will be between -1 and 1,
 // so we need to scale them up to see the waveform
 for(int i = 0; i < in.bufferSize() - 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(pressed==false)
  {
      timer.start();
  }

  if(timer.isFinished())
  {
    finishedrec=true;
    pressed=false;
   
  }

   if(finishedrec==true)
   {
        //println("timer ended.");
       recorder.endRecord();
       timer.reset();
       name++; //change the file name, everytime +1
       recorder.save();
       println("Done saving.");
       println(name);//check the name
       finishedrec=false;
   }
 if ( recorder.isRecording() )
 {
   text("Currently recording...", 5, 15);
 }
 else
 {
   text("Not recording.", 5, 15);
 }
}
//class Timer: Timer timer;

void keyReleased()
{
 if ( key == 'r' )
 {
   // to indicate that you want to start or stop capturing audio data, you must call
   // beginRecord() and endRecord() on the AudioRecorder object. You can start and stop
   // as many times as you like, the audio data will be appended to the end of the buffer
   // (in the case of buffered recording) or to the end of the file (in the case of streamed recording).
   /*if ( recorder.isRecording() )
   {
     recorder.endRecord();
   }
   else
   {
     //#######################################
     newFile();
     //#######################################
     recorder.beginRecord();
   }*/
    //#######################################
     newFile();
     //#######################################
     recorder.beginRecord();
   
     //timer
     pressed=true;
 }
/* if (key == 'f'){
   //end record
   recorder.endRecord();
   
   //save
   name++; //change the file name, everytime +1
   recorder.save();
   println("Done saving.");
   println(name);//check the name
   
 }*/

 /*if ( key == 's' )
 {
   // we've filled the file out buffer,
   // now write it to the file we specified in createRecorder
   // in the case of buffered recording, if the buffer is large,
   // this will appear to freeze the sketch for sometime
   // in the case of streamed recording,
   // it will not freeze as the data is already in the file and all that is being done
   // is closing the file.
   // the method returns the recorded audio as an AudioRecording,
   // see the example  AudioRecorder >> RecordAndPlayback for more about that
   
   name++; //change the file name, everytime +1
   recorder.save();
   println("Done saving.");
   println(name);//check the name
 }*/
}

void stop()
{
 // always close Minim audio classes when you are done with them
 in.close();
 minim.stop();
 
 super.stop();
}

// incoming osc message are forwarded to the oscEvent method.
void oscEvent(OscMessage theOscMessage) {
 //print the address patte
Page Index Toggle Pages: 1