Tree-Axis ``` Processing  


Back  
Name  

AudioFile

   
Examples  
// Example by Krister Olsson

import krister.Ess.*;

AudioStream myStream;
SineWave myWave;

boolean recording=false;
AudioFile myFile;
int bytesWritten;

void setup() {
  size(256,200);

  // start up Ess
  Ess.start(this);

  // create a new AudioStream
  myStream=new AudioStream();

  // our wave
  myWave=new SineWave(240,.33);
  
  // our AudioFile
  myFile=new AudioFile();

  // start
  myStream.start();
}

void draw() {
}

void audioStreamWrite(AudioStream theStream) {
  // next wave
  myWave.generate(myStream);

  // adjust our phase
  myWave.phase+=myStream.size;
  myWave.phase%=myStream.sampleRate; 
  
  // record
  if (recording) {
    myFile.write(myStream);
    bytesWritten+=myStream.size*2;
  }
}

void keyPressed() {
  if (recording) {
    // stop
    myFile.close();
    
    println("Finished recording. "+bytesWritten+" bytes written.");
  } else {
    // start
    myFile.open("out.aif",myStream.sampleRate,Ess.WRITE);
    bytesWritten=0;
    
    println("Recording started.");
  }
  
  recording=!recording;
}

// we are done, clean up Ess

public void stop() {
  Ess.stop();
  super.stop();
}


Description   The AudioFile class is used to read from or write to sound streams. AIFF, WAVE, AU, and if the appropriate JARs are installed (see the Ess home page), MP3 files may be opened for reading from within the sketch's data folder, the Web (unsigned applets can only load sounds from their own subdomain), or the local filesystem (applications and signed applets only). When loading a stereo sound a left/right channel may be specified, or both channels may be mixed to one mono channel. Only 16-bit samples are supported. See the example mp3Stream to learn how to play an mp3 stream. Files may be opened for writing in either AIFF or WAVE format (applications and signed applets only). In this case, the format for the file is chosen based on the suffix of the filename. If an unrecognized suffix or no suffix is present, AIFF is chosen
   
   
Constructors  
AudioFile()
AudioFile(filename, rate, mode)
AudioFile(filename, rate, mode, lrChannel)
   
Parameters  
filename   String: the sound to open

rate   float: the sample rate of the sound to open. NOTE: Currently, when opening a sound to read, the actual rate of the sound will always override this value. As such, 0 may be passed. This will change, though passing 0 will always indicate to use the actual rate of the sound

mode   Ess.READ if we are opening to read, Ess.WRITE if we are opening to write

lrChannel   for stereo sounds being opened to read, the channel to read: Ess.MIX (the default), Ess.LEFT, or Ess.RIGHT

   
Usage   Web & Application
   
 
 






   
 
Updated: Tue May 31 04:52:38 PDT 2006


 
  Questions, comments, corrections: e-mail Krister Olsson.