-
Notifications
You must be signed in to change notification settings - Fork 0
/
testcompression.js
29 lines (22 loc) · 1.15 KB
/
testcompression.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
var fs = require('fs');
const path = require('path');
const flac = require('flac-bindings');
var wav = require('wav');
var file = fs.createReadStream(path.join(__dirname, '/stravinsky.wav'));
var reader = new wav.Reader({
channels: 2, // 2 channels
bitDepth: 16, // 16-bit samples
sampleRate: 44100 // 44,100 Hz sample rate
});
var flacFileStreamDefault = new flac.FileEncoder({ samplerate: 44100, bitsPerSample: 16, file: path.join(__dirname, '/stravinskyCompDefault.flac') });
var flacFileStream0 = new flac.FileEncoder({ samplerate: 44100, bitsPerSample: 16, compressionLevel: 0, file: path.join(__dirname, '/stravinskyComp0.flac') });
var flacFileStream5 = new flac.FileEncoder({ samplerate: 44100, bitsPerSample: 16, compressionLevel: 6, file: path.join(__dirname, '/stravinskyComp6.flac') });
// the "format" event gets emitted at the end of the WAVE header
//reader.on('format', function (format) {
// the WAVE header is stripped from the output of the reader
reader.pipe(flacFileStreamDefault);
reader.pipe(flacFileStream0);
reader.pipe(flacFileStream5);
//});
// pipe the WAVE file to the Reader instance
file.pipe(reader);