Writing Wave files
SpessaSynth has a helper function for writing wave files.
audioBufferToWav
Converts an audio buffer into a fully valid wave file.
const file = audioBufferToWav(
audioBuffer,
(normalizeAudio = true),
(channelOffset = 0),
(metadata = {}),
(loop = undefined),
(channelCount = all)
);
audioBuffer-AudioBuffer- the buffer to write. Multiple channels are allowed.normalizeAudio- optionalboolean- if true, the gain of the entire song will be adjusted, so the max sample is always 32,767 or min is always -32,768 (whichever is greater). Recommended.channelOffset- optionalnumber- if the buffer has more than two channels, you can specify the channel offset to use. This is especially useful in one output modemetadata- optionalObjectdescribed below. All options are string and are optional:title- the song’s titleartist- the song’s artistalbum- the song’s albumgenre- the song’s genre
loop- optionalObjectthat will write loop points to the file (using thecuechunk)start- start time in secondsend- end time in seconds
channelCount- optionalnumberthat limits the channel count to a given number. Otherwise, all channels fromchannelOffsetto the last channel are used.
The metadata uses the INFO chunk to write the information. It is encoded with utf-8