Skip to content

Commit

Permalink
Merge pull request #83 from eshaz/opus-decode-length
Browse files Browse the repository at this point in the history
Ogg Opus decode length
  • Loading branch information
eshaz authored Jun 8, 2023
2 parents 3482378 + c972ad0 commit 1bd891d
Show file tree
Hide file tree
Showing 56 changed files with 1,201 additions and 287 deletions.
26 changes: 26 additions & 0 deletions demo/flac-decoder.js
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,7 @@
along with this program. If not, see <https://www.gnu.org/licenses/>
*/


const getCrcTable = (crcTable, crcInitialValueFunction, crcFunction) => {
for (let byte = 0; byte < crcTable[length]; byte++) {
let crc = crcInitialValueFunction(byte);
Expand Down Expand Up @@ -874,6 +875,7 @@
along with this program. If not, see <https://www.gnu.org/licenses/>
*/


class HeaderCache {
constructor(onCodecHeader, onCodecUpdate) {
this._onCodecHeader = onCodecHeader;
Expand Down Expand Up @@ -972,6 +974,7 @@
along with this program. If not, see <https://www.gnu.org/licenses/>
*/


/**
* @abstract
* @description Abstract class containing methods for parsing codec frames
Expand Down Expand Up @@ -1049,6 +1052,7 @@
along with this program. If not, see <https://www.gnu.org/licenses/>
*/


/**
* @abstract
*/
Expand Down Expand Up @@ -1078,6 +1082,7 @@
along with this program. If not, see <https://www.gnu.org/licenses/>
*/


class CodecFrame extends Frame {
static *[getFrame](Header, Frame, codecParser, headerCache, readOffset) {
const headerValue = yield* Header[getHeader](
Expand Down Expand Up @@ -1134,6 +1139,7 @@
along with this program. If not, see <https://www.gnu.org/licenses/>
*/


const unsynchronizationFlag = "unsynchronizationFlag";
const extendedHeaderFlag = "extendedHeaderFlag";
const experimentalFlag = "experimentalFlag";
Expand Down Expand Up @@ -1222,6 +1228,7 @@
along with this program. If not, see <https://www.gnu.org/licenses/>
*/


class CodecHeader {
/**
* @private
Expand Down Expand Up @@ -1255,6 +1262,7 @@
along with this program. If not, see <https://www.gnu.org/licenses/>
*/


// http://www.mp3-tech.org/programmer/frame_header.html

const bitrateMatrix = {
Expand Down Expand Up @@ -1562,6 +1570,7 @@
along with this program. If not, see <https://www.gnu.org/licenses/>
*/


class MPEGFrame extends CodecFrame {
static *[getFrame](codecParser, headerCache, readOffset) {
return yield* super[getFrame](
Expand Down Expand Up @@ -1596,6 +1605,7 @@
along with this program. If not, see <https://www.gnu.org/licenses/>
*/


class MPEGParser extends Parser {
constructor(codecParser, headerCache, onCodec) {
super(codecParser, headerCache);
Expand Down Expand Up @@ -1632,6 +1642,7 @@
along with this program. If not, see <https://www.gnu.org/licenses/>
*/


const mpegVersionValues = {
0b00000000: "MPEG-4",
0b00001000: "MPEG-2",
Expand Down Expand Up @@ -1863,6 +1874,7 @@
along with this program. If not, see <https://www.gnu.org/licenses/>
*/


class AACFrame extends CodecFrame {
static *[getFrame](codecParser, headerCache, readOffset) {
return yield* super[getFrame](
Expand Down Expand Up @@ -1897,6 +1909,7 @@
along with this program. If not, see <https://www.gnu.org/licenses/>
*/


class AACParser extends Parser {
constructor(codecParser, headerCache, onCodec) {
super(codecParser, headerCache);
Expand Down Expand Up @@ -1933,6 +1946,7 @@
along with this program. If not, see <https://www.gnu.org/licenses/>
*/


class FLACFrame extends CodecFrame {
static _getFrameFooterCrc16(data) {
return (data[data[length] - 2] << 8) + data[data[length] - 1];
Expand Down Expand Up @@ -1973,6 +1987,7 @@
along with this program. If not, see <https://www.gnu.org/licenses/>
*/


const getFromStreamInfo = "get from STREAMINFO metadata block";

const blockingStrategyValues = {
Expand Down Expand Up @@ -2310,6 +2325,7 @@
along with this program. If not, see <https://www.gnu.org/licenses/>
*/


const MIN_FLAC_FRAME_SIZE = 2;
const MAX_FLAC_FRAME_SIZE = 512 * 1024;

Expand Down Expand Up @@ -2457,6 +2473,7 @@
along with this program. If not, see <https://www.gnu.org/licenses/>
*/


class OggPageHeader {
static *[getHeader](codecParser, headerCache, readOffset) {
const header = {};
Expand Down Expand Up @@ -2584,6 +2601,7 @@
along with this program. If not, see <https://www.gnu.org/licenses/>
*/


class OggPage extends Frame {
static *[getFrame](codecParser, headerCache, readOffset) {
const header = yield* OggPageHeader[getHeader](
Expand Down Expand Up @@ -2646,6 +2664,7 @@
along with this program. If not, see <https://www.gnu.org/licenses/>
*/


class OpusFrame extends CodecFrame {
constructor(data, header) {
super(
Expand Down Expand Up @@ -2674,6 +2693,7 @@
along with this program. If not, see <https://www.gnu.org/licenses/>
*/


/* prettier-ignore */
const channelMappingFamilies = {
0b00000000: vorbisOpusChannelMapping.slice(0,2),
Expand Down Expand Up @@ -2919,6 +2939,7 @@
along with this program. If not, see <https://www.gnu.org/licenses/>
*/


class OpusParser extends Parser {
constructor(codecParser, headerCache, onCodec) {
super(codecParser, headerCache);
Expand Down Expand Up @@ -2983,6 +3004,7 @@
along with this program. If not, see <https://www.gnu.org/licenses/>
*/


class VorbisFrame extends CodecFrame {
constructor(data, header, samples) {
super(header, data, samples);
Expand All @@ -3007,6 +3029,7 @@
along with this program. If not, see <https://www.gnu.org/licenses/>
*/


const blockSizes = {
// 0b0110: 64,
// 0b0111: 128,
Expand Down Expand Up @@ -3139,6 +3162,7 @@
along with this program. If not, see <https://www.gnu.org/licenses/>
*/


class VorbisParser extends Parser {
constructor(codecParser, headerCache, onCodec) {
super(codecParser, headerCache);
Expand Down Expand Up @@ -3335,6 +3359,7 @@
along with this program. If not, see <https://www.gnu.org/licenses/>
*/


class OggParser extends Parser {
constructor(codecParser, headerCache, onCodec) {
super(codecParser, headerCache);
Expand Down Expand Up @@ -3459,6 +3484,7 @@
along with this program. If not, see <https://www.gnu.org/licenses/>
*/


const noOp = () => {};

class CodecParser {
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.

Binary file modified demo/mpg123-decoder.min.js
Binary file not shown.
Loading

0 comments on commit 1bd891d

Please sign in to comment.