// Create an empty sample, and write sine-wave data from an array into it.
Sample mySample;
float[] data;
void setup() {
size(100,100);
Sonia.start(this);
mySample = new Sample(1024); // Create an empty sample with 1024 frames.
data = new float[1024]; // create an array with as many frames as as sample.
//populate the array with sample data, a sine 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.write(data); // write the data from the 'data' array into the sample
mySample.repeat(); // loop the sample
}
public void stop(){
Sonia.stop();
super.stop();
}
|