Back
Class   Sample
   
Name  

write()

   
Examples  
// 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(); 
} 

Description   Writes data from an array into a mono sample object (use writeChannel() for stereo samples). The sample data comes in floats of -1.0 to 1.0 per frame. A 44.1 kHz sample has 44100 frames per second.
   
Syntax  
mySample.write(dataArray)
mySample.write(dataArray, firstDataFrame, firstSampleFrame, numFrames)
   
Parameters  
dataArray   float[]: an array that can hold float values

firstDataFrame   int: First index element to be read from the data[] array

firstSampleFrame   int: First sample frame to be written

numFrames   int: number of sample frames to write

   
Returns   None
   
Usage   Web & Application
   
Related   read()
readChannel()
writeChannel()