Question

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?

Was it helpful?

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

OTHER TIPS

This is the approach to record from an audio file into an AudioRecorder object. You load a file, play it and then you choose what section to save into another file that you can play using and AudioPlayer object or your favorite sound player offered by your OS.

Related to

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

Despite it says it is an error, it doesn't affect executing your program. I would consider this a warning and ignore it. If you want to fix it, I believe you will need to edit the file's tags to properly set their values.

INSTRUCTIONS: In the code, define your file to play. When you run the sketch, press r to begin recording, r again to stop recording. Don't forget to press s to save the file to an audio file which will be located in the data folder.

NOTE: If you need to play wav files, you will need a Sampler object instead of a FilePlayer one.

//REFERENCE: https:// forum.processing.org/one/topic/how-can-i-detect-sound-with-my-mic-in-my-computer.html
//REFERENCE: https:// forum.processing.org/two/discussion/21842/is-it-possible-to-perform-fft-with-fileplayer-object-minim

/**
 * This sketch demonstrates how to use an <code>AudioRecorder</code> to record audio to disk. 
 * Press 'r' to toggle recording on and off and the press 's' to save to disk. 
 * The recorded file will be placed in the sketch folder of the sketch.
 * <p>
 * For more information about Minim and additional features, 
 * visit <a href="<a href="http://code.compartmental.net/minim/" target="_blank" rel="nofollow">http://code.compartmental.net/minim/</a>" target="_blank" rel="nofollow"><a href="http://code.compartmental.net/minim/</a>" target="_blank" rel="nofollow">http://code.compartmental.net/minim/</a></a>;
 */

import ddf.minim.*;
import ddf.minim.ugens.*;
import ddf.minim.analysis.*;

Minim         minim;
FilePlayer player;
AudioOutput out;
AudioRecorder recorder;

void setup()
{
  size(512, 200, P3D);
  textFont(createFont("Arial", 12));

  minim = new Minim(this);  
  player = new FilePlayer(minim.loadFileStream("energeticDJ.mp3"));
  // IT DOESN'T WORK FOR WAV files  ====> player = new FilePlayer(minim.loadFileStream("fair1939.wav"));
  out = minim.getLineOut();
  TickRate rateControl = new TickRate(1.f);
  player.patch(rateControl).patch(out);
  recorder = minim.createRecorder(out, dataPath("myrecording.wav"),true);

  player.loop(0);

}

void draw()
{
  background(0); 
  stroke(255);

  // draw a line to show where in the song playback is currently located
  float posx = map(player.position(), 0, player.length(), 0, width);
  stroke(0, 200, 0);
  line(posx, 0, posx, height);



  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
    {
      recorder.beginRecord();
    }
  }
  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
    recorder.save();
    println("Done saving.");
  }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top