Skip to content

Commit

Permalink
Merge pull request #5 from audiocogs/browserify
Browse files Browse the repository at this point in the history
Switch build system to Browserify
  • Loading branch information
devongovett committed Jun 17, 2014
2 parents fef4ab2 + ef3808d commit 79230c4
Show file tree
Hide file tree
Showing 16 changed files with 2,510 additions and 2,483 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/node_modules/
build/
11 changes: 11 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
browser: src/*.js
mkdir -p build/
./node_modules/.bin/browserify \
--extension .coffee \
--transform browserify-shim \
--debug \
. \
| ./node_modules/.bin/exorcist build/aac.js.map > build/aac.js

clean:
rm -rf build/
20 changes: 8 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,17 @@ AAC.js was written by [@devongovett](http://github.com/devongovett) of [Audiocog

## Building

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

npm install importer -g
importer src/decoder.js -p 3030
npm install
make browser

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

importer src/decoder.js build.js

aac.js depends on [Aurora.js](https://github.com/audiocogs/aurora.js), our audio codec framework. You will need
to include either a prebuilt version of Aurora.js, or start another `importer` development server for Aurora before
aac.js will work. You can use the [test.html](https://github.com/audiocogs/aurora.js/blob/master/src/test.html) file
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
page as well in order to add support for AAC files.
AAC.js depends on [Aurora.js](https://github.com/audiocogs/aurora.js), our audio codec framework.
For detailed information on how to use Aurora.js, check out the [documentation](https://github.com/audiocogs/aurora.js/wiki).

## Features

Expand Down
37 changes: 37 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"name": "aac",
"version": "0.1.0",
"description": "An AAC decoder for Aurora.js",
"main": "src/decoder.js",
"peerDependencies": {
"av": "~0.4.0"
},
"devDependencies": {
"exorcist": "^0.1.6",
"browserify": "^4.1.10",
"browserify-shim": "^3.5.0"
},
"browserify": {
"transform": ["browserify-shim"]
},
"browserify-shim": {
"av": "global:AV"
},
"repository": {
"type": "git",
"url": "git://github.com/audiocogs/aac.js"
},
"keywords": [
"audio",
"av",
"aurora.js",
"aurora",
"decode"
],
"author": "Devon Govett <devongovett@gmail.com>",
"license": "LGPL",
"bugs": {
"url": "https://github.com/audiocogs/aac.js/issues"
},
"homepage": "https://github.com/audiocogs/aac.js"
}
5 changes: 4 additions & 1 deletion src/adts_demuxer.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
var AV = require('av');
var tables = require('./tables');

var ADTSDemuxer = AV.Demuxer.extend(function() {
AV.Demuxer.register(this);

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

this.emit('format', {
formatID: 'aac ',
sampleRate: SAMPLE_RATES[header.samplingIndex],
sampleRate: tables.SAMPLE_RATES[header.samplingIndex],
channelsPerFrame: header.chanConfig,
bitsPerChannel: 16
});
Expand Down
257 changes: 128 additions & 129 deletions src/cce.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,145 +18,144 @@
* If not, see <http://www.gnu.org/licenses/>.
*/

var CCEElement = (function() {
// Channel Coupling Element
function CCEElement(config) {
this.ics = new ICStream(config);
this.channelPair = new Array(8);
this.idSelect = new Int32Array(8);
this.chSelect = new Int32Array(8);
this.gain = new Array(16);
}
CCEElement.BEFORE_TNS = 0;
CCEElement.AFTER_TNS = 1;
CCEElement.AFTER_IMDCT = 2;
const CCE_SCALE = new Float32Array([
1.09050773266525765921,
1.18920711500272106672,
1.4142135623730950488016887,
2.0
]);
CCEElement.prototype = {
decode: function(stream, config) {
var channelPair = this.channelPair,
idSelect = this.idSelect,
chSelect = this.chSelect;

this.couplingPoint = 2 * stream.read(1);
this.coupledCount = stream.read(3);

var gainCount = 0;
for (var i = 0; i <= this.coupledCount; i++) {
gainCount++;
channelPair[i] = stream.read(1);
idSelect[i] = stream.read(4);

if (channelPair[i]) {
chSelect[i] = stream.read(2);
if (chSelect[i] === 3)
gainCount++;

} else {
chSelect[i] = 2;
}
var ICStream = require('./ics');
var Huffman = require('./huffman');

// Channel Coupling Element
function CCEElement(config) {
this.ics = new ICStream(config);
this.channelPair = new Array(8);
this.idSelect = new Int32Array(8);
this.chSelect = new Int32Array(8);
this.gain = new Array(16);
}

CCEElement.BEFORE_TNS = 0;
CCEElement.AFTER_TNS = 1;
CCEElement.AFTER_IMDCT = 2;

const CCE_SCALE = new Float32Array([
1.09050773266525765921,
1.18920711500272106672,
1.4142135623730950488016887,
2.0
]);

CCEElement.prototype = {
decode: function(stream, config) {
var channelPair = this.channelPair,
idSelect = this.idSelect,
chSelect = this.chSelect;

this.couplingPoint = 2 * stream.read(1);
this.coupledCount = stream.read(3);

var gainCount = 0;
for (var i = 0; i <= this.coupledCount; i++) {
gainCount++;
channelPair[i] = stream.read(1);
idSelect[i] = stream.read(4);

if (channelPair[i]) {
chSelect[i] = stream.read(2);
if (chSelect[i] === 3)
gainCount++;

} else {
chSelect[i] = 2;
}

this.couplingPoint += stream.read(1);
this.couplingPoint |= (this.couplingPoint >>> 1);

var sign = stream.read(1),
scale = CCE_SCALE[stream.read(2)];

this.ics.decode(stream, config, false);

var groupCount = this.ics.info.groupCount,
maxSFB = this.ics.info.maxSFB,
bandTypes = this.ics.bandTypes;

for (var i = 0; i < gainCount; i++) {
var idx = 0,
cge = 1,
gain = 0,
gainCache = 1;

if (i > 0) {
cge = this.couplingPoint === CCEElement.AFTER_IMDCT ? 1 : stream.read(1);
gain = cge ? Huffman.decodeScaleFactor(stream) - 60 : 0;
gainCache = Math.pow(scale, -gain);
}

var gain_i = this.gain[i] = new Float32Array(120);

if (this.couplingPoint === CCEElement.AFTER_IMDCT) {
gain_i[0] = gainCache;
} else {
for (var g = 0; g < groupCount; g++) {
for (var sfb = 0; sfb < maxSFB; sfb++) {
if (bandTypes[idx] !== ICStream.ZERO_BT) {
if (cge === 0) {
var t = Huffman.decodeScaleFactor(stream) - 60;
if (t !== 0) {
var s = 1;
t = gain += t;
if (sign) {
s -= 2 * (t * 0x1);
t >>>= 1;
}
gainCache = Math.pow(scale, -t) * s;
}

this.couplingPoint += stream.read(1);
this.couplingPoint |= (this.couplingPoint >>> 1);

var sign = stream.read(1),
scale = CCE_SCALE[stream.read(2)];

this.ics.decode(stream, config, false);

var groupCount = this.ics.info.groupCount,
maxSFB = this.ics.info.maxSFB,
bandTypes = this.ics.bandTypes;

for (var i = 0; i < gainCount; i++) {
var idx = 0,
cge = 1,
gain = 0,
gainCache = 1;

if (i > 0) {
cge = this.couplingPoint === CCEElement.AFTER_IMDCT ? 1 : stream.read(1);
gain = cge ? Huffman.decodeScaleFactor(stream) - 60 : 0;
gainCache = Math.pow(scale, -gain);
}

var gain_i = this.gain[i] = new Float32Array(120);

if (this.couplingPoint === CCEElement.AFTER_IMDCT) {
gain_i[0] = gainCache;
} else {
for (var g = 0; g < groupCount; g++) {
for (var sfb = 0; sfb < maxSFB; sfb++) {
if (bandTypes[idx] !== ICStream.ZERO_BT) {
if (cge === 0) {
var t = Huffman.decodeScaleFactor(stream) - 60;
if (t !== 0) {
var s = 1;
t = gain += t;
if (sign) {
s -= 2 * (t * 0x1);
t >>>= 1;
}
gainCache = Math.pow(scale, -t) * s;
}
gain_i[idx++] = gainCache;
}
gain_i[idx++] = gainCache;
}
}
}
}
},

applyIndependentCoupling: function(index, data) {
var gain = this.gain[index][0],
iqData = this.ics.data;

for (var i = 0; i < data.length; i++) {
data[i] += gain * iqData[i];
}
},

applyDependentCoupling: function(index, data) {
var info = this.ics.info,
swbOffsets = info.swbOffsets,
groupCount = info.groupCount,
maxSFB = info.maxSFB,
bandTypes = this.ics.bandTypes,
iqData = this.ics.data;

var idx = 0,
offset = 0,
gains = this.gain[index];

for (var g = 0; g < groupCount; g++) {
var len = info.groupLength[g];

for (var sfb = 0; sfb < maxSFB; sfb++, idx++) {
if (bandTypes[idx] !== ICStream.ZERO_BT) {
var gain = gains[idx];
for (var group = 0; group < len; group++) {
for (var k = swbOffsets[sfb]; k < swbOffsets[swb + 1]; k++) {
data[offset + group * 128 + k] += gain * iqData[offset + group * 128 + k];
}
}
},

applyIndependentCoupling: function(index, data) {
var gain = this.gain[index][0],
iqData = this.ics.data;

for (var i = 0; i < data.length; i++) {
data[i] += gain * iqData[i];
}
},

applyDependentCoupling: function(index, data) {
var info = this.ics.info,
swbOffsets = info.swbOffsets,
groupCount = info.groupCount,
maxSFB = info.maxSFB,
bandTypes = this.ics.bandTypes,
iqData = this.ics.data;

var idx = 0,
offset = 0,
gains = this.gain[index];

for (var g = 0; g < groupCount; g++) {
var len = info.groupLength[g];

for (var sfb = 0; sfb < maxSFB; sfb++, idx++) {
if (bandTypes[idx] !== ICStream.ZERO_BT) {
var gain = gains[idx];
for (var group = 0; group < len; group++) {
for (var k = swbOffsets[sfb]; k < swbOffsets[swb + 1]; k++) {
data[offset + group * 128 + k] += gain * iqData[offset + group * 128 + k];
}
}
}

offset += len * 128;
}

offset += len * 128;
}
};

return CCEElement;

})();
}
};

module.exports = CCEElement;
Loading

0 comments on commit 79230c4

Please sign in to comment.