New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

audio-feeder

Package Overview
Dependencies
Maintainers
1
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

audio-feeder - npm Package Compare versions

Comparing version 0.4.14 to 0.4.15

29

dist/AudioFeeder.js

@@ -1216,7 +1216,5 @@ (function webpackUniversalModuleDefinition(root, factory) {

this._flashBuffer = '';
this._flushTimeout = null;
this._flushInterval = 40; // flush added buffers no more often than every X ms
this._cachedFlashState = null;
this._cachedFlashTime = 0;
this._cachedFlashInterval = 40; // resync state no more often than every X ms
this._cachedFlashInterval = 185; // resync state no more often than every X ms

@@ -1384,3 +1382,2 @@ this._waitUntilReadyQueue = [];

FlashBackend.prototype._resampleFlash = function(samples) {
var sampleincr = 1;
var samplecount = samples[0].length;

@@ -1391,3 +1388,3 @@ var newSamples = new Float32Array(samplecount * 2);

for(var s = 0; s < samplecount; s++) {
var idx = (s * sampleincr) | 0;
var idx = s;
var idx_out = s * 2;

@@ -1409,4 +1406,11 @@

var str = '';
for (var i = 0; i < len; i++) {
for (var i = 0; i < len; i += 8) {
str += binBytes[samples[i]];
str += binBytes[samples[i + 1]];
str += binBytes[samples[i + 2]];
str += binBytes[samples[i + 3]];
str += binBytes[samples[i + 4]];
str += binBytes[samples[i + 5]];
str += binBytes[samples[i + 6]];
str += binBytes[samples[i + 7]];
}

@@ -1426,9 +1430,6 @@ return str;

this._flashBuffer = '';
this._flushTimeout = null;
if (chunk.length > 0) {
this.waitUntilReady(function() {
this._cachedFlashState = flashElement.write(chunk);
this._cachedFlashTime = Date.now();
});
this._cachedFlashState = flashElement.write(chunk);
this._cachedFlashTime = Date.now();
}

@@ -1450,6 +1451,6 @@ };

this._flashBuffer += str;
if (!this._flushTimeout) {
if (this._flashBuffer.length >= this.bufferSize * 8) {
// consolidate multiple consecutive tiny buffers in one pass;
// pushing data to Flash is relatively expensive on slow machines
this._flushTimeout = setTimeout(this._flushFlashBuffer.bind(this), this._flushInterval);
this._flushFlashBuffer();
}

@@ -1517,2 +1518,3 @@ }

FlashBackend.prototype.start = function() {
this._flushFlashBuffer();
this._flashaudio.flashElement.start();

@@ -1537,2 +1539,3 @@ this._paused = false;

FlashBackend.prototype.flush = function() {
this._flashBuffer = '';
this._flashaudio.flashElement.flush();

@@ -1539,0 +1542,0 @@ this._cachedFlashState = null;

@@ -1,1 +0,1 @@

!function(a,b){"object"==typeof exports&&"object"==typeof module?module.exports=b():"function"==typeof define&&define.amd?define([],b):"object"==typeof exports?exports.AudioFeeder=b():a.AudioFeeder=b()}(this,function(){return function(a){function b(d){if(c[d])return c[d].exports;var e=c[d]={exports:{},id:d,loaded:!1};return a[d].call(e.exports,e,e.exports,b),e.loaded=!0,e.exports}var c={};return b.m=a,b.c=c,b.p="",b(0)}([function(a,b,c){!function(){function b(a){this._options=a||{},this._backend=null,this._resampleFractional=0}var d=(c(1),c(2)),e=c(4);b.prototype.rate=0,b.prototype.targetRate=0,b.prototype.channels=0,b.prototype.bufferSize=0,Object.defineProperty(b.prototype,"bufferDuration",{get:function(){return this.targetRate?this.bufferSize/this.targetRate:0}}),Object.defineProperty(b.prototype,"bufferThreshold",{get:function(){return this._backend?this._backend.bufferThreshold/this.targetRate:0},set:function(a){if(!this._backend)throw"Invalid state: AudioFeeder cannot set bufferThreshold before init";this._backend.bufferThreshold=Math.round(a*this.targetRate)}}),Object.defineProperty(b.prototype,"playbackPosition",{get:function(){if(this._backend){var a=this.getPlaybackState();return a.playbackPosition}return 0}}),Object.defineProperty(b.prototype,"durationBuffered",{get:function(){if(this._backend){var a=this.getPlaybackState();return a.samplesQueued/this.targetRate}return 0}}),Object.defineProperty(b.prototype,"muted",{get:function(){if(this._backend)return this._backend.muted;throw"Invalid state: cannot get mute before init"},set:function(a){if(!this._backend)throw"Invalid state: cannot set mute before init";this._backend.muted=a}}),b.prototype.mute=function(){this.muted=!0},b.prototype.unmute=function(){this.muted=!1},Object.defineProperty(b.prototype,"volume",{get:function(){if(this._backend)return this._backend.volume;throw"Invalid state: cannot get volume before init"},set:function(a){if(!this._backend)throw"Invalid state: cannot set volume before init";this._backend.volume=a}}),b.prototype.init=function(a,b){if(this.channels=a,this.rate=b,d.isSupported())this._backend=new d(a,b,this._options);else{if(!e.isSupported())throw"No supported backend";this._backend=new e(a,b,this._options)}this.targetRate=this._backend.rate,this.bufferSize=this._backend.bufferSize,this._backend.onstarved=function(){this.onstarved&&this.onstarved()}.bind(this),this._backend.onbufferlow=function(){this.onbufferlow&&this.onbufferlow()}.bind(this)},b.prototype._resample=function(a){var b=this.rate,c=this.channels,d=this._backend.rate,e=this._backend.channels;if(b==d&&c==e)return a;var f=[],g=Math.trunc(this._resampleFractional),h=a[0].length,i=h*d/b+g,j=Math.round(i);this._resampleFractional-=g,this._resampleFractional+=i-j;for(var k=0;k<e;k++){var l=k;k>=c&&(l=0);for(var m=a[l],n=new Float32Array(j),o=0;o<n.length;o++)n[o]=m[o*h/i|0];f.push(n)}return f},b.prototype.bufferData=function(a){if(!this._backend)throw"Invalid state: AudioFeeder cannot bufferData before init";var b=this._resample(a);this._backend.appendBuffer(b)},b.prototype.getPlaybackState=function(){if(this._backend)return this._backend.getPlaybackState();throw"Invalid state: AudioFeeder cannot getPlaybackState before init"},b.prototype.waitUntilReady=function(a){if(!this._backend)throw"Invalid state: AudioFeeder cannot waitUntilReady before init";this._backend.waitUntilReady(a)},b.prototype.start=function(){if(!this._backend)throw"Invalid state: AudioFeeder cannot start before init";this._backend.start()},b.prototype.stop=function(){if(!this._backend)throw"Invalid state: AudioFeeder cannot stop before init";this._backend.stop()},b.prototype.flush=function(){if(!this._backend)throw"Invalid state: AudioFeeder cannot flush before init";this._backend.flush()},b.prototype.close=function(){this._backend&&(this._backend.close(),this._backend=null)},b.prototype.onstarved=null,b.prototype.onbufferlow=null,b.isSupported=function(){return!!Float32Array&&(d.isSupported()||e.isSupported())},b.initSharedAudioContext=function(){return d.isSupported()?d.initSharedAudioContext():null},a.exports=b}()},function(a,b){function c(a,b){if(a<1||a!==Math.round(a))throw"Invalid channel count for BufferQueue";this.channels=a,this.bufferSize=b,this.flush()}c.prototype.flush=function(){this._buffers=[],this._pendingBuffer=this.createBuffer(this.bufferSize),this._pendingPos=0},c.prototype.sampleCount=function(){var a=0;return this._buffers.forEach(function(b){a+=b[0].length}),a},c.prototype.createBuffer=function(a){for(var b=[],c=0;c<this.channels;c++)b[c]=new Float32Array(a);return b},c.prototype.validate=function(a){if(a.length!==this.channels)return!1;for(var b,c=0;c<a.length;c++){var d=a[c];if(!(d instanceof Float32Array))return!1;if(0==c)b=d.length;else if(d.length!==b)return!1}return!0},c.prototype.appendBuffer=function(a){if(!this.validate(a))throw"Invalid audio buffer passed to BufferQueue.appendBuffer";for(var b=a[0],c=b.length,d=this.channels,e=this._pendingPos,f=this._pendingBuffer,g=this.bufferSize,h=0;h<c;h++){for(var i=0;i<d;i++)f[i][e]=a[i][h];++e==g&&(this._buffers.push(f),e=this._pendingPos=0,f=this._pendingBuffer=this.createBuffer(g))}this._pendingPos=e},c.prototype.prependBuffer=function(a){if(!this.validate(a))throw"Invalid audio buffer passed to BufferQueue.prependBuffer";var b=this._buffers.slice(0);b.push(this.trimBuffer(this._pendingBuffer,0,this._pendingPos)),this.flush(),this.appendBuffer(a);for(var c=0;c<b.length;c++)this.appendBuffer(b[c])},c.prototype.nextBuffer=function(){if(this._buffers.length)return this._buffers.shift();var a=this.trimBuffer(this._pendingBuffer,0,this._pendingPos);return this._pendingBuffer=this.createBuffer(this.bufferSize),this._pendingPos=0,a},c.prototype.trimBuffer=function(a,b,c){var d=a[0].length,e=b+Math.min(c,d);if(0==b&&e>=d)return a;for(var f=[],g=0;g<this.channels;g++)f[g]=a[g].subarray(b,e);return f},a.exports=c},function(a,b,c){!function(){function b(a,c,d){var f=d.audioContext||b.initSharedAudioContext();if(this._context=f,this.output=d.output||f.destination,this.rate=f.sampleRate,this.channels=Math.min(a,2),d.bufferSize&&(this.bufferSize=0|d.bufferSize),this.bufferThreshold=2*this.bufferSize,this._bufferQueue=new e(this.channels,this.bufferSize),this._playbackTimeAtBufferTail=f.currentTime,this._queuedTime=0,this._delayedTime=0,this._dropped=0,this._liveBuffer=this._bufferQueue.createBuffer(this.bufferSize),f.createScriptProcessor)this._node=f.createScriptProcessor(this.bufferSize,0,this.channels);else{if(!f.createJavaScriptNode)throw new Error("Bad version of web audio API?");this._node=f.createJavaScriptNode(this.bufferSize,0,this.channels)}}var d=window.AudioContext||window.webkitAudioContext,e=c(1),f=c(3);b.prototype.bufferSize=4096,b.prototype.bufferThreshold=8192,b.prototype._volume=1,Object.defineProperty(b.prototype,"volume",{get:function(){return this._volume},set:function(a){this._volume=+a}}),b.prototype._muted=!1,Object.defineProperty(b.prototype,"muted",{get:function(){return this._muted},set:function(a){this._muted=!!a}}),b.prototype._audioProcess=function(a){var b,c,d,e,g;g="number"==typeof a.playbackTime?a.playbackTime:this._context.currentTime+this.bufferSize/this.rate;var h=this._playbackTimeAtBufferTail;if(h<g&&(this._delayedTime+=g-h),this._bufferQueue.sampleCount()<this.bufferSize&&this.onstarved&&this.onstarved(),this._bufferQueue.sampleCount()<this.bufferSize){for(b=0;b<this.channels;b++)for(d=a.outputBuffer.getChannelData(b),e=0;e<this.bufferSize;e++)d[e]=0;return void this._dropped++}var i=this.muted?0:this.volume,j=this._bufferQueue.nextBuffer();if(j[0].length<this.bufferSize)throw"Audio buffer not expected length.";for(b=0;b<this.channels;b++)for(c=j[b],this._liveBuffer[b].set(j[b]),d=a.outputBuffer.getChannelData(b),e=0;e<c.length;e++)d[e]=c[e]*i;this._queuedTime+=this.bufferSize/this.rate,this._playbackTimeAtBufferTail=g+this.bufferSize/this.rate,this._bufferQueue.sampleCount()<Math.max(this.bufferSize,this.bufferThreshold)&&this.onbufferlow&&f(this.onbufferlow.bind(this))},b.prototype._samplesQueued=function(){var a=this._bufferQueue.sampleCount(),b=Math.floor(this._timeAwaitingPlayback()*this.rate);return a+b},b.prototype._timeAwaitingPlayback=function(){return Math.max(0,this._playbackTimeAtBufferTail-this._context.currentTime)},b.prototype.getPlaybackState=function(){return{playbackPosition:this._queuedTime-this._timeAwaitingPlayback(),samplesQueued:this._samplesQueued(),dropped:this._dropped,delayed:this._delayedTime}},b.prototype.waitUntilReady=function(a){a()},b.prototype.appendBuffer=function(a){this._bufferQueue.appendBuffer(a)},b.prototype.start=function(){this._node.onaudioprocess=this._audioProcess.bind(this),this._node.connect(this.output),this._playbackTimeAtBufferTail=this._context.currentTime},b.prototype.stop=function(){if(this._node){var a=this._timeAwaitingPlayback();if(a>0){var b=Math.round(a*this.rate),c=this._liveBuffer?this._liveBuffer[0].length:0;b>c?(this._bufferQueue.prependBuffer(this._liveBuffer),this._bufferQueue.prependBuffer(this._bufferQueue.createBuffer(b-c))):this._bufferQueue.prependBuffer(this._bufferQueue.trimBuffer(this._liveBuffer,c-b,b)),this._playbackTimeAtBufferTail-=a}this._node.onaudioprocess=null,this._node.disconnect()}},b.prototype.flush=function(){this._bufferQueue.flush()},b.prototype.close=function(){this.stop(),this._context=null},b.prototype.onstarved=null,b.prototype.onbufferlow=null,b.isSupported=function(){return!!d},b.sharedAudioContext=null,b.initSharedAudioContext=function(){if(!b.sharedAudioContext&&b.isSupported()){var a,c=new d;if(c.createScriptProcessor)a=c.createScriptProcessor(1024,0,2);else{if(!c.createJavaScriptNode)throw new Error("Bad version of web audio API?");a=c.createJavaScriptNode(1024,0,2)}a.connect(c.destination),a.disconnect(),b.sharedAudioContext=c}return b.sharedAudioContext},a.exports=b}()},function(a,b){a.exports=function(){if("undefined"!=typeof window.setImmediate)return window.setImmediate;if(window&&window.postMessage){var a=[];return window.addEventListener("message",function(b){if(b.source===window){var c=b.data;if("object"==typeof c&&c.nextTickBrowserPingMessage){var d=a.pop();d&&d()}}}),function(b){a.push(b),window.postMessage({nextTickBrowserPingMessage:!0},document.location.toString())}}return function(a){setTimeout(a,0)}}()},function(a,b,c){!function(){function b(a){for(var b=new Uint8Array(a),c=b.length,d="",e=0;e<c;e++)d+=h[b[e]];return d}function d(a){return this instanceof arguments.callee?void("function"==typeof this.init&&this.init.apply(this,a&&a.callee?a:arguments)):new arguments.callee(arguments)}var e=c(5),f=c(3),g=function(a,b,c){c=c||{};var g={};"string"==typeof c.base&&(g.swf=c.base+"/"+e),c.bufferSize&&(this.bufferSize=0|c.bufferSize),this._flashaudio=new d(g),this._flashBuffer="",this._flushTimeout=null,this._flushInterval=40,this._cachedFlashState=null,this._cachedFlashTime=0,this._cachedFlashInterval=40,this._waitUntilReadyQueue=[],this.onready=function(){for(this._flashaudio.flashElement.setBufferSize(this.bufferSize),this._flashaudio.flashElement.setBufferThreshold(this.bufferThreshold);this._waitUntilReadyQueue.length;){var a=this._waitUntilReadyQueue.shift();a.apply(this)}},this.onlog=function(a){console.log("AudioFeeder FlashBackend: "+a)},this.bufferThreshold=2*this.bufferSize;var h={ready:"sync",log:"sync",starved:"sync",bufferlow:"async"};this._callbackName="AudioFeederFlashBackendCallback"+this._flashaudio.id;window[this._callbackName]=function(a){var b=h[a],c=this["on"+a];b&&c&&("async"===b?f(c.bind(this)):(c.apply(this,Array.prototype.slice.call(arguments,1)),this._flushFlashBuffer()))}.bind(this)};g.prototype.rate=44100,g.prototype.channels=2,g.prototype.bufferSize=4096,g.prototype._bufferThreshold=8192,Object.defineProperty(g.prototype,"bufferThreshold",{get:function(){return this._bufferThreshold},set:function(a){this._bufferThreshold=0|a,this.waitUntilReady(function(){this._flashaudio.flashElement.setBufferThreshold(this._bufferThreshold)}.bind(this))}}),g.prototype._volume=1,Object.defineProperty(g.prototype,"volume",{get:function(){return this._volume},set:function(a){this._volume=+a,this.waitUntilReady(this._flashVolumeUpdate.bind(this))}}),g.prototype._muted=!1,Object.defineProperty(g.prototype,"muted",{get:function(){return this._muted},set:function(a){this._muted=!!a,this.waitUntilReady(this._flashVolumeUpdate.bind(this))}}),g.prototype._paused=!0,g.prototype._flashVolumeUpdate=function(){this._flashaudio&&this._flashaudio.flashElement&&this._flashaudio.flashElement.setVolume&&this._flashaudio.flashElement.setVolume(this.muted?0:this.volume)},g.prototype._resampleFlash=function(a){for(var b=1,c=a[0].length,d=new Float32Array(2*c),e=a[0],f=this.channels>1?a[1]:e,g=0;g<c;g++){var h=g*b|0,i=2*g;d[i]=e[h],d[i+1]=f[h]}return d};for(var h=[],i=0;i<256;i++)h[i]=String.fromCharCode(i+57344);g.prototype._flushFlashBuffer=function(){var a=this._flashBuffer,b=this._flashaudio.flashElement;this._flashBuffer="",this._flushTimeout=null,a.length>0&&this.waitUntilReady(function(){this._cachedFlashState=b.write(a),this._cachedFlashTime=Date.now()})},g.prototype.appendBuffer=function(a){var c=this._resampleFlash(a);if(c.length>0){var d=b(c.buffer);this._flashBuffer+=d,this._flushTimeout||(this._flushTimeout=setTimeout(this._flushFlashBuffer.bind(this),this._flushInterval))}},g.prototype.getPlaybackState=function(){if(this._flashaudio&&this._flashaudio.flashElement&&this._flashaudio.flashElement.write){var a,b=Date.now(),c=this._paused?0:b-this._cachedFlashTime;if(this._cachedFlashState&&c<this._cachedFlashInterval){var d=this._cachedFlashState;a={playbackPosition:d.playbackPosition+c/1e3,samplesQueued:d.samplesQueued-Math.max(0,Math.round(c*this.rate/1e3)),dropped:d.dropped,delayed:d.delayed}}else a=this._flashaudio.flashElement.getPlaybackState(),this._cachedFlashState=a,this._cachedFlashTime=b;return a.samplesQueued+=this._flashBuffer.length/8,a}return{playbackPosition:0,samplesQueued:0,dropped:0,delayed:0}},g.prototype.waitUntilReady=function(a){this._flashaudio&&this._flashaudio.flashElement.write?a.apply(this):this._waitUntilReadyQueue.push(a)},g.prototype.start=function(){this._flashaudio.flashElement.start(),this._paused=!1,this._cachedFlashState=null},g.prototype.stop=function(){this._flashaudio.flashElement.stop(),this._paused=!0,this._cachedFlashState=null},g.prototype.flush=function(){this._flashaudio.flashElement.flush(),this._cachedFlashState=null},g.prototype.close=function(){this.stop();var a=this._flashaudio.flashWrapper;a.parentNode.removeChild(a),this._flashaudio=null,delete window[this._callbackName]},g.prototype.onstarved=null,g.prototype.onbufferlow=null,g.isSupported=function(){if(navigator.userAgent.indexOf("Trident")!==-1)try{new ActiveXObject("ShockwaveFlash.ShockwaveFlash");return!0}catch(a){return!1}return!1},d.nextId=1,d.prototype={nextId:null,swf:e,flashWrapper:null,flashElement:null,init:function(a){var b=this;b.id=d.nextId++,a&&"undefined"!=typeof a.swf&&(b.swf=a.swf),b.flashWrapper=document.createElement("div"),b.flashWrapper.id="dynamicaudio-flashwrapper-"+b.id;var c=b.flashWrapper.style;c.position="fixed",c.width="11px",c.height="11px",c.bottom=c.left="0px",c.overflow="hidden",b.flashElement=document.createElement("div"),b.flashElement.id="dynamicaudio-flashelement-"+b.id,b.flashWrapper.appendChild(b.flashElement),document.body.appendChild(b.flashWrapper);var e=b.flashElement.id,f='<param name="FlashVars" value="objectId='+b.id+'">';b.flashWrapper.innerHTML="<object id='"+e+"' width='10' height='10' type='application/x-shockwave-flash' data='"+b.swf+"' style='visibility: visible;'><param name='allowscriptaccess' value='always'>"+f+"</object>",b.flashElement=document.getElementById(e)}},a.exports=g}()},function(a,b,c){a.exports=c.p+"dynamicaudio.swf?version=2c1ce3bfb7e6fa65c26d726a00017a94"}])});
!function(a,b){"object"==typeof exports&&"object"==typeof module?module.exports=b():"function"==typeof define&&define.amd?define([],b):"object"==typeof exports?exports.AudioFeeder=b():a.AudioFeeder=b()}(this,function(){return function(a){function b(d){if(c[d])return c[d].exports;var e=c[d]={exports:{},id:d,loaded:!1};return a[d].call(e.exports,e,e.exports,b),e.loaded=!0,e.exports}var c={};return b.m=a,b.c=c,b.p="",b(0)}([function(a,b,c){!function(){function b(a){this._options=a||{},this._backend=null,this._resampleFractional=0}var d=(c(1),c(2)),e=c(4);b.prototype.rate=0,b.prototype.targetRate=0,b.prototype.channels=0,b.prototype.bufferSize=0,Object.defineProperty(b.prototype,"bufferDuration",{get:function(){return this.targetRate?this.bufferSize/this.targetRate:0}}),Object.defineProperty(b.prototype,"bufferThreshold",{get:function(){return this._backend?this._backend.bufferThreshold/this.targetRate:0},set:function(a){if(!this._backend)throw"Invalid state: AudioFeeder cannot set bufferThreshold before init";this._backend.bufferThreshold=Math.round(a*this.targetRate)}}),Object.defineProperty(b.prototype,"playbackPosition",{get:function(){if(this._backend){var a=this.getPlaybackState();return a.playbackPosition}return 0}}),Object.defineProperty(b.prototype,"durationBuffered",{get:function(){if(this._backend){var a=this.getPlaybackState();return a.samplesQueued/this.targetRate}return 0}}),Object.defineProperty(b.prototype,"muted",{get:function(){if(this._backend)return this._backend.muted;throw"Invalid state: cannot get mute before init"},set:function(a){if(!this._backend)throw"Invalid state: cannot set mute before init";this._backend.muted=a}}),b.prototype.mute=function(){this.muted=!0},b.prototype.unmute=function(){this.muted=!1},Object.defineProperty(b.prototype,"volume",{get:function(){if(this._backend)return this._backend.volume;throw"Invalid state: cannot get volume before init"},set:function(a){if(!this._backend)throw"Invalid state: cannot set volume before init";this._backend.volume=a}}),b.prototype.init=function(a,b){if(this.channels=a,this.rate=b,d.isSupported())this._backend=new d(a,b,this._options);else{if(!e.isSupported())throw"No supported backend";this._backend=new e(a,b,this._options)}this.targetRate=this._backend.rate,this.bufferSize=this._backend.bufferSize,this._backend.onstarved=function(){this.onstarved&&this.onstarved()}.bind(this),this._backend.onbufferlow=function(){this.onbufferlow&&this.onbufferlow()}.bind(this)},b.prototype._resample=function(a){var b=this.rate,c=this.channels,d=this._backend.rate,e=this._backend.channels;if(b==d&&c==e)return a;var f=[],g=Math.trunc(this._resampleFractional),h=a[0].length,i=h*d/b+g,j=Math.round(i);this._resampleFractional-=g,this._resampleFractional+=i-j;for(var k=0;k<e;k++){var l=k;k>=c&&(l=0);for(var m=a[l],n=new Float32Array(j),o=0;o<n.length;o++)n[o]=m[o*h/i|0];f.push(n)}return f},b.prototype.bufferData=function(a){if(!this._backend)throw"Invalid state: AudioFeeder cannot bufferData before init";var b=this._resample(a);this._backend.appendBuffer(b)},b.prototype.getPlaybackState=function(){if(this._backend)return this._backend.getPlaybackState();throw"Invalid state: AudioFeeder cannot getPlaybackState before init"},b.prototype.waitUntilReady=function(a){if(!this._backend)throw"Invalid state: AudioFeeder cannot waitUntilReady before init";this._backend.waitUntilReady(a)},b.prototype.start=function(){if(!this._backend)throw"Invalid state: AudioFeeder cannot start before init";this._backend.start()},b.prototype.stop=function(){if(!this._backend)throw"Invalid state: AudioFeeder cannot stop before init";this._backend.stop()},b.prototype.flush=function(){if(!this._backend)throw"Invalid state: AudioFeeder cannot flush before init";this._backend.flush()},b.prototype.close=function(){this._backend&&(this._backend.close(),this._backend=null)},b.prototype.onstarved=null,b.prototype.onbufferlow=null,b.isSupported=function(){return!!Float32Array&&(d.isSupported()||e.isSupported())},b.initSharedAudioContext=function(){return d.isSupported()?d.initSharedAudioContext():null},a.exports=b}()},function(a,b){function c(a,b){if(a<1||a!==Math.round(a))throw"Invalid channel count for BufferQueue";this.channels=a,this.bufferSize=b,this.flush()}c.prototype.flush=function(){this._buffers=[],this._pendingBuffer=this.createBuffer(this.bufferSize),this._pendingPos=0},c.prototype.sampleCount=function(){var a=0;return this._buffers.forEach(function(b){a+=b[0].length}),a},c.prototype.createBuffer=function(a){for(var b=[],c=0;c<this.channels;c++)b[c]=new Float32Array(a);return b},c.prototype.validate=function(a){if(a.length!==this.channels)return!1;for(var b,c=0;c<a.length;c++){var d=a[c];if(!(d instanceof Float32Array))return!1;if(0==c)b=d.length;else if(d.length!==b)return!1}return!0},c.prototype.appendBuffer=function(a){if(!this.validate(a))throw"Invalid audio buffer passed to BufferQueue.appendBuffer";for(var b=a[0],c=b.length,d=this.channels,e=this._pendingPos,f=this._pendingBuffer,g=this.bufferSize,h=0;h<c;h++){for(var i=0;i<d;i++)f[i][e]=a[i][h];++e==g&&(this._buffers.push(f),e=this._pendingPos=0,f=this._pendingBuffer=this.createBuffer(g))}this._pendingPos=e},c.prototype.prependBuffer=function(a){if(!this.validate(a))throw"Invalid audio buffer passed to BufferQueue.prependBuffer";var b=this._buffers.slice(0);b.push(this.trimBuffer(this._pendingBuffer,0,this._pendingPos)),this.flush(),this.appendBuffer(a);for(var c=0;c<b.length;c++)this.appendBuffer(b[c])},c.prototype.nextBuffer=function(){if(this._buffers.length)return this._buffers.shift();var a=this.trimBuffer(this._pendingBuffer,0,this._pendingPos);return this._pendingBuffer=this.createBuffer(this.bufferSize),this._pendingPos=0,a},c.prototype.trimBuffer=function(a,b,c){var d=a[0].length,e=b+Math.min(c,d);if(0==b&&e>=d)return a;for(var f=[],g=0;g<this.channels;g++)f[g]=a[g].subarray(b,e);return f},a.exports=c},function(a,b,c){!function(){function b(a,c,d){var f=d.audioContext||b.initSharedAudioContext();if(this._context=f,this.output=d.output||f.destination,this.rate=f.sampleRate,this.channels=Math.min(a,2),d.bufferSize&&(this.bufferSize=0|d.bufferSize),this.bufferThreshold=2*this.bufferSize,this._bufferQueue=new e(this.channels,this.bufferSize),this._playbackTimeAtBufferTail=f.currentTime,this._queuedTime=0,this._delayedTime=0,this._dropped=0,this._liveBuffer=this._bufferQueue.createBuffer(this.bufferSize),f.createScriptProcessor)this._node=f.createScriptProcessor(this.bufferSize,0,this.channels);else{if(!f.createJavaScriptNode)throw new Error("Bad version of web audio API?");this._node=f.createJavaScriptNode(this.bufferSize,0,this.channels)}}var d=window.AudioContext||window.webkitAudioContext,e=c(1),f=c(3);b.prototype.bufferSize=4096,b.prototype.bufferThreshold=8192,b.prototype._volume=1,Object.defineProperty(b.prototype,"volume",{get:function(){return this._volume},set:function(a){this._volume=+a}}),b.prototype._muted=!1,Object.defineProperty(b.prototype,"muted",{get:function(){return this._muted},set:function(a){this._muted=!!a}}),b.prototype._audioProcess=function(a){var b,c,d,e,g;g="number"==typeof a.playbackTime?a.playbackTime:this._context.currentTime+this.bufferSize/this.rate;var h=this._playbackTimeAtBufferTail;if(h<g&&(this._delayedTime+=g-h),this._bufferQueue.sampleCount()<this.bufferSize&&this.onstarved&&this.onstarved(),this._bufferQueue.sampleCount()<this.bufferSize){for(b=0;b<this.channels;b++)for(d=a.outputBuffer.getChannelData(b),e=0;e<this.bufferSize;e++)d[e]=0;return void this._dropped++}var i=this.muted?0:this.volume,j=this._bufferQueue.nextBuffer();if(j[0].length<this.bufferSize)throw"Audio buffer not expected length.";for(b=0;b<this.channels;b++)for(c=j[b],this._liveBuffer[b].set(j[b]),d=a.outputBuffer.getChannelData(b),e=0;e<c.length;e++)d[e]=c[e]*i;this._queuedTime+=this.bufferSize/this.rate,this._playbackTimeAtBufferTail=g+this.bufferSize/this.rate,this._bufferQueue.sampleCount()<Math.max(this.bufferSize,this.bufferThreshold)&&this.onbufferlow&&f(this.onbufferlow.bind(this))},b.prototype._samplesQueued=function(){var a=this._bufferQueue.sampleCount(),b=Math.floor(this._timeAwaitingPlayback()*this.rate);return a+b},b.prototype._timeAwaitingPlayback=function(){return Math.max(0,this._playbackTimeAtBufferTail-this._context.currentTime)},b.prototype.getPlaybackState=function(){return{playbackPosition:this._queuedTime-this._timeAwaitingPlayback(),samplesQueued:this._samplesQueued(),dropped:this._dropped,delayed:this._delayedTime}},b.prototype.waitUntilReady=function(a){a()},b.prototype.appendBuffer=function(a){this._bufferQueue.appendBuffer(a)},b.prototype.start=function(){this._node.onaudioprocess=this._audioProcess.bind(this),this._node.connect(this.output),this._playbackTimeAtBufferTail=this._context.currentTime},b.prototype.stop=function(){if(this._node){var a=this._timeAwaitingPlayback();if(a>0){var b=Math.round(a*this.rate),c=this._liveBuffer?this._liveBuffer[0].length:0;b>c?(this._bufferQueue.prependBuffer(this._liveBuffer),this._bufferQueue.prependBuffer(this._bufferQueue.createBuffer(b-c))):this._bufferQueue.prependBuffer(this._bufferQueue.trimBuffer(this._liveBuffer,c-b,b)),this._playbackTimeAtBufferTail-=a}this._node.onaudioprocess=null,this._node.disconnect()}},b.prototype.flush=function(){this._bufferQueue.flush()},b.prototype.close=function(){this.stop(),this._context=null},b.prototype.onstarved=null,b.prototype.onbufferlow=null,b.isSupported=function(){return!!d},b.sharedAudioContext=null,b.initSharedAudioContext=function(){if(!b.sharedAudioContext&&b.isSupported()){var a,c=new d;if(c.createScriptProcessor)a=c.createScriptProcessor(1024,0,2);else{if(!c.createJavaScriptNode)throw new Error("Bad version of web audio API?");a=c.createJavaScriptNode(1024,0,2)}a.connect(c.destination),a.disconnect(),b.sharedAudioContext=c}return b.sharedAudioContext},a.exports=b}()},function(a,b){a.exports=function(){if("undefined"!=typeof window.setImmediate)return window.setImmediate;if(window&&window.postMessage){var a=[];return window.addEventListener("message",function(b){if(b.source===window){var c=b.data;if("object"==typeof c&&c.nextTickBrowserPingMessage){var d=a.pop();d&&d()}}}),function(b){a.push(b),window.postMessage({nextTickBrowserPingMessage:!0},document.location.toString())}}return function(a){setTimeout(a,0)}}()},function(a,b,c){!function(){function b(a){for(var b=new Uint8Array(a),c=b.length,d="",e=0;e<c;e+=8)d+=h[b[e]],d+=h[b[e+1]],d+=h[b[e+2]],d+=h[b[e+3]],d+=h[b[e+4]],d+=h[b[e+5]],d+=h[b[e+6]],d+=h[b[e+7]];return d}function d(a){return this instanceof arguments.callee?void("function"==typeof this.init&&this.init.apply(this,a&&a.callee?a:arguments)):new arguments.callee(arguments)}var e=c(5),f=c(3),g=function(a,b,c){c=c||{};var g={};"string"==typeof c.base&&(g.swf=c.base+"/"+e),c.bufferSize&&(this.bufferSize=0|c.bufferSize),this._flashaudio=new d(g),this._flashBuffer="",this._cachedFlashState=null,this._cachedFlashTime=0,this._cachedFlashInterval=185,this._waitUntilReadyQueue=[],this.onready=function(){for(this._flashaudio.flashElement.setBufferSize(this.bufferSize),this._flashaudio.flashElement.setBufferThreshold(this.bufferThreshold);this._waitUntilReadyQueue.length;){var a=this._waitUntilReadyQueue.shift();a.apply(this)}},this.onlog=function(a){console.log("AudioFeeder FlashBackend: "+a)},this.bufferThreshold=2*this.bufferSize;var h={ready:"sync",log:"sync",starved:"sync",bufferlow:"async"};this._callbackName="AudioFeederFlashBackendCallback"+this._flashaudio.id;window[this._callbackName]=function(a){var b=h[a],c=this["on"+a];b&&c&&("async"===b?f(c.bind(this)):(c.apply(this,Array.prototype.slice.call(arguments,1)),this._flushFlashBuffer()))}.bind(this)};g.prototype.rate=44100,g.prototype.channels=2,g.prototype.bufferSize=4096,g.prototype._bufferThreshold=8192,Object.defineProperty(g.prototype,"bufferThreshold",{get:function(){return this._bufferThreshold},set:function(a){this._bufferThreshold=0|a,this.waitUntilReady(function(){this._flashaudio.flashElement.setBufferThreshold(this._bufferThreshold)}.bind(this))}}),g.prototype._volume=1,Object.defineProperty(g.prototype,"volume",{get:function(){return this._volume},set:function(a){this._volume=+a,this.waitUntilReady(this._flashVolumeUpdate.bind(this))}}),g.prototype._muted=!1,Object.defineProperty(g.prototype,"muted",{get:function(){return this._muted},set:function(a){this._muted=!!a,this.waitUntilReady(this._flashVolumeUpdate.bind(this))}}),g.prototype._paused=!0,g.prototype._flashVolumeUpdate=function(){this._flashaudio&&this._flashaudio.flashElement&&this._flashaudio.flashElement.setVolume&&this._flashaudio.flashElement.setVolume(this.muted?0:this.volume)},g.prototype._resampleFlash=function(a){for(var b=a[0].length,c=new Float32Array(2*b),d=a[0],e=this.channels>1?a[1]:d,f=0;f<b;f++){var g=f,h=2*f;c[h]=d[g],c[h+1]=e[g]}return c};for(var h=[],i=0;i<256;i++)h[i]=String.fromCharCode(i+57344);g.prototype._flushFlashBuffer=function(){var a=this._flashBuffer,b=this._flashaudio.flashElement;this._flashBuffer="",a.length>0&&(this._cachedFlashState=b.write(a),this._cachedFlashTime=Date.now())},g.prototype.appendBuffer=function(a){var c=this._resampleFlash(a);if(c.length>0){var d=b(c.buffer);this._flashBuffer+=d,this._flashBuffer.length>=8*this.bufferSize&&this._flushFlashBuffer()}},g.prototype.getPlaybackState=function(){if(this._flashaudio&&this._flashaudio.flashElement&&this._flashaudio.flashElement.write){var a,b=Date.now(),c=this._paused?0:b-this._cachedFlashTime;if(this._cachedFlashState&&c<this._cachedFlashInterval){var d=this._cachedFlashState;a={playbackPosition:d.playbackPosition+c/1e3,samplesQueued:d.samplesQueued-Math.max(0,Math.round(c*this.rate/1e3)),dropped:d.dropped,delayed:d.delayed}}else a=this._flashaudio.flashElement.getPlaybackState(),this._cachedFlashState=a,this._cachedFlashTime=b;return a.samplesQueued+=this._flashBuffer.length/8,a}return{playbackPosition:0,samplesQueued:0,dropped:0,delayed:0}},g.prototype.waitUntilReady=function(a){this._flashaudio&&this._flashaudio.flashElement.write?a.apply(this):this._waitUntilReadyQueue.push(a)},g.prototype.start=function(){this._flushFlashBuffer(),this._flashaudio.flashElement.start(),this._paused=!1,this._cachedFlashState=null},g.prototype.stop=function(){this._flashaudio.flashElement.stop(),this._paused=!0,this._cachedFlashState=null},g.prototype.flush=function(){this._flashBuffer="",this._flashaudio.flashElement.flush(),this._cachedFlashState=null},g.prototype.close=function(){this.stop();var a=this._flashaudio.flashWrapper;a.parentNode.removeChild(a),this._flashaudio=null,delete window[this._callbackName]},g.prototype.onstarved=null,g.prototype.onbufferlow=null,g.isSupported=function(){if(navigator.userAgent.indexOf("Trident")!==-1)try{new ActiveXObject("ShockwaveFlash.ShockwaveFlash");return!0}catch(a){return!1}return!1},d.nextId=1,d.prototype={nextId:null,swf:e,flashWrapper:null,flashElement:null,init:function(a){var b=this;b.id=d.nextId++,a&&"undefined"!=typeof a.swf&&(b.swf=a.swf),b.flashWrapper=document.createElement("div"),b.flashWrapper.id="dynamicaudio-flashwrapper-"+b.id;var c=b.flashWrapper.style;c.position="fixed",c.width="11px",c.height="11px",c.bottom=c.left="0px",c.overflow="hidden",b.flashElement=document.createElement("div"),b.flashElement.id="dynamicaudio-flashelement-"+b.id,b.flashWrapper.appendChild(b.flashElement),document.body.appendChild(b.flashWrapper);var e=b.flashElement.id,f='<param name="FlashVars" value="objectId='+b.id+'">';b.flashWrapper.innerHTML="<object id='"+e+"' width='10' height='10' type='application/x-shockwave-flash' data='"+b.swf+"' style='visibility: visible;'><param name='allowscriptaccess' value='always'>"+f+"</object>",b.flashElement=document.getElementById(e)}},a.exports=g}()},function(a,b,c){a.exports=c.p+"dynamicaudio.swf?version=2c1ce3bfb7e6fa65c26d726a00017a94"}])});
{
"name": "audio-feeder",
"version": "0.4.14",
"version": "0.4.15",
"description": "Abstraction for streaming raw PCM audio in browser via Web Audio API.",

@@ -5,0 +5,0 @@ "main": "dist/AudioFeeder.js",

@@ -17,2 +17,4 @@ audio-feeder

## Updates
* 0.4.15 - 2019-02-09
* Flash: replace flush timer with a buffer size limit
* 0.4.14 - 2019-02-08

@@ -19,0 +21,0 @@ * Flash: fix clicking regression from 0.4.13

@@ -32,7 +32,5 @@ (function() {

this._flashBuffer = '';
this._flushTimeout = null;
this._flushInterval = 40; // flush added buffers no more often than every X ms
this._cachedFlashState = null;
this._cachedFlashTime = 0;
this._cachedFlashInterval = 40; // resync state no more often than every X ms
this._cachedFlashInterval = 185; // resync state no more often than every X ms

@@ -200,3 +198,2 @@ this._waitUntilReadyQueue = [];

FlashBackend.prototype._resampleFlash = function(samples) {
var sampleincr = 1;
var samplecount = samples[0].length;

@@ -207,3 +204,3 @@ var newSamples = new Float32Array(samplecount * 2);

for(var s = 0; s < samplecount; s++) {
var idx = (s * sampleincr) | 0;
var idx = s;
var idx_out = s * 2;

@@ -225,4 +222,11 @@

var str = '';
for (var i = 0; i < len; i++) {
for (var i = 0; i < len; i += 8) {
str += binBytes[samples[i]];
str += binBytes[samples[i + 1]];
str += binBytes[samples[i + 2]];
str += binBytes[samples[i + 3]];
str += binBytes[samples[i + 4]];
str += binBytes[samples[i + 5]];
str += binBytes[samples[i + 6]];
str += binBytes[samples[i + 7]];
}

@@ -242,9 +246,6 @@ return str;

this._flashBuffer = '';
this._flushTimeout = null;
if (chunk.length > 0) {
this.waitUntilReady(function() {
this._cachedFlashState = flashElement.write(chunk);
this._cachedFlashTime = Date.now();
});
this._cachedFlashState = flashElement.write(chunk);
this._cachedFlashTime = Date.now();
}

@@ -266,6 +267,6 @@ };

this._flashBuffer += str;
if (!this._flushTimeout) {
if (this._flashBuffer.length >= this.bufferSize * 8) {
// consolidate multiple consecutive tiny buffers in one pass;
// pushing data to Flash is relatively expensive on slow machines
this._flushTimeout = setTimeout(this._flushFlashBuffer.bind(this), this._flushInterval);
this._flushFlashBuffer();
}

@@ -333,2 +334,3 @@ }

FlashBackend.prototype.start = function() {
this._flushFlashBuffer();
this._flashaudio.flashElement.start();

@@ -353,2 +355,3 @@ this._paused = false;

FlashBackend.prototype.flush = function() {
this._flashBuffer = '';
this._flashaudio.flashElement.flush();

@@ -355,0 +358,0 @@ this._cachedFlashState = null;

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc