minfied file added

pull/14/head
Samir 7 years ago
parent 9634feb1b1
commit d4bd3bbbf0

@ -55,8 +55,23 @@ Decoder fire an event *decode* whenever it completes decoding. Usually it decode
**How to run example?** **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: 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* *node server.js*
then, visit *example/index.html* page through any webserver. 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

@ -26,6 +26,6 @@
}); });
} }
</script> </script>
<script type="text/javascript" src="../pcm-player.js"></script> <script type="text/javascript" src="../pcm-player.min.js"></script>
</body> </body>
</html> </html>

@ -4,9 +4,7 @@
"description": "A minimalist javascript audio player for PCM streaming audio", "description": "A minimalist javascript audio player for PCM streaming audio",
"main": "dist/pcm_player.js", "main": "dist/pcm_player.js",
"scripts": { "scripts": {
"build": "rollup -c", "minify": "./node_modules/uglify-js/bin/uglifyjs pcm-player.js --compress --mangle --output pcm-player.min.js"
"pro": "NODE_ENV=production rollup -c",
"test": "karma start karma.conf.js"
}, },
"repository": { "repository": {
"type": "git", "type": "git",
@ -14,6 +12,7 @@
}, },
"author": "Samir Das", "author": "Samir Das",
"devDependencies": { "devDependencies": {
"uglify-js": "^3.3.23",
"ws": "^3.3.0" "ws": "^3.3.0"
}, },
"dependencies": {} "dependencies": {}

1
pcm-player.min.js vendored

@ -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<t.length;e++)i[e]=t[e]/this.maxValue;return i},PCMPlayer.prototype.volume=function(t){this.gainNode.gain.value=t},PCMPlayer.prototype.destroy=function(){this.interval&&clearInterval(this.interval),this.samples=null,this.audioCtx.close(),this.audioCtx=null},PCMPlayer.prototype.flush=function(){if(this.samples.length){var t,e,i,n,a,s=this.audioCtx.createBufferSource(),r=this.samples.length/this.option.channels,o=this.audioCtx.createBuffer(this.option.channels,r,this.option.sampleRate);for(e=0;e<this.option.channels;e++)for(t=o.getChannelData(e),i=e,a=50,n=0;n<r;n++)t[n]=this.samples[i],n<50&&(t[n]=t[n]*n/50),r-51<=n&&(t[n]=t[n]*a--/50),i+=this.option.channels;this.startTime<this.audioCtx.currentTime&&(this.startTime=this.audioCtx.currentTime),console.log("start vs current "+this.startTime+" vs "+this.audioCtx.currentTime+" duration: "+o.duration),s.buffer=o,s.connect(this.gainNode),s.start(this.startTime),this.startTime+=o.duration,this.samples=new Float32Array}};
Loading…
Cancel
Save