-
Notifications
You must be signed in to change notification settings - Fork 8
/
example.js
46 lines (37 loc) · 951 Bytes
/
example.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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
const SampleRate = require('./index.js');
const fs = require('fs');
const header = require('./waveheader.js');
let options = {
type: SampleRate.SRC_SINC_MEDIUM_QUALITY,
channels: 2,
fromRate: 44100,
fromDepth: 16,
toRate: 48000,
toDepth: 32
}
const resample = new SampleRate(options);
// Start read at byte 44 to avoid WAV header data
var rs = fs.createReadStream('infile.wav', {start: 44});
var ws = fs.createWriteStream('outfile.wav');
ws.write(header(0, {
bitDepth: options.toDepth,
sampleRate: options.toRate,
channels: options.channels
}));
resample.on('pipe', () => {
console.log('PIPE Event')
})
resample.on('unpipe', () => {
console.log('UNPIPE Event')
})
resample.on('finish', () => {
console.log('FINISH Event ')
})
resample.on('error', () => {
console.log('ERROR Event ')
})
resample.on('end', () => {
console.log('END Event')
ws.end();
})
rs.pipe(resample).pipe(ws);