Skip to content

Commit 79230c4

Browse files
committed
Merge pull request #5 from audiocogs/browserify
Switch build system to Browserify
2 parents fef4ab2 + ef3808d commit 79230c4

16 files changed

Lines changed: 2510 additions & 2483 deletions

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/node_modules/
2+
build/

Makefile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
browser: src/*.js
2+
mkdir -p build/
3+
./node_modules/.bin/browserify \
4+
--extension .coffee \
5+
--transform browserify-shim \
6+
--debug \
7+
. \
8+
| ./node_modules/.bin/exorcist build/aac.js.map > build/aac.js
9+
10+
clean:
11+
rm -rf build/

README.md

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,17 @@ AAC.js was written by [@devongovett](http://github.com/devongovett) of [Audiocog
2121

2222
## Building
2323

24-
Currently, the [importer](https://github.com/devongovett/importer) module is used to build aac.js. You can run
25-
the development server on port `3030` by first installing `importer` with npm, and then running it like this:
24+
We use [browserify](https://github.com/substack/node-browserify) to build AAC.js. You can download a
25+
prebuilt version from the Github [releases](https://github.com/audiocogs/aac.js/releases) page.
26+
To build AAC.js for the browser yourself, use the following commands:
2627

27-
npm install importer -g
28-
importer src/decoder.js -p 3030
28+
npm install
29+
make browser
2930

30-
You can also build a static version like this:
31+
This will place a built `aac.js` file, as well as a source map in the `build/` directory.
3132

32-
importer src/decoder.js build.js
33-
34-
aac.js depends on [Aurora.js](https://github.com/audiocogs/aurora.js), our audio codec framework. You will need
35-
to include either a prebuilt version of Aurora.js, or start another `importer` development server for Aurora before
36-
aac.js will work. You can use the [test.html](https://github.com/audiocogs/aurora.js/blob/master/src/test.html) file
37-
in the Aurora.js repo as an example of how to use the APIs to play back audio files. Just include aac.js on that
38-
page as well in order to add support for AAC files.
33+
AAC.js depends on [Aurora.js](https://github.com/audiocogs/aurora.js), our audio codec framework.
34+
For detailed information on how to use Aurora.js, check out the [documentation](https://github.com/audiocogs/aurora.js/wiki).
3935

4036
## Features
4137

package.json

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
"name": "aac",
3+
"version": "0.1.0",
4+
"description": "An AAC decoder for Aurora.js",
5+
"main": "src/decoder.js",
6+
"peerDependencies": {
7+
"av": "~0.4.0"
8+
},
9+
"devDependencies": {
10+
"exorcist": "^0.1.6",
11+
"browserify": "^4.1.10",
12+
"browserify-shim": "^3.5.0"
13+
},
14+
"browserify": {
15+
"transform": ["browserify-shim"]
16+
},
17+
"browserify-shim": {
18+
"av": "global:AV"
19+
},
20+
"repository": {
21+
"type": "git",
22+
"url": "git://github.com/audiocogs/aac.js"
23+
},
24+
"keywords": [
25+
"audio",
26+
"av",
27+
"aurora.js",
28+
"aurora",
29+
"decode"
30+
],
31+
"author": "Devon Govett <devongovett@gmail.com>",
32+
"license": "LGPL",
33+
"bugs": {
34+
"url": "https://github.com/audiocogs/aac.js/issues"
35+
},
36+
"homepage": "https://github.com/audiocogs/aac.js"
37+
}

src/adts_demuxer.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
var AV = require('av');
2+
var tables = require('./tables');
3+
14
var ADTSDemuxer = AV.Demuxer.extend(function() {
25
AV.Demuxer.register(this);
36

@@ -55,7 +58,7 @@ var ADTSDemuxer = AV.Demuxer.extend(function() {
5558

5659
this.emit('format', {
5760
formatID: 'aac ',
58-
sampleRate: SAMPLE_RATES[header.samplingIndex],
61+
sampleRate: tables.SAMPLE_RATES[header.samplingIndex],
5962
channelsPerFrame: header.chanConfig,
6063
bitsPerChannel: 16
6164
});

src/cce.js

Lines changed: 128 additions & 129 deletions
Original file line numberDiff line numberDiff line change
@@ -18,145 +18,144 @@
1818
* If not, see <http://www.gnu.org/licenses/>.
1919
*/
2020

21-
var CCEElement = (function() {
22-
23-
// Channel Coupling Element
24-
function CCEElement(config) {
25-
this.ics = new ICStream(config);
26-
this.channelPair = new Array(8);
27-
this.idSelect = new Int32Array(8);
28-
this.chSelect = new Int32Array(8);
29-
this.gain = new Array(16);
30-
}
31-
32-
CCEElement.BEFORE_TNS = 0;
33-
CCEElement.AFTER_TNS = 1;
34-
CCEElement.AFTER_IMDCT = 2;
35-
36-
const CCE_SCALE = new Float32Array([
37-
1.09050773266525765921,
38-
1.18920711500272106672,
39-
1.4142135623730950488016887,
40-
2.0
41-
]);
42-
43-
CCEElement.prototype = {
44-
decode: function(stream, config) {
45-
var channelPair = this.channelPair,
46-
idSelect = this.idSelect,
47-
chSelect = this.chSelect;
48-
49-
this.couplingPoint = 2 * stream.read(1);
50-
this.coupledCount = stream.read(3);
51-
52-
var gainCount = 0;
53-
for (var i = 0; i <= this.coupledCount; i++) {
54-
gainCount++;
55-
channelPair[i] = stream.read(1);
56-
idSelect[i] = stream.read(4);
57-
58-
if (channelPair[i]) {
59-
chSelect[i] = stream.read(2);
60-
if (chSelect[i] === 3)
61-
gainCount++;
62-
63-
} else {
64-
chSelect[i] = 2;
65-
}
21+
var ICStream = require('./ics');
22+
var Huffman = require('./huffman');
23+
24+
// Channel Coupling Element
25+
function CCEElement(config) {
26+
this.ics = new ICStream(config);
27+
this.channelPair = new Array(8);
28+
this.idSelect = new Int32Array(8);
29+
this.chSelect = new Int32Array(8);
30+
this.gain = new Array(16);
31+
}
32+
33+
CCEElement.BEFORE_TNS = 0;
34+
CCEElement.AFTER_TNS = 1;
35+
CCEElement.AFTER_IMDCT = 2;
36+
37+
const CCE_SCALE = new Float32Array([
38+
1.09050773266525765921,
39+
1.18920711500272106672,
40+
1.4142135623730950488016887,
41+
2.0
42+
]);
43+
44+
CCEElement.prototype = {
45+
decode: function(stream, config) {
46+
var channelPair = this.channelPair,
47+
idSelect = this.idSelect,
48+
chSelect = this.chSelect;
49+
50+
this.couplingPoint = 2 * stream.read(1);
51+
this.coupledCount = stream.read(3);
52+
53+
var gainCount = 0;
54+
for (var i = 0; i <= this.coupledCount; i++) {
55+
gainCount++;
56+
channelPair[i] = stream.read(1);
57+
idSelect[i] = stream.read(4);
58+
59+
if (channelPair[i]) {
60+
chSelect[i] = stream.read(2);
61+
if (chSelect[i] === 3)
62+
gainCount++;
63+
64+
} else {
65+
chSelect[i] = 2;
6666
}
67-
68-
this.couplingPoint += stream.read(1);
69-
this.couplingPoint |= (this.couplingPoint >>> 1);
70-
71-
var sign = stream.read(1),
72-
scale = CCE_SCALE[stream.read(2)];
73-
74-
this.ics.decode(stream, config, false);
75-
76-
var groupCount = this.ics.info.groupCount,
77-
maxSFB = this.ics.info.maxSFB,
78-
bandTypes = this.ics.bandTypes;
79-
80-
for (var i = 0; i < gainCount; i++) {
81-
var idx = 0,
82-
cge = 1,
83-
gain = 0,
84-
gainCache = 1;
85-
86-
if (i > 0) {
87-
cge = this.couplingPoint === CCEElement.AFTER_IMDCT ? 1 : stream.read(1);
88-
gain = cge ? Huffman.decodeScaleFactor(stream) - 60 : 0;
89-
gainCache = Math.pow(scale, -gain);
90-
}
91-
92-
var gain_i = this.gain[i] = new Float32Array(120);
93-
94-
if (this.couplingPoint === CCEElement.AFTER_IMDCT) {
95-
gain_i[0] = gainCache;
96-
} else {
97-
for (var g = 0; g < groupCount; g++) {
98-
for (var sfb = 0; sfb < maxSFB; sfb++) {
99-
if (bandTypes[idx] !== ICStream.ZERO_BT) {
100-
if (cge === 0) {
101-
var t = Huffman.decodeScaleFactor(stream) - 60;
102-
if (t !== 0) {
103-
var s = 1;
104-
t = gain += t;
105-
if (sign) {
106-
s -= 2 * (t * 0x1);
107-
t >>>= 1;
108-
}
109-
gainCache = Math.pow(scale, -t) * s;
67+
}
68+
69+
this.couplingPoint += stream.read(1);
70+
this.couplingPoint |= (this.couplingPoint >>> 1);
71+
72+
var sign = stream.read(1),
73+
scale = CCE_SCALE[stream.read(2)];
74+
75+
this.ics.decode(stream, config, false);
76+
77+
var groupCount = this.ics.info.groupCount,
78+
maxSFB = this.ics.info.maxSFB,
79+
bandTypes = this.ics.bandTypes;
80+
81+
for (var i = 0; i < gainCount; i++) {
82+
var idx = 0,
83+
cge = 1,
84+
gain = 0,
85+
gainCache = 1;
86+
87+
if (i > 0) {
88+
cge = this.couplingPoint === CCEElement.AFTER_IMDCT ? 1 : stream.read(1);
89+
gain = cge ? Huffman.decodeScaleFactor(stream) - 60 : 0;
90+
gainCache = Math.pow(scale, -gain);
91+
}
92+
93+
var gain_i = this.gain[i] = new Float32Array(120);
94+
95+
if (this.couplingPoint === CCEElement.AFTER_IMDCT) {
96+
gain_i[0] = gainCache;
97+
} else {
98+
for (var g = 0; g < groupCount; g++) {
99+
for (var sfb = 0; sfb < maxSFB; sfb++) {
100+
if (bandTypes[idx] !== ICStream.ZERO_BT) {
101+
if (cge === 0) {
102+
var t = Huffman.decodeScaleFactor(stream) - 60;
103+
if (t !== 0) {
104+
var s = 1;
105+
t = gain += t;
106+
if (sign) {
107+
s -= 2 * (t * 0x1);
108+
t >>>= 1;
110109
}
110+
gainCache = Math.pow(scale, -t) * s;
111111
}
112-
gain_i[idx++] = gainCache;
113112
}
113+
gain_i[idx++] = gainCache;
114114
}
115115
}
116116
}
117117
}
118-
},
119-
120-
applyIndependentCoupling: function(index, data) {
121-
var gain = this.gain[index][0],
122-
iqData = this.ics.data;
123-
124-
for (var i = 0; i < data.length; i++) {
125-
data[i] += gain * iqData[i];
126-
}
127-
},
128-
129-
applyDependentCoupling: function(index, data) {
130-
var info = this.ics.info,
131-
swbOffsets = info.swbOffsets,
132-
groupCount = info.groupCount,
133-
maxSFB = info.maxSFB,
134-
bandTypes = this.ics.bandTypes,
135-
iqData = this.ics.data;
136-
137-
var idx = 0,
138-
offset = 0,
139-
gains = this.gain[index];
140-
141-
for (var g = 0; g < groupCount; g++) {
142-
var len = info.groupLength[g];
143-
144-
for (var sfb = 0; sfb < maxSFB; sfb++, idx++) {
145-
if (bandTypes[idx] !== ICStream.ZERO_BT) {
146-
var gain = gains[idx];
147-
for (var group = 0; group < len; group++) {
148-
for (var k = swbOffsets[sfb]; k < swbOffsets[swb + 1]; k++) {
149-
data[offset + group * 128 + k] += gain * iqData[offset + group * 128 + k];
150-
}
118+
}
119+
},
120+
121+
applyIndependentCoupling: function(index, data) {
122+
var gain = this.gain[index][0],
123+
iqData = this.ics.data;
124+
125+
for (var i = 0; i < data.length; i++) {
126+
data[i] += gain * iqData[i];
127+
}
128+
},
129+
130+
applyDependentCoupling: function(index, data) {
131+
var info = this.ics.info,
132+
swbOffsets = info.swbOffsets,
133+
groupCount = info.groupCount,
134+
maxSFB = info.maxSFB,
135+
bandTypes = this.ics.bandTypes,
136+
iqData = this.ics.data;
137+
138+
var idx = 0,
139+
offset = 0,
140+
gains = this.gain[index];
141+
142+
for (var g = 0; g < groupCount; g++) {
143+
var len = info.groupLength[g];
144+
145+
for (var sfb = 0; sfb < maxSFB; sfb++, idx++) {
146+
if (bandTypes[idx] !== ICStream.ZERO_BT) {
147+
var gain = gains[idx];
148+
for (var group = 0; group < len; group++) {
149+
for (var k = swbOffsets[sfb]; k < swbOffsets[swb + 1]; k++) {
150+
data[offset + group * 128 + k] += gain * iqData[offset + group * 128 + k];
151151
}
152152
}
153153
}
154-
155-
offset += len * 128;
156154
}
155+
156+
offset += len * 128;
157157
}
158-
};
159-
160-
return CCEElement;
161-
162-
})();
158+
}
159+
};
160+
161+
module.exports = CCEElement;

0 commit comments

Comments
 (0)