Writing Wave Files - spessasus/spessasynth_core GitHub Wiki
Writing Wave files
SpessaSynth has a helper function for writing wave files.
audioToWav
Converts PCM audio data into a fully valid wave file.
const file = audioToWav(audioData, sampleRate, normalizeAudio = true, metadata = {}, loop = undefined);
audioData
- anArray
ofFloat32Array
s representing the data. For stereo, pass[leftData, rightData]
.sampleRate
-number
the sample rate, in Hertz.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.metadata
- optionalObject
described 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
- optionalObject
that will write loop points to the file (using thecue
chunk)start
- start time in secondsend
- end time in seconds
The metadata uses the INFO
chunk to write the information. It is encoded with utf-8
Example code
Refer to examples/midi_to_wav_node
for an example of rendering audio data to a wav file.