Takes a WavSpec and iterable of normalized float samples, creates WAV format header, converts samples to specified bit depth and returns Uint8Array of complete WAV file, ready for export.
remarks
If using more than one channel, the source samples need to be already interleaved, i.e. for stereo: left, right, left, right etc.
At most, only the number of samples specified in the given header spec are consumed & written. The source iterable does not need to be limited explicitly.
Takes a WavSpec and iterable of normalized float samples, creates WAV format header, converts samples to specified bit depth and returns
Uint8Array
of complete WAV file, ready for export.If using more than one channel, the source samples need to be already interleaved, i.e. for stereo: left, right, left, right etc.
At most, only the number of samples specified in the given header spec are consumed & written. The source iterable does not need to be limited explicitly.
import { osc, sin } from "@thi.ng/dsp"; const FS = 48000; // write 1 second 24bit mono WAV file, 440Hz sine fs.writeFileSync( "sine-440.wav", wavByteArray( { sampleRate: FS, channels: 1, length: FS, bits: 24 }, osc(sin, 440 / FS) ) )