// Create an empty STEREO sample, and write sine-wave data from an array into its LEFT channel.
Sample mySample;
float[] data;
void setup() {
size(100,100);
Sonia.start(this);
mySample = new Sample(1024,44100,2); // create an empty STEREO sample, at 44100 sampling rate.
data = new float[1024]; // create an array with the same length of the sample's channel.
// Populate the array with sample data, a sin wave in this case
for(int i = 0; i < 1024; i++){
float oneCycle = TWO_PI/1024;
int freq = 10;
data[i] = sin(i*oneCycle*freq);
}
mySample.writeChannel(Sonia.LEFT, data); // write the data from the 'data' array into the sample's LEFT channel
mySample.repeat(); // Loop the sample - notice that only the left channel is playing the sine wave.
}
public void stop(){
Sonia.stop();
super.stop();
}
|