@audio/decode-caf 1.4.0 → 1.4.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/README.md CHANGED
@@ -43,6 +43,8 @@ Create a decoder instance.
43
43
  - `ulaw`: G.711 µ-law.
44
44
  - `ima4`: IMA/QuickTime ADPCM.
45
45
 
46
+ Other formats (AAC and ALAC packets, as in Apple Loops) throw `CAF: unsupported format '<id>'`.
47
+
46
48
  ## License
47
49
 
48
50
  [ॐ](https://github.com/krishnized/license/) · [MIT](./LICENSE)
package/decode-caf.js CHANGED
@@ -6,6 +6,7 @@
6
6
  */
7
7
 
8
8
  const EMPTY = Object.freeze({ channelData: [], sampleRate: 0 })
9
+ const FORMATS = new Set(['lpcm', 'alaw', 'ulaw', 'ima4'])
9
10
 
10
11
  // IMA/QuickTime ADPCM tables
11
12
  const IMA_STEP = new Int16Array([7,8,9,10,11,12,13,14,16,17,19,21,23,25,28,31,34,37,41,45,50,55,60,66,73,80,88,97,107,118,130,143,157,173,190,209,230,253,279,307,337,371,408,449,494,544,598,658,724,796,876,963,1060,1166,1282,1411,1552,1707,1878,2066,2272,2499,2749,3024,3327,3660,4026,4428,4871,5358,5894,6484,7132,7845,8630,9493,10442,11487,12635,13899,15289,16818,18500,20350,22385,24623,27086,29794,32767])
@@ -76,6 +77,8 @@ function scanCafHdr(buf) {
76
77
  channelsPerFrame: dv.getUint32(off + 24, false),
77
78
  bitsPerChannel: dv.getUint32(off + 28, false),
78
79
  }
80
+ // compressed formats (aac, alac, ...) carry packets this decoder can't read: say so, don't wait forever
81
+ if (!FORMATS.has(desc.formatID)) throw Error(`CAF: unsupported format '${desc.formatID}'`)
79
82
  } else if (type === 'data') {
80
83
  if (!desc) return null
81
84
  let dataStart = off + 4 // skip editCount
@@ -88,7 +91,7 @@ function scanCafHdr(buf) {
88
91
  if (formatID === 'alaw' || formatID === 'ulaw') frameBytes = ch
89
92
  else if (formatID === 'ima4') frameBytes = desc.bytesPerPacket || 34 * ch // packet = 34 bytes/channel
90
93
  else frameBytes = ch * bytesPerSample
91
- if (!frameBytes) return null
94
+ if (!frameBytes) throw Error(`CAF: invalid ${formatID} description (${ch} channels, ${bits} bits)`)
92
95
  return { ...desc, dataStart, frameBytes, dataSize }
93
96
  }
94
97
  if (size < 0) break
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@audio/decode-caf",
3
- "version": "1.4.0",
3
+ "version": "1.4.1",
4
4
  "description": "Decode CAF (Core Audio Format) audio to PCM samples",
5
5
  "type": "module",
6
6
  "main": "decode-caf.js",