UNPKG

gibber.lib

Version:

standalone libraries from Gibber to include in web pages

2 lines 920 kB
!function(e){if("object"==typeof exports)module.exports=e();else if("function"==typeof define&&define.amd)define(e);else{var t;"undefined"!=typeof window?t=window:"undefined"!=typeof global?t=global:"undefined"!=typeof self&&(t=self),t.Gibber=e()}}(function(){var define,module,exports;return function e(t,i,n){function r(a,s){if(!i[a]){if(!t[a]){var l="function"==typeof require&&require;if(!s&&l)return l(a,!0);if(o)return o(a,!0);throw new Error("Cannot find module '"+a+"'")}var c=i[a]={exports:{}};t[a][0].call(c.exports,function(e){var i=t[a][1][e];return r(i?i:e)},c,c.exports,e,t,i,n)}return i[a].exports}for(var o="function"==typeof require&&require,a=0;a<n.length;a++)r(n[a]);return r}({1:[function(_dereq_,module,exports){(function(global){!function(e,t){"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?module.exports=t():e.Gibberish=t()}(this,function(){function createInput(){console.log("connecting audio input..."),navigator.getUserMedia({audio:!0},function(e){console.log("audio input connected"),Gibberish.mediaStreamSource=Gibberish.context.createMediaStreamSource(e),Gibberish.mediaStreamSource.connect(Gibberish.node),_hasInput=!0},function(e){console.log(e),console.log("error opening audio input")})}var Gibberish={memo:{},codeblock:[],analysisCodeblock:[],analysisUgens:[],dirtied:[],id:0,isDirty:!1,out:null,debug:!1,callback:"",audioFiles:{},sequencers:[],callbackArgs:["input"],callbackObjects:[],analysisCallbackArgs:[],analysisCallbackObjects:[],onBlock:null,createCallback:function(){this.memo={},this.codeblock.length=0,this.callbackArgs.length=0,this.callbackObjects.length=0,this.analysisCallbackArgs.length=0,this.dirtied.length=0,this.codestring="",this.args=["input"],this.memo={},this.out.codegen();var e=this.codeblock.slice(0);if(this.analysisUgens.length>0){this.analysisCodeblock.length=0;for(var t=0;t<this.analysisUgens.length;t++)this.analysisCallbackArgs.push(this.analysisUgens[t].analysisSymbol)}if(this.args=this.args.concat(this.callbackArgs),this.args=this.args.concat(this.analysisCallbackArgs),this.codestring+=e.join(" "),this.codestring+="\n ",this.analysisUgens.length>0){this.analysisCodeblock.length=0;for(var t=0;t<this.analysisUgens.length;t++)this.codeblock.length=0,this.analysisUgens[t].analysisCodegen();this.codestring+=this.analysisCodeblock.join("\n "),this.codestring+="\n "}return this.codestring+="return "+this.out.variable+";\n",this.callbackString=this.codestring,this.debug&&console.log(this.callbackString),[this.args,this.codestring]},audioProcess:function(e){var t,i,n=e.outputBuffer.getChannelData(0),r=e.outputBuffer.getChannelData(1),o=e.inputBuffer.getChannelData(0),a=Gibberish,s=a.callback,l=a.sequencers,c=(Gibberish.out.callback,a.callbackObjects.slice(0));null!==a.onBlock&&a.onBlock(a.context),c.unshift(0);for(var u=0,h=e.outputBuffer.length;h>u;u++){for(var f=0;f<l.length;f++)l[f].tick();if(a.isDirty){t=a.createCallback();try{s=a.callback=new Function(t[0],t[1])}catch(e){console.error("ERROR WITH CALLBACK : \n\n",t)}a.isDirty=!1,c=a.callbackObjects.slice(0),c.unshift(0)}c[0]=o[u],i=s.apply(null,c),n[u]=i[0],r[u]=i[1]}},audioProcessFirefox:function(e){var t,i=Gibberish,n=i.callback,r=i.sequencers,o=i.callbackObjects.slice(0);o.unshift(0);for(var a=0,s=e.length;s>a;a+=2){for(var l=0;l<r.length;l++)r[l].tick();if(i.isDirty){t=i.createCallback();try{n=i.callback=new Function(t[0],t[1])}catch(c){console.error("ERROR WITH CALLBACK : \n\n",n)}i.isDirty=!1,o=i.callbackObjects.slice(0),o.unshift(0)}var u=n.apply(null,o);e[a]=u[0],e[a+1]=u[1]}},clear:function(){this.out.inputs.length=0,this.analysisUgens.length=0,this.sequencers.length=0,this.callbackArgs.length=2,this.callbackObjects.length=1,Gibberish.dirty(this.out)},dirty:function(e){if("undefined"!=typeof e){for(var t=!1,i=0;i<this.dirtied.length;i++)this.dirtied[i].variable===e.variable&&(t=!0);t||(this.isDirty=!0,this.dirtied.push(e))}else this.isDirty=!0},generateSymbol:function(e){return e+"_"+this.id++},AudioDataDestination:function(e,t){var i=new Audio;i.mozSetup(2,e);var n,r=0,o=e/2,a=null;setInterval(function(){var e;if(a){if(e=i.mozWriteAudio(a.subarray(n)),r+=e,n+=e,n<a.length)return;a=null}var s=i.mozCurrentSampleOffset(),l=s+o-r;if(l>0){var c=new Float32Array(l);t(c),e=i.mozWriteAudio(c),s=i.mozCurrentSampleOffset(),e<c.length&&(a=c,n=e),r+=e}},100)},init:function(){var e,t,i="undefined"==typeof arguments[0]?1024:arguments[0];return"undefined"!=typeof webkitAudioContext?e=webkitAudioContext:"undefined"!=typeof AudioContext&&(e=AudioContext),t=function(){if("undefined"!=typeof e){if(document&&document.documentElement&&"ontouchstart"in document.documentElement&&(window.removeEventListener("touchstart",t),"ontouchstart"in document.documentElement)){var i=Gibberish.context.createBufferSource();i.connect(Gibberish.context.destination),i.noteOn(0)}}else alert("Your browser does not support javascript audio synthesis. Please download a modern web browser that is not Internet Explorer.");Gibberish.onstart&&Gibberish.onstart()},Gibberish.context=new e,Gibberish.node=Gibberish.context.createScriptProcessor(i,2,2,Gibberish.context.sampleRate),Gibberish.node.onaudioprocess=Gibberish.audioProcess,Gibberish.node.connect(Gibberish.context.destination),Gibberish.out=new Gibberish.Bus2,Gibberish.out.codegen(),Gibberish.dirty(Gibberish.out),document&&document.documentElement&&"ontouchstart"in document.documentElement?window.addEventListener("touchstart",t):t(),this},makePanner:function(){for(var e=[],t=[],i=Math.sqrt(2)/2,n=0;1024>n;n++){var r=-1+n/1024*2;e[n]=i*(Math.cos(r)-Math.sin(r)),t[n]=i*(Math.cos(r)+Math.sin(r))}return function(i,n,r){var o,a,s,l,c,u,h="object"==typeof i,f=h?i[0]:i,p=h?i[1]:i;return o=1023*(n+1)/2,a=0|o,s=o-a,a=1023&a,l=1023===a?0:a+1,c=e[a],u=e[l],r[0]=(c+s*(u-c))*f,c=t[a],u=t[l],r[1]=(c+s*(u-c))*p,r}},defineUgenProperty:function(e,t,i){var n=i.properties[e]={value:t,binops:[],parent:i,name:e};Object.defineProperty(i,e,{configurable:!0,get:function(){return n.value},set:function(e){n.value=e,Gibberish.dirty(i)}})},polyInit:function(e){e.mod=e.polyMod,e.removeMod=e.removePolyMod,e.voicesClear=function(){if(e.children.length>0){for(var t=0;t<e.children.length;t++)e.children[t].disconnect();e.children.length=0,e.voiceCount=0}};for(var t in e.polyProperties)!function(t){var i=e.polyProperties[t];Object.defineProperty(e,t,{configurable:!0,get:function(){return i},set:function(n){i=n;for(var r=0;r<e.children.length;r++)e.children[r][t]=i}})}(t);var i=e.maxVoices;Object.defineProperty(e,"maxVoices",{get:function(){return i},set:function(e){i=e,this.voicesClear(),this.initVoices()}})},interpolate:function(e,t){var i=0|t,n=i+1>e.length-1?0:i+1;return frac=t-i,e[i]+frac*(e[n]-e[i])},pushUnique:function(e,t){for(var i=e,n=!0,r=0;r<t.length;r++)if(i===t[r]){n=!1;break}n&&t.push(i)},"export":function(e,t){for(var i in Gibberish[e])t[i]=Gibberish[e][i]},ugen:function(){Gibberish.extend(this,{processProperties:function(){if("object"!=typeof arguments[0][0]||"undefined"!=typeof arguments[0][0].type||Array.isArray(arguments[0][0])||"op"===arguments[0][0].name){var e=0;for(var t in this.properties)"object"==typeof this.properties[t]&&"undefined"!=typeof this.properties[t].binops?"undefined"!=typeof arguments[0][e]&&(this.properties[t].value=arguments[0][e++]):"undefined"!=typeof arguments[0][e]&&(this.properties[t]=arguments[0][e++])}else{var i=arguments[0][0];for(var t in i)"undefined"!=typeof i[t]&&("object"==typeof this.properties[t]&&"undefined"!=typeof this.properties[t].binops?this.properties[t].value=i[t]:this[t]=i[t])}return this},valueOf:function(){return this.codegen(),this.variable},codegen:function(){var e="",t=null;if(Gibberish.memo[this.symbol])return Gibberish.memo[this.symbol];t=this.variable?this.variable:Gibberish.generateSymbol("v"),Gibberish.memo[this.symbol]=t,this.variable=t,e+="var "+t+" = "+this.symbol+"(";for(var i in this.properties){var n=this.properties[i],r="";if(Array.isArray(n.value)){0===n.value.length&&(r=0);for(var o=0;o<n.value.length;o++){var a=n.value[o];r+="object"==typeof a?null!==a?a.valueOf():"null":"function"==typeof n.value?n.value():n.value,r+=o<n.value.length-1?", ":""}}else"object"==typeof n.value?null!==n.value&&(r=n.value.codegen?n.value.valueOf():n.value):"undefined"!==n.name&&(r="function"==typeof n.value?n.value():n.value);if(0!=n.binops.length){for(var s=0;s<n.binops.length;s++)e+="(";for(var l=0;l<n.binops.length;l++){var c,u=n.binops[l];c="number"==typeof u.ugen?u.ugen:null!==u.ugen?u.ugen.valueOf():"null","="===u.binop?(e=e.replace(r,""),e+=c):"++"===u.binop?e+=" + Math.abs("+c+")":(0===l&&(e+=r),e+=" "+u.binop+" "+c+")")}}else e+=r;e+=", "}return" "===e.charAt(e.length-1)&&(e=e.slice(0,-2)),e+=");\n",this.codeblock=e,-1===Gibberish.codeblock.indexOf(this.codeblock)&&Gibberish.codeblock.push(this.codeblock),-1===Gibberish.callbackArgs.indexOf(this.symbol)&&"op"!==this.name&&Gibberish.callbackArgs.push(this.symbol),-1===Gibberish.callbackObjects.indexOf(this.callback)&&"op"!==this.name&&Gibberish.callbackObjects.push(this.callback),this.dirty=!1,t},init:function(){if(this.initalized||(this.symbol=Gibberish.generateSymbol(this.name),this.codeblock=null,this.variable=null),"undefined"==typeof this.properties&&(this.properties={}),!this.initialized){this.destinations=[];for(var e in this.properties)Gibberish.defineUgenProperty(e,this.properties[e],this)}if(arguments.length>0&&"object"==typeof arguments[0][0]&&"undefined"===arguments[0][0].type){var t=arguments[0][0];for(var e in t)this[e]=t[e]}return this.initialized=!0,this},mod:function(e,t,i){var n=this.properties[e],r={ugen:t,binop:i};n.binops.push(r),Gibberish.dirty(this)},removeMod:function(e,t){if("undefined"==typeof t)this.properties[e].binops.length=0;else if("number"==typeof t)this.properties[e].binops.splice(t,1);else if("object"==typeof t)for(var i=0,n=this.properties[e].binops.length;n>i;i++)this.properties[e].binops[i].ugen===t&&this.properties[e].binops.splice(i,1);Gibberish.dirty(this)},polyMod:function(e,t,i){for(var n=0;n<this.children.length;n++)this.children[n].mod(e,t,i);Gibberish.dirty(this)},removePolyMod:function(){var e=Array.prototype.slice.call(arguments,0);if("amp"!==arguments[0]&&"pan"!==arguments[0])for(var t=0;t<this.children.length;t++)this.children[t].removeMod.apply(this.children[t],e);else this.removeMod.apply(this,e);Gibberish.dirty(this)},smooth:function(e){var t=new Gibberish.OnePole;this.mod(e,t,"=")},connect:function(e,t){return"undefined"==typeof e&&(e=Gibberish.out),-1===this.destinations.indexOf(e)&&(e.addConnection(this,1,t),this.destinations.push(e)),this},send:function(e,t){return-1===this.destinations.indexOf(e)?(e.addConnection(this,t),this.destinations.push(e)):e.adjustSendAmount(this,t),this},disconnect:function(e,t){var i;if(e)i=this.destinations.indexOf(e),i>-1&&this.destinations.splice(i,1),e.removeConnection(this);else{for(var n=0;n<this.destinations.length;n++)this.destinations[n].removeConnection(this);this.destinations=[]}return Gibberish.dirty(this),this}})}};Array2=function(){this.length=0},Array2.prototype=[],Array2.prototype.remove=function(e,t){if(t="undefined"==typeof t?!0:t,"undefined"==typeof e){for(var i=0;i<this.length;i++)delete this[i];this.length=0}else if("number"==typeof e)this.splice(e,1);else if("string"==typeof e){for(var n=[],i=0;i<this.length;i++){var r=this[i];if(r.type===e||r.name===e){if(!t)return void this.splice(i,1);n.push(i)}}for(var i=0;i<n.length;i++)this.splice(n[i],1)}else if("object"==typeof e)for(var o=this.indexOf(e);o>-1;)this.splice(o,1),o=this.indexOf(e);this.parent&&Gibberish.dirty(this.parent)},Array2.prototype.get=function(e){if("number"==typeof e)return this[e];if("string"==typeof e)for(var t=0;t<this.length;t++){var i=this[t];if(i.name===e)return i}else if("object"==typeof e){var n=this.indexOf(e);if(n>-1)return this[n]}return null},Array2.prototype.replace=function(e,t){if(t.parent=this,t.input=e.input,"number"!=typeof e){var i=this.indexOf(e);i>-1&&this.splice(i,1,t)}else this.splice(e,1,t);this.parent&&Gibberish.dirty(this.parent)},Array2.prototype.insert=function(e,t){if(e.parent=this,this.input=this.parent,Array.isArray(e))for(var i=0;i<e.length;i++)this.splice(t+i,0,e[i]);else this.splice(t,0,e);this.parent&&Gibberish.dirty(this.parent)},Array2.prototype.add=function(){for(var e=0;e<arguments.length;e++)arguments[e].parent=this,arguments[e].input=this.parent,this.push(arguments[e]);this.parent&&(console.log("DIRTYING"),Gibberish.dirty(this.parent))};var rnd=Math.random;Gibberish.rndf=function(e,t,i,n){if(n="undefined"==typeof n?!0:n,"undefined"==typeof i&&"object"!=typeof e){1==arguments.length?(t=arguments[0],e=0):2==arguments.length?(e=arguments[0],t=arguments[1]):(e=0,t=1);var r=t-e,o=Math.random(),a=r*o;return e+a}var s=[],l=[];"undefined"==typeof i&&(i=t||e.length);for(var c=0;i>c;c++){var u;if("object"==typeof arguments[0])u=arguments[0][rndi(0,arguments[0].length-1)];else if(n)u=Gibberish.rndf(e,t);else{for(u=Gibberish.rndf(e,t);l.indexOf(u)>-1;)u=Gibberish.rndf(e,t);l.push(u)}s.push(u)}return s},Gibberish.Rndf=function(){{var e,t,i,n;Math.random}return 0===arguments.length?(e=0,t=1):1===arguments.length?(t=arguments[0],e=0):2===arguments.length?(e=arguments[0],t=arguments[1]):3===arguments.length?(e=arguments[0],t=arguments[1],i=arguments[2]):(e=arguments[0],t=arguments[1],i=arguments[2],n=arguments[3]),function(){var r,o,a;return o="function"==typeof e?e():e,a="function"==typeof t?t():t,r="undefined"==typeof i?Gibberish.rndf(o,a):Gibberish.rndf(o,a,i,n)}},Gibberish.rndi=function(e,t,i,n){var r;if(0===arguments.length?(e=0,t=1):1===arguments.length?(t=arguments[0],e=0):2===arguments.length?(e=arguments[0],t=arguments[1]):(e=arguments[0],t=arguments[1],i=arguments[2],n=arguments[3]),r=t-e,i>r&&(n=!0),"undefined"==typeof i)return r=t-e,Math.round(e+Math.random()*r);for(var o=[],a=[],s=0;i>s;s++){var l;if(n)l=Gibberish.rndi(e,t);else{for(l=Gibberish.rndi(e,t);a.indexOf(l)>-1;)l=Gibberish.rndi(e,t);a.push(l)}o.push(l)}return o},Gibberish.Rndi=function(){{var e,t,i,n,r;Math.random,Math.round}return 0===arguments.length?(e=0,t=1):1===arguments.length?(t=arguments[0],e=0):2===arguments.length?(e=arguments[0],t=arguments[1]):3===arguments.length?(e=arguments[0],t=arguments[1],i=arguments[2]):(e=arguments[0],t=arguments[1],i=arguments[2],n=arguments[3]),r=t-e,"number"==typeof i&&i>r&&(n=!0),function(){var r,o,a;return o="function"==typeof e?e():e,a="function"==typeof t?t():t,r="undefined"==typeof i?Gibberish.rndi(o,a):Gibberish.rndi(o,a,i,n)}},Gibberish.extend=function(e,t){for(var i in t){{i.split(".")}t[i]instanceof Array&&t[i].length<100?(e[i]=t[i].slice(0),"fx"===i&&(e[i].parent=t[i].parent)):"object"!=typeof t[i]||null===t[i]||t[i]instanceof Float32Array?e[i]=t[i]:(e[i]=e[i]||{},arguments.callee(e[i],t[i]))}return e},Function.prototype.clone=function(){return eval("["+this.toString()+"]")[0]},String.prototype.format=function(e,t,i){function n(){var n=this,r=arguments.length+1;for(e=0;r>e;i=arguments[e++])t=i,n=n.replace(RegExp("\\{"+(e-1)+"\\}","g"),t);return n}return n.native=String.prototype.format,n}(),Gibberish.future=function(e,t){var i=new Gibberish.Sequencer({values:[function(){},function(){e(),i.stop(),i.disconnect()}],durations:[t]}).start();return i.cancel=function(){i.stop(),i.disconnect()},i},Gibberish.Proxy=function(){var e=0;Gibberish.extend(this,{name:"proxy",type:"effect",properties:{},callback:function(){return e}}).init(),this.input=arguments[0],e=this.input.parent[this.input.name],delete this.input.parent[this.input.name],this.input.parent.properties[this.input.name].value=this,Object.defineProperty(this.input.parent,this.input.name,{get:function(){return e},set:function(t){e=t}}),Gibberish.dirty(this.input.parent)},Gibberish.Proxy.prototype=new Gibberish.ugen,Gibberish.Proxy2=function(){var e=arguments[0],t=arguments[1];Gibberish.extend(this,{name:"proxy2",type:"effect",properties:{},callback:function(){var i=e[t];return Array.isArray(i)?(i[0]+i[1]+i[2])/3:i}}).init(),this.getInput=function(){return e},this.setInput=function(t){e=t},this.getName=function(){return t},this.setName=function(e){t=e}},Gibberish.Proxy2.prototype=new Gibberish.ugen,Gibberish.Proxy3=function(){var e=arguments[0],t=arguments[1];Gibberish.extend(this,{name:"proxy3",type:"effect",properties:{},callback:function(){var i=e[t];return i||0}}),this.init(),this.codegen=function(){console.log(" CALLED "),this.variable||(this.variable=Gibberish.generateSymbol("v")),Gibberish.callbackArgs.push(this.symbol),Gibberish.callbackObjects.push(this.callback),this.codeblock="var "+this.variable+" = "+this.symbol+"("+e.properties[t].codegen()+");\n"}},Gibberish.Proxy3.prototype=new Gibberish.ugen,Gibberish.oscillator=function(){this.type="oscillator",this.oscillatorInit=function(){return this.fx=new Array2,this.fx.parent=this,this}},Gibberish.oscillator.prototype=new Gibberish.ugen,Gibberish._oscillator=new Gibberish.oscillator,Gibberish.Wavetable=function(){var e=0,t=null,i=Gibberish.context.sampleRate/1024;this.properties={frequency:440,amp:.25,sync:0},this.getTable=function(){return t},this.setTable=function(e){t=e,i=Gibberish.context.sampleRate/t.length},this.getTableFreq=function(){return i},this.setTableFreq=function(e){i=e},this.getPhase=function(){return e},this.setPhase=function(t){e=t},this.callback=function(n,r){var o,a,s,l,c;for(e+=n/i;e>=1024;)e-=1024;return o=0|e,a=e-o,o=1023&o,s=1023===o?0:o+1,l=t[o],c=t[s],(l+a*(c-l))*r}},Gibberish.Wavetable.prototype=Gibberish._oscillator,Gibberish.Table=function(e){this.__proto__=new Gibberish.Wavetable,this.name="table";var t=2*Math.PI;if("undefined"==typeof e){e=new Float32Array(1024);for(var i=1024;i--;)e[i]=Math.sin(i/1024*t)}this.setTable(e),this.init(),this.oscillatorInit()},Gibberish.asmSine=function(e,t,i){"use asm";function n(){for(var e=1024,t=1024;e=e-1|0;)t-=1,l[e>>2]=+a(+(t/1024)*6.2848);u=44100/1024}function r(e,t,i){e=+e,t=+t,i=+i;var n=0,r=0,o=0,a=0,h=0,f=0;return s=+(s+e/u),s>=1024&&(s=+(s-1024)),n=+c(s),a=s-n,r=~~n,o=(r|0)==1024?0:r+1|0,h=+l[r>>2],f=+l[o>>2],+((h+a*(f-h))*t)}function o(e){return e|=0,+l[e>>2]}var a=e.Math.sin,s=0,l=new e.Float32Array(i),c=e.Math.floor,u=0;return{init:n,gen:r,get:o}},Gibberish.asmSine2=function(){this.properties={frequency:440,amp:.5,sr:Gibberish.context.sampleRate},this.name="sine";var e=new ArrayBuffer(4096),t=Gibberish.asmSine(window,null,e);return t.init(),this.getTable=function(){return e},this.get=t.get,this.callback=t.gen,this.init(),this.oscillatorInit(),this.processProperties(arguments),this},Gibberish.asmSine2.prototype=Gibberish._oscillator,Gibberish.Sine=function(){this.__proto__=new Gibberish.Wavetable,this.name="sine";for(var e=2*Math.PI,t=new Float32Array(1024),i=1024;i--;)t[i]=Math.sin(i/1024*e);this.setTable(t),this.init(arguments),this.oscillatorInit(),this.processProperties(arguments)},Gibberish.Sine2=function(){this.__proto__=new Gibberish.Sine,this.name="sine2";var e=this.__proto__.callback,t=Gibberish.makePanner(),i=[0,0];this.callback=function(n,r,o){var a=e(n,r);return i=t(a,o,i)},this.init(),this.oscillatorInit(),Gibberish.defineUgenProperty("pan",0,this),this.processProperties(arguments)},Gibberish.Square=function(){this.__proto__=new Gibberish.Wavetable,this.name="square";for(var e=(2*Math.PI,new Float32Array(1024)),t=1024;t--;)e[t]=t/1024>.5?1:-1;this.setTable(e),this.init(arguments),this.oscillatorInit(),this.processProperties(arguments)},Gibberish.Saw=function(){this.__proto__=new Gibberish.Wavetable,this.name="saw";for(var e=new Float32Array(1024),t=1024;t--;)e[t]=4*((t/1024/2+.25)%.5-.25);this.setTable(e),this.init(arguments),this.oscillatorInit(),this.processProperties(arguments)},Gibberish.Saw2=function(){this.__proto__=new Gibberish.Saw,this.name="saw2";var e=this.__proto__.callback,t=Gibberish.makePanner(),i=[0,0];this.callback=function(n,r,o){var a=e(n,r);return i=t(a,o,i)},this.init(),Gibberish.defineUgenProperty("pan",0,this)},Gibberish.Triangle=function(){this.__proto__=new Gibberish.Wavetable,this.name="triangle";for(var e=new Float32Array(1024),t=Math.abs,i=1024;i--;)e[i]=1-4*t((i/1024+.25)%1-.5);this.setTable(e),this.init(arguments),this.oscillatorInit(),this.processProperties(arguments)},Gibberish.Triangle2=function(){this.__proto__=new Gibberish.Triangle,this.name="triangle2";var e=this.__proto__.callback,t=Gibberish.makePanner(),i=[0,0];this.callback=function(n,r,o){var a=e(n,r);return t(a,o,i)},this.init(),this.oscillatorInit(),Gibberish.defineUgenProperty("pan",0,this),this.processProperties(arguments)},Gibberish.Saw3=function(){var e=0,t=0,i=2.5,n=-1.5,r=0,o=Math.sin,a=11;pi_2=2*Math.PI,flip=0,signHistory=0,ignore=!1,sr=Gibberish.context.sampleRate,Gibberish.extend(this,{name:"saw",properties:{frequency:440,amp:.15,sync:0,sr:Gibberish.context.sampleRate},callback:function(s){var l=s/sr,c=.5-l,u=a*c*c*c*c,h=.376-.752*l,f=1-2*l,p=0;return t+=l,t-=t>1?2:0,e=.5*(e+o(pi_2*(t+e*u))),p=i*e+n*r,r=e,p+=h,p*=f}}),Object.defineProperty(this,"scale",{get:function(){return a},set:function(e){a=e}}),this.init(),this.oscillatorInit(),this.processProperties(arguments)},Gibberish.Saw3.prototype=Gibberish._oscillator,Gibberish.PWM=function(){var e=0,t=0,i=0,n=0,r=0,o=2.5,a=-1.5,s=Math.sin,l=11;pi_2=2*Math.PI,test=0,sr=Gibberish.context.sampleRate,Gibberish.extend(this,{name:"pwm",properties:{frequency:440,amp:.15,pulsewidth:.05,sr:Gibberish.context.sampleRate},callback:function(c,u,h){var f=c/sr,p=.5-f,d=l*p*p*p*p,m=1-2*f,g=0;return r+=f,r-=r>1?2:0,e=.5*(e+s(pi_2*(r+e*d))),t=.5*(t+s(pi_2*(r+t*d+h))),g=t-e,g=o*g+a*(i-n),i=e,n=t,g*m*u}}),Object.defineProperty(this,"scale",{get:function(){return l},set:function(e){l=e}}),this.init(),this.oscillatorInit(),this.processProperties(arguments)},Gibberish.PWM.prototype=Gibberish._oscillator,Gibberish.Noise=function(){var e=Math.random;Gibberish.extend(this,{name:"noise",properties:{amp:1},callback:function(t){return(2*e()-1)*t}}),this.init(),this.oscillatorInit(),this.processProperties(arguments)},Gibberish.Noise.prototype=Gibberish._oscillator,Gibberish.KarplusStrong=function(){var e=[0],t=0,i=Math.random,n=Gibberish.makePanner(),r=Gibberish.context.sampleRate,o=[0,0];Gibberish.extend(this,{name:"karplus_strong",frequency:0,properties:{blend:1,damping:0,amp:1,channels:2,pan:0},note:function(t){if("undefined"!=typeof t){var n=Math.floor(r/t);e.length=0;for(var o=0;n>o;o++)e[o]=2*i()-1;this.frequency=t}},callback:function(r,a,s,l,c){var u=e.shift(),h=i()>r?-1:1;a=a>0?a:0;var f=h*(u+t)*(.5-a/100);return t=f,e.push(f),f*=s,1===l?f:n(f,c,o)}}).init().oscillatorInit().processProperties(arguments)},Gibberish.KarplusStrong.prototype=Gibberish._oscillator,Gibberish.PolyKarplusStrong=function(){this.__proto__=new Gibberish.Bus2,Gibberish.extend(this,{name:"poly_karplus_strong",maxVoices:5,voiceCount:0,_frequency:0,polyProperties:{blend:1,damping:0},note:function(e,t){var i=this.children[this.voiceCount++];this.voiceCount>=this.maxVoices&&(this.voiceCount=0),i.note(e,t),this._frequency=e},initVoices:function(){for(var e=0;e<this.maxVoices;e++){var t={blend:this.blend,damping:this.damping,channels:2,amp:1},i=new Gibberish.KarplusStrong(t).connect(this);this.children.push(i)}}}),this.amp=1/this.maxVoices,this.children=[],"object"==typeof arguments[0]&&(this.maxVoices=arguments[0].maxVoices?arguments[0].maxVoices:this.maxVoices),Gibberish.polyInit(this),this.initVoices(),this.processProperties(arguments),this.initialized=!1,Gibberish._synth.oscillatorInit.call(this),Gibberish.dirty(this)},Gibberish.bus=function(){this.type="bus",this.inputCodegen=function(){var e,t=this.value.valueOf();return e=t+", "+this.amp,this.codeblock=e,e},this.addConnection=function(){var e=arguments[2],t={value:arguments[0],amp:arguments[1],codegen:this.inputCodegen,valueOf:function(){return this.codegen()}};"undefined"!=typeof e?this.inputs.splice(e,0,t):this.inputs.push(t),Gibberish.dirty(this)},this.removeConnection=function(e){for(var t=0;t<this.inputs.length;t++)if(this.inputs[t].value===e){this.inputs.splice(t,1),Gibberish.dirty(this);break}},this.adjustSendAmount=function(e,t){for(var i=0;i<this.inputs.length;i++)if(this.inputs[i].value===e){this.inputs[i].amp=t,Gibberish.dirty(this);break}},this.callback=function(){var e=arguments[arguments.length-2],t=arguments[arguments.length-1];output[0]=output[1]=0;for(var i=0;i<arguments.length-2;i+=2){var n="object"==typeof arguments[i],r=arguments[i+1];output[0]+=n?arguments[i][0]*r:arguments[i]*r,output[1]+=n?arguments[i][1]*r:arguments[i]*r}return output[0]*=e,output[1]*=e,panner(output,t,output)}},Gibberish.bus.prototype=new Gibberish.ugen,Gibberish._bus=new Gibberish.bus,Gibberish.Bus=function(){return Gibberish.extend(this,{name:"bus",properties:{inputs:[],amp:1},callback:function(){for(var e=0,t=arguments.length-1,i=arguments[t],n=0;t>n;n++)e+=arguments[n];return e*=i}}),this.init(),this.processProperties(arguments),this},Gibberish.Bus.prototype=Gibberish._bus,Gibberish.Bus2=function(){this.name="bus2",this.type="bus",this.properties={inputs:[],amp:1,pan:0};var e=[0,0],t=Gibberish.makePanner();this.callback=function(){var i=arguments,n=i.length,r=i[n-2],o=i[n-1];e[0]=e[1]=0;for(var a=0,s=n-2;s>a;a+=2){var l="object"==typeof i[a],c=i[a+1];e[0]+=l?i[a][0]*c||0:i[a]*c||0,e[1]+=l?i[a][1]*c||0:i[a]*c||0}return e[0]*=r,e[1]*=r,t(e,o,e)},this.show=function(){console.log(e,args)},this.getOutput=function(){return e},this.getArgs=function(){return args},this.init(arguments),this.processProperties(arguments)},Gibberish.Bus2.prototype=Gibberish._bus,Gibberish.envelope=function(){this.type="envelope"},Gibberish.envelope.prototype=new Gibberish.ugen,Gibberish._envelope=new Gibberish.envelope,Gibberish.ExponentialDecay=function(){var e=Math.pow,t=0,i=0;Gibberish.extend(this,{name:"ExponentialDecay",properties:{decay:.5,length:11050},callback:function(n,r){return t=e(n,i),i+=1/r,t},trigger:function(){i="number"==typeof arguments[0]?arguments[0]:0}}).init()},Gibberish.ExponentialDecay.prototype=Gibberish._envelope,Gibberish.Line=function(e,t,i,n){var r,o={name:"line",properties:{start:e||0,end:isNaN(t)?1:t,time:i||Gibberish.context.sampleRate,loops:n||!1},retrigger:function(e,t){a=0,this.start=r,this.end=e,this.time=t,s=(e-r)/t},getPhase:function(){return a},getIncr:function(){return s},getOut:function(){return r}},a=0,s=(t-e)/i;return this.callback=function(e,t,i,n){var o=(t-e)/i;return r=i>a?e+a++*o:t,a=r>=t&&n?0:a,r},this.setPhase=function(e){a=e},Gibberish.extend(this,o),this.init(),this},Gibberish.Line.prototype=Gibberish._envelope,Gibberish.Ease=function(e,t,i,n,r){var o=Math.sqrt,a=0,s=0;e=e||0,t=t||1,i=i||Gibberish.context.sampleRate,r=r||!1,n="undefined"==typeof n?1:n;var l={name:"ease",properties:{},retrigger:function(e,t){s=0,this.start=a,this.end=e,this.time=t},getPhase:function(){return s},getOut:function(){return a}};return this.callback=function(){var l=s++/i,c=n?1-o(1-l*l):o(1-(1-l)*(1-l));return a=i>s?e+c*(t-e):t,s=a>=t&&r?0:s,a},this.setPhase=function(e){s=e},this.setEase=function(e){n=e},Gibberish.extend(this,l),this.init(),this},Gibberish.Ease.prototype=Gibberish._envelope,Gibberish.Curve=function(e,t,i,n,r,o,a){var s=Math.sqrt,l=0,c=0;console.log("FDAE IN ",o),e=e||0,t=t||1,i=i||Gibberish.context.sampleRate,n=n||.94,r=r||.26,a=a||!1,o="undefined"==typeof o?1:o;var u={name:"curve",properties:{},retrigger:function(e,t){c=0,this.start=l,this.end=e,this.time=t,incr=(e-l)/t},getPhase:function(){return c},getOut:function(){return l}};return this.callback=function(){var u=c++/i,h=1-2*n,f=(s(n*n+h*u)-n)/h,p=(1-2*r)*f*f+2*r*f;return l=i>c?e+p*(t-e):t,o||(l=1-l),c=l>=t&&a?0:c,l},this.setPhase=function(e){c=e},Gibberish.extend(this,u),this.init(),this},Gibberish.Curve.prototype=Gibberish._envelope,Gibberish.Lines=function(e,t,i){var n,r=e[0],o=0,a=1,s=0,l=0,c=0,u=!1;"undefined"==typeof e&&(e=[0,1]),"undefined"==typeof t&&(t=[44100]),l=e[a],c=t[0],n=(l-e[0])/c,i=i||!1;var h={name:"lines",properties:{},retrigger:function(){o=0,r=e[0],c=t[0],l=e[1],a=1,s=0,n=(l-r)/c,u=!1},getPhase:function(){return o},getOut:function(){return r}};return h.run=h.retrigger,this.callback=function(){if(o>=c&&!u)if(a<e.length-1){var h=t[++s%t.length];c=o+h,l=e[++a%e.length],n=(l-r)/h}else i?(o=0,r=e[0],c=t[0],l=e[1],a=1,s=0,n=(l-r)/c):(u=!0,r=e[e.length-1]);else u||(r+=n,o++);return r},this.setPhase=function(e){o=e},Gibberish.extend(this,h),this.init(),this},Gibberish.Lines.prototype=Gibberish._envelope,Gibberish.AD=function(e,t){var i=0,n=0;Gibberish.extend(this,{name:"AD",properties:{attack:e||1e4,decay:t||1e4},run:function(){return n=0,i=0,this},callback:function(e,t){if(e=0>e?22050:e,t=0>t?22050:t,0===n){var r=1/e;i+=r,i>=1&&n++}else if(1===n){var r=1/t;i-=r,0>=i&&(i=0,n++)}return i},getState:function(){return n}}).init().processProperties(arguments)},Gibberish.AD.prototype=Gibberish._envelope,Gibberish.ADSR=function(e,t,i,n,r,o,a){var s={name:"adsr",type:"envelope",requireReleaseTrigger:"undefined"!=typeof a?a:!1,properties:{attack:isNaN(e)?1e4:e,decay:isNaN(t)?1e4:t,sustain:isNaN(i)?22050:i,release:isNaN(n)?1e4:n,attackLevel:r||1,sustainLevel:o||.5,releaseTrigger:0},run:function(){this.setPhase(0),this.setState(0)},stop:function(){this.releaseTrigger=1}};Gibberish.extend(this,s);var l=0,c=0,u=0,h=this;return this.callback=function(e,t,i,n,r,o,a){var s=0;return u=1===u?1:a,0===c?(s=l/e*r,++l/e>=1&&(c++,l=t)):1===c?(s=l/t*(r-o)+o,--l<=0&&(null!==i?(c+=1,l=i):(c+=2,l=n))):2===c?(s=o,h.requireReleaseTrigger&&u?(c++,l=n,h.releaseTrigger=0,u=0):l--<=0&&!h.requireReleaseTrigger&&(c++,l=n)):3===c&&(l--,s=l/n*o,0>=l&&c++),s},this.call=function(){return this.callback(this.attack,this.decay,this.sustain,this.release,this.attackLevel,this.sustainLevel,this.releaseTrigger)},this.getPhase=function(){return l},this.setPhase=function(e){l=e},this.setState=function(e){c=e,l=0},this.getState=function(){return c},this.init(),this},Gibberish.ADSR.prototype=Gibberish._envelope,Gibberish.ADR=function(e,t,i,n,r){var o={name:"adr",type:"envelope",properties:{attack:isNaN(e)?11025:e,decay:isNaN(t)?11025:t,release:isNaN(i)?22050:i,attackLevel:n||1,releaseLevel:r||.2},run:function(){this.setPhase(0),this.setState(0)}};Gibberish.extend(this,o);var a=0,s=0;return this.callback=function(e,t,i,n,r){var o=0;return 0===s?(o=a/e*n,++a/e===1&&(s++,a=t)):1===s?(o=a/t*(n-r)+r,--a<=0&&(s+=1,a=i)):2===s&&(a--,o=a/i*r,0>=a&&s++),o},this.setPhase=function(e){a=e},this.setState=function(e){s=e,a=0},this.getState=function(){return s},this.init(),this},Gibberish.ADR.prototype=Gibberish._envelope,Gibberish.analysis=function(){this.type="analysis",this.codegen=function(){if(Gibberish.memo[this.symbol])return Gibberish.memo[this.symbol];var e=this.variable?this.variable:Gibberish.generateSymbol("v");return Gibberish.memo[this.symbol]=e,this.variable=e,Gibberish.callbackArgs.push(this.symbol),Gibberish.callbackObjects.push(this.callback),this.codeblock="var "+this.variable+" = "+this.symbol+"();\n",-1===Gibberish.codeblock.indexOf(this.codeblock)&&Gibberish.codeblock.push(this.codeblock),this.variable},this.analysisCodegen=function(){var e=0;this.input.codegen?(e=this.input.codegen(),e.indexOf("op")>-1&&console.log("ANALYSIS BUG")):e=this.input.value?"undefined"!=typeof this.input.value.codegen?this.input.value.codegen():this.input.value:"null";var t=this.analysisSymbol+"("+e+",";for(var i in this.properties)"input"!==i&&(t+=this[i]+",");return t=t.slice(0,-1),t+=");",this.analysisCodeblock=t,-1===Gibberish.analysisCodeblock.indexOf(this.analysisCodeblock)&&Gibberish.analysisCodeblock.push(this.analysisCodeblock),-1===Gibberish.callbackObjects.indexOf(this.analysisCallback)&&Gibberish.callbackObjects.push(this.analysisCallback),t},this.remove=function(){Gibberish.analysisUgens.splice(Gibberish.analysisUgens.indexOf(this),1)},this.analysisInit=function(){this.analysisSymbol=Gibberish.generateSymbol(this.name),Gibberish.analysisUgens.push(this),Gibberish.dirty()}},Gibberish.analysis.prototype=new Gibberish.ugen,Gibberish._analysis=new Gibberish.analysis,Gibberish.Follow=function(){this.name="follow",this.properties={input:0,bufferSize:4410,mult:1,useAbsoluteValue:!0},this.storage=[]; var e=Math.abs,t=[0],i=0,n=0,r=0;this.analysisCallback=function(o,a,s,l){"object"==typeof o&&(o=o[0]+o[1]),i+=l?e(o):o,i-=t[n],t[n]=l?e(o):o,n=(n+1)%a,t[n]=t[n]?t[n]:0,r=i/a*s},this.callback=this.getValue=function(){return r},this.init(),this.analysisInit(),this.processProperties(arguments);var o=(this.__lookupSetter__("bufferSize"),this.bufferSize);Object.defineProperty(this,"bufferSize",{get:function(){return o},set:function(e){o=e,i=0,t=[0],n=0}}),this.getStorage=function(){return this.storage}},Gibberish.Follow.prototype=Gibberish._analysis,Gibberish.SingleSampleDelay=function(){this.name="single_sample_delay",this.properties={input:arguments[0]||0,amp:arguments[1]||1};var e=0;this.analysisCallback=function(t){e=t},this.callback=function(){return e},this.getValue=function(){return e},this.init(),this.analysisInit(),this.processProperties(arguments)},Gibberish.SingleSampleDelay.prototype=Gibberish._analysis,Gibberish.Record=function(e,t,i){var n=new Float32Array(t),r=0,o=!1,a=this;Gibberish.extend(this,{name:"record",oncomplete:i,properties:{input:0,size:t||0},analysisCallback:function(e,t){o&&(n[r++]="object"==typeof e?e[0]+e[1]:e,r>=t&&(o=!1,a.remove()))},record:function(){return r=0,o=!0,this},getBuffer:function(){return n},getPhase:function(){return r},remove:function(){"undefined"!=typeof this.oncomplete&&this.oncomplete();for(var e=0;e<Gibberish.analysisUgens.length;e++){var t=Gibberish.analysisUgens[e];if(t===this)return Gibberish.callbackArgs.indexOf(this.analysisSymbol)>-1&&Gibberish.callbackArgs.splice(Gibberish.callbackArgs.indexOf(this.analysisSymbol),1),Gibberish.callbackObjects.indexOf(this.analysisCallback)>-1&&Gibberish.callbackObjects.splice(Gibberish.callbackObjects.indexOf(this.analysisCallback),1),void Gibberish.analysisUgens.splice(e,1)}}}),this.properties.input=e,this.init(),this.analysisInit(),Gibberish.dirty()},Gibberish.Record.prototype=Gibberish._analysis,Gibberish.effect=function(){this.type="effect"},Gibberish.effect.prototype=new Gibberish.ugen,Gibberish._effect=new Gibberish.effect,Gibberish.Distortion=function(){var e=Math.abs,t=Math.log,i=Math.LN2;Gibberish.extend(this,{name:"distortion",properties:{input:0,amount:50},callback:function(n,r){var o;return r=r>2?r:2,"number"==typeof n?(o=n*r,n=o/(1+e(o))/(t(r)/i)):(o=n[0]*r,n[0]=o/(1+e(o))/(t(r)/i),o=n[1]*r,n[1]=o/(1+e(o))/(t(r)/i)),n}}).init().processProperties(arguments)},Gibberish.Distortion.prototype=Gibberish._effect,Gibberish.Gain=function(){Gibberish.extend(this,{name:"gain",properties:{input:0,amount:1},callback:function(e,t){return"number"==typeof e?e*=t:(e[0]*=t,e[1]*=t),e}}).init().processProperties(arguments)},Gibberish.Gain.prototype=Gibberish._effect,Gibberish.Delay=function(){var e=[],t=0;e.push(new Float32Array(2*Gibberish.context.sampleRate)),e.push(new Float32Array(2*Gibberish.context.sampleRate)),Gibberish.extend(this,{name:"delay",properties:{input:0,time:22050,feedback:.5,wet:1,dry:1,rate:1},callback:function(i,n,r,o,a,s){var l="number"==typeof i?1:2,c=t++%88200;n/=s;var u=(c+(0|n))%88200;return 1===l?(e[0][u]=i+e[0][c]*r,i=i*a+e[0][c]*o):(e[0][u]=i[0]+e[0][c]*r,i[0]=i[0]*a+e[0][c]*o,e[1][u]=i[1]+e[1][c]*r,i[1]=i[1]*a+e[1][c]*o),i}});var i=Math.round(this.properties.time);Object.defineProperty(this,"time",{configurable:!0,get:function(){return i},set:function(e){i=Math.round(e),Gibberish.dirty(this)}}),this.init(),this.processProperties(arguments)},Gibberish.Delay.prototype=Gibberish._effect,Gibberish.Decimator=function(){var e=0,t=[],i=Math.pow,n=Math.floor;Gibberish.extend(this,{name:"decimator",properties:{input:0,bitDepth:16,sampleRate:1},callback:function(r,o,a){e+=a;var s="number"==typeof r?1:2;if(1===s){if(e>=1){var l=i(o,2);t[0]=n(r*l)/l,e-=1}r=t[0]}else{if(e>=1){var l=i(o,2);t[0]=n(r[0]*l)/l,t[1]=n(r[1]*l)/l,e-=1}r=t}return r}}).init().processProperties(arguments)},Gibberish.Decimator.prototype=Gibberish._effect,Gibberish.RingModulation=function(){var e=(new Gibberish.Sine).callback,t=[0,0];Gibberish.extend(this,{name:"ringmod",properties:{input:0,frequency:440,amp:.5,mix:.5},callback:function(i,n,r,o){var a="number"==typeof i?1:2,s=1===a?i:i[0],l=e(n,r);if(s=s*(1-o)+s*l*o,2===a){var c=i[1];return c=c*(1-o)+c*l*o,t[0]=s,t[1]=c,t}return s}}).init().processProperties(arguments)},Gibberish.RingModulation.prototype=Gibberish._effect,Gibberish.DCBlock=function(){var e=0,t=0;Gibberish.extend(this,{name:"dcblock",type:"effect",properties:{input:0},reset:function(){e=0,t=0},callback:function(i){var n=i-e+.9997*t;return e=i,t=n,n}}).init().processProperties(arguments)},Gibberish.DCBlock.prototype=Gibberish._effect,Gibberish.Tremolo=function(){var e=(new Gibberish.Sine).callback;Gibberish.extend(this,{name:"tremolo",type:"effect",properties:{input:0,frequency:2.5,amp:.5},callback:function(t,i,n){var r="number"==typeof t?1:2,o=e(i,n);return 1===r?t*=o:(t[0]*=o,t[1]*=o),t}}).init().processProperties(arguments)},Gibberish.Tremolo.prototype=Gibberish._effect,Gibberish.OnePole=function(){var e=0;Gibberish.extend(this,{name:"onepole",type:"effect",properties:{input:0,a0:.15,b1:.85},callback:function(t,i,n){var r=t*i+e*n;return e=r,r},smooth:function(t,i){this.input=i[t],e=this.input,i[t]=this,this.obj=i,this.property=t,this.oldSetter=i.__lookupSetter__(t),this.oldGetter=i.__lookupGetter__(t);var n=this;Object.defineProperty(i,t,{get:function(){return n.input},set:function(e){n.input=e}})},remove:function(){Object.defineProperty(this.obj,this.property,{get:this.oldGetter,set:this.oldSetter}),this.obj[this.property]=this.input}}).init().processProperties(arguments)},Gibberish.OnePole.prototype=Gibberish._effect,Gibberish.Filter24=function(){var e=[0,0,0,0],t=[0,0,0,0],i=[0,0],n=isNaN(arguments[0])?.1:arguments[0],r=isNaN(arguments[1])?3:arguments[1];_isLowPass="undefined"!=typeof arguments[2]?arguments[2]:!0,Gibberish.extend(this,{name:"filter24",properties:{input:0,cutoff:n,resonance:r,isLowPass:_isLowPass},callback:function(n,r,o,a){var s="number"==typeof n?1:2,l=1===s?n:n[0],c=e[3]*o;if(c=c>1?1:c,r=0>r?0:r,r=r>1?1:r,l-=c,e[0]=e[0]+(-e[0]+l)*r,e[1]=e[1]+(-e[1]+e[0])*r,e[2]=e[2]+(-e[2]+e[1])*r,e[3]=e[3]+(-e[3]+e[2])*r,l=a?e[3]:l-e[3],2===s){var u=n[1];return c=t[3]*o,c=c>1?1:c,u-=c,t[0]=t[0]+(-t[0]+u)*r,t[1]=t[1]+(-t[1]+t[0])*r,t[2]=t[2]+(-t[2]+t[1])*r,t[3]=t[3]+(-t[3]+t[2])*r,u=a?t[3]:u-t[3],i[0]=l,i[1]=u,i}return l}}).init().processProperties(arguments)},Gibberish.Filter24.prototype=Gibberish._effect,Gibberish.SVF=function(){var e=[0,0],t=[0,0],i=Math.PI,n=[0,0];Gibberish.extend(this,{name:"SVF",properties:{input:0,cutoff:440,Q:2,mode:0,sr:Gibberish.context.sampleRate},callback:function(r,o,a,s,l){var c="number"==typeof r?1:2,u=1===c?r:r[0],h=2*i*o/l;a=1/a;var f=t[0]+h*e[0],p=u-f-a*e[0],d=h*p+e[0],m=p+f;if(e[0]=d,t[0]=f,u=0===s?f:1===s?p:2===s?d:m,2===c){var g=r[1],f=t[1]+h*e[1],p=g-f-a*e[1],d=h*p+e[1],m=p+f;e[1]=d,t[1]=f,g=0===s?f:1===s?p:2===s?d:m,n[0]=u,n[1]=g}else n=u;return n}}).init().processProperties(arguments)},Gibberish.SVF.prototype=Gibberish._effect,Gibberish.Biquad=function(){var e=0,t=0,i=0,n=0,r=0,o=0,a=0,s=0,l=[0,0],c=.001639,u=.003278,h=.001639,f=-1.955777,p=.960601,d="LP",m=2e3,g=.5,v=Gibberish.context.sampleRate;Gibberish.extend(this,{name:"biquad",properties:{input:null},calculateCoefficients:function(){switch(d){case"LP":var e=2*Math.PI*m/v,t=Math.sin(e),i=Math.cos(e),n=t/(2*g);c=(1-i)/2,u=1-i,h=c,a0=1+n,f=-2*i,p=1-n;break;case"HP":var e=2*Math.PI*m/v,t=Math.sin(e),i=Math.cos(e),n=t/(2*g);c=(1+i)/2,u=-(1+i),h=c,a0=1+n,f=-2*i,p=1-n;break;case"BP":var e=2*Math.PI*m/v,t=Math.sin(e),i=Math.cos(e),r=Math.log(2)/2*g*e/t,n=t*(Math.exp(r)-Math.exp(-r))/2;c=n,u=0,h=-n,a0=1+n,f=-2*i,p=1-n;break;default:return}c/=a0,u/=a0,h/=a0,f/=a0,p/=a0},callback:function(d){var m=isNaN(d)?2:1,g=0,v=0,y=1===m?d:d[0];return g=c*y+u*e+h*t-f*i-p*n,t=e,e=y,n=i,i=g,2===m&&(inR=d[1],v=c*inR+u*r+h*o-f*a-p*s,o=r,r=inR,s=a,a=v,l[0]=g,l[1]=v),1===m?g:l}}).init(),Object.defineProperties(this,{mode:{get:function(){return d},set:function(e){d=e,this.calculateCoefficients()}},cutoff:{get:function(){return m},set:function(e){m=e,this.calculateCoefficients()}},Q:{get:function(){return g},set:function(e){g=e,this.calculateCoefficients()}}}),this.processProperties(arguments),this.calculateCoefficients()},Gibberish.Biquad.prototype=Gibberish._effect,Gibberish.Flanger=function(){var e=[new Float32Array(88200),new Float32Array(88200)],t=88200,i=(new Gibberish.Sine).callback,n=Gibberish.interpolate,r=-100,o=0;Gibberish.extend(this,{name:"flanger",properties:{input:0,rate:.25,feedback:0,amount:125,offset:125},callback:function(a,s,l,c){var u="number"==typeof a?1:2,h=r+i(s,.95*c);h>t?h-=t:0>h&&(h+=t);var f=n(e[0],h);return e[0][o]=1===u?a+f*l:a[0]+f*l,2===u?(a[0]+=f,f=n(e[1],h),e[1][o]=a[1]+f*l,a[1]+=f):a+=f,++o>=t&&(o=0),++r>=t&&(r=0),a}}).init().processProperties(arguments),r=-1*this.offset},Gibberish.Flanger.prototype=Gibberish._effect,Gibberish.Vibrato=function(){var e=[new Float32Array(88200),new Float32Array(88200)],t=88200,i=(new Gibberish.Sine).callback,n=Gibberish.interpolate,r=-100,o=0;Gibberish.extend(this,{name:"vibrato",properties:{input:0,rate:5,amount:.5,offset:125},callback:function(a,s,l,c){var u="number"==typeof a?1:2,h=r+i(s,l*c-1);h>t?h-=t:0>h&&(h+=t);var f=n(e[0],h);return e[0][o]=1===u?a:a[0],2===u?(a[0]=f,f=n(e[1],h),e[1][o]=a[1],a[1]=f):a=f,++o>=t&&(o=0),++r>=t&&(r=0),a}}).init().processProperties(arguments),r=-1*this.offset},Gibberish.Vibrato.prototype=Gibberish._effect,Gibberish.BufferShuffler=function(){var e=[new Float32Array(88200),new Float32Array(88200)],t=88200,i=0,n=0,r=0,o=0,a=0,s=Math.random,l=1,c=!1,u=!1,h=!1,f=Gibberish.interpolate,p=!1,d=1,m=!1,g=Gibberish.rndf,v=[0,0];Gibberish.extend(this,{name:"buffer_shuffler",properties:{input:0,chance:.25,rate:11025,length:22050,reverseChange:.5,pitchChance:.5,pitchMin:.25,pitchMax:2,wet:1,dry:0},callback:function(y,b,x,w,_,S,M,C,A,T){var E="number"==typeof y?1:2;a?++o%(w-400)===0&&(c=!1,u=!0,l=1,o=0):(e[0][n]=1===E?y:y[0],e[1][n]=1===E?y:y[1],n++,n%=t,m=0===n?1:m,r++,r%x==0&&s()<b&&(h=s()<_,a=!0,h||(i=n-w,0>i&&(i=t+i)),p=s()<S,p&&(d=g(M,C)),l=1,c=!0,u=!1)),i+=h?-1*d:d,0>i?i+=t:i>=t&&(i-=t);var k,P,R,L,D=f(e[0],i);return c?(l-=.0025,R=D*(1-l),k=1===E?R+y*l:R+y[0]*l,2===E&&(L=f(e[1],i),R=L*(1-l),P=1===E?k:R+y[1]*l),.0025>=l&&(c=!1)):u?(l-=.0025,R=D*l,k=1===E?R+y*l:R+y[0]*(1-l),2===E&&(L=f(e[1],i),R=L*l,P=R+y[1]*(1-l)),.0025>=l&&(u=!1,a=!1,h=!1,d=1,p=0)):1===E?k=a&&m?D*A+y*T:y:(L=f(e[1],i),k=a&&m?D*A+y[0]*T:y[0],P=a&&m?L*A+y[1]*T:y[1]),v=[k,P],1===E?k:v}}).init().processProperties(arguments)},Gibberish.BufferShuffler.prototype=Gibberish._effect,Gibberish.AllPass=function(e){var t=-1,i=new Float32Array(e||500),n=i.length;Gibberish.extend(this,{name:"allpass",properties:{input:0},callback:function(e){t=++t%n;var r=i[t],o=-1*e+r;return i[t]=e+.5*r,o}})},Gibberish.Comb=function(e){var t=new Float32Array(e||1200),i=t.length,n=0,r=0;Gibberish.extend(this,{name:"comb",properties:{input:0,feedback:.84,damping:.2},callback:function(e,o,a){var s=++n%i,l=t[s];return r=l*(1-a)+r*a,t[s]=e+r*o,l}})},Gibberish.Reverb=function(){var e={combCount:8,combTuning:[1116,1188,1277,1356,1422,1491,1557,1617],allPassCount:4,allPassTuning:[556,441,341,225],allPassFeedback:.5,fixedGain:.015,scaleDamping:.4,scaleRoom:.28,offsetRoom:.7,stereoSpread:23},t=.84,i=[],n=[],r=[0,0];Gibberish.extend(this,{name:"reverb",roomSize:.5,properties:{input:0,wet:.5,dry:.55,roomSize:.84,damping:.5},callback:function(e,t,o,a,s){for(var l="object"==typeof e?2:1,c=1===l?e:e[0]+e[1],u=.015*c,h=u,f=0;8>f;f++){var p=i[f](u,.98*a,.4*s);h+=p}for(var f=0;4>f;f++)h=n[f](h);return r[0]=r[1]=c*o+h*t,r}}).init().processProperties(arguments),this.setFeedback=function(e){t=e};for(var o=0;8>o;o++)i.push(new Gibberish.Comb(e.combTuning[o]).callback);for(var o=0;4>o;o++)n.push(new Gibberish.AllPass(e.allPassTuning[o],e.allPassFeedback).callback)},Gibberish.Reverb.prototype=Gibberish._effect,Gibberish.StereoReverb=function(){var e={combCount:8,combTuning:[1116,1188,1277,1356,1422,1491,1557,1617],allPassCount:4,allPassTuning:[556,441,341,225],allPassFeedback:.5,fixedGain:.015,scaleDamping:.4,scaleRoom:.28,offsetRoom:.7,stereoSpread:23},t=.84,i=[],n=[],r=[],o=[],a=[0,0];Gibberish.extend(this,{name:"reverb",roomSize:.5,properties:{input:0,wet:.5,dry:.55,roomSize:.84,damping:.5},callback:function(e,t,s,l,c){for(var u="object"==typeof e?2:1,h=e[0],f=1===u?h:e[1],p=outL=.015*h,d=outR=.015*f,m=0;8>m;m++)outL+=i[m](p,.98*l,.4*c),outR+=n[m](d,.98*l,.4*c);for(var m=0;4>m;m++)outL=r[m](outL),outR=o[m](outR);return a[0]=h*s+outL*t,a[1]=f*s+outR*t,a}}).init().processProperties(arguments),this.setFeedback=function(e){t=e};for(var s=0;8>s;s++)i.push(new Gibberish.Comb(e.combTuning[s]).callback),n.push(new Gibberish.Comb(e.combTuning[s]).callback);for(var s=0;4>s;s++)r.push(new Gibberish.AllPass(e.allPassTuning[s],e.allPassFeedback).callback),o.push(new Gibberish.AllPass(e.allPassTuning[s],e.allPassFeedback).callback)},Gibberish.StereoReverb.prototype=Gibberish._effect,Gibberish.Granulator=function(e){var t=[];buffer=null,interpolate=Gibberish.interpolate,panner=Gibberish.makePanner(),bufferLength=0,debug=0,write=0,self=this,out=[0,0],_out=[0,0],rndf=Gibberish.rndf,numberOfGrains=e.numberOfGrains||20,console.log("NUMBER OF GRAINS",numberOfGrains),Gibberish.extend(this,{name:"granulator",bufferLength:88200,reverse:!0,spread:.5,properties:{speed:1,speedMin:-0,speedMax:0,grainSize:1e3,position:.5,positionMin:0,positionMax:0,amp:.2,fade:.1,pan:0,shouldWrite:!1},setBuffer:function(e){buffer=e,bufferLength=e.length},callback:function(e,i,n,r,o,a,s,l,c,u){for(var h=0;numberOfGrains>h;h++){var f=t[h];if(f._speed>0){f.pos>f.end&&(f.pos=(s+rndf(o,a))*buffer.length,f.start=f.pos,f.end=f.start+r,f._speed=e+rndf(i,n),f._speed=f._speed<.1?.1:f._speed,f._speed=f._speed<.1&&f._speed>0?.1:f._speed,f._speed=f._speed>-.1&&f._speed<0?-.1:f._speed,f.fadeAmount=f._speed*c*r,f.pan=rndf(-1*self.spread,self.spread));for(var p=f.pos;p>buffer.length;)p-=buffer.length;for(;0>p;)p+=buffer.length;var d=interpolate(buffer,p);d*=f.pos<f.fadeAmount+f.start?(f.pos-f.start)/f.fadeAmount:1,d*=f.pos>f.end-f.fadeAmount?(f.end-f.pos)/f.fadeAmount:1}else{f.pos<f.end&&(f.pos=(s+rndf(o,a))*buffer.length,f.start=f.pos,f.end=f.start-r,f._speed=e+rndf(i,n),f._speed=f._speed<.1&&f._speed>0?.1:f._speed,f._speed=f._speed>-.1&&f._speed<0?-.1:f._speed,f.fadeAmount=f._speed*c*r);for(var p=f.pos;p>buffer.length;)p-=buffer.length;for(;0>p;)p+=buffer.length;var d=interpolate(buffer,p);d*=f.pos>f.start-f.fadeAmount?(f.start-f.pos)/f.fadeAmount:1,d*=f.pos<f.end+f.fadeAmount?(f.end-f.pos)/f.fadeAmount:1}_out=panner(d*l,f.pan,_out),out[0]+=_out[0],out[1]+=_out[1],f.pos+=f._speed}return panner(out,u,out)}}).init().processProperties(arguments);for(var i=0;numberOfGrains>i;i++)t[i]={pos:self.position+Gibberish.rndf(self.positionMin,self.positionMax),_speed:self.speed+Gibberish.rndf(self.speedMin,self.speedMax)},t[i].start=t[i].pos,t[i].end=t[i].pos+self.grainSize,t[i].fadeAmount=t[i]._speed*self.fade*self.grainSize,t[i].pan=Gibberish.rndf(-1*self.spread,self.spread),console.log("GRAIN",i,"POS",t[i].pos,"SPEED",t[i]._speed);this.grains=t,"undefined"!=typeof e.buffer&&(buffer=e.buffer,bufferLength=buffer.length)},Gibberish.Granulator.prototype=Gibberish._effect,Gibberish.synth=function(){this.type="oscillator",this.oscillatorInit=function(){this.fx=new Array2,this.fx.parent=this}},Gibberish.synth.prototype=new Gibberish.ugen,Gibberish._synth=new Gibberish.synth,Gibberish.Synth=function(e){this.name="synth",this.properties={frequency:0,pulsewidth:.5,attack:22050,decay:22050,sustain:22050,release:22050,attackLevel:1,sustainLevel:.5,releaseTrigger:0,glide:.15,amp:.25,channels:2,pan:0,sr:Gibberish.context.sampleRate},this.note=function(n,r){if("undefined"!=typeof n)if(0!==r){if("object"!=typeof this.frequency){if(t&&n===u&&e.requireReleaseTrigger)return this.releaseTrigger=1,void(u=null);this.frequency=u=n,this.releaseTrigger=0,"object"==typeof n&&Gibberish.dirty(this)}else this.frequency[0]=u=n,this.releaseTrigger=0,Gibberish.dirty(this);"undefined"!=typeof r&&(this.amp=r),i.run()}else this.releaseTrigger=1},e=e||{};var t="undefined"==typeof e.useADSR?!1:e.useADSR,i=t?new Gibberish.ADSR:new Gibberish.AD,n=i.getState,r=i.callback,o=new Gibberish.PWM,a=o.callback,s=(new Gibberish.OnePole).callback,l=Gibberish.makePanner(),c=this,u=0,h=[0,0];i.requireReleaseTrigger=e.requireReleaseTrigger||!1,this.callback=function(e,i,o,u,f,p,d,m,g,v,y,b,x,w){v=v>=1?.99999:v,e=s(e,1-v,v);var _,S;return t?(_=r(o,u,f,p,d,m,g),g&&(c.releaseTrigger=0),n()<4?(S=a(e,1,i,w)*_*y,1===b?S:l(S,x,h)):(S=h[0]=h[1]=0,1===b?S:h)):n()<2?(_=r(o,u),S=a(e,1,i,w)*_*y,1===b?S:l(S,x,h)):(S=h[0]=h[1]=0,1===b?S:h)},this.getEnv=function(){return i},this.getOsc=function(){return o},this.setOsc=function(e){o=e,a=o.callback};var f="PWM";Object.defineProperty(this,"waveform",{get:function(){return f},set:function(e){this.setOsc(new Gibberish[e])}}),this.init(),this.oscillatorInit(),this.processProperties(arguments)},Gibberish.Synth.prototype=Gibberish._synth,Gibberish.PolySynth=function(){this.__proto__=new Gibberish.Bus2,Gibberish.extend(this,{name:"polysynth",maxVoices:5,voiceCount:0,frequencies:[],_frequency:0,polyProperties:{frequency:0,glide:0,attack:22050,decay:22050,sustain:22050,release:22050,attackLevel:1,sustainLevel:.5,pulsewidth:.5,waveform:"PWM"},note:function(e,t){if("undefined"!=typeof e){var i=this.frequencies.indexOf(e),n=i>-1?i:this.voiceCount++,r=this.children[n];r.note(e,t),-1===i?(this.frequencies[n]=e,this._frequency=e,this.voiceCount>=this.maxVoices&&(this.voiceCount=0)):delete this.frequencies[n]}},initVoices:function(){for(var e=0;e<this.maxVoices;e++){var t={waveform:this.waveform,attack:this.attack,decay:this.decay,sustain:this.sustain,release:this.release,attackLevel:this.attackLevel,sustainLevel:this.sustainLevel,pulsewidth:this.pulsewidth,channels:2,amp:1,u