-
Notifications
You must be signed in to change notification settings - Fork 344
/
Copy pathaudio.js
44 lines (42 loc) · 1.43 KB
/
audio.js
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
var AudioSpecificConfig = function() {};
AudioSpecificConfig.getAudioObjectType = function(stream) {
var tmp = stream.readUint8();
var audioObjectType = tmp >> 3;
if (audioObjectType === 0x1F) {
audioObjectType = 32;
audioObjectType += tmp & 0x7;
tmp = stream.readUint8();
audioObjectType += tmp >> 2;
}
return audioObjectType;
}
AudioSpecificConfig.prototype.parse = function(stream, audioObjectType) {
var tmp = stream.readUint8();
this.samplingFrequencyIndex = tmp >> 4;
if (this.samplingFrequencyIndex === 0xF) {
this.samplingFrequency = (tmp & 0xF) << 20;
this.samplingFrequency += stream.readUint8() << 12;
this.samplingFrequency += stream.readUint8() << 4;
tmp = stream.readUint8();
this.samplingFrequency += (tmp >> 4);
}
this.channelConfiguration = (tmp & 0xF);
this.sbrPresentFlag = -1;
this.psPresentFlag = -1;
if (audioObjectType === 5 || audioObjectType === 29) {
this.extensionAudioObjectType = 5;
this.sbrPresentFlag = 1;
if (audioObjectType === 29) {
this.psPresentFlag = 1;
}
tmp = stream.readUint8();
this.extensionSamplingFrequencyIndex = tmp >> 4;
if (this.extensionSamplingFrequencyIndex === 0xF) {
this.extensionSamplingFrequencyIndex = (tmp & 0xF) << 20;
this.extensionSamplingFrequencyIndex += stream.readUint8() << 12;
this.extensionSamplingFrequencyIndex += stream.readUint8() << 4;
tmp = stream.readUint8();
this.extensionSamplingFrequencyIndex += (tmp >> 4);
}
}
}