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 › Sonia & Dynamic Sample Size
Page Index Toggle Pages: 1
Sonia & Dynamic Sample Size (Read 940 times)
Sonia & Dynamic Sample Size
Jul 30th, 2005, 9:31pm
 
Hello,

don´t know anyone discuss about this before..

is there any way to generate a sampleobject with a dynamic size?
normally, i have to intialize a sample object like this:
sample [sampleNum] = new Sample(44100*SampleTime);

i look for a way to do something like:
record a sample as long as the mousebutton is pressed - without a pre-defined sampletime (otherwise i have somtimes soundobjects with a few seconds of silence, if the recorded sound is shorter than the pre-defined sampletime)

thanks & excuse my corrupt english...
Re: Sonia & Dynamic Sample Size
Reply #1 - Jul 30th, 2005, 11:18pm
 

I'd be interested in this too!
Re: Sonia & Dynamic Sample Size
Reply #2 - Jan 31st, 2006, 1:21am
 
I'd like to bump this topic.
Re: Sonia & Dynamic Sample Size
Reply #3 - Nov 1st, 2006, 5:46am
 
this is a little (ugly) that hack should work, though im sure theres a nicer way:

Sample bufferSample;
public void mousePressed()
{
   int maxSampleLength = 10; // 10 seconds max
   bufferSample = new Sample(44100 * maxSampleLength);  
   LiveInput.startRec(bufferSample);
}

public void mouseReleased()
{
   LiveInput.stopRec(bufferSample);
   float[] frames = new float[bufferSample.getNumFrames()];  
   bufferSample.read(frames);
   int endframe = bufferSample.getNumFrames();    
   int zeroCounter = 0;  
   for (int i = 0; i < frames.length; i++) {
     if (frames[i]==0)
       zeroCounter++;
     else
       zeroCounter = 0;
     if (zeroCounter == 100)
       endframe = i;
   }
   println("sample length: "+endframe/44100f);    

   float[] data = new float[endframe];
   System.arraycopy(frames, 0, data, 0, endframe);

   Sample newSample = new Sample(data.length);
   newSample.write(data);
   newSample.play();
}

cheers,
daniel
Page Index Toggle Pages: 1