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 & HelpSound,  Music Libraries › set position & volume
Page Index Toggle Pages: 1
set position & volume (Read 976 times)
set position & volume
Jul 3rd, 2007, 11:06am
 
Hi there!

I'm new in Processing, so I've got 2 problems to solve:
I work with the new Minim Library, because I want to record and playback sound. Important for my code is, that it works with only two keys, because at the end I want to use a switch (Arduino) to control processing.

The first problem: If I want to record something, but the player is already playing, the player should stop. After the recording the player should play again from the position it stopped before. I don't get it to set a position when the player stops and to let the player play again from this position. What did I wrong?

The second problem: After every loop, the player should set its volume down, I don't know how to do this.

Perhaps someone can help me? Is for my studies and I don't have really much time...

Thank you!!!


Here is the code:


import ddf.minim.*;

AudioInput in;
AudioRecorder recorder;
AudioPlayer player = null;


int pos = 0;

void setup()
{
 size(512, 200);


 Minim.start(this);


 in = Minim.getLineIn(Minim.STEREO, 512);

 recorder = Minim.createRecorder(in, "myrecording.wav", true);


}

void draw()
{
 background(0);
}

void keyPressed()
{

 if ( key == 's' )
 {
   if ( recorder.isRecording() )
   {
     recorder.endRecord();
   }

   AudioRecording recording = recorder.save();
   player = new AudioPlayer(recording);
   //player.loop();
   println(player.length()+" "+ player.position()+" "+pos);
   player.skip((int)pos);
   player.loop();
   println(player.length());
 


   if (recording.length() > 50000){
     recorder = Minim.createRecorder(in, "myrecording.wav", true);
   }
 }
 else if ( key == 'r' )
 {

   if ( recorder.isRecording() )
   {

     //recorder.endRecord();

   }
   //else if (player.isPlaying())
   //{
   if (player != null)
   {
     player.pause();  
     pos = player.position();
     println("pos" + pos);
     println("pause");      
     println(player.length());  
   }
   recorder.beginRecord();


 }
}



void stop()
{

 in.close();
 if ( player != null )
 {
   player.close();
 }
 super.stop();
}

Re: set position & volume
Reply #1 - Jul 7th, 2007, 5:05am
 
I'm not sure I quite understand what you are trying to accomplish. Why do you need to skip to the last position you were playing from when you make a new recording? It is meaningless at that point because you create an entirely new player with the AudioRecording you get back. It's possible that your second recording will be shorter than the position the first recording left off at, which means it will just skip to the end. Also, you should keep in mind that because you are using a single recorder, every time you start recording after having saved, the file will be overwritten. This means that you could run into trouble if it ever happens that you are playing the file at the same time you save to it.

As to your second problem, there is no callback mechanism for when a loop starts over. However, you aren't the first person to mention wanting such a thing so I may put something into the next version to allow for listening on that sort of stuff, similar to the Line events in JavaSound.
Re: set position & volume
Reply #2 - Jul 11th, 2007, 9:25pm
 
Perhaps I don't understand what the problem is, because I'm new in Processing, but I thought it should work:

I want to get the position where the old player stopped, to let the new player begin at this position. The number I will get should always be smaller than the length of the recorded file. Because before I play again from the last position, I continue recording. Finally it should just work like a pause.

The Recorder is the same until the file gets a defined length. After that I make a new Recorder which overwrites the old file.

Sorry for wasting your time, but I don't know it better.
Re: set position & volume
Reply #3 - Jul 19th, 2007, 1:58pm
 
hi
i am writing code in c for recording signal by microfone in linux .if u have any idia then tell me how i do this
Page Index Toggle Pages: 1