audioprocessingrecordminim

minim loadFile before audio file is recorded/created


I am trying to create an app that would allow the user some sounds and then use this in a playback fashion.

I would like to have my application play a .wav file that the user will record.

I am having trouble figuring out how to code this, as I keep getting a error.

    ==== JavaSound Minim Error ====
    ==== Error invoking createInput on the file loader object: null

Snippet of code:

   import ddf.minim.*;

   AudioInput in;
   AudioRecorder recorder;

   RadioButtons r;
   boolean showGUI = false;
   color bgCol = color(0);

   Minim minim;

   //Recording players
   AudioPlayer player1; 
   AudioPlayer player2;

   void newFile()
   {
      countname =(name+1);
      recorder = minim.createRecorder(in, "data/" + countname + ".wav", true);
   }
   ......

   void setup(){

       minim = new Minim(this);
       in = minim.getLineIn(Minim.MONO, 2048);
       newFile();
       player1 = minim.loadFile("data/" + countname + ".wav");// recording #1
       player2 = minim.loadFile("data/" + countname + ".wav");//recording #2


   void draw() {
   // Draw the image to the screen at coordinate (0,0)
       image(img,0,0);

       //recording button
       if(r.get() == 0)
       {
            for(int i = 0; i < in.left.size()-1; i++)
       }

            if ( recorder.isRecording() )
        {
            text("Currently recording...", 5, 15);
             }
            else
        {
            text("Not recording.", 5, 15);
          }
         }
     //play button
     if(r.get() == 1)
     {
     if(mousePressed){
     .......
     player_1.cue(0);
     player_1.play();
     }
     if(mousePressed){
     .......
     player_2.cue(0);
     player_2.play();
     }
     } 

The place where I have a problem is here:

       player1 = minim.loadFile("data/" + countname + ".wav");// recording #1
       player2 = minim.loadFile("data/" + countname + ".wav");//recording #2

The files that will be recorded will be 1.wav, 2.wav. But I can not place this in the

       player1.minim.loadFile ("1.wav");
       player2.mminim.loadFile("2.wav");

How would I do this?


Solution

  • As indicated in the JavaDoc page for AudioRecorder [1], calls to beginRecord(), endRecord() and save() will need to happen so that whatever you want to record is actually recorded and then also saved to disk. As long as that does not happen there is nothing for loadFile() to load and you will therefore receive errors. So the problem lies in your program flow. Only when your program reaches a state where a file has already been recorded and saved, you can actually load that.

    There are probably also ways for you to play back whatever is being recorded right at the moment it arrives in your audio input buffer (one would usually refer to such as 'monitoring'), but as i understand it, that is not what you want.

    Aside this general conceptual flaw there also seem to be other problems in your code, e.g. countname is not being iterated between two subsequent loadFile calls (I assume that it should be iterated though); Also at some point you have "player_1.play();" (note the underscore), although you're probably refering to this, differently written variable earlier initialized with "player1 = minim.loadFile(...)" ? ...

    [1] http://code.compartmental.net/minim/javadoc/ddf/minim/AudioRecorder.html