@audio/decode-aiff 1.3.0 → 1.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/decode-aiff.js +9 -5
- package/package.json +1 -1
package/decode-aiff.js
CHANGED
|
@@ -292,8 +292,12 @@ function asr(x, n) {
|
|
|
292
292
|
}
|
|
293
293
|
|
|
294
294
|
function decodeGSM(b, ssndOff, ssndSize, nCh, nFrames, sr) {
|
|
295
|
-
let
|
|
296
|
-
|
|
295
|
+
let blocks = Math.floor(Math.min(ssndSize, b.length - ssndOff) / 33)
|
|
296
|
+
// COMM counts samples (libsndfile, so Audacity), or blocks as Apple counts ima4
|
|
297
|
+
let len = nFrames > blocks ? Math.min(nFrames, blocks * 160) : nFrames * 160
|
|
298
|
+
let totalFrames = Math.ceil(len / 160)
|
|
299
|
+
// the last block's padding past len falls off the array (typed arrays drop out-of-range writes)
|
|
300
|
+
let channelData = [new Float32Array(len)]
|
|
297
301
|
let out = channelData[0], p = ssndOff
|
|
298
302
|
|
|
299
303
|
// Decoder state (mirrors struct gsm_state)
|
|
@@ -372,9 +376,9 @@ function decodeGSM(b, ssndOff, ssndSize, nCh, nFrames, sr) {
|
|
|
372
376
|
return { channelData, sampleRate: sr }
|
|
373
377
|
}
|
|
374
378
|
|
|
375
|
-
// GSM 6.10 bit unpacking: 33 bytes
|
|
379
|
+
// GSM 6.10 bit unpacking: 33 bytes = 0xD signature nibble + 260 bits of LARc[8] and 4 subframes
|
|
376
380
|
function gsmBits(buf, off) {
|
|
377
|
-
let bc =
|
|
381
|
+
let bc = 4
|
|
378
382
|
function r(n) {
|
|
379
383
|
let val = 0
|
|
380
384
|
for (let i = 0; i < n; i++) {
|
|
@@ -441,7 +445,7 @@ function gsmRpeDecode(xmaxc, Mc, xMc, erp) {
|
|
|
441
445
|
// 4.2.16: APCM inverse quantization
|
|
442
446
|
let fac = GSM_FAC[mant]
|
|
443
447
|
let shift = 6 - exp
|
|
444
|
-
let round = shift >
|
|
448
|
+
let round = shift > 0 ? 1 << (shift - 1) : 0 // gsm_asl(1, shift-1)
|
|
445
449
|
|
|
446
450
|
let xMp = new Int32Array(13)
|
|
447
451
|
for (let i = 0; i < 13; i++) {
|