Skip to content

Commit

Permalink
Merge pull request #13 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 cf4e23d + 4d752f6 commit dbabc67
Show file tree
Hide file tree
Showing 8 changed files with 100 additions and 21 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/flac.js.map > build/flac.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 @@ of [Audiocogs](http://audiocogs.org/).

## Building

Currently, the [importer](https://github.com/devongovett/importer) module is used to build flac.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 flac.js. You can download a
prebuilt version from the Github [releases](https://github.com/audiocogs/flac.js/releases) page.
To build flac.js for the browser yourself, use the following commands:

npm install importer -g
importer flac.js -p 3030
npm install
make browser

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

importer flac.js build.js

flac.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
flac.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 flac.js on that
page as well in order to add support for FLAC files.
flac.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).

## License

Expand Down
6 changes: 0 additions & 6 deletions flac.js

This file was deleted.

2 changes: 2 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
exports.FLACDemuxer = require('./src/demuxer');
exports.FLACDecoder = require('./src/decoder');
33 changes: 33 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"name": "flac.js",
"version": "0.1.0",
"description": "A FLAC decoder for Aurora.js",
"peerDependencies": {
"av": "~0.4.0"
},
"devDependencies": {
"exorcist": "^0.1.6",
"browserify": "^4.1.10",
"browserify-shim": "^3.5.0"
},
"browserify-shim": {
"av": "global:AV"
},
"repository": {
"type": "git",
"url": "git://github.com/audiocogs/flac.js"
},
"keywords": [
"audio",
"av",
"aurora.js",
"aurora",
"decode"
],
"author": "Devon Govett <[email protected]>",
"license": "LGPL",
"bugs": {
"url": "https://github.com/audiocogs/flac.js/issues"
},
"homepage": "https://github.com/audiocogs/flac.js"
}
6 changes: 5 additions & 1 deletion src/decoder.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
*
*/

var AV = require('av');

var FLACDecoder = AV.Decoder.extend(function() {
AV.Decoder.register('flac', this);

Expand Down Expand Up @@ -484,4 +486,6 @@ var FLACDecoder = AV.Decoder.extend(function() {
// shouldn't get here
return output + 4;
}
});
});

module.exports = FLACDecoder;
41 changes: 39 additions & 2 deletions src/demuxer.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
*
*/

var AV = require('av');

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

Expand Down Expand Up @@ -89,7 +91,40 @@ var FLACDemuxer = AV.Demuxer.extend(function() {
stream.advance(16); // skip MD5 hashes
this.readBlockHeaders = false;
break;


/*
I am only looking at the least significant 32 bits of sample number and offset data
This is more than sufficient for the longest flac file I have (~50 mins 2-channel 16-bit 44.1k which uses about 7.5% of the UInt32 space for the largest offset)
Can certainly be improved by storing sample numbers and offests as doubles, but would require additional overriding of the searchTimestamp and seek functions (possibly more?)
Also the flac faq suggests it would be possible to find frame lengths and thus create seek points on the fly via decoding but I assume this would be slow
I may look into these thigns though as my project progresses
*/
case SEEKTABLE:
for(var s=0; s<this.size/18; s++)
{
if(stream.peekUInt32(0) == 0xFFFFFFFF && stream.peekUInt32(1) == 0xFFFFFFFF)
{
//placeholder, ignore
stream.advance(18);
} else {
if(stream.readUInt32() > 0)
{
this.emit('error', 'Seek points with sample number >UInt32 not supported');
}
var samplenum = stream.readUInt32();
if(stream.readUInt32() > 0)
{
this.emit('error', 'Seek points with stream offset >UInt32 not supported');
}
var offset = stream.readUInt32();

stream.advance(2);

this.addSeekPoint(offset, samplenum);
}
}
break;

case VORBIS_COMMENT:
// see http://www.xiph.org/vorbis/doc/v-comment.html
this.metadata || (this.metadata = {});
Expand Down Expand Up @@ -147,4 +182,6 @@ var FLACDemuxer = AV.Demuxer.extend(function() {
}
}

});
});

module.exports = FLACDemuxer;

0 comments on commit dbabc67

Please sign in to comment.