-
-
Notifications
You must be signed in to change notification settings - Fork 88
/
test-file-aiff.ts
124 lines (100 loc) · 4.74 KB
/
test-file-aiff.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
import * as path from 'path';
import {Parsers} from './metadata-parsers';
import {assert} from 'chai';
import {IFormat} from '../src';
const t = assert;
describe('Parse AIFF (Audio Interchange File Format)', () => {
const samplePath = path.join(__dirname, 'samples', 'aiff');
const ULAW = 'ITU-T G.711 mu-law';
function checkFormat(format: IFormat, compressionType: string, sampleRate: number, channels: number, bitsPerSample: number, samples: number) {
const lossless = compressionType === 'PCM';
const dataFormat = lossless ? 'AIFF' : 'AIFF-C';
const duration = samples / format.sampleRate;
t.strictEqual(format.dataformat, dataFormat, `format.dataformat = '${dataFormat}'`);
t.strictEqual(format.lossless, lossless, `format.lossless = ${lossless}`);
t.strictEqual(format.sampleRate, sampleRate, `format.sampleRate = ${sampleRate} kHz`);
t.strictEqual(format.bitsPerSample, bitsPerSample, `format.bitsPerSample = ${bitsPerSample} bit`);
t.strictEqual(format.numberOfChannels, channels, `format.numberOfChannels = ${channels} channels`);
t.strictEqual(format.numberOfSamples, samples, `format.numberOfSamples = ${samples} samples`);
t.strictEqual(format.duration, duration, `format.duration = ${duration} sec.`);
t.strictEqual(format.encoder, compressionType, `format.encoder = ${compressionType}`);
}
describe('Parse AIFF', () => {
Parsers.forEach(parser => {
it(parser.description, () => {
// AIFF file, AIFF file, stereo 8-bit data
// Source: http://www-mmsp.ece.mcgill.ca/Documents/AudioFormats/AIFF/Samples.html
return parser.initParser(path.join(samplePath, 'M1F1-int8-AFsp.aif'), 'audio/aiff', {native: true}).then(metadata => {
checkFormat(metadata.format, 'PCM', 8000, 2, 8, 23493);
});
});
});
});
describe('Parse AIFF-C', () => {
Parsers.forEach(parser => {
it(parser.description, () => {
// AIFF-C file, stereo A-law data (compression type: alaw)
// Source: http://www-mmsp.ece.mcgill.ca/Documents/AudioFormats/AIFF/Samples.html
return parser.initParser(path.join(samplePath, 'M1F1-AlawC-AFsp.aif'), 'audio/aiff', {native: true}).then(metadata => {
checkFormat(metadata.format, 'Alaw 2:1', 8000, 2, 16, 23493);
});
});
});
});
describe('Parse perverse Files', () => {
describe('AIFF-C file (9 samples) with an odd length intermediate chunk', () => {
Parsers.forEach(parser => {
it(parser.description, () => {
return parser.initParser(path.join(samplePath, 'Pmiscck.aif'), 'audio/aiff', {native: true}).then(metadata => {
checkFormat(metadata.format, ULAW, 8000, 1, 16, 9);
});
});
});
});
describe('AIFF-C file with 0 samples (no SSND chunk)', () => {
Parsers.forEach(parser => {
it(parser.description, () => {
return parser.initParser(path.join(samplePath, 'Pnossnd.aif'), 'audio/aiff', {native: true}).then(metadata => {
checkFormat(metadata.format, ULAW, 8000, 1, 16, 0);
});
});
});
});
describe('AIFF-C file (9 samples), SSND chunk has a 5 byte offset to the data and trailing junk in the SSND chunk', () => {
Parsers.forEach(parser => {
it(parser.description, () => {
return parser.initParser(path.join(samplePath, 'Poffset.aif'), 'audio/aiff', {native: true}).then(metadata => {
checkFormat(metadata.format, ULAW, 8000, 1, 16, 9);
});
});
});
});
describe('AIFF-C file (9 samples) with SSND chunk ahead of the COMM chunk', () => {
Parsers.forEach(parser => {
it(parser.description, () => {
return parser.initParser(path.join(samplePath, 'Porder.aif'), 'audio/aiff', {native: true}).then(metadata => {
checkFormat(metadata.format, ULAW, 8000, 1, 16, 9);
});
});
});
});
describe.skip('AIFF-C file (9 samples) with trailing junk after the FORM chunk', () => {
Parsers.forEach(parser => {
it(parser.description, () => {
return parser.initParser(path.join(samplePath, 'Ptjunk.aif'), 'audio/aiff', {native: true}).then(metadata => {
checkFormat(metadata.format, ULAW, 8000, 1, 16, 9);
});
});
});
});
describe('AIFF-C file (9 samples) with COMM chunk declaring 92 bytes (1 byte longer than actual file length), SSND with 9 bytes, missing trailing fill byte', () => {
Parsers.forEach(parser => {
it(parser.description, () => {
return parser.initParser(path.join(samplePath, 'Fnonull.aif'), 'audio/aiff', {native: true}).then(metadata => {
checkFormat(metadata.format, ULAW, 8000, 1, 16, 9);
});
});
});
});
});
});