Zemen
YaBB Newbies
Offline
Posts: 17
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