Writing WAV files
object WaveWriter {
constructor WaveWriter();
bool createWavFile( string filename, number samplerate, [channels: default 1]);
bool addSamples( IQData samples );
bool addSamples( FloatData samples );
bool close();
}
- Example
const SAMPLE_RATE = 48e3 ;
var wave = new WaveWriter();
if( wave.createWavFile('test.wav', SAMPLE_RATE, 1) == false ) {
print('Cannot create file');
exit(0);
}
var stereo_audio = DSP.tone( 440, SAMPLE_RATE, SAMPLE_RATE );
wave.addSamples( stereo_audio.getReal() );
wave.close();
.createWavFile
bool createWavFile( string filename, number samplerate, [channels: default 1]);
Create a new WAV file with the following parameters:
- filename : full path the file. If existing, the file will be overwritten.
- samplerate: integer, the sample rate in Hz.
- channels: 1 for MONO, 2 for STEREO
.addSamples
Append samples to the file.
- for MONO WAV file (channels=1) : add only FloatData
- for STEREO WAV file (channels=2) : add only IQData
bool addSamples( samples );
.close
Close file on disk.
Last update: January 8, 2024