Audio recording and OscEvent

edited November 2013 in Library Questions

Dear, I am trying to built an audio-recording program which is activated from a remote location. If this is the command line to start the program from keyboard how can I change it using OscEvent?

void keyReleased()
{
 if ( key == 'r' )
 {
     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
 }
}

Answers

  • I have tried a solution but but it ends up giving me an error and I can't seem to figure out why...

    here is the code:

    ////// AUDIO RECORDER ////////
    ////// AUDIO RECORDER ////////
    ////// AUDIO RECORDER ////////
    
    import oscP5.*;
    import netP5.*;
    import ddf.minim.*;
    OscP5 oscP5rec1;
    NetAddress myMaster;
    
    Minim minim;
    AudioInput in;
    AudioRecorder recorder;
    
    /*##########################*/
    int countname; //change the name
    int name = 0; //set the number in key's' function
    int turn;
    
    
    void setup()
    {
     size(512, 200, P2D);
     textMode(SCREEN);
     minim = new Minim(this);
     oscP5rec1 = new OscP5(this,11000); 
     myMaster = new NetAddress("127.0.0.1",8000);
    
     newFile();//go to change file name
     textFont(createFont("SanSerif", 12));
     }
    
    
     void draw()
    {
     background(0);
     stroke(255);
     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 stop()
    {
     in.close();
     minim.stop();
    
     super.stop();
    }
    
    //////FUNCTIONS////////
    //////FUNCTIONS////////
    //////FUNCTIONS////////
    
    void newFile()
    {    
    if (turn == 1){   
     countname =( name + 1);
     recorder = minim.createRecorder(in, "file/" + countname + ".wav", true);
     recorder.beginRecord();
    }
    if (turn == 2){  
      recorder.endRecord();
      name++; //change the file name, everytime +1
      recorder.save();
      println("Done saving.");
      println(name);//check the name
    
    
     countname =( name + 1);
     recorder = minim.createRecorder(in, "file/" + countname + ".wav", true);
     recorder.beginRecord();
    }
    }
    
    //////MESSAGES////////
    //////MESSAGES////////
    //////MESSAGES////////
    
    void oscEvent(OscMessage theOscMessage1) {
      String w = theOscMessage1.addrPattern();
      if (w.equals("/init1")) { 
        String dataIn3=""+ theOscMessage1.arguments()[2]; 
        turn=int(dataIn3);    
         };  
    
        if (w.equals("/next1")) {
        String dataIn3=""+ theOscMessage1.arguments()[2];
        turn=int(dataIn3);     
        }
    
      };
    
  • "it ends up giving me an error and I can't seem to figure out why..."
    Neither us, since we cannot see the error message...

    Side note:
    String dataIn3=""+ theOscMessage1.arguments()[2];
    in Processing, this can be written:
    String dataIn3 = str(theOscMessage1.arguments()[2]);

  • I am sorry for not being enough clear. It is one of my first experience with processing. I am trying to have an audio recording program controlled by the OscEvent. In this way any turn of a parallel experiment can have its own registration.

    Now I have solved the problem that I had with the messaging format

    int turn = theOscMessage1.get(0).intValue();

    But I don't have a clear how to let the program reevaluate the newFile() and startAgain() any time the message "turn" is received. I tried to change the code in the following way, is it very stupid my error?

    void setup()
    {
     size(512, 200, P2D);
     textMode(SCREEN);
     minim = new Minim(this);
     oscP5rec1 = new OscP5(this,11000);
     myMaster = new NetAddress("127.0.0.1",8000);
     in = minim.getLineIn(Minim.STEREO, 2048);
     newFile();   //CREATE THE FIRST FILE
     recorder.beginRecord();  // START THE RECORDING
     textFont(createFont("SanSerif", 12));
     startAgain();  // STOP THE PREVIOUS RECORDING AND START A NEW ONE EACH TIME YOU RECEIVE A NEW MESSAGE "TURN"
     }
    
    
     void draw()
    {
     background(0);
     stroke(255);
    
    }
    
    
    void stop()
    {
     in.close();
     minim.stop();
     super.stop();
    }
    
    //////FUNCTIONS////////
    //////FUNCTIONS////////
    //////FUNCTIONS////////
    
    void newFile()
    { 
     countname =( name + 1);
     recorder = minim.createRecorder(in, "file/" + countname + ".wav", true);
    }
    
    void startAgain(){
    if (turn==2){     // ALL THE TURN DIFFERENT FROM THE FIRST ONE
      recorder.endRecord();
      name++; //change the file name, everytime +1
      recorder.save();
      println("Done saving.");
      println(name);//check the name
    
     countname =( name + 1);
     recorder = minim.createRecorder(in, "file/" + countname + ".wav", true);
     recorder.beginRecord();
    }
    }
    
    //////MESSAGES////////
    //////MESSAGES////////
    //////MESSAGES////////
    
    void oscEvent(OscMessage theOscMessage1) {
      String w = theOscMessage1.addrPattern();
      if (w.equals("/init1")) {
         int turn = theOscMessage1.get(0).intValue();  // TURN VALUE ==1
           print(turn);  
         } 
    
        if (w.equals("/next1")) {
         int turn = theOscMessage1.get(0).intValue(); // TURN VALUE ==2
           print(turn);
    
        }
    
      };
    
  • to be more clear. Each time a task is completed the "master" start this function

        void nextMove(){
          OscMessage next3Message = new OscMessage("/next3");
          next3Message.add(2);    // which will be assigned to variable turn in the previous
          oscP5gmaster.send(next3Message, myClient3);  //myClient3 is the audiorecording 
        }
    
  • Answer ✓

    hi, I cannot resolve your problem but inside your code from the 6 nov. I can see some errors : line 63 & line 67 : you create two time the turn local variable : instead create one global variable (upper void setup() ) - like this you could test it inside void draw() for example.

    then still in the same code, your personnal function void newFile() & void startAgain() will only start one time because you invoke them only at void setup().

    if you'd like to start some function depending the value of turn, you have to compare it inside void draw() (which is read in loop while the sketch is on).

    here an example : two functions are started depending the variable turn, which can be change with OSC message.

    import oscP5.*;
    OscP5 oscP5;
    
    int turn  ; 
    
    void setup() {
      size(400, 400);
      frameRate(30);
      oscP5  =new OscP5(this, 12000);
      myFunctionNewFile();
    }
    
    void draw() {
      if (turn == 1) {
        myFunctionNewFile();
      }
      if ( turn == 2) {
        myFunctionStartAgain();
      }
    }
    
    void myFunctionNewFile() {
      println("initiate");
    }
    void myFunctionStartAgain() {
      println("new recording");
    }
    
    void oscEvent(OscMessage theOscMessage) {
    
      if (theOscMessage.checkAddrPattern("/init")==true) {
        if (theOscMessage.checkTypetag("i")) {
          turn = theOscMessage.get(0).intValue();
        }
      }
    
      if (theOscMessage.checkAddrPattern("/next")==true) {
        if (theOscMessage.checkTypetag("i")) {
          turn = theOscMessage.get(0).intValue();
        }
      }
    }
    

    nb : here the two functions will be read in loop while turn is equal to 1 or 2...

  • edited November 2013

    thanks, I was able to change the code with your hints.

    Now it's working.

    I post the code here:

        import oscP5.*;
        import netP5.*;
        import ddf.minim.*;
        OscP5 oscP5rec1;
        NetAddress myMaster;
    
        Minim minim;
        AudioInput in;
        AudioRecorder recorder;
    
        /*##########################*/
        int countname; //change the name
        int name = 0; //set the number in key's' function
        int turn;
    
        void setup()
        {
         size(512, 200, P2D);
         textMode(SCREEN);
         minim = new Minim(this);
         oscP5rec1 = new OscP5(this,12000); 
         myMaster = new NetAddress("127.0.0.1",8000);
         in = minim.getLineIn(Minim.STEREO, 2048);
         textFont(createFont("SanSerif", 12));
         myFunctionNewFile();
         }
    
    
         void draw()
        {
         background(0);
         stroke(255);
    
           if (turn == 1) {
            myFunctionNewFile();
          }
          if ( turn == 2) {
            myFunctionStartAgain();
          }
    
         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);
         }
    
         text(turn, 5, 35);
    
          if ( recorder.isRecording() )
         {
           text("Currently recording...", 5, 15);
         }
         else
         {
           text("Not recording.", 5, 15);
         }
        }
    void myFunctionNewFile() 
    {  
      countname =( name + 1);
     recorder = minim.createRecorder(in, "file/" + countname + ".wav", true);
     println("file/" + countname + ".wav");  
     if (turn==1){
     recorder.beginRecord();
     turn=0;   
     }
    }
    
    void myFunctionStartAgain() {
       println("new recording");
       recorder.endRecord();
       name++; //change the file name, everytime +1
       recorder.save();
       println("Done saving.");
       println(name);//check the name
       countname =( name + 1);
       recorder = minim.createRecorder(in, "file/" + countname + ".wav", true);
       println("file/" + countname + ".wav");  
       recorder.beginRecord();
       turn=0;
    }
    
Sign In or Register to comment.