sono
Version:
A simple yet powerful JavaScript library for working with Web Audio
2 lines • 71.3 kB
JavaScript
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):e.sono=t()}(this,function(){"use strict";function e(e,t){return t={exports:{}},e(t,t.exports),t.exports}function t(e){var t=e.createBuffer(1,1,e.sampleRate),n=e.createBufferSource();n.buffer=t,n.connect(e.destination),n.start(0),n.stop(0),n.disconnect()}function n(){function e(){}function t(){return{value:1,defaultValue:1,linearRampToValueAtTime:e,setValueAtTime:e,exponentialRampToValueAtTime:e,setTargetAtTime:e,setValueCurveAtTime:e,cancelScheduledValues:e}}function n(){return{connect:e,disconnect:e,frequencyBinCount:0,smoothingTimeConstant:0,fftSize:0,minDecibels:0,maxDecibels:0,getByteTimeDomainData:e,getByteFrequencyData:e,getFloatTimeDomainData:e,getFloatFrequencyData:e,gain:t(),panningModel:0,setPosition:e,setOrientation:e,setVelocity:e,distanceModel:0,refDistance:0,maxDistance:0,rolloffFactor:0,coneInnerAngle:360,coneOuterAngle:360,coneOuterGain:0,type:0,frequency:t(),Q:t(),detune:t(),delayTime:t(),buffer:0,threshold:t(),knee:t(),ratio:t(),attack:t(),release:t(),reduction:t(),oversample:0,curve:0,sampleRate:1,length:0,duration:0,numberOfChannels:0,getChannelData:function(){return[]},copyFromChannel:e,copyToChannel:e,dopplerFactor:0,speedOfSound:0,start:e}}var r=Date.now();return window.Uint8Array||(window.Uint8Array=window.Float32Array=Array),{isFake:!0,activeSourceCount:0,createAnalyser:n,createBuffer:n,createBufferSource:n,createMediaElementSource:n,createMediaStreamSource:n,createBiquadFilter:n,createChannelMerger:n,createChannelSplitter:n,createDynamicsCompressor:n,createConvolver:n,createDelay:n,createGain:n,createOscillator:n,createPanner:n,createScriptProcessor:n,createWaveShaper:n,decodeAudioData:e,destination:n,listener:n(),sampleRate:44100,state:"",get currentTime(){return(Date.now()-r)/1e3}}}function r(e){if("string"!=typeof e)return"";if("data:"===e.slice(0,5)){var t=e.match(/data:audio\/(ogg|mp3|opus|wav|m4a)/i);if(t&&t.length>1)return t[1].toLowerCase()}e=e.split("?")[0],e=e.slice(e.lastIndexOf("/")+1);var n=e.split(".");return 1===n.length||""===n[0]&&2===n.length?"":n.pop().toLowerCase()}function o(e){var t=void 0;if(Array.isArray(e))for(var n=0;n<e.length;n++){t=e[n];var o=r(t);if(Ot.indexOf(o)>-1)break}else"object"===(void 0===e?"undefined":mt(e))&&Object.keys(e).some(function(n){t=e[n];var o=r(t);return Ot.indexOf(o)>-1});return t||e}function i(e){return!!(e&&window.AudioBuffer&&e instanceof window.AudioBuffer)}function a(e){return!!(e&&window.ArrayBuffer&&e instanceof window.ArrayBuffer)}function u(e){return!!(e&&window.HTMLMediaElement&&e instanceof window.HTMLMediaElement)}function s(e){return!!(e&&"function"==typeof e.getAudioTracks&&e.getAudioTracks().length&&window.MediaStreamTrack&&e.getAudioTracks()[0]instanceof window.MediaStreamTrack)}function c(e){return!(!e||"string"!=typeof e||"sine"!==e&&"square"!==e&&"sawtooth"!==e&&"triangle"!==e)}function f(e){return!(!e||"string"!=typeof e||!(e.indexOf(".")>-1||"data:"===e.slice(0,5)))}function l(e){if(!e||u(e))return!1;var t=d(e);return f(t)||a(t)||Array.isArray(t)&&f(t[0])}function d(e){return e.src||e.url||e.data||e}function h(e,t){function n(e,t){var n=void 0;return e||0===e?(g.some(function(t){return(t===e||t.id===e)&&(n=t,!0)}),n&&t?t(n):n):n}function r(e){return n(e,function(e){return g.splice(g.indexOf(e),1)}),k}function o(e){return e.gain.disconnect(),e.gain.connect(m),g.push(e),e.once("destroy",r),k}function i(e,t){return g.forEach(function(n){return n.play(e,t)}),k}function a(){return g.forEach(function(e){e.playing&&e.pause()}),k}function u(){return g.forEach(function(e){e.paused&&e.play()}),k}function s(){return g.forEach(function(e){return e.stop()}),k}function c(e){return g.forEach(function(t){return t.seek(e)}),k}function f(){return b=k.volume,k.volume=0,k}function l(){return k.volume=b||1,k}function d(e){return k.volume=e,k}function h(t,n){if(e){var r=m.gain,o=e.currentTime;r.cancelScheduledValues(o),r.setValueAtTime(r.value,o),r.linearRampToValueAtTime(t,o+n)}else g.forEach(function(e){return e.fade(t,n)});return k}function p(){g.forEach(function(e){return e.load()})}function v(){g.forEach(function(e){return e.unload()})}function y(){for(;g.length;)g.pop().destroy()}var g=[],_=new Tt(e),m=e.createGain(),b=1,k=null;return e&&(_.setSource(m),_.setDestination(t||e.destination)),k={add:o,find:n,remove:r,play:i,pause:a,resume:u,stop:s,seek:c,setVolume:d,mute:f,unMute:l,fade:h,load:p,unload:v,destroy:y,gain:m,get effects(){return _._nodes},set effects(e){_.removeAll().add(e)},get fx(){return this.effects},set fx(e){this.effects=e},get sounds(){return g},get volume(){return m.gain.value},set volume(t){isNaN(t)||(t=Math.min(Math.max(t,0),1),e?(m.gain.cancelScheduledValues(e.currentTime),m.gain.value=t,m.gain.setValueAtTime(t,e.currentTime)):m.gain.value=t,g.forEach(function(e){e.context||(e.groupVolume=t)}))}}}function p(){this._events=this._events||{},this._maxListeners=this._maxListeners||void 0}function v(e){return"function"==typeof e}function y(e){return"number"==typeof e}function g(e){return"object"==typeof e&&null!==e}function _(e){return void 0===e}function m(e,t){function n(){y.off(),_&&"function"==typeof _.removeEventListener&&(_.removeEventListener("load",c),_.removeEventListener("canplaythrough",c),_.removeEventListener("error",i),_.onerror=null),k&&(k.removeEventListener("progress",o),k.removeEventListener("load",s),k.removeEventListener("error",i))}function r(e){y.emit("progress",1),y.emit("loaded",e),y.emit("complete",e),n()}function o(e){e.lengthComputable&&(b=e.loaded/e.total,y.emit("progress",b))}function i(){a();var t="";k?t=k.status+" "+k.statusText:_&&_.error&&(t=Ct[_.error.code]),y.listenerCount("error")&&y.emit("error",new Error("Load Error: "+t+" "+e)),n()}function a(){window.clearTimeout(w)}function u(e){g.decodeAudioData(e,function(e){_=e,k=null,b=1,r(e)},i)}function s(){if(k.status>=400)return void i();u(k.response)}function c(){if(a(),_){if(!_.readyState)return void i();b=1,r(_)}}function f(){a(),n(),k&&4!==k.readyState&&k.abort(),k=null}function l(){f(),k=null,_=null,g=null}function d(){if(e instanceof window.ArrayBuffer)return void u(e);k=new XMLHttpRequest,k.open("GET",e,!0),k.responseType="arraybuffer",k.addEventListener("progress",o),k.addEventListener("load",s),k.addEventListener("error",i),k.send()}function h(){_&&_.tagName||(_=document.createElement("audio")),m||(a(),w=window.setTimeout(c,3e3),_.addEventListener("canplaythrough",c,!1),_.addEventListener("load",c,!1)),_.addEventListener("error",i,!1),_.preload="auto",_.onerror=i,_.src=e,_.load(),m&&r(_)}function p(){var n=arguments.length>0&&void 0!==arguments[0]&&arguments[0];!e||t&&!n||(g?d():h())}function v(t){e=t,p()}var y=new qt,g=null,_=null,m=!1,b=0,k=null,w=null,x={on:y.on.bind(y),once:y.once.bind(y),off:y.off.bind(y),load:v,start:p,cancel:f,destroy:l};return Object.defineProperties(x,{data:{get:function(){return _}},progress:{get:function(){return b}},audioContext:{set:function(e){g=e}},isTouchLocked:{set:function(e){m=e}},url:{get:function(){return e}}}),Object.freeze(x)}function b(e){var t="sono "+e.VERSION,n="Supported:"+e.isSupported+" WebAudioAPI:"+e.hasWebAudio+" TouchLocked:"+e.isTouchLocked+" State:"+(e.context&&e.context.state)+" Extensions:"+e.file.extensions;if(navigator.userAgent.indexOf("Chrome")>-1){var r=["%c ♫ "+t+" ♫ %c "+n+" ","color: #FFFFFF; background: #379F7A","color: #1F1C0D; background: #E0FBAC"];console.log.apply(console,r)}else window.console&&window.console.log.call&&console.log.call(console,t+" "+n)}function k(e,t,n){function r(){return!y&&t&&(y=t.createBufferSource(),y.buffer=e),y}function o(){if(y){y.onended=null;try{y.disconnect(),y.stop(0)}catch(e){}y=null}d=!1,h=0,v=!1,g=0}function i(){var e=t.currentTime-g;o(),h=e,v=!1,d=!0}function a(){o(),f=!0,"function"==typeof n&&n(c)}function u(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;if(!v){for(e=e?t.currentTime+e:0,n&&(h=0),h&&(n=h);n>c.duration;)n%=c.duration;r(),y.onended=a,y.start(e,n),y.loop=l,y.playbackRate.value=p,g=t.currentTime-n,f=!1,d=!1,h=0,v=!0}}function s(){o(),e=null,t=null,n=null,y=null}var c={},f=!1,l=!1,d=!1,h=0,p=1,v=!1,y=null,g=0;return Object.defineProperties(c,{play:{value:u},pause:{value:i},stop:{value:o},destroy:{value:s},currentTime:{get:function(){if(h)return h;if(g){for(var e=t.currentTime-g;e>c.duration;)e%=c.duration;return e}return 0},set:function(e){h=e}},duration:{get:function(){return e?e.duration:0}},ended:{get:function(){return f}},loop:{get:function(){return l},set:function(e){l=!!e,y&&(y.loop=l)}},paused:{get:function(){return d}},playbackRate:{get:function(){return p},set:function(e){p=e,y&&(y.playbackRate.value=p)}},playing:{get:function(){return v}},progress:{get:function(){return c.duration?c.currentTime/c.duration:0}},sourceNode:{get:function(){return r()}}}),Object.freeze(c)}function w(e,t,n){if(Dt)return Dt;e=e||2,n=n||44100,t=n||e;var r=window.OfflineAudioContext||window.webkitOfflineAudioContext;return Dt=r?new r(e,t,n):null}function x(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:e.length;if(!_t||_t.isFake)return e;for(var r=e.numberOfChannels,o=_t.createBuffer(r,n,e.sampleRate),i=0;i<r;i++)o.getChannelData(i).set(e.getChannelData(i).slice(t,t+n));return o}function T(e){for(var t=e.numberOfChannels,n=0;n<t;n++)Array.prototype.reverse.call(e.getChannelData(n));return e}function O(e,t,n,r,o){_t.isFake||(e.setValueAtTime(t,_t.currentTime),o?e.linearRampToValueAtTime(n,_t.currentTime+r):e.exponentialRampToValueAtTime(n,_t.currentTime+r))}function S(e){if(_t.isFake)return 0;var t=_t.sampleRate/2,n=Math.log(t/40)/Math.LN2;return t*Math.pow(2,n*(e-1))}function L(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:":",n=Math.floor(e/60),r=Math.floor(e%3600%60);return(n<10?"0"+n:n)+t+(r<10?"0"+r:r)}function E(e){return"number"==typeof e&&!isNaN(e)&&isFinite(e)}function M(e,t,n,r){function o(){return p}function i(e){e.stop(),b||g.push(e)}function a(e){if(e!==v&&_.length){var t=_.indexOf(e);_.splice(t,1),i(e)}r()}function u(t){return new e(t,n,a)}function s(){return b||!v.playing?v:g.length>0?g.pop():(m++,u(t.tagName?t.cloneNode():t))}function c(e,t){var n=s();p&&n.sourceNode.connect(p),n!==v&&_.push(n),n.play(e,t)}function f(){for(v.stop();_.length;)i(_.pop())}function l(){v.pause(),_.forEach(function(e){return e.pause()})}function d(e){f(),g.length=0,v.load(e)}function h(){for(v.destroy();_.length;)_.pop().destroy();for(;g.length;)g.pop().destroy();p.disconnect()}var p=n.createGain(),v=u(t),y={},g=[],_=[],m=0,b=!1;return Object.defineProperties(y,{play:{value:c},pause:{value:l},stop:{value:f},load:{value:d},destroy:{value:h},currentTime:{get:function(){return v.currentTime||0},set:function(e){v.currentTime=e,_.forEach(function(t){return t.currentTime=e})}},duration:{get:function(){return v.duration||0}},ended:{get:function(){return v.ended&&_.every(function(e){return e.ended})}},info:{get:function(){return{pooled:g.length,active:_.length+1,created:m+1}}},loop:{get:function(){return v.loop},set:function(e){v.loop=!!e,_.forEach(function(t){return t.loop=!!e})}},paused:{get:function(){return v.paused}},playbackRate:{get:function(){return v.playbackRate},set:function(e){v.playbackRate=e,_.forEach(function(t){return t.playbackRate=e})}},playing:{get:function(){return v.playing}},progress:{get:function(){return v.progress}},singlePlay:{get:function(){return b},set:function(e){b=e}},sourceNode:{get:function(){return o()}},volume:{get:function(){return v.volume},set:function(e){v.hasOwnProperty("volume")&&(v.volume=e,_.forEach(function(t){return t.volume=e}))}},groupVolume:{get:function(){return v.groupVolume},set:function(e){v.hasOwnProperty("groupVolume")&&(v.groupVolume=e,_.forEach(function(t){return t.groupVolume=e}))}}}),Object.freeze(y)}function A(e,t,n){function r(){return!m&&t&&(m=t.createMediaElementSource(e)),m}function o(t){e.src=t,e.load(),d=!1,y=!1,_=!1}function i(){e.removeEventListener("canplaythrough",i),_&&e.play()}function a(){if(v)return e.currentTime=0,e.currentTime>0&&e.load(),void e.play();d=!0,y=!1,_=!1,"function"==typeof h&&h(l)}function u(t,n){clearTimeout(p),e.volume=k*b,e.playbackRate=g,n&&(e.currentTime=n),t?p=setTimeout(u,t):e.play(),d=!1,y=!1,_=!0,e.removeEventListener("ended",a),e.addEventListener("ended",a,!1),e.readyState<1&&(e.removeEventListener("canplaythrough",i),e.addEventListener("canplaythrough",i,!1),e.play())}function s(){clearTimeout(p),e&&(e.pause(),_=!1,y=!0)}function c(){if(clearTimeout(p),e){e.pause();try{e.currentTime=0,e.currentTime>0&&e.load()}catch(e){}_=!1,y=!1}}function f(){e.removeEventListener("ended",a),e.removeEventListener("canplaythrough",i),c(),e=null,t=null,h=null,m=null}var l={},d=!1,h=n,p=null,v=!1,y=!1,g=1,_=!1,m=null,b=1,k=1;return Object.defineProperties(l,{play:{value:u},pause:{value:s},stop:{value:c},load:{value:o},destroy:{value:f},currentTime:{get:function(){return e?e.currentTime:0},set:function(t){e&&(e.currentTime=t)}},duration:{get:function(){return e?e.duration:0}},ended:{get:function(){return d}},loop:{get:function(){return v},set:function(e){v=!!e}},paused:{get:function(){return y}},playbackRate:{get:function(){return g},set:function(t){g=t,e&&(e.playbackRate=g)}},playing:{get:function(){return _}},progress:{get:function(){return e&&e.duration?e.currentTime/e.duration:0}},sourceNode:{get:function(){return r()}},volume:{get:function(){return k},set:function(t){k=t,e&&(e.volume=k*b)}},groupVolume:{get:function(){return b},set:function(t){b=t,e&&(e.volume=k*b)}}}),Object.freeze(l)}function P(e,t){function n(){return!l&&t&&(l=t.createMediaStreamSource(e),navigator.mozGetUserMedia&&(window.mozHack=l)),l}function r(e){e=e?t.currentTime+e:0,n(),l.start(e),d=t.currentTime-c,u=!1,f=!0,s=!1,c=0}function o(){if(l){try{l.stop(0)}catch(e){}l=null}u=!0,s=!1,c=0,f=!1,d=0}function i(){var e=t.currentTime-d;o(),c=e,f=!1,s=!0}function a(){o(),t=null,l=null,e=null,window.mozHack=null}var u=!1,s=!1,c=0,f=!1,l=null,d=0,h={play:r,pause:i,stop:o,destroy:a,duration:0,progress:0};return Object.defineProperties(h,{currentTime:{get:function(){return c||(d?t.currentTime-d:0)},set:function(e){c=e}},ended:{get:function(){return u}},paused:{get:function(){return s}},playing:{get:function(){return f}},sourceNode:{get:function(){return n()}}}),Object.freeze(h)}function q(e,t){function n(){return!l&&t&&(l=t.createOscillator(),l.type=e,l.frequency.value=h),l}function r(e){e=e||0,e&&(e=t.currentTime+e),n(),l.start(e),d=c?t.currentTime-c:t.currentTime,u=!1,f=!0,s=!1,c=0}function o(){if(l){try{l.stop(0)}catch(e){}l=null}u=!0,s=!1,c=0,f=!1,d=0}function i(){var e=t.currentTime-d;o(),c=e,f=!1,s=!0}function a(){o(),t=null,l=null}var u=!1,s=!1,c=0,f=!1,l=null,d=0,h=200,p=null;return p={play:r,pause:i,stop:o,destroy:a},Object.defineProperties(p,{currentTime:{get:function(){return c||(d?t.currentTime-d:0)},set:function(e){c=e}},duration:{value:0},ended:{get:function(){return u}},frequency:{get:function(){return h},set:function(e){h=e,l&&(l.frequency.value=e)}},paused:{get:function(){return s}},playing:{get:function(){return f}},progress:{value:0},sourceNode:{get:function(){return n()}}}),Object.freeze(p)}function C(e,t){function n(){o.length&&(u=o.slice(0).sort(function(e,t){return t.duration-e.duration})[0])}var r=new h(e,t),o=r.sounds,i=1,a=!1,u=void 0,s=r.add;r.add=function(e){return s(e),n(),r};var c=r.remove;return r.remove=function(e){return c(e),n(),r},Object.defineProperties(r,{currentTime:{get:function(){return u?u.currentTime:0},set:function(e){this.stop(),this.play(0,e)}},duration:{get:function(){return u?u.duration:0}},loop:{get:function(){return a},set:function(e){a=!!e,o.forEach(function(e){e.loop=a})}},paused:{get:function(){return!!u&&u.paused}},progress:{get:function(){return u?u.progress:0}},playbackRate:{get:function(){return i},set:function(e){i=e,o.forEach(function(e){e.playbackRate=i})}},playing:{get:function(){return!!u&&u.playing}}}),r}function R(e){return Kt.find(e)}function D(e){var t=new C(_t,Kt.gain);return e&&e.forEach(function(e){return t.add(e)}),t}function j(e){var t=Mt.getSupportedFile(e.src||e.url||e.data||e),n=new Ft(Object.assign({},e||{},{src:t,context:_t,destination:Kt.gain}));return n.isTouchLocked=Jt,e&&(n.id=e.id||e.name||"",n.loop=!!e.loop,n.volume=e.volume,n.effects=e.effects||[]),Kt.add(n),n}function F(e,t){var n=j(e).prepare();return t&&t.add(n.loader),n}function V(e){var t=e.src||e.url||e.data||e,n=void 0,r=void 0;if(Mt.containsURL(t))n=F(e),r=n.loader;else{if(!Array.isArray(t)||!Mt.containsURL(t[0].src||t[0].url)){var o="sono.load: No audio file URLs found in config.";if(!e.onError)throw new Error(o);return e.onError("[ERROR] "+o),null}n=[],r=new m.Group,t.forEach(function(e){return n.push(F(e,r))})}return e.onProgress&&r.on("progress",function(t){return e.onProgress(t)}),e.onComplete&&r.once("complete",function(){r.off("progress"),e.onComplete(n)}),r.once("error",function(t){r.off("error"),e.onError&&e.onError(t)}),r.start(),n}function G(e){if(Mt.containsURL(e))return V(e);var t=j(e);return t.data=e.data||e,t}function B(e){return Kt.find(e,function(e){return e.destroy()}),en}function z(){return Kt.destroy(),en}function I(){return Kt.mute(),en}function N(){return Kt.unMute(),en}function U(e,t){return Kt.fade(e,t),en}function W(){return Kt.pause(),en}function H(){return Kt.resume(),en}function Q(){return Kt.stop(),en}function X(e,t,n){return Kt.find(e,function(e){return e.play(t,n)}),en}function Z(e){return Kt.find(e,function(e){return e.pause()}),en}function K(e){return Kt.find(e,function(e){return e.stop()}),en}function J(){Kt.sounds.forEach(function(e){e.playing&&(e.pause(),Yt.push(e))})}function Y(){for(;Yt.length;)Yt.pop().play()}function $(e,t){return(arguments.length>2&&void 0!==arguments[2]?arguments[2]:Tt.prototype)[e]=t,en[e]=t,t}function ee(e){var t=Math.log(e/440)*Math.LOG2E*12;return Math.round(t)+69}function te(e){return 440*Math.pow(2,(e-69)/12)}function ne(e,t){return Math.floor(1200*Math.log(e/te(t))*Math.LOG2E)}function re(){for(var e=null,t=arguments.length,n=Array(t),r=0;r<t;r++)n[r]=arguments[r];for(var o=0;o<n.length;o++)if(E(n[o])){e=n[o];break}return e}function oe(e){var t=Math.log(fn/cn)/Math.LN2,n=Math.pow(2,t*(e-1));return fn*n}function ie(e){return void 0!==e}function ae(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;return E(e)?e:t}function ue(e,t){var n=e.x,r=e.y,o=e.z,i=t.x,a=t.y,u=t.z;e.x=r*u-o*a,e.y=o*i-n*u,e.z=n*a-r*i}function se(e){if(0===e.x&&0===e.y&&0===e.z)return e;var t=Math.sqrt(e.x*e.x+e.y*e.y+e.z*e.z),n=1/t;return e.x*=n,e.y*=n,e.z*=n,e}function ce(e,t){var n=vn.get(t.x,t.y,t.z);ue(n,yn),ue(n,t),se(n),se(t),e.setOrientation(t.x,t.y,t.z,n.x,n.y,n.z),vn.dispose(t),vn.dispose(n)}function fe(e,t){e.setPosition(t.x,t.y,t.z),vn.dispose(t)}function le(e){var t=e.time,n=e.decay,r=e.reverse,o=e.buffer,i=en.context.sampleRate,a=Math.floor(i*t),u=void 0;u=o&&o.length===a?o:en.context.createBuffer(2,a,i);for(var s=u.getChannelData(0),c=u.getChannelData(1),f=void 0,l=void 0,d=0;d<a;d++)f=r?a-d:d,l=Math.pow(1-f/a,n),s[d]=(2*Math.random()-1)*l,c[d]=(2*Math.random()-1)*l;return u}function de(e,t,n){function r(t){c=t,e(c)}function o(e){t&&"PermissionDeniedError"===e.name||"PERMISSION_DENIED"===e?t():n(e.message||e)}function i(){return u?(navigator.mediaDevices.getUserMedia?navigator.mediaDevices.getUserMedia({audio:!0}).then(r).catch(o):navigator.getUserMedia({audio:!0},r,o),s):s}function a(){return c.stop?c.stop():c.getAudioTracks()[0].stop(),c=null,s}navigator.getUserMedia=navigator.mediaDevices.getUserMedia||navigator.getUserMedia||navigator.webkitGetUserMedia||navigator.mozGetUserMedia||navigator.msGetUserMedia,n=n||function(e){};var u=!!navigator.getUserMedia,s={},c=null;return Object.assign(s,{connect:i,disconnect:a,isSupported:u,get stream(){return c}})}function he(){function e(e,t){for(var n=new Float32Array(t),r=0,o=0;o<e.length;o++)n.set(e[o],r),r+=e[o].length;return n}function t(){if(!a.length)return en.context.createBuffer(2,i,en.context.sampleRate);var t=a.length*i,n=en.context.createBuffer(2,t,en.context.sampleRate);return n.getChannelData(0).set(e(a,t)),n.getChannelData(1).set(e(u,t)),n}function n(){f&&(f.onaudioprocess=null,h.disconnect(),f.disconnect())}function r(){n(),f=en.context.createScriptProcessor(i,2,2),h.connect(f),f.connect(p),f.connect(en.context.destination),f.onaudioprocess=function(e){var t=e.inputBuffer.getChannelData(0),n=e.inputBuffer.getChannelData(1);if(o){var r=e.outputBuffer.getChannelData(0),i=e.outputBuffer.getChannelData(1);r.set(t),i.set(n)}l&&(a.push(new Float32Array(t)),u.push(new Float32Array(n)))}}var o=arguments.length>0&&void 0!==arguments[0]&&arguments[0],i=4096,a=[],u=[],s=0,c=0,f=null,l=!1,d=null,h=en.context.createGain(),p=en.context.createGain();p.gain.value=o?1:0;var v={_in:h,_out:p,connect:function(e){p.connect(e._in||e)},disconnect:function(){for(var e=arguments.length,t=Array(e),n=0;n<e;n++)t[n]=arguments[n];p.disconnect(t)}};return{start:function(e){e&&(r(),a.length=0,u.length=0,s=en.context.currentTime,c=0,d=e,e.effects.add(v),l=!0)},stop:function(){return d.effects.remove(v),d=null,c=en.context.currentTime,l=!1,n(),t()},getDuration:function(){return l?en.context.currentTime-s:c-s},get isRecording(){return l}}}function pe(){var e=void 0,t=void 0;return function(n,r){if(!window.Float32Array||!window.AudioBuffer)return[];var o=e===n,i=t&&t.length===r;if(o&&i)return t;if(t=new Float32Array(r),!n)return t;e=n;for(var a=Math.floor(e.length/r),u=Math.max(Math.floor(a/5),1),s=0,c=0;c<e.numberOfChannels;c++)for(var f=e.getChannelData(c),l=0;l<r;l++)for(var d=l*a,h=d+a;d<h;d+=u){var p=f[d];p<0&&(p=-p),p>t[l]&&(t[l]=p),p>s&&(s=p)}for(var v=1/s,y=0;y<t.length;y++)t[y]*=v;return t}}function ve(e){function t(){c?(_.fillStyle=c,_.fillRect(d,h,y,g)):_.clearRect(d,h,y,g),_.lineWidth=f,m=null,"function"!=typeof s&&(_.strokeStyle=s,_.beginPath())}function n(e,t,n){if("function"==typeof s){var r=s(e,t,n);r!==m&&(m=r,_.stroke(),_.strokeStyle=m,_.beginPath())}}function r(e,t,n){return"function"==typeof p?p(e,t,n):e}function o(t,n){return t&&"function"==typeof t.waveform?t.waveform(n):t||(e.waveform?e.waveform:e.sound?e.sound.waveform(n):null)}function i(e){if(t(),"circular"===u){var i=o(e,360),s=Math.floor(i.length*l),c=Tn/s,p=void 0,v=void 0,m=void 0,L=void 0;for(b=0;b<s;b++){var E=r(i[b],b,s);n(b,s,E),p=b*c-xn,L=Math.cos(p),m=Math.sin(p),"fill"===a&&(k=O+T*L,w=S+T*m,_.moveTo(k,w)),v=T+(x-T)*E,k=O+v*L,w=S+v*m,"line"===a&&0===b&&_.moveTo(k,w),_.lineTo(k,w)}"line"===a&&_.closePath()}else{var M=o(e,y),A=y-f/2,P=Math.min(M.length,A);P=Math.floor(P*l);var q=A/P;for(b=0;b<P;b++){var C=r(M[b],b,P);n(b,P,C),"line"===a&&b>0&&_.lineTo(k,w),k=d+b*q,w=h+g-Math.round(g*C),w=Math.floor(Math.min(w,h+g-f/2)),"fill"===a?(k=Math.ceil(k+f/2),_.moveTo(k,w),_.lineTo(k,h+g)):_.lineTo(k,w)}}_.stroke()}var a=e.style||"fill",u=e.shape||"linear",s=e.color||0,c=e.bgColor,f=e.lineWidth||1,l=e.percent||1,d=e.x||0,h=e.y||0,p=e.transform,v=e.canvas,y=e.width||v&&v.width,g=e.height||v&&v.height,_=null,m=void 0,b=void 0,k=void 0,w=void 0,x=void 0,T=void 0,O=void 0,S=void 0;return v||e.context||(v=document.createElement("canvas"),y=y||v.width,g=g||v.height,v.width=y,v.height=g),"circular"===u&&(x=e.radius||Math.min(g/2,y/2),T=e.innerRadius||x/2,O=d+y/2,S=h+g/2),_=e.context||v.getContext("2d"),i.canvas=v,(e.waveform||e.sound)&&i(),i}var ye=e(function(e){var t=e.exports="undefined"!=typeof window&&window.Math==Math?window:"undefined"!=typeof self&&self.Math==Math?self:Function("return this")();"number"==typeof __g&&(__g=t)}),ge=e(function(e){var t=e.exports={version:"2.4.0"};"number"==typeof __e&&(__e=t)}),_e=function(e){return"object"==typeof e?null!==e:"function"==typeof e},me=function(e){if(!_e(e))throw TypeError(e+" is not an object!");return e},be=function(e){try{return!!e()}catch(e){return!0}},ke=!be(function(){return 7!=Object.defineProperty({},"a",{get:function(){return 7}}).a}),we=ye.document,xe=_e(we)&&_e(we.createElement),Te=function(e){return xe?we.createElement(e):{}},Oe=!ke&&!be(function(){return 7!=Object.defineProperty(Te("div"),"a",{get:function(){return 7}}).a}),Se=function(e,t){if(!_e(e))return e;var n,r;if(t&&"function"==typeof(n=e.toString)&&!_e(r=n.call(e)))return r;if("function"==typeof(n=e.valueOf)&&!_e(r=n.call(e)))return r;if(!t&&"function"==typeof(n=e.toString)&&!_e(r=n.call(e)))return r;throw TypeError("Can't convert object to primitive value")},Le=Object.defineProperty,Ee=ke?Object.defineProperty:function(e,t,n){if(me(e),t=Se(t,!0),me(n),Oe)try{return Le(e,t,n)}catch(e){}if("get"in n||"set"in n)throw TypeError("Accessors not supported!");return"value"in n&&(e[t]=n.value),e},Me={f:Ee},Ae=function(e,t){return{enumerable:!(1&e),configurable:!(2&e),writable:!(4&e),value:t}},Pe=ke?function(e,t,n){return Me.f(e,t,Ae(1,n))}:function(e,t,n){return e[t]=n,e},qe={}.hasOwnProperty,Ce=function(e,t){return qe.call(e,t)},Re=0,De=Math.random(),je=function(e){return"Symbol(".concat(void 0===e?"":e,")_",(++Re+De).toString(36))},Fe=e(function(e){var t=je("src"),n=Function.toString,r=(""+n).split("toString");ge.inspectSource=function(e){return n.call(e)},(e.exports=function(e,n,o,i){var a="function"==typeof o;a&&(Ce(o,"name")||Pe(o,"name",n)),e[n]!==o&&(a&&(Ce(o,t)||Pe(o,t,e[n]?""+e[n]:r.join(String(n)))),e===ye?e[n]=o:i?e[n]?e[n]=o:Pe(e,n,o):(delete e[n],Pe(e,n,o)))})(Function.prototype,"toString",function(){return"function"==typeof this&&this[t]||n.call(this)})}),Ve=function(e){if("function"!=typeof e)throw TypeError(e+" is not a function!");return e},Ge=function(e,t,n){if(Ve(e),void 0===t)return e;switch(n){case 1:return function(n){return e.call(t,n)};case 2:return function(n,r){return e.call(t,n,r)};case 3:return function(n,r,o){return e.call(t,n,r,o)}}return function(){return e.apply(t,arguments)}},Be=function(e,t,n){var r,o,i,a,u=e&Be.F,s=e&Be.G,c=e&Be.S,f=e&Be.P,l=e&Be.B,d=s?ye:c?ye[t]||(ye[t]={}):(ye[t]||{}).prototype,h=s?ge:ge[t]||(ge[t]={}),p=h.prototype||(h.prototype={});s&&(n=t);for(r in n)o=!u&&d&&void 0!==d[r],i=(o?d:n)[r],a=l&&o?Ge(i,ye):f&&"function"==typeof i?Ge(Function.call,i):i,d&&Fe(d,r,i,e&Be.U),h[r]!=i&&Pe(h,r,a),f&&p[r]!=i&&(p[r]=i)};ye.core=ge,Be.F=1,Be.G=2,Be.S=4,Be.P=8,Be.B=16,Be.W=32,Be.U=64,Be.R=128;var ze=Be,Ie={}.toString,Ne=function(e){return Ie.call(e).slice(8,-1)},Ue=Object("z").propertyIsEnumerable(0)?Object:function(e){return"String"==Ne(e)?e.split(""):Object(e)},We=function(e){if(void 0==e)throw TypeError("Can't call method on "+e);return e},He=function(e){return Ue(We(e))},Qe=Math.ceil,Xe=Math.floor,Ze=function(e){return isNaN(e=+e)?0:(e>0?Xe:Qe)(e)},Ke=Math.min,Je=function(e){return e>0?Ke(Ze(e),9007199254740991):0},Ye=Math.max,$e=Math.min,et=function(e,t){return e=Ze(e),e<0?Ye(e+t,0):$e(e,t)},tt=ye["__core-js_shared__"]||(ye["__core-js_shared__"]={}),nt=function(e){return tt[e]||(tt[e]={})}("keys"),rt=function(e){return function(t,n,r){var o,i=He(t),a=Je(i.length),u=et(r,a);if(e&&n!=n){for(;a>u;)if((o=i[u++])!=o)return!0}else for(;a>u;u++)if((e||u in i)&&i[u]===n)return e||u||0;return!e&&-1}}(!1),ot=function(e){return nt[e]||(nt[e]=je(e))}("IE_PROTO"),it=function(e,t){var n,r=He(e),o=0,i=[];for(n in r)n!=ot&&Ce(r,n)&&i.push(n);for(;t.length>o;)Ce(r,n=t[o++])&&(~rt(i,n)||i.push(n));return i},at="constructor,hasOwnProperty,isPrototypeOf,propertyIsEnumerable,toLocaleString,toString,valueOf".split(","),ut=Object.keys||function(e){return it(e,at)},st=Object.getOwnPropertySymbols,ct={f:st},ft={}.propertyIsEnumerable,lt={f:ft},dt=function(e){return Object(We(e))},ht=Object.assign,pt=!ht||be(function(){var e={},t={},n=Symbol(),r="abcdefghijklmnopqrst";return e[n]=7,r.split("").forEach(function(e){t[e]=e}),7!=ht({},e)[n]||Object.keys(ht({},t)).join("")!=r})?function(e,t){for(var n=dt(e),r=arguments.length,o=1,i=ct.f,a=lt.f;r>o;)for(var u,s=Ue(arguments[o++]),c=i?ut(s).concat(i(s)):ut(s),f=c.length,l=0;f>l;)a.call(s,u=c[l++])&&(n[u]=s[u]);return n}:ht;ze(ze.S+ze.F,"Object",{assign:pt});var vt=navigator&&/(iPhone|iPad|iPod)/i.test(navigator.userAgent),yt=window.AudioContext||window.webkitAudioContext||n,gt=new yt;gt||(gt=new n),vt&&44100!==gt.sampleRate&&(t(gt),gt.close(),gt=new yt),"suspended"===gt.state&&"function"==typeof gt.resume&&window.setTimeout(function(){return gt.resume()},1e3);var _t=gt,mt="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},bt=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},kt=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),wt=function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)},xt=function(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t},Tt=function(){function e(t){var n=this;bt(this,e),this.context=t,this._destination=null,this._source=null,this._nodes=[],this._nodes.has=function(e){return n.has(e)},this._nodes.add=function(e){return n.add(e)},this._nodes.remove=function(e){return n.remove(e)},this._nodes.toggle=function(e,t){return n.toggle(e,t)},this._nodes.removeAll=function(){return n.removeAll()},Object.keys(e.prototype).forEach(function(t){n._nodes.hasOwnProperty(t)||"function"!=typeof e.prototype[t]||(n._nodes[t]=n[t].bind(n))})}return e.prototype.setSource=function(e){return this._source=e,this._updateConnections(),e},e.prototype.setDestination=function(e){return this._connectToDestination(e),e},e.prototype.has=function(e){return!!e&&this._nodes.indexOf(e)>-1},e.prototype.add=function(e){if(!e)return null;if(this.has(e))return e;if(Array.isArray(e)){for(var t=void 0,n=0;n<e.length;n++)t=this.add(e[n]);return t}return this._nodes.push(e),this._updateConnections(),e},e.prototype.remove=function(e){if(!e)return null;if(!this.has(e))return e;for(var t=this._nodes.length,n=0;n<t;n++)if(e===this._nodes[n]){this._nodes.splice(n,1);break}return e.disconnect(),this._updateConnections(),e},e.prototype.toggle=function(e,t){t=!!t;var n=this.has(e);return arguments.length>1&&n===t?this:(n?this.remove(e):this.add(e),this)},e.prototype.removeAll=function(){for(;this._nodes.length;){this._nodes.pop().disconnect()}return this._updateConnections(),this},e.prototype.destroy=function(){this.removeAll(),this.context=null,this._destination=null,this._source&&this._source.disconnect(),this._source=null},e.prototype._connect=function(e,t){e.disconnect(),e.connect(t._in||t)},e.prototype._connectToDestination=function(e){var t=this._nodes[this._nodes.length-1]||this._source;t&&this._connect(t,e),this._destination=e},e.prototype._updateConnections=function(){if(this._source){for(var e=void 0,t=void 0,n=0;n<this._nodes.length;n++)e=this._nodes[n],t=0===n?this._source:this._nodes[n-1],this._connect(t,e);this._destination&&this._connectToDestination(this._destination)}},e}(),Ot=[],St={},Lt=[{ext:"ogg",type:'audio/ogg; codecs="vorbis"'},{ext:"mp3",type:"audio/mpeg;"},{ext:"opus",type:'audio/ogg; codecs="opus"'},{ext:"wav",type:'audio/wav; codecs="1"'},{ext:"m4a",type:"audio/x-m4a;"},{ext:"m4a",type:"audio/aac;"}],Et=document.createElement("audio");Et&&(Lt.forEach(function(e){var t=!!Et.canPlayType(e.type);t&&-1===Ot.indexOf(e.ext)&&Ot.push(e.ext),St[e.ext]=t}),Et=null);var Mt={canPlay:St,containsURL:l,extensions:Ot,getFileExtension:r,getSrc:d,getSupportedFile:o,isAudioBuffer:i,
isArrayBuffer:a,isMediaElement:u,isMediaStream:s,isOscillatorType:c,isURL:f};h.Effects=Tt;var At=p;p.EventEmitter=p,p.prototype._events=void 0,p.prototype._maxListeners=void 0,p.defaultMaxListeners=10,p.prototype.setMaxListeners=function(e){if(!y(e)||e<0||isNaN(e))throw TypeError("n must be a positive number");return this._maxListeners=e,this},p.prototype.emit=function(e){var t,n,r,o,i,a;if(this._events||(this._events={}),"error"===e&&(!this._events.error||g(this._events.error)&&!this._events.error.length)){if((t=arguments[1])instanceof Error)throw t;var u=new Error('Uncaught, unspecified "error" event. ('+t+")");throw u.context=t,u}if(n=this._events[e],_(n))return!1;if(v(n))switch(arguments.length){case 1:n.call(this);break;case 2:n.call(this,arguments[1]);break;case 3:n.call(this,arguments[1],arguments[2]);break;default:o=Array.prototype.slice.call(arguments,1),n.apply(this,o)}else if(g(n))for(o=Array.prototype.slice.call(arguments,1),a=n.slice(),r=a.length,i=0;i<r;i++)a[i].apply(this,o);return!0},p.prototype.addListener=function(e,t){var n;if(!v(t))throw TypeError("listener must be a function");return this._events||(this._events={}),this._events.newListener&&this.emit("newListener",e,v(t.listener)?t.listener:t),this._events[e]?g(this._events[e])?this._events[e].push(t):this._events[e]=[this._events[e],t]:this._events[e]=t,g(this._events[e])&&!this._events[e].warned&&(n=_(this._maxListeners)?p.defaultMaxListeners:this._maxListeners)&&n>0&&this._events[e].length>n&&(this._events[e].warned=!0,console.trace),this},p.prototype.on=p.prototype.addListener,p.prototype.once=function(e,t){function n(){this.removeListener(e,n),r||(r=!0,t.apply(this,arguments))}if(!v(t))throw TypeError("listener must be a function");var r=!1;return n.listener=t,this.on(e,n),this},p.prototype.removeListener=function(e,t){var n,r,o,i;if(!v(t))throw TypeError("listener must be a function");if(!this._events||!this._events[e])return this;if(n=this._events[e],o=n.length,r=-1,n===t||v(n.listener)&&n.listener===t)delete this._events[e],this._events.removeListener&&this.emit("removeListener",e,t);else if(g(n)){for(i=o;i-- >0;)if(n[i]===t||n[i].listener&&n[i].listener===t){r=i;break}if(r<0)return this;1===n.length?(n.length=0,delete this._events[e]):n.splice(r,1),this._events.removeListener&&this.emit("removeListener",e,t)}return this},p.prototype.removeAllListeners=function(e){var t,n;if(!this._events)return this;if(!this._events.removeListener)return 0===arguments.length?this._events={}:this._events[e]&&delete this._events[e],this;if(0===arguments.length){for(t in this._events)"removeListener"!==t&&this.removeAllListeners(t);return this.removeAllListeners("removeListener"),this._events={},this}if(n=this._events[e],v(n))this.removeListener(e,n);else if(n)for(;n.length;)this.removeListener(e,n[n.length-1]);return delete this._events[e],this},p.prototype.listeners=function(e){return this._events&&this._events[e]?v(this._events[e])?[this._events[e]]:this._events[e].slice():[]},p.prototype.listenerCount=function(e){if(this._events){var t=this._events[e];if(v(t))return 1;if(t)return t.length}return 0},p.listenerCount=function(e,t){return e.listenerCount(t)};var Pt=At.EventEmitter,qt=function(e){function t(){return bt(this,t),xt(this,e.call(this))}return wt(t,e),t.prototype.off=function(e,t){return t?this.removeListener(e,t):e?this.removeAllListeners(e):this.removeAllListeners()},t}(Pt),Ct=["","ABORTED","NETWORK","DECODE","SRC_NOT_SUPPORTED"];m.Group=function(){function e(e){var t=c+e;u.emit("progress",t/f)}function t(){c++,o(),u.emit("progress",c/f),r()}function n(e){o(),u.listenerCount("error")&&u.emit("error",e),r()}function r(){if(0===s.length)return l=null,void u.emit("complete");l=s.pop(),l.on("progress",e),l.once("loaded",t),l.once("error",n),l.start()}function o(){l.off("progress",e),l.off("loaded",t),l.off("error",n)}function i(e){return s.push(e),f++,e}function a(){f=s.length,r()}var u=new qt,s=[],c=0,f=0,l=null;return Object.freeze({on:u.on.bind(u),once:u.once.bind(u),off:u.off.bind(u),add:i,start:a})};var Rt=navigator&&/Firefox/i.test(navigator.userAgent),Dt=void 0,jt={getOfflineContext:w,cloneBuffer:x,reverseBuffer:T,ramp:O,getFrequency:S,timeCode:L},Ft=function(e){function t(n){bt(this,t);var r=xt(this,e.call(this));return r.id=n.id||null,r._context=n.context||_t,r._destination=n.destination||r._context.destination,r._effects=new Tt(r._context),r._gain=r._context.createGain(),r._config=n,r._data=null,r._fadeTimeout=null,r._isTouchLocked=!1,r._loader=null,r._loop=!1,r._offset=0,r._playbackRate=1,r._playWhenReady=null,r._source=null,r._wave=null,r._userData={},r._effects.setDestination(r._gain),r._gain.connect(r._destination),r._onEnded=r._onEnded.bind(r),r._onLoad=r._onLoad.bind(r),r._onLoadError=r._onLoadError.bind(r),r}return wt(t,e),t.prototype.prepare=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null,t=arguments.length>1&&void 0!==arguments[1]&&arguments[1],n=!t&&!this._source&&!!this._config.deferLoad;if(e){var r=Mt.getSrc(e),o=Mt.getSupportedFile(r)||this._config.src;this._config=Object.assign(this._config,e,{src:o})}return this._source&&this._data&&this._data.tagName?this._source.load(this._config.src):(this._loader=new m(this._config.src,n),this._loader.audioContext=this._config.asMediaElement||this._context.isFake?null:this._context,this._loader.isTouchLocked=this._isTouchLocked,this._loader.once("loaded",this._onLoad),this._loader.once("error",this._onLoadError)),this},t.prototype.load=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;return this.stop(),this._source=null,!e||Mt.containsURL(e)?(this._loader&&this._loader.destroy(),this.prepare(e,!0),this._loader.start()):this.data=e.data||e,this},t.prototype.play=function(e,t){var n=this;return!this._source||this._isTouchLocked?(this._playWhenReady=function(){n._source&&n.play(e,t)},this._config.deferLoad&&(this._loader||this.prepare(null,!0),this._loader.start(!0)),this):(this._playWhenReady=null,this._effects.setSource(this._source.sourceNode),this._offset&&void 0===t&&(t=this._offset,this._offset=0),this._source.play(e,t),this._source.hasOwnProperty("volume")&&(this._source.volume=this._gain.gain.value),this._source.hasOwnProperty("loop")&&(this._source.loop=this._loop),this.emit("play",this),this)},t.prototype.pause=function(){return this._source&&this._source.pause(),this.emit("pause",this),this},t.prototype.stop=function(e){return this._source&&this._source.stop(e||0),this.emit("stop",this),this},t.prototype.seek=function(e){return this.currentTime=e,this},t.prototype.fade=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1;if(!this._source)return this;var n=this._gain.gain;if(!this._context||this._context.isFake||Rt)this._fadePolyfill(e,t);else{var r=this._context.currentTime;n.cancelScheduledValues(r),n.setValueAtTime(n.value,r),n.linearRampToValueAtTime(e,r+t)}return this.emit("fade",this,e),this},t.prototype._fadePolyfill=function(e,t){var n=this;return window.clearTimeout(this._fadeTimeout),function e(t,r){n._fadeTimeout=window.setTimeout(function(){if(n.volume=n.volume+.2*(t-n.volume),Math.abs(n.volume-t)>.05)return void e(t,r);n.volume=t},1e3*r)}(e,t/10),this},t.prototype.unload=function(){this._source&&this._source.destroy(),this._loader&&this._loader.destroy(),this._data=null,this._playWhenReady=null,this._source=null,this._loader=null,this._config.deferLoad=!0,this.emit("unload",this)},t.prototype.reload=function(){return this.load(null,!0)},t.prototype.destroy=function(){this._source&&this._source.destroy(),this._effects&&this._effects.destroy(),this._gain&&this._gain.disconnect(),this._loader&&(this._loader.off("loaded"),this._loader.off("error"),this._loader.destroy()),this._gain=null,this._context=null,this._destination=null,this._data=null,this._playWhenReady=null,this._source=null,this._effects=null,this._loader=null,this._config=null,this.emit("destroy",this),this.off()},t.prototype.waveform=function(e){var t=this;return this._wave||(this._wave=jt.waveform()),this._data||this.once("ready",function(){return t._wave(t._data,e)}),this._wave(this._data,e)},t.prototype._createSource=function(e){var t=Mt.isAudioBuffer(e);if(t||Mt.isMediaElement(e)){var n=t?k:A;this._source=new M(n,e,this._context,this._onEnded),this._source.singlePlay=!!this._config.singlePlay,this._source.playbackRate=this._playbackRate,this._source.currentTime=this._offset}else if(Mt.isMediaStream(e))this._source=new P(e,this._context);else{if(!Mt.isOscillatorType(e&&e.type||e))throw new Error("Cannot detect data type: "+e);this._source=new q(e.type||e,this._context)}this._effects.setSource(this._source.sourceNode),this.emit("ready",this),this._playWhenReady&&this._playWhenReady()},t.prototype._onEnded=function(){this.emit("ended",this)},t.prototype._onLoad=function(e){this._data=e,this.emit("loaded",this),this._createSource(e)},t.prototype._onLoadError=function(e){if(this.listenerCount("error"))return void this.emit("error",this,e)},kt(t,[{key:"context",get:function(){return this._context}},{key:"currentTime",get:function(){return this._source?this._source.currentTime:this._offset},set:function(e){if(this._source){var t=this._source.playing;this._source.stop(),this._source.currentTime=e,t&&this.play(0,e)}else this._offset=e}},{key:"data",get:function(){return this._data},set:function(e){e&&(this._data=e,this._createSource(e))}},{key:"duration",get:function(){return this._source?this._source.duration:0}},{key:"effects",get:function(){return this._effects._nodes},set:function(e){this._effects.removeAll().add(e)}},{key:"fx",get:function(){return this.effects},set:function(e){this.effects=e}},{key:"ended",get:function(){return!!this._source&&this._source.ended}},{key:"frequency",get:function(){return this._source?this._source.frequency:0},set:function(e){this._source&&this._source.hasOwnProperty("frequency")&&(this._source.frequency=e)}},{key:"gain",get:function(){return this._gain}},{key:"groupVolume",get:function(){return this._source.groupVolume},set:function(e){this._source&&this._source.hasOwnProperty("groupVolume")&&(this._source.groupVolume=e)}},{key:"isTouchLocked",set:function(e){this._isTouchLocked=e,this._loader&&(this._loader.isTouchLocked=e),!e&&this._playWhenReady&&this._playWhenReady()}},{key:"loader",get:function(){return this._loader}},{key:"loop",get:function(){return this._loop},set:function(e){this._loop=!!e,this._source&&this._source.hasOwnProperty("loop")&&this._source.loop!==this._loop&&(this._source.loop=this._loop)}},{key:"singlePlay",get:function(){return this._config.singlePlay},set:function(e){this._config.singlePlay=e,this._source.singlePlay=e}},{key:"config",get:function(){return this._config}},{key:"paused",get:function(){return!!this._source&&this._source.paused}},{key:"playing",get:function(){return!!this._source&&this._source.playing}},{key:"playbackRate",get:function(){return this._playbackRate},set:function(e){this._playbackRate=e,this._source&&(this._source.playbackRate=e)}},{key:"progress",get:function(){return this._source?this._source.progress||0:0}},{key:"sourceInfo",get:function(){return this._source&&this._source.info?this._source.info:{}}},{key:"sourceNode",get:function(){return this._source?this._source.sourceNode:null}},{key:"volume",get:function(){return this._gain.gain.value},set:function(e){if(E(e)){window.clearTimeout(this._fadeTimeout),e=Math.min(Math.max(e,0),1);var t=this._gain.gain,n=this._context.currentTime;t.cancelScheduledValues(n),t.value=e,Rt||t.setValueAtTime(e,n),this._source&&this._source.hasOwnProperty("volume")&&(this._source.volume=e)}}},{key:"userData",get:function(){return this._userData}}]),t}(qt);Ft.__source={BufferSource:k,MediaSource:A,MicrophoneSource:P,OscillatorSource:q};var Vt,Gt,Bt,zt,It,Nt,Ut,Wt,Ht,Qt,Xt,Zt,Kt=new h(_t,_t.destination),Jt=function(e,n){function r(){e&&"suspended"===e.state?e.resume().then(function(){t(e),o()}):o()}function o(){document.body.removeEventListener("touchstart",r),document.body.removeEventListener("touchend",r),n()}function i(){document.body.addEventListener("touchstart",r,!1),document.body.addEventListener("touchend",r,!1)}var a=vt;return a&&("loading"===document.readyState?document.addEventListener("DOMContentLoaded",i):i()),a}(_t,function(){Jt=!1,Kt.sounds.forEach(function(e){return e.isTouchLocked=!1})}),Yt=[],$t=function(e,t){function n(){document[i]?e():t()}function r(e){o=e,o?document.addEventListener(a,n,!1):document.removeEventListener(a,n)}var o=!1,i=null,a=null;return void 0!==document.hidden?(i="hidden",a="visibilitychange"):void 0!==document.mozHidden?(i="mozHidden",a="mozvisibilitychange"):void 0!==document.msHidden?(i="msHidden",a="msvisibilitychange"):void 0!==document.webkitHidden&&(i="webkitHidden",a="webkitvisibilitychange"),void 0!==a&&r(!0),{get enabled(){return o},set enabled(e){r(e)}}}(J,Y),en=(Xt={canPlay:Mt.canPlay,context:_t,create:G,createGroup:D,createSound:G,destroyAll:z,destroy:B,effects:Kt.effects,extensions:Mt.extensions,fade:U,file:Mt,gain:Kt.gain,getOfflineContext:jt.getOfflineContext,get:R,getSound:R,group:D,hasWebAudio:!_t.isFake,isSupported:Mt.extensions.length>0,load:V,log:function(){return b(en)},mute:I,pause:Z,pauseAll:W,play:X,register:$,resumeAll:H,stop:K,stopAll:Q,unMute:N,utils:jt,VERSION:"2.1.6"},Vt="effects",Zt={},Zt[Vt]=Zt[Vt]||{},Zt[Vt].get=function(){return Kt.effects},Gt="effects",Zt[Gt]=Zt[Gt]||{},Zt[Gt].set=function(e){Kt.effects.removeAll().add(e)},Bt="fx",Zt[Bt]=Zt[Bt]||{},Zt[Bt].get=function(){return this.effects},zt="fx",Zt[zt]=Zt[zt]||{},Zt[zt].set=function(e){this.effects=e},It="isTouchLocked",Zt[It]=Zt[It]||{},Zt[It].get=function(){return Jt},Nt="playInBackground",Zt[Nt]=Zt[Nt]||{},Zt[Nt].get=function(){return!$t.enabled},Ut="playInBackground",Zt[Ut]=Zt[Ut]||{},Zt[Ut].set=function(e){$t.enabled=!e,e||Y()},Wt="sounds",Zt[Wt]=Zt[Wt]||{},Zt[Wt].get=function(){return Kt.sounds.slice(0)},Ht="volume",Zt[Ht]=Zt[Ht]||{},Zt[Ht].get=function(){return Kt.volume},Qt="volume",Zt[Qt]=Zt[Qt]||{},Zt[Qt].set=function(e){Kt.volume=e},Xt.__test={Effects:Tt,Group:h,Sound:Ft},function(e,t){for(var n in t){var r=t[n];r.configurable=r.enumerable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,n,r)}}(Xt,Zt),Xt),tn=function(){function e(t){bt(this,e),this._node=this._in=this._out=t}return e.prototype.connect=function(e){this._node.connect(e._in||e)},e.prototype.disconnect=function(){for(var e=arguments.length,t=Array(e),n=0;n<e;n++)t[n]=arguments[n];this._node.disconnect(t)},e.prototype.update=function(){throw new Error("update must be overridden")},kt(e,[{key:"context",get:function(){return _t}},{key:"numberOfInputs",get:function(){return 1}},{key:"numberOfOutputs",get:function(){return 1}},{key:"channelCount",get:function(){return 1}},{key:"channelCountMode",get:function(){return"max"}},{key:"channelInterpretation",get:function(){return"speakers"}}]),e}(),nn=function(e){function t(){var n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=n.fftSize,o=void 0===r?2048:r,i=n.minDecibels,a=void 0===i?-100:i,u=n.maxDecibels,s=void 0===u?-30:u,c=n.smoothing,f=void 0===c?.9:c,l=n.useFloats,d=void 0!==l&&l;bt(this,t);var h=xt(this,e.call(this,en.context.createAnalyser()));return h._useFloats=!!d,h._waveform=null,h._frequencies=null,h._node.fftSize=o,h.update({minDecibels:a,maxDecibels:s,smoothing:f}),h}return wt(t,e),t.prototype.update=function(e){var t=e.minDecibels,n=e.maxDecibels,r=e.smoothing;E(r)&&(this._node.smoothingTimeConstant=r),E(t)&&(this._node.minDecibels=t),E(n)&&(this._node.maxDecibels=n)},t.prototype.getWaveform=function(){var e=this._useFloats&&this._node.getFloatTimeDomainData;return this._waveform||(this._waveform=this._createArray(e,this._node.fftSize)),e?this._node.getFloatTimeDomainData(this._waveform):this._node.getByteTimeDomainData(this._waveform),this._waveform},t.prototype.getFrequencies=function(){var e=this._useFloats&&this._node.getFloatFrequencyData;return this._frequencies||(this._frequencies=this._createArray(e,this._node.frequencyBinCount)),e?this._node.getFloatFrequencyData(this._frequencies):this._node.getByteFrequencyData(this._frequencies),this._frequencies},t.prototype.getAmplitude=function(e){this._amplitudeWorker||this._createAmplitudeAnalyser(),this._amplitudeCallback=e||this._amplitudeCallback;var t=new Float32Array(this._node.fftSize);t.set(this.getFrequencies(!0)),this._amplitudeWorker.postMessage({sum:0,length:t.byteLength,numSamples:this._node.fftSize/2,b:t.buffer},[t.buffer])},t.prototype.getPitch=function(e){this._pitchWorker||this._createPitchAnalyser(),this._pitchCallback=e||this._pitchCallback;var t=new Float32Array(this._node.fftSize);t.set(this.getWaveform(!0)),this._pitchWorker.postMessage({sampleRate:en.context.sampleRate,b:t.buffer},[t.buffer])},t.prototype._createArray=function(e,t){return e?new Float32Array(t):new Uint8Array(t)},t.prototype._createAmplitudeAnalyser=function(){var e=this,t=new Blob(["onmessage = function(e) {\n var data = e.data;\n var f = new Float32Array(data.b);\n for (var i = 0; i < f.length; i++) {\n data.sum += f[i];\n }\n data.sum /= f.length;\n postMessage(Math.max(1.0 - (data.sum / data.numSamples * -1.0), 0));\n };"]),n=URL.createObjectURL(t);this._amplitudeWorker=new Worker(n),this._amplitudeWorker.onmessage=function(t){e._amplitudeCallback&&e._amplitudeCallback(t.data)}},t.prototype._createPitchAnalyser=function(){var e=this,t=new Blob(["onmessage = function(e) {\n var data = e.data;\n var sampleRate = data.sampleRate;\n var buf = new Float32Array(data.b);\n var SIZE = buf.length;\n var MAX_SAMPLES = Math.floor(SIZE / 2);\n var bestOffset = -1;\n var bestCorrel = 0;\n var rms = 0;\n var foundGoodCorrelation = false;\n var correls = new Array(MAX_SAMPLES);\n