apple1-videocard-lib/tools/wavconv/samples2wav.js
2022-01-13 14:11:03 +01:00

16 lines
444 B
JavaScript

const WavEncoder = require("wav-encoder");
// turns the samples into an actual WAV file
// returns the array of bytes to be written to file
function samples2wav(samples, samplerate) {
const wavData = {
sampleRate: samplerate,
channelData: [ new Float32Array(samples) ]
};
const buffer = WavEncoder.encode.sync(wavData, { bitDepth: 16, float: false });
return Buffer.from(buffer)
}
module.exports = { samples2wav };