ogg-opus-decoder
Advanced tools
Comparing version 1.3.2 to 1.3.3
{ | ||
"name": "ogg-opus-decoder", | ||
"version": "1.3.2", | ||
"version": "1.3.3", | ||
"description": "Web Assembly streaming Ogg Opus decoder", | ||
"main": "dist/ogg-opus-decoder.min.js", | ||
"module": "index.js", | ||
"type": "module", | ||
"main": "./index.js", | ||
"exports": "./index.js", | ||
"types": "types.d.ts", | ||
@@ -17,7 +18,2 @@ "files": [ | ||
], | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/eshaz/wasm-audio-decoders.git" | ||
}, | ||
"type": "module", | ||
"keywords": [ | ||
@@ -47,5 +43,14 @@ "Opus", | ||
"homepage": "https://github.com/eshaz/wasm-audio-decoders/tree/master/src/ogg-opus-decoder", | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/eshaz/wasm-audio-decoders.git", | ||
"directory": "src/ogg-opus-decoder" | ||
}, | ||
"funding": { | ||
"type": "individual", | ||
"url": "https://github.com/sponsors/eshaz" | ||
}, | ||
"dependencies": { | ||
"@wasm-audio-decoders/common": "1.0.0" | ||
"@wasm-audio-decoders/common": "2.0.0" | ||
} | ||
} |
# `ogg-opus-decoder` | ||
`ogg-opus-decoder` is a Web Assembly Ogg Opus audio decoder. | ||
* 116.1 KiB minified bundle size | ||
* 115.9 KiB minified bundle size | ||
* Browser and NodeJS support | ||
@@ -6,0 +6,0 @@ * Built in Web Worker support |
@@ -15,7 +15,6 @@ import { WASMAudioDecoderCommon } from "@wasm-audio-decoders/common"; | ||
// Max data to send per iteration. 64k is the max for enqueueing in libopusfile. | ||
this._inputPtrSize = 64 * 1024; | ||
this._inputPtrSize = 32 * 1024; | ||
// 120ms buffer recommended per http://opus-codec.org/docs/opusfile_api-0.7/group__stream__decoding.html | ||
// per channel | ||
this._outputPtrSize = 120 * 48; // 120ms @ 48 khz. | ||
this._outputPtrSize = 120 * 48 * 32; // 120ms @ 48 khz. | ||
this._outputChannels = 8; // max opus output channels | ||
@@ -40,2 +39,3 @@ | ||
[-139]: "OP_EBADTIMESTAMP: The first or last granule position of a link failed basic validity checks.", | ||
[-140]: "Input buffer overflow" | ||
} | ||
@@ -52,6 +52,5 @@ } | ||
this._decoder = this._common.wasm._ogg_opus_decoder_create(); | ||
this._decoderMethod = this._forceStereo | ||
? this._common.wasm._ogg_opus_decode_float_stereo_deinterleaved | ||
: this._common.wasm._ogg_opus_decode_float_deinterleaved; | ||
this._decoder = this._common.wasm._ogg_opus_decoder_create( | ||
this._forceStereo | ||
); | ||
} | ||
@@ -73,6 +72,2 @@ | ||
/* WARNING: When decoding chained Ogg files (i.e. streaming) the first two Ogg packets | ||
of the next chain must be present when decoding. Errors will be returned by | ||
libopusfile if these initial Ogg packets are incomplete. | ||
*/ | ||
decode(data) { | ||
@@ -92,3 +87,6 @@ if (!(data instanceof Uint8Array)) | ||
offset, | ||
offset + Math.min(this._inputPtrSize, data.length - offset) | ||
offset + | ||
(this._inputPtrSize > data.length - offset | ||
? data.length - offset | ||
: this._inputPtrSize) | ||
); | ||
@@ -100,36 +98,20 @@ | ||
const enqueueResult = this._common.wasm._ogg_opus_decoder_enqueue( | ||
const samplesDecoded = this._common.wasm._ogg_opus_decoder_decode( | ||
this._decoder, | ||
this._inputPtr, | ||
dataToSend.length | ||
dataToSend.length, | ||
this._channelsDecodedPtr, | ||
this._outputPtr | ||
); | ||
if (enqueueResult) | ||
throw { | ||
code: enqueueResult, | ||
message: "Failed to enqueue bytes for decoding.", | ||
}; | ||
if (samplesDecoded < 0) throw { code: samplesDecoded }; | ||
// continue to decode until no more bytes are left to decode | ||
let samplesDecoded; | ||
while ( | ||
(samplesDecoded = this._decoderMethod( | ||
this._decoder, | ||
this._channelsDecodedPtr, | ||
this._outputPtr | ||
)) > 0 | ||
) { | ||
output.push( | ||
this._common.getOutputChannels( | ||
this._output, | ||
this._channelsDecoded[0], | ||
samplesDecoded | ||
) | ||
); | ||
decodedSamples += samplesDecoded; | ||
} | ||
if (samplesDecoded < 0) | ||
throw { code: samplesDecoded, message: "Failed to decode." }; | ||
decodedSamples += samplesDecoded; | ||
output.push( | ||
this._common.getOutputChannels( | ||
this._output, | ||
this._channelsDecoded[0], | ||
samplesDecoded | ||
) | ||
); | ||
} | ||
@@ -139,5 +121,3 @@ } catch (e) { | ||
throw new Error( | ||
`${e.message} libopusfile ${e.code} ${ | ||
this._errors[e.code] || "Unknown Error" | ||
}` | ||
`libopusfile ${e.code} ${this._errors[e.code] || "Unknown Error"}` | ||
); | ||
@@ -144,0 +124,0 @@ throw e; |
@@ -1,14 +0,10 @@ | ||
type OpusDecodedAudio = { | ||
channelData: Float32Array[]; | ||
samplesDecoded: number; | ||
sampleRate: 48000; | ||
}; | ||
declare module "ogg-opus-decoder" { | ||
export interface OpusDecodedAudio { | ||
channelData: Float32Array[]; | ||
samplesDecoded: number; | ||
sampleRate: 48000; | ||
} | ||
type OggOpusDecoderOptions = { | ||
forceStereo?: boolean | ||
} | ||
declare module 'ogg-opus-decoder' { | ||
export class OggOpusDecoder { | ||
public constructor(options?: OggOpusDecoderOptions) | ||
public constructor(options?: { forceStereo?: boolean }); | ||
ready: Promise<void>; | ||
@@ -21,3 +17,3 @@ reset: () => Promise<void>; | ||
export class OggOpusDecoderWebWorker { | ||
public constructor(options?: OggOpusDecoderOptions) | ||
public constructor(options?: { forceStereo?: boolean }); | ||
ready: Promise<void>; | ||
@@ -24,0 +20,0 @@ reset: () => Promise<void>; |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
High entropy strings
Supply chain riskContains high entropy strings. This could be a sign of encrypted data, leaked secrets or obfuscated code.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
High entropy strings
Supply chain riskContains high entropy strings. This could be a sign of encrypted data, leaked secrets or obfuscated code.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
263048
1099
+ Added@wasm-audio-decoders/common@2.0.0(transitive)
- Removed@wasm-audio-decoders/common@1.0.0(transitive)