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 › Rec/save/play multiple samples
Page Index Toggle Pages: 1
Rec/save/play multiple samples (Read 1137 times)
Rec/save/play multiple samples
May 14th, 2007, 12:26pm
 
Hi

I'm trying to build kind of an answering machine using buttons to rec., stop and play samples.
I can get it to do it with one sample but i would like to save more than one sample to play. (So I can listen to more than one recording)

This is the code i've written: (i use processing 090)

import pitaru.sonia_v2_9.*;

Sample mySampleObj;

void setup(){
 size(400,200);
 background(0,50,0);
 Sonia.start(this);
 LiveInput.start();
 int recTimeSec = 10;
 mySampleObj = new Sample(44100*recTimeSec);
}

void draw(){
 
}

void keyPressed(){
 if(key == 'r'){
   LiveInput.startRec(mySampleObj);
   print("REC");
 }
 
    if(key == 's'){
       LiveInput.stopRec(mySampleObj);
       print("STOP");  
 }

   if(key == 'p'){
   mySampleObj.play();
   print("PLAY");
 }
}

public void stop(){
 Sonia.stop();
 super.stop();
}


I have an idea on how to solve it but i'm not sure how to do it.
I was thinking to make a variable that counts up as I record new samples and then starts over and counts up again when reached a certain number of samples.

kind of a list with sample1, sample2, sample3...

Can anyone help me?

thanx for your time..

//Mads Köser
Re: Rec/save/play multiple samples
Reply #1 - May 14th, 2007, 3:36pm
 
Yup, that's the ticket. You'll need more than one Sample object and you'll need to keep track of which you will record to next. Shouldn't be too tricky.
Re: Rec/save/play multiple samples
Reply #2 - May 15th, 2007, 12:11am
 
Should it then be:
Sample mySampleObj;
Sample mySampleObj1;
Sample mySampleObj2;

void setup(){  
 size(400,200);
 background(0,50,0);
 Sonia.start(this);  
 LiveInput.start();  
 int recTimeSec = 10;  
 mySampleObj = new Sample(44100*recTimeSec);
 mySampleObj1 = new Sample(44100*recTimeSec);
 mySampleObj2 = new Sample(44100*recTimeSec);  
}  

or how should i call them. I'm new to this so i'm not so sure in how to do these things..

//Mads Köser
Re: Rec/save/play multiple samples
Reply #3 - May 15th, 2007, 12:40am
 
You can call them whatever you like, it's your code. But you might consider using an array of Samples instead of a bunch of different variables. So, like:

Code:

Sample[] mySamples = new Sample[3];

void setup(){
size(400,200);
background(0,50,0);
Sonia.start(this);
LiveInput.start();
int recTimeSec = 10;
for ( int i = 0; i < mySamples.length; i++)
{
mySamples[i] = new Sample(44100*recTimeSec);
}
}


Now you could change the number of samples you have just by changing the number in the array allocation.
Re: Rec/save/play multiple samples
Reply #4 - May 15th, 2007, 11:12am
 
I'll try it out and write again - i think i can get it working. Thanx for the help so far..
Re: Rec/save/play multiple samples
Reply #5 - May 15th, 2007, 1:34pm
 
This is my code now but it gives me the error:

"Perhaps you wanted the overoaded version "void startRec(pitaru.sonia_v2_9.Sampe $1);" instead?"

What did I do wrong?

CODE:
import pitaru.sonia_v2_9.*;

Sample[] mySamples = new Sample[3];
 
void setup(){  
 size(400,200);  
 background(0,50,0);  
 Sonia.start(this);  
 LiveInput.start();  
 int recTimeSec = 10;
 for ( int i = 0; i < mySamples.length; i++)
 {
   mySamples[i] = new Sample(44100*recTimeSec);
 }
}    

void draw(){
 
}

void keyPressed(){
 if(key == 'r'){
   LiveInput.startRec(mySamples);
   print("REC");
 }
 
    if(key == 's'){
       LiveInput.stopRec(mySamples);
       print("STOP");  
 }

   if(key == 'p'){
   mySample.play();
   print("PLAY");
 }
}

public void stop(){
 Sonia.stop();
 super.stop();
}

Thanx for your quick responses
Re: Rec/save/play multiple samples
Reply #6 - May 15th, 2007, 2:01pm
 
you've defined mySamples as an array, so you need to give an index, something like:

LiveInput.startRec(mySamples[0]);

F
Re: Rec/save/play multiple samples
Reply #7 - May 15th, 2007, 2:06pm
 
looking at your code you need some way to set / keep track of which item in the array you want to use or is active.

int myCurrentSample = 0;

LiveInput.startRec(mySamples[myCurrentSample]);

now, since you probably don't want to record over the last sample, updated it inside keypressed:

if(key == 'r'){
   myCurrentSample ++;
   if ( myCurrentSample >= mySamples.length ) {
       println("no more sample slots available");
       return;
  }
   LiveInput.startRec(mySamples);
   print("REC");
 }
Re: Rec/save/play multiple samples
Reply #8 - May 16th, 2007, 10:59am
 
So it kind of works now.. It counts the samples and start over - but it seems like i can't play the samples - or theres no sound when i do so. What could be the problem?

CODE:
import pitaru.sonia_v2_9.*;

Sample[] mySamples = new Sample[5];
int myCurrentSample = 0;



void setup(){  
 size(400,200);  
 background(0,50,0);  
 Sonia.start(this);  
 LiveInput.start();  
 int recTimeSec = 10;
 for ( int i = 0; i < mySamples.length; i++)
 {
   mySamples[i] = new Sample(44100*recTimeSec);
 }
}    

void draw(){

}

void keyPressed(){

 if(key == 'r'){  
   myCurrentSample ++;
   if ( myCurrentSample >= mySamples.length ) {
     println("no more sample slots available");
     myCurrentSample = 0;
     //return;
   }
   LiveInput.startRec(mySamples[myCurrentSample]);  
   print("REC");  
 }
 if(key == 's'){  
   LiveInput.stopRec(mySamples[myCurrentSample]);  
   print("STOP");  
 }
 if(key == 'p'){  
   mySamples[myCurrentSample].play();  
   print("PLAY");  
 }
 print(myCurrentSample);
}

public void stop(){
 Sonia.stop();
 super.stop();
}



Thanx ones again
//Mads Köser
Page Index Toggle Pages: 1