From 560f4f59430af62051d77d6518dc9ee51858ccf0 Mon Sep 17 00:00:00 2001 From: Devon Govett Date: Mon, 16 Jun 2014 22:17:50 -0700 Subject: [PATCH 1/3] Browserify --- flac.js | 6 ------ index.js | 2 ++ package.json | 25 +++++++++++++++++++++++++ src/decoder.js | 6 +++++- src/demuxer.js | 41 +++++++++++++++++++++++++++++++++++++++-- 5 files changed, 71 insertions(+), 9 deletions(-) delete mode 100644 flac.js create mode 100644 index.js create mode 100644 package.json diff --git a/flac.js b/flac.js deleted file mode 100644 index 26b832d..0000000 --- a/flac.js +++ /dev/null @@ -1,6 +0,0 @@ -(function() { - -//import "src/demuxer.js" -//import "src/decoder.js" - -})(); \ No newline at end of file diff --git a/index.js b/index.js new file mode 100644 index 0000000..002dedf --- /dev/null +++ b/index.js @@ -0,0 +1,2 @@ +exports.FLACDemuxer = require('./src/demuxer'); +exports.FLACDecoder = require('./src/decoder'); diff --git a/package.json b/package.json new file mode 100644 index 0000000..b87cb22 --- /dev/null +++ b/package.json @@ -0,0 +1,25 @@ +{ + "name": "flac.js", + "version": "0.1.0", + "description": "A FLAC decoder for Aurora.js", + "peerDependencies": { + "av": "~0.4.0" + }, + "repository": { + "type": "git", + "url": "git://github.com/audiocogs/flac.js" + }, + "keywords": [ + "audio", + "av", + "aurora.js", + "aurora", + "decode" + ], + "author": "Devon Govett ", + "license": "LGPL", + "bugs": { + "url": "https://github.com/audiocogs/flac.js/issues" + }, + "homepage": "https://github.com/audiocogs/flac.js" +} diff --git a/src/decoder.js b/src/decoder.js index a502ec6..43a19fb 100644 --- a/src/decoder.js +++ b/src/decoder.js @@ -18,6 +18,8 @@ * */ +var AV = require('av'); + var FLACDecoder = AV.Decoder.extend(function() { AV.Decoder.register('flac', this); @@ -484,4 +486,6 @@ var FLACDecoder = AV.Decoder.extend(function() { // shouldn't get here return output + 4; } -}); \ No newline at end of file +}); + +module.exports = FLACDecoder; diff --git a/src/demuxer.js b/src/demuxer.js index ad430fe..bcefe7a 100644 --- a/src/demuxer.js +++ b/src/demuxer.js @@ -14,6 +14,8 @@ * */ +var AV = require('av'); + var FLACDemuxer = AV.Demuxer.extend(function() { AV.Demuxer.register(this); @@ -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 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 = {}); @@ -147,4 +182,6 @@ var FLACDemuxer = AV.Demuxer.extend(function() { } } -}); \ No newline at end of file +}); + +module.exports = FLACDemuxer; From 231e9437c7893ca30e038307c16a141b43caa866 Mon Sep 17 00:00:00 2001 From: Devon Govett Date: Mon, 16 Jun 2014 23:48:26 -0700 Subject: [PATCH 2/3] Add Makefile to build browser standalone version --- .gitignore | 2 ++ Makefile | 11 +++++++++++ package.json | 8 ++++++++ 3 files changed, 21 insertions(+) create mode 100644 .gitignore create mode 100644 Makefile diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0741e07 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/node_modules/ +build/ diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..14d00ce --- /dev/null +++ b/Makefile @@ -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/ diff --git a/package.json b/package.json index b87cb22..722142f 100644 --- a/package.json +++ b/package.json @@ -5,6 +5,14 @@ "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" From 4d752f668b17ff1a344ad5abf9a4a25963312fb4 Mon Sep 17 00:00:00 2001 From: Devon Govett Date: Tue, 17 Jun 2014 00:11:25 -0700 Subject: [PATCH 3/3] Update readme --- README.md | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 1e01334..4bf9d72 100644 --- a/README.md +++ b/README.md @@ -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