Closed j-k closed 8 years ago
The FileWriter is currently broken, I hope to get that fixed soon. But assuming it works, it could look something like this.
const output = new FileWriter('test.wav')
for (let i = 0; i < output.sampleRate; i++) {
for (let c = 0; c < output.channels; c++) {
const chunk = new Buffer(4)
chunk.writeUInt16(Math.sin(i * X))
output.write(chunk)
}
}
output.end()
To answer your question, write buffers to it with .write(_)
and when you are done, call .end()
. This is how all streams behave in Node.js.
How can one pass actual data to the FileWriter before the file is written? This is not explained in the API. I would like to put a one second 440 Hz sine wave (sample by sample) into a WAV file that is generated with Math.sin().