Skip to content

Commit dc5b376

Browse files
authored
Merge pull request #1212 from Borewit/fix-uncompressed-aiff-c
Fix parsing uncompressed AIFF-C audio file
2 parents 1704636 + 9661700 commit dc5b376

File tree

4 files changed

+34
-5
lines changed

4 files changed

+34
-5
lines changed

lib/aiff/AiffParser.ts

+13-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,18 @@ import * as iff from '../iff';
1111

1212
const debug = initDebug('music-metadata:parser:aiff');
1313

14+
const compressionTypes = {
15+
NONE: 'not compressed PCM Apple Computer',
16+
sowt: 'PCM (byte swapped)',
17+
fl32: '32-bit floating point IEEE 32-bit float',
18+
fl64: '64-bit floating point IEEE 64-bit float Apple Computer',
19+
alaw: 'ALaw 2:1 8-bit ITU-T G.711 A-law',
20+
ulaw: 'µLaw 2:1 8-bit ITU-T G.711 µ-law Apple Computer',
21+
ULAW: 'CCITT G.711 u-law 8-bit ITU-T G.711 µ-law',
22+
ALAW: 'CCITT G.711 A-law 8-bit ITU-T G.711 A-law',
23+
FL32: 'Float 32 IEEE 32-bit float '
24+
};
25+
1426
/**
1527
* AIFF - Audio Interchange File Format
1628
*
@@ -75,7 +87,7 @@ export class AIFFParser extends BasicParser {
7587
this.metadata.setFormat('numberOfChannels', common.numChannels);
7688
this.metadata.setFormat('numberOfSamples', common.numSampleFrames);
7789
this.metadata.setFormat('duration', common.numSampleFrames / common.sampleRate);
78-
this.metadata.setFormat('codec', common.compressionName);
90+
this.metadata.setFormat('codec', common.compressionName ?? compressionTypes[common.compressionType]);
7991
return header.chunkSize;
8092

8193
case 'ID3 ': // ID3-meta-data

lib/aiff/AiffToken.ts

+8-4
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,15 @@ export class Common implements IGetToken<ICommon> {
4545
res.compressionType = FourCcToken.get(buf, off + 18);
4646
if (this.len > 22) {
4747
const strLen = buf.readInt8(off + 22);
48-
const padding = (strLen + 1) % 2;
49-
if (23 + strLen + padding === this.len) {
50-
res.compressionName = new Token.StringType(strLen, 'binary').get(buf, off + 23);
48+
if (strLen > 0) {
49+
const padding = (strLen + 1) % 2;
50+
if (23 + strLen + padding === this.len) {
51+
res.compressionName = new Token.StringType(strLen, 'binary').get(buf, off + 23);
52+
} else {
53+
throw new Error('Illegal pstring length');
54+
}
5155
} else {
52-
throw new Error('Illegal pstring length');
56+
res.compressionName = undefined;
5357
}
5458
}
5559
} else {

test/samples/aiff/hit-broken.aif

257 KB
Binary file not shown.

test/test-file-aiff.ts

+13
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,19 @@ describe('Parse AIFF (Audio Interchange File Format)', () => {
4646
checkFormat(metadata.format, 'Alaw 2:1', 8000, 2, 16, 23493);
4747
});
4848
});
49+
50+
// Issue: https://github.com/Borewit/music-metadata/issues/1211
51+
it('Uncompressed AIFC', async () => {
52+
53+
const filePath = path.join(aiffSamplePath, 'hit-broken.aif');
54+
55+
const {format} = await mm.parseFile(filePath);
56+
57+
assert.strictEqual(format.container, 'AIFF-C', 'format.container');
58+
assert.strictEqual(format.codec, '32-bit floating point IEEE 32-bit float', 'format.codec');
59+
assert.strictEqual(format.sampleRate, 44100, 'format.sampleRate');
60+
});
61+
4962
});
5063

5164
describe('Parse perverse Files', () => {

0 commit comments

Comments
 (0)