Rantanen / node-opus

Opus bindings for Node.js
MIT License
79 stars 32 forks source link

wrong decode #75

Closed vinnitu closed 5 years ago

vinnitu commented 5 years ago
var opus = require('node-opus');

// var channels = 1;
var rate = 24000;
var encoder = new opus.OpusEncoder( rate );

var encoded = new Uini8Array([56,255,168,198,27,96,104,141,249,196,107,126,250,251,91,53,81,141,38,101,62,36,181,66,0,171,100,114,9,111,252,155,64,247,247,30,203,1,198,137,50,168,63,71,7,71,178,156,88,104,94,40,103,2,216,187,
68,244,191,92,105,73,102,172,170,38,52,219,132,194,112,197,173,88,161,182,144,64,55,14,92,114,133,104,167,224,78,167,121,229,245,138,218,10,125,190,54,8,210,190,197,169,84,249,245,156,140,108,89,91,147,95
,12,144,85,41,48,179,194,8,190,213,75,147,18,132,130,91,203,24,1,88,24,215,148]);

var frame_size = rate/100;
var decoded = encoder.decode( encoded, frame_size );

console.log(decoded.length == 11520); // must be equal but not, why?
console.log(decoded);

// must be [0,192,207,188,0,128,111,188,0,128,0,188,0,0,48... but not, why?
Rantanen commented 5 years ago

Must be equal based on what? Where did you get that reference data?

Opus is a lossy format and there's various things, such as sample rates that would change the output.

vinnitu commented 5 years ago

I saw it in zello-channel-api in https://github.com/zelloptt/zello-channel-api/blob/master/sdks/js/dist/zcc.decoder.js

t.prototype.decodeFloat32=function(e){return new Float32Array(this._decode(e,4,_opus_decode_float))}

I added console.log to debug it

t.prototype.decodeFloat23 = function(e) {
    console.log(e); // encoded
    const x = this._decode(e,4,_opus_decode_float);
    console.log(x); // decoded
    return new Float32Array(x);
}

I know sampleRate and channels and try use your code to do this task but unsuccessfully

Rantanen commented 5 years ago

Based on the comments in that other issue, you're after raw opus frames. The OpusEncoder gives you opus audio within ogg container, so this is not what you want.

vinnitu commented 5 years ago

Yes, I need to get pcm data from raw opus frames. In my example var encoded is such data.

vinnitu commented 5 years ago
const encoder = new opus.OpusEncoder(sampleRate, channels);
const decoded = encoder.decode(packet);

that is all, sorry for time