Back
Class   Sample
   
Name  

writeChannel()

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

Description   Writes data from an array into the specified channel of a sample object. 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.writeChannel(channel, dataArray)
mySample.writeChannel(channel, dataArray, firstDataFrame, firstSampleFrame, numFrames)
   
Parameters  
channel   int: 0 or Sonia.LEFT for Left channel, 1 or Sonia.RIGHT for Right channel

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   write()
read()
readChannel()