FAQ
Cover
This is the archive Discourse for the Processing (ALPHA) software.
Please visit the new Processing forum for current information.

   Processing 1.0 _ALPHA_
   Topics & Contributions
   Sound
(Moderators: pitaru, REAS)
   Sonia - playing it backwards
« Previous topic | Next topic »

Pages: 1 
   Author  Topic: Sonia - playing it backwards  (Read 403 times)
md


Sonia - playing it backwards
« on: May 17th, 2004, 5:32pm »

I'm trying to play a sample backwards.
What am I missing here?
 
code:
--------------------------------------
 
Sample mySample;
float[] sampleData;
int streamSize;
 
void setup(){
  size(200, 200);
  Sonia.start(this);
   
  mySample = new Sample("test.aif");
  streamSize = mySample.getNumFrames();
  sampleData = new float[streamSize];
  mySample.read(sampleData);
   
  LiveOutput.start(streamSize,streamSize*2);  
  LiveOutput.startStream();  
}
 
void loop(){
}
 
void liveOutputEvent(){
    for(int i=LiveOutput.data.length;i>0;i--) {
 LiveOutput.data[i] = sampleData[i];
    }
}
 
public void stop(){  
  Sonia.stop();  
  super.stop();
}
 
mattgilbert

tangramkid WWW Email
Re: Sonia - playing it backwards
« Reply #1 on: May 17th, 2004, 8:31pm »

The problem is with your liveOutputEvent block. I see that you're trying to update the data backwards, but what you have doesn't do that.  
 
Code:

void liveOutputEvent(){
    for(int i=LiveOutput.data.length;i>0;i--) {
 LiveOutput.data[i] = sampleData[i];
    }
}  

does almost exactly the same thing as
Code:

void liveOutputEvent(){
    for(int i=0;i<LiveOutput.data.length;i++) {
 LiveOutput.data[i] = sampleData[i];
    }
}  

to reverse the order of the floats in LiveOutput.data, you need something like:
Code:

void liveOutputEvent(){
    for(int i=0;i<LiveOutput.data.length;i++) {
 LiveOutput.data[i] = sampleData[sampleData.length-1-i];
    }
}  

the difference being that I'm pulling the floats from sampleData[] starting at the end with the sampleData[sampleData.length-1-i] part. At the beginning of the update, when i=0, this takes the last element in the sampleData[] (element sampleData.length-1, since the elements are numbered starting at zero), and puts it in the first element of LiveOutput.data[]. Then it works forwards on LiveOutput.data[] and backwards on sampleData, reversing the order of the data.
 
Did I explain that ok?
 
Matt
 
 
 
 
md


Re: Sonia - playing it backwards
« Reply #2 on: May 17th, 2004, 9:17pm »

Off course! I gues I spend too mutch time inside.
Your answer was great! Thanks for your time 'and your understanding '
 
-m
 
mattgilbert

tangramkid WWW Email
Re: Sonia - playing it backwards
« Reply #3 on: May 19th, 2004, 7:13am »

right on.
 
Pages: 1 

« Previous topic | Next topic »