@audio/decode-aac 1.1.0 → 1.1.2
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/README.md +4 -4
- package/decode-aac.js +13 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
# decode-aac
|
|
1
|
+
# @audio/decode-aac
|
|
2
2
|
|
|
3
3
|
Decode AAC/M4A audio to PCM float samples. FAAD2 compiled to WASM — works in Node.js and browsers, no native dependencies.
|
|
4
4
|
|
|
5
5
|
## Install
|
|
6
6
|
|
|
7
7
|
```
|
|
8
|
-
npm i @audio/aac
|
|
8
|
+
npm i @audio/decode-aac
|
|
9
9
|
```
|
|
10
10
|
|
|
11
11
|
## Usage
|
|
12
12
|
|
|
13
13
|
```js
|
|
14
|
-
import decode from '@audio/aac
|
|
14
|
+
import decode from '@audio/decode-aac'
|
|
15
15
|
|
|
16
16
|
// M4A or raw ADTS — auto-detected
|
|
17
17
|
let { channelData, sampleRate } = await decode(uint8array)
|
|
@@ -22,7 +22,7 @@ let { channelData, sampleRate } = await decode(uint8array)
|
|
|
22
22
|
### Streaming
|
|
23
23
|
|
|
24
24
|
```js
|
|
25
|
-
import { decoder } from '@audio/aac
|
|
25
|
+
import { decoder } from '@audio/decode-aac'
|
|
26
26
|
|
|
27
27
|
let dec = await decoder()
|
|
28
28
|
let { channelData, sampleRate } = dec.decode(chunk)
|
package/decode-aac.js
CHANGED
|
@@ -360,11 +360,18 @@ function parseBoxes(buf, start, end, cb) {
|
|
|
360
360
|
} else if (size < 8) {
|
|
361
361
|
break
|
|
362
362
|
}
|
|
363
|
-
if (off + size > end) size = end - off
|
|
364
363
|
|
|
365
364
|
let bodyOff = off + 8
|
|
365
|
+
let truncated = off + size > end
|
|
366
366
|
|
|
367
|
-
|
|
367
|
+
// mdat carries raw frames — partial is fine; callers honour availability
|
|
368
|
+
if (type === 'mdat') {
|
|
369
|
+
cb(type, buf.subarray(bodyOff, truncated ? end : off + size), bodyOff)
|
|
370
|
+
if (truncated) break
|
|
371
|
+
}
|
|
372
|
+
// any other box must be fully present before parsing — partial tables yield garbage
|
|
373
|
+
else if (truncated) break
|
|
374
|
+
else if (type === 'stsd') parseSampleDesc(buf, bodyOff, size - 8, cb)
|
|
368
375
|
else if (CONTAINERS.has(type)) parseBoxes(buf, bodyOff + (type === 'meta' ? 4 : 0), off + size, cb)
|
|
369
376
|
else cb(type, buf.subarray(bodyOff, off + size), bodyOff)
|
|
370
377
|
|
|
@@ -432,8 +439,10 @@ function extractFrames(buf, stsz, stco, stsc) {
|
|
|
432
439
|
}
|
|
433
440
|
let off = stco[ci]
|
|
434
441
|
for (let s = 0; s < spc && si < stsz.length; s++) {
|
|
435
|
-
let sz = stsz[si
|
|
436
|
-
if (off + sz
|
|
442
|
+
let sz = stsz[si]
|
|
443
|
+
if (off + sz > buf.length) return frames // sequential: first missing → rest missing
|
|
444
|
+
frames.push(buf.subarray(off, off + sz))
|
|
445
|
+
si++
|
|
437
446
|
off += sz
|
|
438
447
|
}
|
|
439
448
|
}
|