 |
 |
 |
 |
| Class |
|
AudioFile |
 |
|
|
| Name |
|
write() |
 |
|
|
| 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 |
|
Writes to a sound stream opened for writing. IMPORTANT: close() must be called when done writing a sound, or no data will be written to disk |
 |
|
|
| Syntax |
|
file.write(buffer)
file.write(buffer, offset, frames)
|
 |
|
|
| Parameters |
|
| file |
|
any instance of AudioFile
|
| buffer |
|
the instance of AudioChannel, AudioStream, or AudioInput, or a floating point array from which to pull data to write
|
| offset |
|
int: the sample frame of the AudioChannel, AudioStream, AudioInput, or floating point array from which to start pulling data to write. The default is the first frame
|
| frames |
|
int: the number of frames to write. The default is the length of the AudioChannel, AudioStream, or floating point array
|
|
 |
|
|
| Returns |
|
nothing |
 |
|
|
| Usage |
|
Web & Application |
 |
|
|
|
|