diff --git a/README.md b/README.md index a1b0675..c2d6e32 100644 --- a/README.md +++ b/README.md @@ -55,8 +55,23 @@ Decoder fire an event *decode* whenever it completes decoding. Usually it decode **How to run example?** An example with simple node server script is available that include some raw pcm data that will be served by websocket and at the client end, it will be played through PCM player. For running the example, first run the node server by following command: +(I am assuming you are on project directory i.e pcm-player) + +*cd example/server* *node server.js* then, visit *example/index.html* page through any webserver. +If you don't have any web server, you can do following: + +(I am assuming you are on project directory i.e pcm-player) + +*npm install http-server -g* + +then run following command + +*http-server* + +Finally visit example page using URL http://192.168.0.105:8081/example/index.html OR URL suggested by http-server + diff --git a/example/index.html b/example/index.html index 7a7b7d4..8de1b81 100644 --- a/example/index.html +++ b/example/index.html @@ -26,6 +26,6 @@ }); } - + diff --git a/package.json b/package.json index 366d2b4..69a903b 100644 --- a/package.json +++ b/package.json @@ -4,9 +4,7 @@ "description": "A minimalist javascript audio player for PCM streaming audio", "main": "dist/pcm_player.js", "scripts": { - "build": "rollup -c", - "pro": "NODE_ENV=production rollup -c", - "test": "karma start karma.conf.js" + "minify": "./node_modules/uglify-js/bin/uglifyjs pcm-player.js --compress --mangle --output pcm-player.min.js" }, "repository": { "type": "git", @@ -14,6 +12,7 @@ }, "author": "Samir Das", "devDependencies": { + "uglify-js": "^3.3.23", "ws": "^3.3.0" }, "dependencies": {} diff --git a/pcm-player.min.js b/pcm-player.min.js new file mode 100644 index 0000000..42c3362 --- /dev/null +++ b/pcm-player.min.js @@ -0,0 +1 @@ +function PCMPlayer(t){this.init(t)}PCMPlayer.prototype.init=function(t){this.option=Object.assign({},{encoding:"16bitInt",channels:1,sampleRate:8e3,flushingTime:1e3},t),this.samples=new Float32Array,this.flush=this.flush.bind(this),this.interval=setInterval(this.flush,this.option.flushingTime),this.maxValue=this.getMaxValue(),this.typedArray=this.getTypedArray(),this.createContext()},PCMPlayer.prototype.getMaxValue=function(){var t={"8bitInt":128,"16bitInt":32768,"32bitInt":2147483648,"32bitFloat":1};return t[this.option.encoding]?t[this.option.encoding]:t["16bitInt"]},PCMPlayer.prototype.getTypedArray=function(){var t={"8bitInt":Int8Array,"16bitInt":Int16Array,"32bitInt":Int32Array,"32bitFloat":Float32Array};return t[this.option.encoding]?t[this.option.encoding]:t["16bitInt"]},PCMPlayer.prototype.createContext=function(){this.audioCtx=new(window.AudioContext||window.webkitAudioContext),this.gainNode=this.audioCtx.createGain(),this.gainNode.gain.value=1,this.gainNode.connect(this.audioCtx.destination),this.startTime=this.audioCtx.currentTime},PCMPlayer.prototype.isTypedArray=function(t){return t.byteLength&&t.buffer&&t.buffer.constructor==ArrayBuffer},PCMPlayer.prototype.feed=function(t){if(this.isTypedArray(t)){t=this.getFormatedValue(t);var e=new Float32Array(this.samples.length+t.length);e.set(this.samples,0),e.set(t,this.samples.length),this.samples=e}},PCMPlayer.prototype.getFormatedValue=function(t){t=new this.typedArray(t.buffer);var e,i=new Float32Array(t.length);for(e=0;e