This repository has been archived by the owner on Apr 24, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 32
/
Decoder.js
69 lines (53 loc) · 2.34 KB
/
Decoder.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
var ogg = require( 'ogg' );
var util = require( 'util' );
var opus = require( '../' );
var path = require( 'path' );
var streamEqual = require( 'stream-equal' );
var fs = require( 'fs' );
describe( 'Decoder', function() {
var SERIALNO = 1;
[ 'random', 'sine' ].forEach( function( file ) {
[ 8000, 48000 ].forEach( function( hzEncode ) {
[ 1, 2 ].forEach( function( chanEncode ) {
[ 8000, 48000 ].forEach( function( hzDecode ) {
[ 1, 2 ].forEach( function( chanDecode ) {
it( util.format(
'should decode %d:%d %s audio in %d:%d Hz',
hzEncode, chanEncode, file, hzDecode, chanDecode ),
function( done ) {
var inputPath = path.join(
path.basename( __dirname ),
'data',
util.format( '%s-%d-%d-%d.opus',
file, hzEncode, chanEncode, 20 ) );
var input = fs.createReadStream( inputPath );
var refPath = path.join(
path.basename( __dirname ),
'data',
util.format( '%s-%d-%d-%d-%d-%d.raw',
file, hzEncode, chanEncode, 20,
hzDecode, chanDecode ) );
var reference = fs.createReadStream( refPath );
var decoder = new opus.Decoder( hzDecode, chanDecode );
var oggDecoder = new ogg.Decoder();
oggDecoder.on( 'stream', function( stream ) {
// Workaround to Node issue #24915
// https://github.com/nodejs/node/issues/24915
stream._readableState.highWaterMark = 1;
stream.pipe( decoder );
});
input.pipe( oggDecoder )
streamEqual( decoder, reference, function( err, equal ) {
if( err )
throw err;
if( ! equal ) {
throw new Error( util.format(
"Streams not equal (%s, %d:%d, %d:%d)",
file, hzEncode, chanEncode,
hzDecode, chanDecode ) );
}
done();
} );
} );
} ) } ) } ) } ) } );
} );