riffr
v0.1.4
Published
Riffr is a nodejs util to create RIFF formatted files.
Downloads
1
Readme
#Riffr Riffr is a nodejs util to create RIFF formatted files.
The example below will generate a WAV file:
const fs = require('fs');
const riffr = require('./riff');
const wavFile = new riffr.RIFF('WAVE');
const formatChunk = new riffr.RIFFChunk('fmt ');
formatChunk.writeBytes([1, 0]); //Type of Format
formatChunk.writeBytes([1, 0]); //Number of Channels
formatChunk.writeBytes([68, 172, 0, 0]); //Sample Rate
formatChunk.writeBytes([68, 172, 0, 0]); //AvgBytesPerSec
formatChunk.writeBytes([1, 0]); //BlockAlign
formatChunk.writeBytes([8, 0]); //Bits per Sample
wavFile.addChunk(formatChunk);
const dataChunk = new riffr.RIFFChunk('data');
for(var i = 0; i < 44100; i++){
const val = (Math.sin(i/32) * 255) + 256;
dataChunk.writeByte(val);
}
wavFile.addChunk(dataChunk);
const buffer = wavFile.toBuffer();
fs.writeFile('test.wav', buffer, function(err){
if(err) {
return console.log(err);
}
console.log("Saved test.wav");
});