Comparing version 0.2.2 to 0.2.3
@@ -82,2 +82,6 @@ 'use strict'; | ||
} | ||
} else { | ||
for (var _ch3 = 0; _ch3 < bsi.nfchans; _ch3++) { | ||
audblk.chincpl[_ch3] = 0; | ||
} | ||
} | ||
@@ -88,14 +92,14 @@ } | ||
if (audblk.cplinu) { | ||
for (var _ch3 = 0; _ch3 < bsi.nfchans; _ch3++) { | ||
if (audblk.chincpl[_ch3]) { | ||
audblk.cplcoe[_ch3] = stream.read(1); | ||
if (audblk.cplcoe[_ch3]) { | ||
audblk.mstrcplco[_ch3] = stream.read(2); | ||
for (var _ch4 = 0; _ch4 < bsi.nfchans; _ch4++) { | ||
if (audblk.chincpl[_ch4]) { | ||
audblk.cplcoe[_ch4] = stream.read(1); | ||
if (audblk.cplcoe[_ch4]) { | ||
audblk.mstrcplco[_ch4] = stream.read(2); | ||
audblk.cplcoexp[_ch3] = new Array(audblk.ncplbnd); | ||
audblk.cplcomant[_ch3] = new Array(audblk.ncplbnd); | ||
audblk.cplco[_ch3] = new Array(audblk.ncplbnd); | ||
audblk.cplcoexp[_ch4] = new Array(audblk.ncplbnd); | ||
audblk.cplcomant[_ch4] = new Array(audblk.ncplbnd); | ||
audblk.cplco[_ch4] = new Array(audblk.ncplbnd); | ||
for (var _bnd2 = 0; _bnd2 < audblk.ncplbnd; _bnd2++) { | ||
audblk.cplcoexp[_ch3][_bnd2] = stream.read(4); | ||
audblk.cplcomant[_ch3][_bnd2] = stream.read(4); | ||
audblk.cplcoexp[_ch4][_bnd2] = stream.read(4); | ||
audblk.cplcomant[_ch4][_bnd2] = stream.read(4); | ||
} | ||
@@ -108,10 +112,10 @@ } | ||
if (!audblk.cplbndstrc[sbnd]) { | ||
if (audblk.cplcoexp[_ch3][_bnd] === 15) { | ||
cplco = audblk.cplcomant[_ch3][_bnd] / 16; | ||
if (audblk.cplcoexp[_ch4][_bnd] === 15) { | ||
cplco = audblk.cplcomant[_ch4][_bnd] / 16; | ||
} else { | ||
cplco = (audblk.cplcomant[_ch3][_bnd] + 16) / 32; | ||
cplco = (audblk.cplcomant[_ch4][_bnd] + 16) / 32; | ||
} | ||
cplco /= Math.pow(2, audblk.cplcoexp[_ch3][_bnd] + 3 * audblk.mstrcplco[_ch3]); | ||
cplco /= Math.pow(2, audblk.cplcoexp[_ch4][_bnd] + 3 * audblk.mstrcplco[_ch4]); | ||
} | ||
audblk.cplco[_ch3][sbnd] = cplco; | ||
audblk.cplco[_ch4][sbnd] = cplco; | ||
} | ||
@@ -154,4 +158,4 @@ } | ||
for (var _ch4 = 0; _ch4 < bsi.nfchans; _ch4++) { | ||
audblk.chexpstr[_ch4] = stream.read(2); | ||
for (var _ch5 = 0; _ch5 < bsi.nfchans; _ch5++) { | ||
audblk.chexpstr[_ch5] = stream.read(2); | ||
} | ||
@@ -163,6 +167,6 @@ | ||
for (var _ch5 = 0; _ch5 < bsi.nfchans; _ch5++) { | ||
if (audblk.chexpstr[_ch5] !== _constants.EXP_REUSE) { | ||
if (!audblk.chincpl[_ch5]) { | ||
audblk.chbwcod[_ch5] = stream.read(6); | ||
for (var _ch6 = 0; _ch6 < bsi.nfchans; _ch6++) { | ||
if (audblk.chexpstr[_ch6] !== _constants.EXP_REUSE) { | ||
if (!audblk.chincpl[_ch6]) { | ||
audblk.chbwcod[_ch6] = stream.read(6); | ||
} | ||
@@ -202,33 +206,33 @@ } | ||
// Exponents for full bandwidth channels | ||
for (var _ch6 = 0; _ch6 < bsi.nfchans; _ch6++) { | ||
if (audblk.chexpstr[_ch6] !== _constants.EXP_REUSE) { | ||
audblk.strtmant[_ch6] = 0; | ||
if (audblk.chincpl[_ch6]) { | ||
audblk.endmant[_ch6] = 37 + 12 * audblk.cplbegf; | ||
for (var _ch7 = 0; _ch7 < bsi.nfchans; _ch7++) { | ||
if (audblk.chexpstr[_ch7] !== _constants.EXP_REUSE) { | ||
audblk.strtmant[_ch7] = 0; | ||
if (audblk.chincpl[_ch7]) { | ||
audblk.endmant[_ch7] = 37 + 12 * audblk.cplbegf; | ||
} else { | ||
audblk.endmant[_ch6] = 37 + 3 * (audblk.chbwcod[_ch6] + 12); | ||
audblk.endmant[_ch7] = 37 + 3 * (audblk.chbwcod[_ch7] + 12); | ||
} | ||
switch (audblk.chexpstr[_ch6]) { | ||
switch (audblk.chexpstr[_ch7]) { | ||
case _constants.EXP_D15: | ||
audblk.nchgrps[_ch6] = (audblk.endmant[_ch6] - 1) / 3 >> 0; | ||
audblk.nchgrps[_ch7] = (audblk.endmant[_ch7] - 1) / 3 >> 0; | ||
break; | ||
case _constants.EXP_D25: | ||
audblk.nchgrps[_ch6] = (audblk.endmant[_ch6] + 2) / 6 >> 0; | ||
audblk.nchgrps[_ch7] = (audblk.endmant[_ch7] + 2) / 6 >> 0; | ||
break; | ||
case _constants.EXP_D45: | ||
audblk.nchgrps[_ch6] = (audblk.endmant[_ch6] + 8) / 12 >> 0; | ||
audblk.nchgrps[_ch7] = (audblk.endmant[_ch7] + 8) / 12 >> 0; | ||
break; | ||
} | ||
audblk.exps[_ch6] = new Array(audblk.nchgrps[_ch6]); | ||
audblk.exps[_ch7] = new Array(audblk.nchgrps[_ch7]); | ||
var absexps = stream.read(4); | ||
for (var _grp = 0; _grp < audblk.nchgrps[_ch6]; _grp++) { | ||
audblk.exps[_ch6][_grp] = stream.read(7); | ||
for (var _grp = 0; _grp < audblk.nchgrps[_ch7]; _grp++) { | ||
audblk.exps[_ch7][_grp] = stream.read(7); | ||
} | ||
// Unpack exponent groups | ||
audblk.exps[_ch6] = (0, _exponents.unpackExponents)(audblk.exps[_ch6], absexps, _constants.EXPONENT_GROUP_SIZE[audblk.chexpstr[_ch6]], 1); | ||
audblk.exps[_ch7] = (0, _exponents.unpackExponents)(audblk.exps[_ch7], absexps, _constants.EXPONENT_GROUP_SIZE[audblk.chexpstr[_ch7]], 1); | ||
audblk.gainrng[_ch6] = stream.read(2); | ||
audblk.gainrng[_ch7] = stream.read(2); | ||
} | ||
@@ -274,5 +278,5 @@ } | ||
audblk.fgaincod = new Array(bsi.nfchans); | ||
for (var _ch7 = 0; _ch7 < bsi.nfchans; _ch7++) { | ||
audblk.fsnroffst[_ch7] = stream.read(4); | ||
audblk.fgaincod[_ch7] = stream.read(3); | ||
for (var _ch8 = 0; _ch8 < bsi.nfchans; _ch8++) { | ||
audblk.fsnroffst[_ch8] = stream.read(4); | ||
audblk.fgaincod[_ch8] = stream.read(3); | ||
} | ||
@@ -300,4 +304,4 @@ | ||
for (var _ch8 = 0; _ch8 < bsi.nfchans; _ch8++) { | ||
audblk.deltbae[_ch8] = stream.read(2); | ||
for (var _ch9 = 0; _ch9 < bsi.nfchans; _ch9++) { | ||
audblk.deltbae[_ch9] = stream.read(2); | ||
} | ||
@@ -324,13 +328,13 @@ | ||
audblk.deltnseg = new Array(bsi.nfchans); | ||
for (var _ch9 = 0; _ch9 < bsi.nfchans; _ch9++) { | ||
if (audblk.deltbae[_ch9] === 0x1) { | ||
audblk.deltnseg[_ch9] = stream.read(2); | ||
for (var _ch10 = 0; _ch10 < bsi.nfchans; _ch10++) { | ||
if (audblk.deltbae[_ch10] === 0x1) { | ||
audblk.deltnseg[_ch10] = stream.read(2); | ||
audblk.deltoffst[_ch9] = new Array(audblk.deltnseg[_ch9] + 1); | ||
audblk.deltlen[_ch9] = new Array(audblk.deltnseg[_ch9] + 1); | ||
audblk.deltba[_ch9] = new Array(audblk.deltnseg[_ch9] + 1); | ||
for (var _seg = 0; _seg <= audblk.deltnseg[_ch9]; _seg++) { | ||
audblk.deltoffst[_ch9][_seg] = stream.read(5); | ||
audblk.deltlen[_ch9][_seg] = stream.read(4); | ||
audblk.deltba[_ch9][_seg] = stream.read(3); | ||
audblk.deltoffst[_ch10] = new Array(audblk.deltnseg[_ch10] + 1); | ||
audblk.deltlen[_ch10] = new Array(audblk.deltnseg[_ch10] + 1); | ||
audblk.deltba[_ch10] = new Array(audblk.deltnseg[_ch10] + 1); | ||
for (var _seg = 0; _seg <= audblk.deltnseg[_ch10]; _seg++) { | ||
audblk.deltoffst[_ch10][_seg] = stream.read(5); | ||
audblk.deltlen[_ch10][_seg] = stream.read(4); | ||
audblk.deltba[_ch10][_seg] = stream.read(3); | ||
} | ||
@@ -341,4 +345,4 @@ } | ||
audblk.cpldeltbae = 2; | ||
for (var _ch10 = 0; _ch10 < bsi.nfchans; _ch10++) { | ||
audblk.deltbae[_ch10] = 2; | ||
for (var _ch11 = 0; _ch11 < bsi.nfchans; _ch11++) { | ||
audblk.deltbae[_ch11] = 2; | ||
} | ||
@@ -354,13 +358,13 @@ } | ||
audblk.baps = new Array(bsi.nfchans); | ||
for (var _ch11 = 0; _ch11 < bsi.nfchans; _ch11++) { | ||
for (var _ch12 = 0; _ch12 < bsi.nfchans; _ch12++) { | ||
var delt = null; | ||
if (audblk.deltbae[_ch11] == 0 || audblk.deltbae[_ch11] == 1) { | ||
if (audblk.deltbae[_ch12] == 0 || audblk.deltbae[_ch12] == 1) { | ||
delt = { | ||
nseg: audblk.deltnseg[_ch11], | ||
offst: audblk.deltoffst[_ch11], | ||
ba: audblk.deltba[_ch11], | ||
len: audblk.deltlen[_ch11] | ||
nseg: audblk.deltnseg[_ch12], | ||
offst: audblk.deltoffst[_ch12], | ||
ba: audblk.deltba[_ch12], | ||
len: audblk.deltlen[_ch12] | ||
}; | ||
} | ||
audblk.baps[_ch11] = (0, _bitallocation.bitAllocation)(bsi, audblk, audblk.strtmant[_ch11], audblk.endmant[_ch11], audblk.exps[_ch11], _tables.FAST_GAIN[audblk.fgaincod[_ch11]], (audblk.csnroffst - 15 << 4) + audblk.fsnroffst[_ch11] << 2, 0, 0, delt); | ||
audblk.baps[_ch12] = (0, _bitallocation.bitAllocation)(bsi, audblk, audblk.strtmant[_ch12], audblk.endmant[_ch12], audblk.exps[_ch12], _tables.FAST_GAIN[audblk.fgaincod[_ch12]], (audblk.csnroffst - 15 << 4) + audblk.fsnroffst[_ch12] << 2, 0, 0, delt); | ||
} | ||
@@ -395,14 +399,14 @@ if (audblk.cplinu) { | ||
audblk.chmant = new Array(bsi.nfchans); | ||
for (var _ch12 = 0; _ch12 < bsi.nfchans; _ch12++) { | ||
audblk.chmant[_ch12] = new Array(256); | ||
audblk.chmant[_ch12].fill(0); | ||
for (var bin = 0; bin < audblk.endmant[_ch12]; bin++) { | ||
if (audblk.baps[_ch12][bin] != 0 || !audblk.dithflag[_ch12]) { | ||
audblk.chmant[_ch12][bin] = mantissas.get(audblk.baps[_ch12][bin]) * Math.pow(2, -audblk.exps[_ch12][bin]); | ||
for (var _ch13 = 0; _ch13 < bsi.nfchans; _ch13++) { | ||
audblk.chmant[_ch13] = new Array(256); | ||
audblk.chmant[_ch13].fill(0); | ||
for (var bin = 0; bin < audblk.endmant[_ch13]; bin++) { | ||
if (audblk.baps[_ch13][bin] != 0 || !audblk.dithflag[_ch13]) { | ||
audblk.chmant[_ch13][bin] = mantissas.get(audblk.baps[_ch13][bin]) * Math.pow(2, -audblk.exps[_ch13][bin]); | ||
} else { | ||
audblk.chmant[_ch12][bin] = (0, _mantissa.getDitherMantissa)() * Math.pow(2, -audblk.exps[_ch12][bin]); | ||
audblk.chmant[_ch13][bin] = (0, _mantissa.getDitherMantissa)() * Math.pow(2, -audblk.exps[_ch13][bin]); | ||
} | ||
} | ||
if (audblk.cplinu && audblk.chincpl[_ch12] && !audblk.got_cplchan) { | ||
if (audblk.cplinu && audblk.chincpl[_ch13] && !audblk.got_cplchan) { | ||
audblk.ncplmant = 12 * audblk.ncplsubnd; | ||
@@ -427,8 +431,8 @@ audblk.cplmant = new Array(audblk.ncplmant); | ||
if (audblk.cplinu) { | ||
for (var _ch13 = 0; _ch13 < bsi.nfchans; _ch13++) { | ||
if (audblk.chincpl[_ch13]) { | ||
for (var _ch14 = 0; _ch14 < bsi.nfchans; _ch14++) { | ||
if (audblk.chincpl[_ch14]) { | ||
for (var _sbnd = 0; _sbnd < audblk.ncplsubnd; _sbnd++) { | ||
for (var _bin3 = 0; _bin3 < 12; _bin3++) { | ||
var mantissa = void 0; | ||
if (audblk.cplmant[_sbnd * 12 + _bin3] == 0 && audblk.dithflag[_ch13]) { | ||
if (audblk.cplmant[_sbnd * 12 + _bin3] == 0 && audblk.dithflag[_ch14]) { | ||
mantissa = (0, _mantissa.getDitherMantissa)() * Math.pow(2, -audblk.cplexps[_sbnd * 12 + _bin3]); | ||
@@ -438,3 +442,3 @@ } else { | ||
} | ||
audblk.chmant[_ch13][(_sbnd + audblk.cplbegf) * 12 + _bin3 + 37] = mantissa * audblk.cplco[_ch13][_sbnd] * 8; | ||
audblk.chmant[_ch14][(_sbnd + audblk.cplbegf) * 12 + _bin3 + 37] = mantissa * audblk.cplco[_ch14][_sbnd] * 8; | ||
} | ||
@@ -462,7 +466,7 @@ } | ||
for (var _ch14 = 0; _ch14 < bsi.nfchans; _ch14++) { | ||
if (audblk.blksw[_ch14]) { | ||
imdct[_ch14].process128(audblk.chmant[_ch14], samples[_ch14], blk * 256); | ||
for (var _ch15 = 0; _ch15 < bsi.nfchans; _ch15++) { | ||
if (audblk.blksw[_ch15]) { | ||
imdct[_ch15].process128(audblk.chmant[_ch15], samples[_ch15], blk * 256); | ||
} else { | ||
imdct[_ch14].process256(audblk.chmant[_ch14], samples[_ch14], blk * 256); | ||
imdct[_ch15].process256(audblk.chmant[_ch15], samples[_ch15], blk * 256); | ||
} | ||
@@ -469,0 +473,0 @@ } |
@@ -53,2 +53,4 @@ 'use strict'; | ||
_this.pcm = false; | ||
_this.samples = null; | ||
_this.imdct = null; | ||
@@ -78,8 +80,16 @@ _this.pcm = pcm; | ||
// Intialize arrays | ||
var samples = new Array(bsi.nfchans); | ||
var imdct = new Array(bsi.nfchans); | ||
for (var i = 0; i < bsi.nfchans; i++) { | ||
samples[i] = new Array(_constants.AUDIO_SAMPLES); | ||
imdct[i] = new _mdct.IMDCT(); | ||
// IMDCT instances must be preserved across chunks for proper decoding. | ||
// Otherwise, overlapping samples will be lost. | ||
if (!this.samples) { | ||
this.samples = new Array(bsi.nfchans); | ||
for (var i = 0; i < bsi.nfchans; i++) { | ||
this.samples[i] = new Array(_constants.AUDIO_SAMPLES); | ||
} | ||
} | ||
if (!this.imdct) { | ||
this.imdct = new Array(bsi.nfchans); | ||
for (var _i = 0; _i < bsi.nfchans; _i++) { | ||
this.imdct[_i] = new _mdct.IMDCT(); | ||
} | ||
} | ||
@@ -89,7 +99,7 @@ // Audio Blocks | ||
for (var blk = 0; blk < 6; blk++) { | ||
(0, _audioblock.readAudioBlock)(this.bitstream, bsi, samples, imdct, audblk, blk); | ||
(0, _audioblock.readAudioBlock)(this.bitstream, bsi, this.samples, this.imdct, audblk, blk); | ||
} | ||
// Downmixing | ||
(0, _downmix.downmix)(bsi, samples); | ||
(0, _downmix.downmix)(bsi, this.samples); | ||
@@ -104,10 +114,10 @@ // Skip auxiliary data | ||
var sample = void 0; | ||
for (var _i = 0; _i < _constants.AUDIO_SAMPLES; _i++) { | ||
sample = samples[0][_i] * 65535; | ||
sampleBytes[_i * 4] = sample & 0xff; | ||
sampleBytes[_i * 4 + 1] = sample >> 8; | ||
for (var _i2 = 0; _i2 < _constants.AUDIO_SAMPLES; _i2++) { | ||
sample = this.samples[0][_i2] * 65535; | ||
sampleBytes[_i2 * 4] = sample & 0xff; | ||
sampleBytes[_i2 * 4 + 1] = sample >> 8; | ||
sample = samples[1][_i] * 65535; | ||
sampleBytes[_i * 4 + 2] = sample & 0xff; | ||
sampleBytes[_i * 4 + 3] = sample >> 8; | ||
sample = this.samples[1][_i2] * 65535; | ||
sampleBytes[_i2 * 4 + 2] = sample & 0xff; | ||
sampleBytes[_i2 * 4 + 3] = sample >> 8; | ||
} | ||
@@ -120,6 +130,6 @@ | ||
var _sample = void 0; | ||
for (var _i2 = 0; _i2 < _constants.AUDIO_SAMPLES; _i2++) { | ||
for (var _i3 = 0; _i3 < _constants.AUDIO_SAMPLES; _i3++) { | ||
for (var ch = 0; ch < CHANNELS; ch++) { | ||
_sample = samples[ch][_i2] * 65535; | ||
result[ch + _i2 * 2] = _sample; | ||
_sample = this.samples[ch][_i3] * 65535; | ||
result[ch + _i3 * 2] = _sample; | ||
} | ||
@@ -126,0 +136,0 @@ } |
{ | ||
"name": "ac3.js", | ||
"description": "JavaScript AC-3 (ATSC A/52) decoder", | ||
"version": "0.2.2", | ||
"version": "0.2.3", | ||
"license": "MIT", | ||
@@ -6,0 +6,0 @@ "contributors": [ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
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
472195
2556