/** * @name Theresa's Sound World * @description A JavaScript library for audio manipulation. * @version v0.11.2 * @tutorial http://theresassoundworld.com * @author Stuart Memo * @license MIT */ !function i(a,c,u){function s(t,e){if(!c[t]){if(!a[t]){var n="function"==typeof require&&require;if(!e&&n)return n(t,!0);if(f)return f(t,!0);var r=new Error("Cannot find module '"+t+"'");throw r.code="MODULE_NOT_FOUND",r}var o=c[t]={exports:{}};a[t][0].call(o.exports,function(e){return s(a[t][1][e]||e)},o,o.exports,i,a,c,u)}return c[t].exports}for(var f="function"==typeof require&&require,e=0;e=u.buffer().length/h.context().sampleRate&&(s=0,r.stopped=!0,c&&c())},a=e||h.now(),i.start(a,s,t)},u.stop=function(e){s=0,this.paused=!1,this.stopped=!0,i&&i.stop(e||h.now())},u.on=function(e,t){"end"===e&&(c=t)},u.pause=function(e){this.paused=!0,i&&(i.stop(e||h.now()),h.disconnect(i)),this.stopped||(s=s+h.now()-a)},u.position=function(e){return e||0===e?(this.paused||this.stopped?s=e:(this.pause(),s=e,this.play()),u):this.paused||this.stopped?s:s+h.now()-a},u.start=u.play,u},h.decode=function(e,t,n){this.context().decodeAudioData(e,t,n)},h.filter=function(){var e=h.createNode({type:"filter"}),t={},n=h.context().createBiquadFilter();return r(arguments[0])?(t.type=arguments[0].type,t.frequency=arguments[0].frequency||1e3,t.Q=arguments[0].Q,t.gain=arguments[0].gain):u.isString(arguments[0])&&(t.type=arguments[0]),e.nodeType="filter",e.type=o(n,"type"),e.frequency=o(n,"frequency"),e.Q=o(n,"Q"),e.gain=o(n,"gain"),e.params={detune:n.detune,frequency:n.frequency,gain:n.gain,Q:n.Q},e.type(t.type||"lowpass"),e.frequency(t.frequency||1e3),e.Q(t.Q||0),e.gain(t.gain||0),this.connect(e.input,n,e.output),e},h.analyser=function(){return this.context().createAnalyser()},h.compressor=function(e){var t=h.createNode({nodeType:"compressor"}),n=this.context().createDynamicsCompressor();return function(e,t){for(var n in t)r(e[n])&&(e[n].value=t[n])}(n,e=function(e,t){for(var n in t)e[n]=t[n];return e}({threshold:-24,knee:30,ratio:12,attack:.003,release:.25},e)),t.threshold=o(n,"threshold"),t.knee=o(n,"knee"),t.ratio=o(n,"ratio"),t.attack=o(n,"attack"),t.release=o(n,"release"),this.connect(t.input,n,t.output),t},h.processor=function(e,t){var n=e||1024,r=h.context().createScriptProcessor(n,1,1);return"function"==typeof t&&(r.onaudioprocess=function(e){t(e)}),r},h.waveShaper=function(){for(var e=this.context().createWaveShaper(),t=new Float32Array(65536),n=0;n<32768;n++)t[n]=n<3e4?.1:-1;return e.curve=t,e},h.envelope=function(e){var t={};return e=e||{},t.name=e.name||"",t.nodeType="envelope",t.startLevel=e.startLevel||0,t.maxLevel=e.maxLevel||1,t.minLevel=e.minLevel||0,t.param=e.param||null,t.attackTime=e.attack||0,t.decayTime=e.decay||0,t.sustainLevel=e.sustain||1,t.releaseTime=e.release||0,d(e.param)&&(t.param=e.param),t.start=function(e){var t=this.attackTime+this.decayTime;this.releaseTime;this.maxLevel=this.startLevel+this.maxLevel,this.sustainLevel=this.startLevel+this.sustainLevel,d(this.param)&&(e=e||h.now(),this.param.setValueAtTime(this.startLevel,e),this.param.linearRampToValueAtTime(this.maxLevel,e+this.attackTime),this.param.setValueAtTime(this.maxLevel,e+this.attackTime),this.param.exponentialRampToValueAtTime(this.sustainLevel,e+t),this.param.setValueAtTime(this.sustainLevel,e+t))},t.release=function(e){var t=this.minLevel;e=e||h.now(),0===this.minLevel&&(t=1e-8),d(this.param)&&(this.param.setValueAtTime(this.sustainLevel,e),this.param.exponentialRampToValueAtTime(t,e+this.releaseTime),this.param.exponentialRampToValueAtTime(t,e+this.releaseTime),this.param.setValueAtTime(this.minLevel,e+this.releaseTime))},t},h.noise=function(){for(var e=this.buffer(),t=this.bufferBox(),n=e.length,r=0;r