opus-decoder
Advanced tools
Comparing version 0.5.4 to 0.6.0
{ | ||
"name": "opus-decoder", | ||
"version": "0.5.4", | ||
"version": "0.6.0", | ||
"description": "Web Assembly streaming Opus decoder", | ||
@@ -50,4 +50,4 @@ "type": "module", | ||
"dependencies": { | ||
"@wasm-audio-decoders/common": "5.1.1" | ||
"@wasm-audio-decoders/common": "6.0.0" | ||
} | ||
} |
# `opus-decoder` | ||
`opus-decoder` is a Web Assembly Opus audio decoder. | ||
* 82.8 KiB minified bundle size | ||
* 83.1 KiB minified bundle size | ||
* Browser and NodeJS support | ||
@@ -89,3 +89,12 @@ * Built in Web Worker support | ||
samplesDecoded: 1234, // number of PCM samples that were decoded per channel | ||
sampleRate: 48000 // sample rate of the decoded PCM | ||
sampleRate: 48000, // sample rate of the decoded PCM | ||
errors: [ // array containing descriptions for any decode errors | ||
{ | ||
message: "libopus -4 OPUS_INVALID_PACKET: The compressed data passed is corrupted", | ||
frameLength: 400, // length of the frame or data in bytes that encountered an error | ||
frameNumber: 21, // position of error relative to total frames decoded | ||
inputBytes: 4905, // position of error relative to total input bytes | ||
outputSamples: 18888, // position of error relative to total output samples | ||
} | ||
] | ||
} | ||
@@ -96,2 +105,4 @@ ``` | ||
Decoding will proceed through any errors. Any errors encountered may result in gaps in the decoded audio. | ||
### Multichannel Output | ||
@@ -98,0 +109,0 @@ |
@@ -26,25 +26,22 @@ import { WASMAudioDecoderCommon } from "@wasm-audio-decoders/common"; | ||
// async | ||
this._init = () => { | ||
return new this._WASMAudioDecoderCommon(this) | ||
.instantiate() | ||
.then((common) => { | ||
this._common = common; | ||
this._init = () => | ||
new this._WASMAudioDecoderCommon(this).instantiate().then((common) => { | ||
this._common = common; | ||
const mapping = this._common.allocateTypedArray( | ||
this._channels, | ||
Uint8Array | ||
); | ||
const mapping = this._common.allocateTypedArray( | ||
this._channels, | ||
Uint8Array | ||
); | ||
mapping.buf.set(this._channelMappingTable); | ||
mapping.buf.set(this._channelMappingTable); | ||
this._decoder = this._common.wasm._opus_frame_decoder_create( | ||
this._channels, | ||
this._streamCount, | ||
this._coupledStreamCount, | ||
mapping.ptr, | ||
this._preSkip, | ||
this._forceStereo | ||
); | ||
}); | ||
}; | ||
this._decoder = this._common.wasm._opus_frame_decoder_create( | ||
this._channels, | ||
this._streamCount, | ||
this._coupledStreamCount, | ||
mapping.ptr, | ||
this._preSkip, | ||
this._forceStereo | ||
); | ||
}); | ||
@@ -76,3 +73,3 @@ Object.defineProperty(this, "ready", { | ||
const samplesDecoded = | ||
let samplesDecoded = | ||
this._common.wasm._opus_frame_decode_float_deinterleaved( | ||
@@ -85,10 +82,13 @@ this._decoder, | ||
let error; | ||
if (samplesDecoded < 0) { | ||
console.error( | ||
error = | ||
"libopus " + | ||
samplesDecoded + | ||
" " + | ||
(OpusDecoder.errors.get(samplesDecoded) || "Unknown Error") | ||
); | ||
return 0; | ||
samplesDecoded + | ||
" " + | ||
(OpusDecoder.errors.get(samplesDecoded) || "Unknown Error"); | ||
console.error(error); | ||
samplesDecoded = 0; | ||
} | ||
@@ -103,2 +103,3 @@ | ||
samplesDecoded: samplesDecoded, | ||
error: error, | ||
}; | ||
@@ -108,5 +109,15 @@ }; | ||
this.decodeFrame = (opusFrame) => { | ||
let errors = []; | ||
const decoded = this._decode(opusFrame); | ||
if (decoded.error) | ||
this._common.addError(errors, decoded.error, opusFrame.length); | ||
this._frameNumber++; | ||
this._inputBytes += opusFrame.length; | ||
this._outputSamples += decoded.samplesDecoded; | ||
return this._WASMAudioDecoderCommon.getDecodedAudioMultiChannel( | ||
errors, | ||
[decoded.outputBuffer], | ||
@@ -121,15 +132,26 @@ this._outputChannels, | ||
let outputBuffers = [], | ||
outputSamples = 0, | ||
errors = [], | ||
samplesDecoded = 0, | ||
i = 0; | ||
while (i < opusFrames.length) { | ||
const decoded = this._decode(opusFrames[i++]); | ||
const opusFrame = opusFrames[i++]; | ||
const decoded = this._decode(opusFrame); | ||
outputBuffers.push(decoded.outputBuffer); | ||
outputSamples += decoded.samplesDecoded; | ||
samplesDecoded += decoded.samplesDecoded; | ||
if (decoded.error) | ||
this._common.addError(errors, decoded.error, opusFrame.length); | ||
this._frameNumber++; | ||
this._inputBytes += opusFrame.length; | ||
this._outputSamples += decoded.samplesDecoded; | ||
} | ||
return this._WASMAudioDecoderCommon.getDecodedAudioMultiChannel( | ||
errors, | ||
outputBuffers, | ||
this._outputChannels, | ||
outputSamples, | ||
samplesDecoded, | ||
48000 | ||
@@ -136,0 +158,0 @@ ); |
@@ -0,1 +1,3 @@ | ||
import { DecodeError } from "@wasm-audio-decoders/common/types"; | ||
declare module "opus-decoder" { | ||
@@ -6,2 +8,3 @@ export interface OpusDecodedAudio { | ||
sampleRate: 48000; | ||
errors: DecodeError[]; | ||
} | ||
@@ -8,0 +11,0 @@ |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
196627
1175
255
+ Added@wasm-audio-decoders/common@6.0.0(transitive)
- Removed@wasm-audio-decoders/common@5.1.1(transitive)