Skip to content

Commit

Permalink
Merge pull request #80 from eshaz/opus-sample-rate
Browse files Browse the repository at this point in the history
Opus sample rate
  • Loading branch information
eshaz authored Apr 22, 2023
2 parents 2b44bb8 + fa48bb9 commit f46747c
Show file tree
Hide file tree
Showing 53 changed files with 1,774 additions and 1,357 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Decodes MPEG Layer I/II/III into PCM

### [`@wasm-audio-decoders/flac`](https://github.com/eshaz/wasm-audio-decoders/tree/master/src/flac)
Decodes FLAC data into PCM
* 62.3 KiB minified bundle size
* 63.7 KiB minified bundle size
* Browser and NodeJS support
* Built in Web Worker support
* Multichannel decoding (up to 8 channels)
Expand All @@ -32,7 +32,7 @@ Decodes FLAC data into PCM

### [`ogg-opus-decoder`](https://github.com/eshaz/wasm-audio-decoders/tree/master/src/ogg-opus-decoder)
Decodes Ogg Opus data into PCM
* 105.1 KiB minified bundle size
* 107.5 KiB minified bundle size
* Browser and NodeJS support
* Built in Web Worker support
* Multichannel decoding (up to 255 channels)
Expand All @@ -41,7 +41,7 @@ Decodes Ogg Opus data into PCM

### [`opus-decoder`](https://github.com/eshaz/wasm-audio-decoders/tree/master/src/opus-decoder)
Decodes raw Opus audio frames into PCM
* 83.3 KiB minified bundle size
* 84.3 KiB minified bundle size
* Browser and NodeJS support
* Built in Web Worker support
* Multichannel decoding (up to 255 channels)
Expand All @@ -51,7 +51,7 @@ Decodes raw Opus audio frames into PCM

### [`@wasm-audio-decoders/ogg-vorbis`](https://github.com/eshaz/wasm-audio-decoders/tree/master/src/ogg-vorbis)
Decodes Ogg Vorbis data into PCM
* 93.7 KiB minified bundle size
* 95.1 KiB minified bundle size
* Browser and NodeJS support
* Built in Web Worker support
* Multichannel decoding (up to 255 channels)
Expand Down
75 changes: 39 additions & 36 deletions demo/flac-decoder.js
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@
const crc = "crc";
const crc16 = crc + "16";
const crc32 = crc + "32";
const data = "data";
const data$1 = "data";
const description = "description";
const duration = "duration";
const emphasis = "emphasis";
Expand All @@ -578,7 +578,7 @@
const outputGain = "outputGain";
const preSkip = "preSkip";
const profile = "profile";
const profileBits = profile + "Bits";
const profileBits = symbol();
const protection = "protection";
const rawData = "rawData";
const segments = "segments";
Expand All @@ -590,17 +590,17 @@

const block = "block";
const blockingStrategy = block + "ingStrategy";
const blockingStrategyBits = block + "ingStrategyBits";
const blockingStrategyBits = symbol();
const blockSize = block + "Size";
const blocksize0 = block + "size0";
const blocksize1 = block + "size1";
const blockSizeBits = block + "SizeBits";
const blockSizeBits = symbol();

const channel = "channel";
const channelMappingFamily = channel + "MappingFamily";
const channelMappingTable = channel + "MappingTable";
const channelMode = channel + "Mode";
const channelModeBits = channel + "ModeBits";
const channelModeBits = symbol();
const channels = channel + "s";

const copyright = "copyright";
Expand All @@ -621,14 +621,14 @@

const page = "page";
const pageChecksum = page + "Checksum";
const pageSegmentBytes = page + "SegmentBytes";
const pageSegmentBytes = symbol();
const pageSegmentTable = page + "SegmentTable";
const pageSequenceNumber = page + "Sequence" + Number$1;

const sample = "sample";
const sampleNumber = sample + Number$1;
const sampleRate = sample + Rate;
const sampleRateBits = sample + Rate + "Bits";
const sampleRateBits = symbol();
const samples = sample + "s";

const stream = "stream";
Expand Down Expand Up @@ -1056,7 +1056,7 @@
constructor(headerValue, dataValue) {
frameStore.set(this, { [header]: headerValue });

this[data] = dataValue;
this[data$1] = dataValue;
}
}

Expand Down Expand Up @@ -1605,7 +1605,7 @@
onCodec(this[codec]);
}

get codec() {
get [codec]() {
return mpeg;
}

Expand Down Expand Up @@ -1906,7 +1906,7 @@
onCodec(this[codec]);
}

get codec() {
get [codec]() {
return "aac";
}

Expand Down Expand Up @@ -2322,7 +2322,7 @@
onCodec(this[codec]);
}

get codec() {
get [codec]() {
return "flac";
}

Expand Down Expand Up @@ -2413,7 +2413,7 @@
// Identification header

this._headerCache[enable]();
this._streamInfo = oggPage[data][subarray](13);
this._streamInfo = oggPage[data$1][subarray](13);
} else if (oggPage[pageSequenceNumber] === 1) ; else {
oggPage[codecFrames] = frameStore
.get(oggPage)
Expand Down Expand Up @@ -2787,9 +2787,9 @@
// * `00000001`: Version number
if (dataValue[8] !== 1) return null;

header[data] = uint8Array.from(dataValue[subarray](0, header[length]));
header[data$1] = uint8Array.from(dataValue[subarray](0, header[length]));

const view = new dataView(header[data][buffer]);
const view = new dataView(header[data$1][buffer]);

header[bitDepth] = 16;

Expand Down Expand Up @@ -2884,7 +2884,7 @@
constructor(header) {
super(header);

this[data] = header[data];
this[data$1] = header[data$1];
this[bandwidth] = header[bandwidth];
this[channelMappingFamily] = header[channelMappingFamily];
this[channelMappingTable] = header[channelMappingTable];
Expand Down Expand Up @@ -2929,7 +2929,7 @@
this._identificationHeader = null;
}

get codec() {
get [codec]() {
return "opus";
}

Expand All @@ -2941,7 +2941,7 @@
// Identification header

this._headerCache[enable]();
this._identificationHeader = oggPage[data];
this._identificationHeader = oggPage[data$1];
} else if (oggPage[pageSequenceNumber] === 1) ; else {
oggPage[codecFrames] = frameStore
.get(oggPage)
Expand Down Expand Up @@ -3042,8 +3042,8 @@
return null;
}

header[data] = uint8Array.from(dataValue[subarray](0, 30));
const view = new dataView(header[data][buffer]);
header[data$1] = uint8Array.from(dataValue[subarray](0, 30));
const view = new dataView(header[data$1][buffer]);

// Byte (8-11 of 30)
// * `CCCCCCCC|CCCCCCCC|CCCCCCCC|CCCCCCCC`: Version number
Expand Down Expand Up @@ -3115,7 +3115,7 @@
this[bitrateNominal] = header[bitrateNominal];
this[blocksize0] = header[blocksize0];
this[blocksize1] = header[blocksize1];
this[data] = header[data];
this[data$1] = header[data$1];
this[vorbisComments] = header[vorbisComments];
this[vorbisSetup] = header[vorbisSetup];
}
Expand Down Expand Up @@ -3155,7 +3155,7 @@
this._currBlockSize = 0;
}

get codec() {
get [codec]() {
return vorbis;
}

Expand All @@ -3166,7 +3166,7 @@
// Identification header

this._headerCache[enable]();
this._identificationHeader = oggPage[data];
this._identificationHeader = oggPage[data$1];
} else if (oggPage[pageSequenceNumber] === 1) {
// gather WEBM CodecPrivate data
if (oggPageSegments[1]) {
Expand Down Expand Up @@ -3348,7 +3348,7 @@
this._pageSequenceNumber = 0;
}

get codec() {
get [codec]() {
return this._codec || "";
}

Expand Down Expand Up @@ -3407,17 +3407,18 @@
this._checkPageSequenceNumber(oggPage);

const oggPageStore = frameStore.get(oggPage);
const { pageSegmentBytes, pageSegmentTable } = headerStore.get(
oggPageStore[header]
);
const headerData = headerStore.get(oggPageStore[header]);

let offset = 0;

oggPageStore[segments] = pageSegmentTable.map((segmentLength) =>
oggPage[data][subarray](offset, (offset += segmentLength))
oggPageStore[segments] = headerData[pageSegmentTable].map((segmentLength) =>
oggPage[data$1][subarray](offset, (offset += segmentLength))
);

if (pageSegmentBytes[pageSegmentBytes[length] - 1] === 0xff) {
if (
headerData[pageSegmentBytes][headerData[pageSegmentBytes][length] - 1] ===
0xff
) {
// continued packet
this._continuedPacket = concatBuffers(
this._continuedPacket,
Expand Down Expand Up @@ -3486,7 +3487,7 @@
* @public
* @returns The detected codec
*/
get codec() {
get [codec]() {
return this._parser[codec];
}

Expand Down Expand Up @@ -3611,19 +3612,19 @@
this._sampleRate = frame[header][sampleRate];

frame[header][bitrate] =
Math.round(frame[data][length] / frame[duration]) * 8;
Math.round(frame[data$1][length] / frame[duration]) * 8;
frame[frameNumber] = this._frameNumber++;
frame[totalBytesOut] = this._totalBytesOut;
frame[totalSamples] = this._totalSamples;
frame[totalDuration] = (this._totalSamples / this._sampleRate) * 1000;
frame[crc32] = this._crc32(frame[data]);
frame[crc32] = this._crc32(frame[data$1]);

this._headerCache[checkCodecUpdate](
frame[header][bitrate],
frame[totalDuration]
);

this._totalBytesOut += frame[data][length];
this._totalBytesOut += frame[data$1][length];
this._totalSamples += frame[samples];
}

Expand Down Expand Up @@ -3691,6 +3692,8 @@
}
}

const data = data$1;

/* **************************************************
* This file is auto-generated during the build process.
* Any edits to this file will be overwritten.
Expand Down Expand Up @@ -4158,13 +4161,13 @@ z”­-w9lþkbö>së®QSU,â~ANÃuã^™X1]ܯA‡p%9µ±àÂÄï±ÍãõÄԊ

async decode(flacData) {
return this._decoder.decodeFrames(
[...this._codecParser.parseChunk(flacData)].map((f) => f.data)
[...this._codecParser.parseChunk(flacData)].map((f) => f[data])
);
}

async flush() {
const decoded = this._decoder.decodeFrames(
[...this._codecParser.flush()].map((f) => f.data)
[...this._codecParser.flush()].map((f) => f[data])
);

await this.reset();
Expand All @@ -4173,7 +4176,7 @@ z”­-w9lþkbö>së®QSU,â~ANÃuã^™X1]ܯA‡p%9µ±àÂÄï±ÍãõÄԊ

async decodeFile(flacData) {
const decoded = this._decoder.decodeFrames(
[...this._codecParser.parseAll(flacData)].map((f) => f.data)
[...this._codecParser.parseAll(flacData)].map((f) => f[data])
);

await this.reset();
Expand Down
4 changes: 2 additions & 2 deletions demo/flac-decoder.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion demo/flac-decoder.min.js.map

Large diffs are not rendered by default.

Loading

0 comments on commit f46747c

Please sign in to comment.