From 672852fd198359c5be629bc4a83a0a734df6b18d Mon Sep 17 00:00:00 2001 From: Maximilian Brauchle Date: Tue, 29 Oct 2024 15:54:02 +0100 Subject: [PATCH 1/3] added sampleRate to typed.d.ts --- src/opus-decoder/types.d.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/opus-decoder/types.d.ts b/src/opus-decoder/types.d.ts index 7a765e9..3661906 100644 --- a/src/opus-decoder/types.d.ts +++ b/src/opus-decoder/types.d.ts @@ -10,6 +10,7 @@ export interface OpusDecodedAudio { export class OpusDecoder { constructor(options?: { forceStereo?: boolean; + sampleRate?: boolean; preSkip?: number; channels?: number; streamCount?: number; From de2aa9010f5e657ca4d380f41439a1770d511bd2 Mon Sep 17 00:00:00 2001 From: Ethan Halsall Date: Wed, 30 Oct 2024 22:09:51 -0500 Subject: [PATCH 2/3] fix(opus-decoder): typescript samplerate --- src/opus-decoder/README.md | 1 + src/opus-decoder/package-lock.json | 4 +-- src/opus-decoder/package.json | 2 +- src/opus-decoder/types.d.ts | 53 +++++++++++++++++++++++++----- test/wasm-audio-decoders.ts | 25 ++++++++++++++ 5 files changed, 73 insertions(+), 12 deletions(-) diff --git a/src/opus-decoder/README.md b/src/opus-decoder/README.md index 95e2a39..87685fd 100644 --- a/src/opus-decoder/README.md +++ b/src/opus-decoder/README.md @@ -185,6 +185,7 @@ Class that decodes Opus frames asynchronously within a web worker. Decoding is p ```javascript const decoder = new OpusDecoderWebWorker({ forceStereo: false, + sampleRate: 48000, channels: 2, streamCount: 1, coupledStreamCount: 1, diff --git a/src/opus-decoder/package-lock.json b/src/opus-decoder/package-lock.json index 9b3831f..d9b94ce 100644 --- a/src/opus-decoder/package-lock.json +++ b/src/opus-decoder/package-lock.json @@ -1,12 +1,12 @@ { "name": "opus-decoder", - "version": "0.7.6", + "version": "0.7.7", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "opus-decoder", - "version": "0.7.6", + "version": "0.7.7", "license": "MIT", "dependencies": { "@wasm-audio-decoders/common": "9.0.5" diff --git a/src/opus-decoder/package.json b/src/opus-decoder/package.json index 838ff3d..08254f8 100644 --- a/src/opus-decoder/package.json +++ b/src/opus-decoder/package.json @@ -1,6 +1,6 @@ { "name": "opus-decoder", - "version": "0.7.6", + "version": "0.7.7", "description": "Web Assembly streaming Opus decoder", "type": "module", "main": "./index.js", diff --git a/src/opus-decoder/types.d.ts b/src/opus-decoder/types.d.ts index 3661906..105dfee 100644 --- a/src/opus-decoder/types.d.ts +++ b/src/opus-decoder/types.d.ts @@ -1,16 +1,28 @@ import { DecodeError } from "@wasm-audio-decoders/common"; -export interface OpusDecodedAudio { +export type OpusDecoderDefaultSampleRate = 48000; +export type OpusDecoderSampleRate = + | 8000 + | 12000 + | 16000 + | 24000 + | OpusDecoderDefaultSampleRate; + +export interface OpusDecodedAudio< + SampleRate extends OpusDecoderSampleRate = OpusDecoderDefaultSampleRate, +> { channelData: Float32Array[]; samplesDecoded: number; - sampleRate: 48000; + sampleRate: SampleRate; errors: DecodeError[]; } -export class OpusDecoder { +export class OpusDecoder< + SampleRate extends OpusDecoderSampleRate | undefined = undefined, +> { constructor(options?: { forceStereo?: boolean; - sampleRate?: boolean; + sampleRate?: SampleRate; preSkip?: number; channels?: number; streamCount?: number; @@ -20,13 +32,24 @@ export class OpusDecoder { ready: Promise; reset: () => Promise; free: () => void; - decodeFrame: (opusFrame: Uint8Array) => OpusDecodedAudio; - decodeFrames: (opusFrames: Uint8Array[]) => OpusDecodedAudio; + decodeFrame: ( + opusFrame: Uint8Array, + ) => OpusDecodedAudio< + SampleRate extends undefined ? OpusDecoderDefaultSampleRate : SampleRate + >; + decodeFrames: ( + opusFrames: Uint8Array[], + ) => OpusDecodedAudio< + SampleRate extends undefined ? OpusDecoderDefaultSampleRate : SampleRate + >; } -export class OpusDecoderWebWorker { +export class OpusDecoderWebWorker< + SampleRate extends OpusDecoderSampleRate | undefined = undefined, +> { constructor(options?: { forceStereo?: boolean; + sampleRate?: SampleRate; preSkip?: number; channels?: number; streamCount?: number; @@ -36,8 +59,20 @@ export class OpusDecoderWebWorker { ready: Promise; reset: () => Promise; free: () => Promise; - decodeFrame: (opusFrame: Uint8Array) => Promise; - decodeFrames: (opusFrames: Uint8Array[]) => Promise; + decodeFrame: ( + opusFrame: Uint8Array, + ) => Promise< + OpusDecodedAudio< + SampleRate extends undefined ? OpusDecoderDefaultSampleRate : SampleRate + > + >; + decodeFrames: ( + opusFrames: Uint8Array[], + ) => Promise< + OpusDecodedAudio< + SampleRate extends undefined ? OpusDecoderDefaultSampleRate : SampleRate + > + >; } export { DecodeError }; diff --git a/test/wasm-audio-decoders.ts b/test/wasm-audio-decoders.ts index 1e4a811..27d8659 100644 --- a/test/wasm-audio-decoders.ts +++ b/test/wasm-audio-decoders.ts @@ -42,6 +42,31 @@ const oggOpusDecoder: OggOpusDecoder = new OggOpusDecoder(); const oggOpusDecoderWebWorker: OggOpusDecoderWebWorker = new OggOpusDecoderWebWorker(); +// test opus decoder sample rates +const opusDecoder8000 = new OpusDecoder({ + sampleRate: 8000, +}); +const opusDecoderWebWorker8000 = new OpusDecoderWebWorker({ + sampleRate: 8000, +}); + +const opusDecoderDecode8000 = opusDecoder8000.decodeFrame(fakeData); +const opusDecoderDecodeSampleRate8000: number = + opusDecoderDecode8000.sampleRate; + +let opusDecoder12000: OpusDecoder<12000>; +opusDecoder12000 = new OpusDecoder({ + sampleRate: 12000, +}); +let opusDecoderWebWorker12000: OpusDecoderWebWorker<12000>; +opusDecoderWebWorker12000 = new OpusDecoderWebWorker({ + sampleRate: 12000, +}); + +const opusDecoderDecode12000 = opusDecoder12000.decodeFrame(fakeData); +const opusDecoderDecodeSampleRate12000: number = + opusDecoderDecode12000.sampleRate; + const flacDecoder: FLACDecoder = new FLACDecoder(); const flacDecoderWebWorker: FLACDecoderWebWorker = new FLACDecoderWebWorker(); From afae32d5906ab62a725fd5e9b9edf4f943ed2827 Mon Sep 17 00:00:00 2001 From: Ethan Halsall Date: Wed, 30 Oct 2024 22:11:59 -0500 Subject: [PATCH 3/3] chore(ogg-opus-decoder): upgrade opus-decoder --- package-lock.json | 10 ++++++---- src/ogg-opus-decoder/package-lock.json | 12 ++++++------ src/ogg-opus-decoder/package.json | 4 ++-- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/package-lock.json b/package-lock.json index 318d468..ee74adc 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5079,6 +5079,7 @@ } }, "src/flac": { + "name": "@wasm-audio-decoders/flac", "version": "0.2.5", "dev": true, "license": "MIT", @@ -5104,13 +5105,13 @@ } }, "src/ogg-opus-decoder": { - "version": "1.6.13", + "version": "1.6.14", "dev": true, "license": "MIT", "dependencies": { "@wasm-audio-decoders/common": "9.0.5", "codec-parser": "2.5.0", - "opus-decoder": "0.7.6" + "opus-decoder": "0.7.7" }, "funding": { "type": "individual", @@ -5118,7 +5119,8 @@ } }, "src/ogg-vorbis": { - "version": "0.1.15", + "name": "@wasm-audio-decoders/ogg-vorbis", + "version": "0.1.16", "dev": true, "license": "MIT", "dependencies": { @@ -5131,7 +5133,7 @@ } }, "src/opus-decoder": { - "version": "0.7.6", + "version": "0.7.7", "dev": true, "license": "MIT", "dependencies": { diff --git a/src/ogg-opus-decoder/package-lock.json b/src/ogg-opus-decoder/package-lock.json index 0bb5705..c58b847 100644 --- a/src/ogg-opus-decoder/package-lock.json +++ b/src/ogg-opus-decoder/package-lock.json @@ -1,17 +1,17 @@ { "name": "ogg-opus-decoder", - "version": "1.6.13", + "version": "1.6.14", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "ogg-opus-decoder", - "version": "1.6.13", + "version": "1.6.14", "license": "MIT", "dependencies": { "@wasm-audio-decoders/common": "9.0.5", "codec-parser": "2.5.0", - "opus-decoder": "0.7.6" + "opus-decoder": "0.7.7" }, "funding": { "type": "individual", @@ -38,9 +38,9 @@ "integrity": "sha512-Ru9t80fV8B0ZiixQl8xhMTLru+dzuis/KQld32/x5T/+3LwZb0/YvQdSKytX9JqCnRdiupvAvyYJINKrXieziQ==" }, "node_modules/opus-decoder": { - "version": "0.7.6", - "resolved": "https://registry.npmjs.org/opus-decoder/-/opus-decoder-0.7.6.tgz", - "integrity": "sha512-5QYSl1YQYbSzWL7vM4dJoyrLC804xIvBFjfKTZZ6/z/EgmdFouOTT+8PDM2V18vzgnhRNPDuyB2aTfl/2hvMRA==", + "version": "0.7.7", + "resolved": "https://registry.npmjs.org/opus-decoder/-/opus-decoder-0.7.7.tgz", + "integrity": "sha512-KWDyCi/9aXnNN+jrjs+aaVdwiwzDdac81S9ul0iv1CTs4+5K4VDZKuJjIImrYOBA2oSNHDjVq4xzn6BE+XbI1A==", "dependencies": { "@wasm-audio-decoders/common": "9.0.5" }, diff --git a/src/ogg-opus-decoder/package.json b/src/ogg-opus-decoder/package.json index f8d028d..9ac4fc4 100644 --- a/src/ogg-opus-decoder/package.json +++ b/src/ogg-opus-decoder/package.json @@ -1,6 +1,6 @@ { "name": "ogg-opus-decoder", - "version": "1.6.13", + "version": "1.6.14", "description": "Web Assembly streaming Ogg Opus decoder", "type": "module", "main": "./index.js", @@ -55,6 +55,6 @@ "dependencies": { "@wasm-audio-decoders/common": "9.0.5", "codec-parser": "2.5.0", - "opus-decoder": "0.7.6" + "opus-decoder": "0.7.7" } }