-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathblip.min.js
1 lines (1 loc) · 9.22 KB
/
blip.min.js
1
!function(){function a(){return f.currentTime}function b(){function a(a){var b=(Math.random().toString(16)+"000000000").substr(2,8);return a?"-"+b.substr(0,4)+"-"+b.substr(4,4):b}return a()+a(!0)+a(!0)+a()}function c(a){this.nodes=a||[]}function d(){return this.inputs=new c,this.outputs=new c,this}var e={};e.version="0.3.1",function(){"use strict";function a(a){a&&(a.setTargetAtTime||(a.setTargetAtTime=a.setTargetValueAtTime))}window.hasOwnProperty("webkitAudioContext")&&!window.hasOwnProperty("AudioContext")&&(window.AudioContext=webkitAudioContext,AudioContext.prototype.hasOwnProperty("createGain")||(AudioContext.prototype.createGain=AudioContext.prototype.createGainNode),AudioContext.prototype.hasOwnProperty("createDelay")||(AudioContext.prototype.createDelay=AudioContext.prototype.createDelayNode),AudioContext.prototype.hasOwnProperty("createScriptProcessor")||(AudioContext.prototype.createScriptProcessor=AudioContext.prototype.createJavaScriptNode),AudioContext.prototype.hasOwnProperty("createPeriodicWave")||(AudioContext.prototype.createPeriodicWave=AudioContext.prototype.createWaveTable),AudioContext.prototype.internal_createGain=AudioContext.prototype.createGain,AudioContext.prototype.createGain=function(){var b=this.internal_createGain();return a(b.gain),b},AudioContext.prototype.internal_createDelay=AudioContext.prototype.createDelay,AudioContext.prototype.createDelay=function(b){var c=b?this.internal_createDelay(b):this.internal_createDelay();return a(c.delayTime),c},AudioContext.prototype.internal_createBufferSource=AudioContext.prototype.createBufferSource,AudioContext.prototype.createBufferSource=function(){var b=this.internal_createBufferSource();return b.start||(b.start=function(a,b,c){b||c?this.noteGrainOn(a,b,c):this.noteOn(a)}),b.stop||(b.stop=b.noteOff),a(b.playbackRate),b},AudioContext.prototype.internal_createDynamicsCompressor=AudioContext.prototype.createDynamicsCompressor,AudioContext.prototype.createDynamicsCompressor=function(){var b=this.internal_createDynamicsCompressor();return a(b.threshold),a(b.knee),a(b.ratio),a(b.reduction),a(b.attack),a(b.release),b},AudioContext.prototype.internal_createBiquadFilter=AudioContext.prototype.createBiquadFilter,AudioContext.prototype.createBiquadFilter=function(){var b=this.internal_createBiquadFilter();return a(b.frequency),a(b.detune),a(b.Q),a(b.gain),b},AudioContext.prototype.hasOwnProperty("createOscillator")&&(AudioContext.prototype.internal_createOscillator=AudioContext.prototype.createOscillator,AudioContext.prototype.createOscillator=function(){var b=this.internal_createOscillator();return b.start||(b.start=b.noteOn),b.stop||(b.stop=b.noteOff),b.setPeriodicWave||(b.setPeriodicWave=b.setWaveTable),a(b.frequency),a(b.detune),b}))}(window);var f=new AudioContext;e.time={},e.time.now=function(){return a()},e.time.in=function(b){return a()+b},e.time.seconds=function(a){return a},e.time.ms=function(a){return.001*a},e.time.samp=function(a){return a/f.sampleRate},e.chance=function(a){var b=Math.random();return a>b},e.random=function(a,b){switch(arguments.length){case 0:return Math.random();case 1:return Math.random()*a;case 2:return Math.random()*(b-a)+a}},e.mtof=function(a){return 440*Math.pow(2,(a-69)/12)},c.prototype={count:function(){return this.nodes.length},each:function(a){for(var b=0;b<this.nodes.length;b++)a.call(this,this.nodes[b],b,this.nodes)},contains:function(a){for(var b=0;b<this.nodes.length;b++)if(this.nodes[b]===a)return!0;return!1},add:function(a){-1===this.nodes.indexOf(a)&&this.nodes.push(a)},remove:function(a){var b=this.nodes.indexOf(a);-1!==b&&this.nodes.splice(b,1)},removeAll:function(){this.nodes=[]}};var g={gain:f.createGain,delay:f.createDelay,panner:f.createPanner,convolver:f.createConvolver,analyser:f.createAnalyser,channelSplitter:f.createChannelSplitter,channelMerger:f.createChannelMerger,dynamicsCompressor:f.createDynamicsCompressor,biquadFilter:f.createBiquadFilter,waveShaper:f.createWaveShaper,oscillator:f.createOscillator,periodicWave:f.createPeriodicWave,bufferSource:f.createBufferSource,audioBufferSource:f.createBufferSource};d.prototype.connect=function(a){return this.node().numberOfOutputs>0&&a.node().numberOfInputs>0&&(this.node().connect(a.node()),this.outputs.add(a),a.inputs.add(this)),this},d.prototype.disconnect=function(a){this.node().disconnect();var b=this;return a?(this.outputs.remove(a),a.inputs.remove(this),this.outputs.each(function(a){this.connect(a)})):(this.outputs.each(function(a){a.inputs.remove(b)}),this.outputs.removeAll()),this},d.prototype.prop=function(a,b){if(arguments.length<2){if("object"==typeof a){for(var c in a)this.node()[c]=a[c];return this}return this.node()[a]}return this.node()[a]=b,this},d.prototype.param=function(a,b){return arguments.length<2?this.node()[a]:("function"!=typeof b?this.node()[a].value=b:b.call(this.node()[a]),this)},d.prototype.start=function(a){this.node().start.call(this.node(),a)},d.prototype.stop=function(a){this.node().stop.call(this.node(),a)},d.prototype.node=function(){return this.node()},d.prototype.toString=function(){return"[object BlipNode]"},d.prototype.valueOf=function(){return this.id()},d.prototype.call=function(a){var b=Array.prototype.slice.call(arguments,1),c=this.node();"function"==typeof c[a]&&c[a].apply(c,b)},e.node=function(a){function c(a){return g[a].apply(f,e)}var e=Array.prototype.slice.call(arguments,1),h=c(a),i=b(),j=new d;return j.node=function(){return h},j.id=function(){return i},j};var h=function(a){var c=new d,e=b();return c.node=function(){return a},c.id=function(){return e},c};e.destination=h(f.destination),e.listener=h(f.listener),e.chain=function(a){function b(){for(var b=0;b<a.length-1;b++)a[b].connect(a[b+1])}a=a||[],b();var c={};return c.node=function(d){return a.push(d),b(),c},c.start=function(){var b=a.slice(0,1);return b.length?b[0]:null},c.end=function(){var b=a.slice(-1);return b.length?b[0]:null},c.from=function(a){return a.connect(c.start()),c},c.to=function(a){return c.end().connect(a),c},c.wire=function(){return b(),c},c},e.loop=function(){function a(){}function b(){n+=h,++m>=l.length&&(m=0,q+=1)}function c(b,c){o.call(a,c,l[b],b)}function d(b,c){p.call(a,c,b)}function e(){for(;n<f.currentTime+k;)if(c(m,n),0===m&&d(q,n),b(),r&&q>=r)return void a.reset();i=window.setTimeout(e,j)}var g,h,i,j=25,k=.1,l=[],m=0,n=0,o=function(){},p=function(){},q=0,r=0;return a.tempo=function(b){return arguments.length?(g=b,h=60/g,a):g},a.tickInterval=function(b){return arguments.length?(h=b,g=60/h,a):h},a.data=function(b){return arguments.length?(l=b,a):l},a.lookahead=function(b){return arguments.length?(j=b,a):j},a.scheduleAheadTime=function(b){return arguments.length?(k=b,a):k},a.limit=function(b){return arguments.length?(r=b,a):r},a.tick=function(b){return arguments.length?(o=b,a):o},a.each=function(b){return arguments.length?(p=b,a):p},a.start=function(b){return n=b||f.currentTime,e(),a},a.stop=function(){return window.clearTimeout(i),a},a.reset=function(){return m=0,q=0,a},a};var i={};e.sampleLoader=function(){function a(){function a(){if(h<g.length){var a=g[h];h++,e(a,b[a])}else d()}function e(b,d){function e(a){var b=a.target,c=b.response;f.decodeAudioData(c,g)}function g(d){i[b]=d,c(b),a()}var h=new XMLHttpRequest;h.open("GET",d,!0),h.responseType="arraybuffer",h.addEventListener("load",e,!1),h.send()}var g=Object.keys(b),h=0;a()}var b={},c=function(){},d=function(){};return a.samples=function(c){return arguments.length?(b=c,a):b},a.each=function(b){return arguments.length?(c=b,a):c},a.done=function(b){return arguments.length?(d=b,a):d},a.load=function(){return a()},a},e.clip=function(){function a(){}var b,c=1,g=1,j=null,k=e.node("gain").connect(e.destination);return a.sample=function(c){return arguments.length?(b=i[c],a):b},a.rate=function(b){return arguments.length?(c=b,a):c},a.gain=function(b){return arguments.length?(g=b,a):g},a.chain=function(b){return arguments.length?(j=b,k.disconnect(e.destination),j.from(k).to(e.destination),a):j},a.play=function(a,e){a=a||0;var i=f.createBufferSource();i.buffer=b,e?("undefined"!=typeof e.gain?"function"==typeof e.gain?k.param("gain",e.gain):k.param("gain",function(){this.setValueAtTime(e.gain,a)}):k.param("gain",e.gain),"undefined"!=typeof e.rate?"function"==typeof e.rate?d.prototype.param.call(h(i),"playbackRate",e.rate):i.playbackRate.setValueAtTime(e.rate,a):d.prototype.param.call(h(i),"playbackRate",c)):(1!==g&&k.param("gain",g),1!==c&&d.prototype.param.call(h(i),"playbackRate",c)),i.connect(k.node()),i.start(a)},a},e.envelope=function(){var b=0,c=0,d=.8,e=0,g=f.createGain(),i=h(g);return i.param("gain",0),i.attack=function(a){return arguments.length?(b=a,i):b},i.decay=function(a){return arguments.length?(c=a,i):c},i.sustain=function(a){return arguments.length?(d=a,i):d},i.release=function(a){return arguments.length?(e=a,i):e},i.noteOn=function(e){return e="number"==typeof e?e:a(),i.param("gain",function(){this.cancelScheduledValues(e),this.setValueAtTime(0,e),this.linearRampToValueAtTime(1,e+b),this.setTargetAtTime(d,e+b,.368*c),this.setValueAtTime(d,e+b+c)}),i},i.noteOff=function(b){return b="number"==typeof b?b:a(),i.param("gain",function(){this.cancelScheduledValues(b),this.setTargetAtTime(0,b,.368*e),this.setValueAtTime(0,b+e)}),i},i.play=function(a,b){return i.noteOn(a),i.noteOff(a+b),i},i},e.getContext=function(){return f},e.getLoadedSamples=function(){return i},e.sample=function(a){return i[a]},window.blip=e}();