mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2024-12-26 07:52:50 -05:00
13 lines
205 KiB
JavaScript
13 lines
205 KiB
JavaScript
|
!function(t,e){"function"==typeof define&&define.amd?define(function(){return e()}):"object"==typeof module?module.exports=e():t.Tone=e()}(this,function(){"use strict";function t(t){i=t()}function e(t){t(i)}var i;/**
|
||
|
* Tone.js
|
||
|
* @author Yotam Mann
|
||
|
* @license http://opensource.org/licenses/MIT MIT License
|
||
|
* @copyright 2014-2016 Yotam Mann
|
||
|
*/
|
||
|
return t(function(){function t(t){return void 0===t}function e(t){return"function"==typeof t}var i,s,n,o;if(t(window.AudioContext)&&(window.AudioContext=window.webkitAudioContext),t(window.OfflineAudioContext)&&(window.OfflineAudioContext=window.webkitOfflineAudioContext),t(AudioContext))throw new Error("Web Audio is not supported in this browser");return i=new AudioContext,e(AudioContext.prototype.createGain)||(AudioContext.prototype.createGain=AudioContext.prototype.createGainNode),e(AudioContext.prototype.createDelay)||(AudioContext.prototype.createDelay=AudioContext.prototype.createDelayNode),e(AudioContext.prototype.createPeriodicWave)||(AudioContext.prototype.createPeriodicWave=AudioContext.prototype.createWaveTable),e(AudioBufferSourceNode.prototype.start)||(AudioBufferSourceNode.prototype.start=AudioBufferSourceNode.prototype.noteGrainOn),e(AudioBufferSourceNode.prototype.stop)||(AudioBufferSourceNode.prototype.stop=AudioBufferSourceNode.prototype.noteOff),e(OscillatorNode.prototype.start)||(OscillatorNode.prototype.start=OscillatorNode.prototype.noteOn),e(OscillatorNode.prototype.stop)||(OscillatorNode.prototype.stop=OscillatorNode.prototype.noteOff),e(OscillatorNode.prototype.setPeriodicWave)||(OscillatorNode.prototype.setPeriodicWave=OscillatorNode.prototype.setWaveTable),t(AudioNode.prototype._nativeConnect)&&(AudioNode.prototype._nativeConnect=AudioNode.prototype.connect,AudioNode.prototype.connect=function(e,i,s){if(e.input)Array.isArray(e.input)?(t(s)&&(s=0),this.connect(e.input[s])):this.connect(e.input,i,s);else try{e instanceof AudioNode?this._nativeConnect(e,i,s):this._nativeConnect(e,i)}catch(n){throw new Error("error connecting to node: "+e)}}),s=function(e,i){t(e)||1===e?this.input=this.context.createGain():e>1&&(this.input=new Array(e)),t(i)||1===i?this.output=this.context.createGain():i>1&&(this.output=new Array(e))},s.prototype.set=function(e,i,n){var o,r,a,h,l,u;this.isObject(e)?n=i:this.isString(e)&&(o={},o[e]=i,e=o);for(r in e){if(i=e[r],a=this,-1!==r.indexOf(".")){for(h=r.split("."),l=0;l<h.length-1;l++)a=a[h[l]];r=h[h.length-1]}u=a[r],t(u)||(s.Signal&&u instanceof s.Signal||s.Param&&u instanceof s.Param?u.value!==i&&(t(n)?u.value=i:u.rampTo(i,n)):u instanceof AudioParam?u.value!==i&&(u.value=i):u instanceof s?u.set(i):u!==i&&(a[r]=i))}return this},s.prototype.get=function(i){var n,o,r,a,h,l,u,c,p;for(t(i)?i=this._collectDefaults(this.constructor):this.isString(i)&&(i=[i]),n={},o=0;o<i.length;o++){if(r=i[o],a=this,h=n,-1!==r.indexOf(".")){for(l=r.split("."),u=0;u<l.length-1;u++)c=l[u],h[c]=h[c]||{},h=h[c],a=a[c];r=l[l.length-1]}p=a[r],this.isObject(i[r])?h[r]=p.get():s.Signal&&p instanceof s.Signal?h[r]=p.value:s.Param&&p instanceof s.Param?h[r]=p.value:p instanceof AudioParam?h[r]=p.value:p instanceof s?h[r]=p.get():e(p)||t(p)||(h[r]=p)}return n},s.prototype._collectDefaults=function(e){var i,s,n=[];if(t(e.defaults)||(n=Object.keys(e.defaults)),!t(e._super))for(i=this._collectDefaults(e._super),s=0;s<i.length;s++)-1===n.indexOf(i[s])&&n.push(i[s]);return n},s.prototype.toString=function(){var t,i,n;for(t in s)if(i=t[0].match(/^[A-Z]$/),n=s[t]===this.constructor,e(s[t])&&i&&n)return t;return"Tone"},s.context=i,s.prototype.context=s.context,s.prototype.bufferSize=2048,s.prototype.blockTime=128/s.context.sampleRate,s.prototype.sampleTime=1/s.context.sampleRate,s.prototype.dispose=function(){return this.isUndef(this.input)||(this.input instanceof AudioNode&&this.input.disconnect(),this.input=null),this.isUndef(this.output)||(this.output instanceof AudioNode&&this.output.disconnect(),this.output=null),this},n=null,s.prototype.noGC=function(){return this.output.connect(n),this},AudioNode.prototype.noGC=function(){return this.connect(n),this},s.prototype.connect=function(t,e,i){return Array.isArray(this.output)?(e=this.defaultArg(e,0),this.output[e].connect(t,0,i)):this.output.connect(t,e,i),this},s.prototype.disconnect=function(t){return Array.isArray(this.output)?(t=this.defaultArg(t,0),this.output[t].disconnect()):this.isUndef(t)?this.output.disconnect():this.output.disconnect(t),this},s.protot
|
||
|
s=null===i?this._initial:i.value,r=this._exponentialApproach(o.time,s,o.value,o.constant,e)):r=o.type===t.TimelineSignal.Type.Curve?this._curveInterpolate(o.time,o.value,o.duration,e):null===n?o.value:n.type===t.TimelineSignal.Type.Linear?this._linearInterpolate(o.time,o.value,n.time,n.value,e):n.type===t.TimelineSignal.Type.Exponential?this._exponentialInterpolate(o.time,o.value,n.time,n.value,e):o.value,r},t.TimelineSignal.prototype.connect=t.SignalBase.prototype.connect,t.TimelineSignal.prototype._exponentialApproach=function(t,e,i,s,n){return i+(e-i)*Math.exp(-(n-t)/s)},t.TimelineSignal.prototype._linearInterpolate=function(t,e,i,s,n){return e+(s-e)*((n-t)/(i-t))},t.TimelineSignal.prototype._exponentialInterpolate=function(t,e,i,s,n){return e=Math.max(this._minOutput,e),e*Math.pow(s/e,(n-t)/(i-t))},t.TimelineSignal.prototype._curveInterpolate=function(t,e,i,s){var n,o,r,a,h,l=e.length;return s>=t+i?e[l-1]:t>=s?e[0]:(n=(s-t)/i,o=Math.floor((l-1)*n),r=Math.ceil((l-1)*n),a=e[o],h=e[r],r===o?a:this._linearInterpolate(o,a,r,h,n*(l-1)))},t.TimelineSignal.prototype.dispose=function(){t.Signal.prototype.dispose.call(this),t.Param.prototype.dispose.call(this),this._events.dispose(),this._events=null},t.TimelineSignal}),e(function(t){return t.Pow=function(e){this._exp=this.defaultArg(e,1),this._expScaler=this.input=this.output=new t.WaveShaper(this._expFunc(this._exp),8192)},t.extend(t.Pow,t.SignalBase),Object.defineProperty(t.Pow.prototype,"value",{get:function(){return this._exp},set:function(t){this._exp=t,this._expScaler.setMap(this._expFunc(this._exp))}}),t.Pow.prototype._expFunc=function(t){return function(e){return Math.pow(Math.abs(e),t)}},t.Pow.prototype.dispose=function(){return t.prototype.dispose.call(this),this._expScaler.dispose(),this._expScaler=null,this},t.Pow}),e(function(t){return t.Envelope=function(){var e=this.optionsObject(arguments,["attack","decay","sustain","release"],t.Envelope.defaults);this.attack=e.attack,this.decay=e.decay,this.sustain=e.sustain,this.release=e.release,this._attackCurve="linear",this._releaseCurve="exponential",this._sig=this.output=new t.TimelineSignal,this._sig.setValueAtTime(0,0),this.attackCurve=e.attackCurve,this.releaseCurve=e.releaseCurve},t.extend(t.Envelope),t.Envelope.defaults={attack:.01,decay:.1,sustain:.5,release:1,attackCurve:"linear",releaseCurve:"exponential"},Object.defineProperty(t.Envelope.prototype,"value",{get:function(){return this.getValueAtTime(this.now())}}),Object.defineProperty(t.Envelope.prototype,"attackCurve",{get:function(){if(this.isString(this._attackCurve))return this._attackCurve;if(this.isArray(this._attackCurve)){for(var e in t.Envelope.Type)if(t.Envelope.Type[e].In===this._attackCurve)return e;return this._attackCurve}},set:function(e){if(t.Envelope.Type.hasOwnProperty(e)){var i=t.Envelope.Type[e];this.isObject(i)?this._attackCurve=i.In:this._attackCurve=i}else{if(!this.isArray(e))throw new Error("Tone.Envelope: invalid curve: "+e);this._attackCurve=e}}}),Object.defineProperty(t.Envelope.prototype,"releaseCurve",{get:function(){if(this.isString(this._releaseCurve))return this._releaseCurve;if(this.isArray(this._releaseCurve)){for(var e in t.Envelope.Type)if(t.Envelope.Type[e].Out===this._releaseCurve)return e;return this._releaseCurve}},set:function(e){if(t.Envelope.Type.hasOwnProperty(e)){var i=t.Envelope.Type[e];this.isObject(i)?this._releaseCurve=i.Out:this._releaseCurve=i}else{if(!this.isArray(e))throw new Error("Tone.Envelope: invalid curve: "+e);this._releaseCurve=e}}}),t.Envelope.prototype.triggerAttack=function(t,e){var i,s,n,o,r,a,h,l,u,c=this.now()+this.blockTime;return t=this.toSeconds(t,c),i=this.toSeconds(this.attack),s=i,n=this.toSeconds(this.decay),e=this.defaultArg(e,1),o=this.getValueAtTime(t),o>0&&(r=1/s,a=1-o,s=a/r),"linear"===this._attackCurve?this._sig.linearRampToValue(e,s,t):"exponential"===this._attackCurve?this._sig.exponentialRampToValue(e,s,t):s>0&&(this._sig.setRampPoint(t),h=this._attackCurve,i>s&&(l=1-s/i,u=Math.floor(l*this._attackCurve.length),h=this._attackCurve.slice(u),h[0]=o),this._sig.setValueCurveAtTime(h
|
||
|
var e=this.getEvent(t);return null!==e?e.state:this._initial},t.TimelineState.prototype.setStateAtTime=function(t,e){this.addEvent({state:t,time:this.toSeconds(e)})},t.TimelineState}),e(function(t){var e,i,s;return t.Clock=function(){var i=this.optionsObject(arguments,["callback","frequency"],t.Clock.defaults);this.callback=i.callback,this._lookAhead="auto",this._computedLookAhead=e/1e3,this._nextTick=-1,this._lastUpdate=-1,this._loopID=-1,this.frequency=new t.TimelineSignal(i.frequency,t.Type.Frequency),this.ticks=0,this._state=new t.TimelineState(t.State.Stopped),this._boundLoop=this._loop.bind(this),t.Clock._worker.addEventListener("message",this._boundLoop),this._readOnly("frequency")},t.extend(t.Clock),t.Clock.defaults={callback:t.noOp,frequency:1,lookAhead:"auto"},Object.defineProperty(t.Clock.prototype,"state",{get:function(){return this._state.getStateAtTime(this.now())}}),Object.defineProperty(t.Clock.prototype,"lookAhead",{get:function(){return this._lookAhead},set:function(t){"auto"===t?this._lookAhead="auto":this._lookAhead=this.toSeconds(t)}}),t.Clock.prototype.start=function(e,i){return e=this.toSeconds(e),this._state.getStateAtTime(e)!==t.State.Started&&this._state.addEvent({state:t.State.Started,time:e,offset:i}),this},t.Clock.prototype.stop=function(e){return e=this.toSeconds(e),this._state.cancel(e),this._state.setStateAtTime(t.State.Stopped,e),this},t.Clock.prototype.pause=function(e){return e=this.toSeconds(e),this._state.getStateAtTime(e)===t.State.Started&&this._state.setStateAtTime(t.State.Paused,e),this},t.Clock.prototype._loop=function(){var i,s,n,o,r,a,h;if("auto"===this._lookAhead?(i=this.now(),-1!==this._lastUpdate&&(s=i-this._lastUpdate,s=Math.min(10*e/1e3,s),this._computedLookAhead=(9*this._computedLookAhead+s)/10),this._lastUpdate=i):this._computedLookAhead=this._lookAhead,n=this.now(),o=2*this._computedLookAhead,r=this._state.getEvent(n+o),a=t.State.Stopped,r&&(a=r.state,-1===this._nextTick&&a===t.State.Started&&(this._nextTick=r.time,this.isUndef(r.offset)||(this.ticks=r.offset))),a===t.State.Started)for(;n+o>this._nextTick;)h=this._nextTick,this._nextTick+=1/this.frequency.getValueAtTime(this._nextTick),this.callback(h),this.ticks++;else a===t.State.Stopped?(this._nextTick=-1,this.ticks=0):a===t.State.Paused&&(this._nextTick=-1)},t.Clock.prototype.getStateAtTime=function(t){return this._state.getStateAtTime(t)},t.Clock.prototype.dispose=function(){cancelAnimationFrame(this._loopID),t.TimelineState.prototype.dispose.call(this),t.Clock._worker.removeEventListener("message",this._boundLoop),this._writable("frequency"),this.frequency.dispose(),this.frequency=null,this._boundLoop=null,this._nextTick=1/0,this.callback=null,this._state.dispose(),this._state=null},window.URL=window.URL||window.webkitURL,e=20,i=new Blob(["setInterval(function(){self.postMessage('tick')}, "+e+")"]),s=URL.createObjectURL(i),t.Clock._worker=new Worker(s),t.Clock}),e(function(t){return t.Emitter=function(){this._events={}},t.extend(t.Emitter),t.Emitter.prototype.on=function(t,e){var i,s,n=t.split(/\W+/);for(i=0;i<n.length;i++)s=n[i],this._events.hasOwnProperty(s)||(this._events[s]=[]),this._events[s].push(e);return this},t.Emitter.prototype.off=function(e,i){var s,n,o,r=e.split(/\W+/);for(s=0;s<r.length;s++)if(e=r[s],this._events.hasOwnProperty(e))if(t.prototype.isUndef(i))this._events[e]=[];else for(n=this._events[e],o=0;o<n.length;o++)n[o]===i&&n.splice(o,1);return this},t.Emitter.prototype.trigger=function(t){var e,i,s,n;if(this._events&&(e=Array.prototype.slice.call(arguments,1),this._events.hasOwnProperty(t)))for(i=this._events[t],s=0,n=i.length;n>s;s++)i[s].apply(this,e);return this},t.Emitter.mixin=function(e){var i,s,n,o=["on","off","trigger"];for(e._events={},i=0;i<o.length;i++)s=o[i],n=t.Emitter.prototype[s],e[s]=n},t.Emitter.prototype.dispose=function(){return t.prototype.dispose.call(this),this._events=null,this},t.Emitter}),e(function(t){t.IntervalTimeline=function(){this._root=null,this._length=0},t.extend(t.IntervalTimeline),t.IntervalTimeline.prototype.addEvent=function(t){if(this.isUndef(t.time)||th
|
||
|
this._right=null,this._merge.dispose(),this._merge=null,this},t.MidSideMerge}),e(function(t){return t.MidSideCompressor=function(e){e=this.defaultArg(e,t.MidSideCompressor.defaults),this._midSideSplit=this.input=new t.MidSideSplit,this._midSideMerge=this.output=new t.MidSideMerge,this.mid=new t.Compressor(e.mid),this.side=new t.Compressor(e.side),this._midSideSplit.mid.chain(this.mid,this._midSideMerge.mid),this._midSideSplit.side.chain(this.side,this._midSideMerge.side),this._readOnly(["mid","side"])},t.extend(t.MidSideCompressor),t.MidSideCompressor.defaults={mid:{ratio:3,threshold:-24,release:.03,attack:.02,knee:16},side:{ratio:6,threshold:-30,release:.25,attack:.03,knee:10}},t.MidSideCompressor.prototype.dispose=function(){return t.prototype.dispose.call(this),this._writable(["mid","side"]),this.mid.dispose(),this.mid=null,this.side.dispose(),this.side=null,this._midSideSplit.dispose(),this._midSideSplit=null,this._midSideMerge.dispose(),this._midSideMerge=null,this},t.MidSideCompressor}),e(function(t){return t.Mono=function(){t.call(this,1,0),this._merge=this.output=new t.Merge,this.input.connect(this._merge,0,0),this.input.connect(this._merge,0,1),this.input.gain.value=this.dbToGain(-10)},t.extend(t.Mono),t.Mono.prototype.dispose=function(){return t.prototype.dispose.call(this),this._merge.dispose(),this._merge=null,this},t.Mono}),e(function(t){return t.MultibandCompressor=function(e){e=this.defaultArg(arguments,t.MultibandCompressor.defaults),this._splitter=this.input=new t.MultibandSplit({lowFrequency:e.lowFrequency,highFrequency:e.highFrequency}),this.lowFrequency=this._splitter.lowFrequency,this.highFrequency=this._splitter.highFrequency,this.output=this.context.createGain(),this.low=new t.Compressor(e.low),this.mid=new t.Compressor(e.mid),this.high=new t.Compressor(e.high),this._splitter.low.chain(this.low,this.output),this._splitter.mid.chain(this.mid,this.output),this._splitter.high.chain(this.high,this.output),this._readOnly(["high","mid","low","highFrequency","lowFrequency"])},t.extend(t.MultibandCompressor),t.MultibandCompressor.defaults={low:t.Compressor.defaults,mid:t.Compressor.defaults,high:t.Compressor.defaults,lowFrequency:250,highFrequency:2e3},t.MultibandCompressor.prototype.dispose=function(){return t.prototype.dispose.call(this),this._splitter.dispose(),this._writable(["high","mid","low","highFrequency","lowFrequency"]),this.low.dispose(),this.mid.dispose(),this.high.dispose(),this._splitter=null,this.low=null,this.mid=null,this.high=null,this.lowFrequency=null,this.highFrequency=null,this},t.MultibandCompressor}),e(function(t){return t.Panner=function(e){t.call(this),this._hasStereoPanner?(this._panner=this.input=this.output=this.context.createStereoPanner(),this.pan=this._panner.pan):(this._crossFade=new t.CrossFade,this._merger=this.output=new t.Merge,this._splitter=this.input=new t.Split,this.pan=new t.Signal(0,t.Type.AudioRange),this._zero=new t.Zero,this._a2g=new t.AudioToGain,this._zero.connect(this._a2g),this.pan.chain(this._a2g,this._crossFade.fade),this._splitter.connect(this._crossFade,0,0),this._splitter.connect(this._crossFade,1,1),this._crossFade.a.connect(this._merger,0,0),this._crossFade.b.connect(this._merger,0,1)),this.pan.value=this.defaultArg(e,0),this._readOnly("pan")},t.extend(t.Panner),t.Panner.prototype._hasStereoPanner=t.prototype.isFunction(t.context.createStereoPanner),t.Panner.prototype.dispose=function(){return t.prototype.dispose.call(this),this._writable("pan"),this._hasStereoPanner?(this._panner.disconnect(),this._panner=null,this.pan=null):(this._zero.dispose(),this._zero=null,this._crossFade.dispose(),this._crossFade=null,this._splitter.dispose(),this._splitter=null,this._merger.dispose(),this._merger=null,this.pan.dispose(),this.pan=null,this._a2g.dispose(),this._a2g=null),this},t.Panner}),e(function(t){return t.PanVol=function(){var e=this.optionsObject(arguments,["pan","volume"],t.PanVol.defaults);this._panner=this.input=new t.Panner(e.pan),this.pan=this._panner.pan,this._volume=this.output=new t.Volume(e.volume),this.volume=this._volume.volume,this._panner.
|
||
|
this._readOnly(["roomSize","dampening"])},t.extend(t.Freeverb,t.StereoEffect),t.Freeverb.defaults={roomSize:.7,dampening:3e3},t.Freeverb.prototype.dispose=function(){var e,i,s;for(t.StereoEffect.prototype.dispose.call(this),e=0;e<this._allpassFiltersL.length;e++)this._allpassFiltersL[e].disconnect(),this._allpassFiltersL[e]=null;for(this._allpassFiltersL=null,i=0;i<this._allpassFiltersR.length;i++)this._allpassFiltersR[i].disconnect(),this._allpassFiltersR[i]=null;for(this._allpassFiltersR=null,s=0;s<this._combFilters.length;s++)this._combFilters[s].dispose(),this._combFilters[s]=null;return this._combFilters=null,this._writable(["roomSize","dampening"]),this.roomSize.dispose(),this.roomSize=null,this.dampening.dispose(),this.dampening=null,this},t.Freeverb}),e(function(t){var e=[.06748,.06404,.08212,.09004],i=[.773,.802,.753,.733],s=[347,113,37];return t.JCReverb=function(){var n,o,r,a,h=this.optionsObject(arguments,["roomSize"],t.JCReverb.defaults);for(t.StereoEffect.call(this,h),this.roomSize=new t.Signal(h.roomSize,t.Type.NormalRange),this._scaleRoomSize=new t.Scale(-.733,.197),this._allpassFilters=[],this._feedbackCombFilters=[],n=0;n<s.length;n++)o=this.context.createBiquadFilter(),o.type="allpass",o.frequency.value=s[n],this._allpassFilters.push(o);for(r=0;r<e.length;r++)a=new t.FeedbackCombFilter(e[r],.1),this._scaleRoomSize.connect(a.resonance),a.resonance.value=i[r],this._allpassFilters[this._allpassFilters.length-1].connect(a),r<e.length/2?a.connect(this.effectReturnL):a.connect(this.effectReturnR),this._feedbackCombFilters.push(a);this.roomSize.connect(this._scaleRoomSize),this.connectSeries.apply(this,this._allpassFilters),this.effectSendL.connect(this._allpassFilters[0]),this.effectSendR.connect(this._allpassFilters[0]),this._readOnly(["roomSize"])},t.extend(t.JCReverb,t.StereoEffect),t.JCReverb.defaults={roomSize:.5},t.JCReverb.prototype.dispose=function(){var e,i;for(t.StereoEffect.prototype.dispose.call(this),e=0;e<this._allpassFilters.length;e++)this._allpassFilters[e].disconnect(),this._allpassFilters[e]=null;for(this._allpassFilters=null,i=0;i<this._feedbackCombFilters.length;i++)this._feedbackCombFilters[i].dispose(),this._feedbackCombFilters[i]=null;return this._feedbackCombFilters=null,this._writable(["roomSize"]),this.roomSize.dispose(),this.roomSize=null,this._scaleRoomSize.dispose(),this._scaleRoomSize=null,this},t.JCReverb}),e(function(t){return t.MidSideEffect=function(){t.Effect.apply(this,arguments),this._midSideSplit=new t.MidSideSplit,this._midSideMerge=new t.MidSideMerge,this.midSend=this._midSideSplit.mid,this.sideSend=this._midSideSplit.side,this.midReturn=this._midSideMerge.mid,this.sideReturn=this._midSideMerge.side,this.effectSend.connect(this._midSideSplit),this._midSideMerge.connect(this.effectReturn)},t.extend(t.MidSideEffect,t.Effect),t.MidSideEffect.prototype.dispose=function(){return t.Effect.prototype.dispose.call(this),this._midSideSplit.dispose(),this._midSideSplit=null,this._midSideMerge.dispose(),this._midSideMerge=null,this.midSend=null,this.sideSend=null,this.midReturn=null,this.sideReturn=null,this},t.MidSideEffect}),e(function(t){return t.Phaser=function(){var e=this.optionsObject(arguments,["frequency","octaves","baseFrequency"],t.Phaser.defaults);t.StereoEffect.call(this,e),this._lfoL=new t.LFO(e.frequency,0,1),this._lfoR=new t.LFO(e.frequency,0,1),this._lfoR.phase=180,this._baseFrequency=e.baseFrequency,this._octaves=e.octaves,this.Q=new t.Signal(e.Q,t.Type.Positive),this._filtersL=this._makeFilters(e.stages,this._lfoL,this.Q),this._filtersR=this._makeFilters(e.stages,this._lfoR,this.Q),this.frequency=this._lfoL.frequency,this.frequency.value=e.frequency,this.effectSendL.connect(this._filtersL[0]),this.effectSendR.connect(this._filtersR[0]),this._filtersL[e.stages-1].connect(this.effectReturnL),this._filtersR[e.stages-1].connect(this.effectReturnR),this._lfoL.frequency.connect(this._lfoR.frequency),this.baseFrequency=e.baseFrequency,this.octaves=e.octaves,this._lfoL.start(),this._lfoR.start(),this._readOnly(["frequency","Q"])},t.extend(t.Phaser,t.StereoEffect),t.Ph
|
||
|
this.frequency.connect(this._carrier.frequency),this.frequency.chain(this.harmonicity,this._modulator.frequency),this.frequency.chain(this.modulationIndex,this._modulationNode),this._modulator.connect(this._modulationNode.gain),this._modulationNode.connect(this._carrier.frequency),this._carrier.connect(this.output),this.detune.connect(this._modulator.detune),this.phase=e.phase,this._readOnly(["modulationIndex","frequency","detune","harmonicity"])},t.extend(t.FMOscillator,t.Oscillator),t.FMOscillator.defaults={frequency:440,detune:0,phase:0,modulationIndex:2,modulationType:"square",harmonicity:1},t.FMOscillator.prototype._start=function(t){t=this.toSeconds(t),this._modulator.start(t),this._carrier.start(t)},t.FMOscillator.prototype._stop=function(t){t=this.toSeconds(t),this._modulator.stop(t),this._carrier.stop(t)},Object.defineProperty(t.FMOscillator.prototype,"type",{get:function(){return this._carrier.type},set:function(t){this._carrier.type=t}}),Object.defineProperty(t.FMOscillator.prototype,"modulationType",{get:function(){return this._modulator.type},set:function(t){this._modulator.type=t}}),Object.defineProperty(t.FMOscillator.prototype,"phase",{get:function(){return this._carrier.phase},set:function(t){this._carrier.phase=t,this._modulator.phase=t}}),Object.defineProperty(t.FMOscillator.prototype,"partials",{get:function(){return this._carrier.partials},set:function(t){this._carrier.partials=t}}),t.FMOscillator.prototype.dispose=function(){return t.Source.prototype.dispose.call(this),this._writable(["modulationIndex","frequency","detune","harmonicity"]),this.frequency.dispose(),this.frequency=null,this.detune=null,this.harmonicity.dispose(),this.harmonicity=null,this._carrier.dispose(),this._carrier=null,this._modulator.dispose(),this._modulator=null,this._modulationNode.dispose(),this._modulationNode=null,this.modulationIndex.dispose(),this.modulationIndex=null,this},t.FMOscillator}),e(function(t){return t.AMOscillator=function(){var e=this.optionsObject(arguments,["frequency","type","modulationType"],t.AMOscillator.defaults);t.Source.call(this,e),this._carrier=new t.Oscillator(e.frequency,e.type),this.frequency=this._carrier.frequency,this.detune=this._carrier.detune,this.detune.value=e.detune,this._modulator=new t.Oscillator(e.frequency,e.modulationType),this._modulationScale=new t.AudioToGain,this.harmonicity=new t.Multiply(e.harmonicity),this.harmonicity.units=t.Type.Positive,this._modulationNode=new t.Gain(0),this.frequency.chain(this.harmonicity,this._modulator.frequency),this.detune.connect(this._modulator.detune),this._modulator.chain(this._modulationScale,this._modulationNode.gain),this._carrier.chain(this._modulationNode,this.output),this.phase=e.phase,this._readOnly(["frequency","detune","harmonicity"])},t.extend(t.AMOscillator,t.Oscillator),t.AMOscillator.defaults={frequency:440,detune:0,phase:0,modulationType:"square",harmonicity:1},t.AMOscillator.prototype._start=function(t){t=this.toSeconds(t),this._modulator.start(t),this._carrier.start(t)},t.AMOscillator.prototype._stop=function(t){t=this.toSeconds(t),this._modulator.stop(t),this._carrier.stop(t)},Object.defineProperty(t.AMOscillator.prototype,"type",{get:function(){return this._carrier.type},set:function(t){this._carrier.type=t}}),Object.defineProperty(t.AMOscillator.prototype,"modulationType",{get:function(){return this._modulator.type},set:function(t){this._modulator.type=t}}),Object.defineProperty(t.AMOscillator.prototype,"phase",{get:function(){return this._carrier.phase},set:function(t){this._carrier.phase=t,this._modulator.phase=t}}),Object.defineProperty(t.AMOscillator.prototype,"partials",{get:function(){return this._carrier.partials},set:function(t){this._carrier.partials=t}}),t.AMOscillator.prototype.dispose=function(){return t.Source.prototype.dispose.call(this),this._writable(["frequency","detune","harmonicity"]),this.frequency=null,this.detune=null,this.harmonicity.dispose(),this.harmonicity=null,this._carrier.dispose(),this._carrier=null,this._modulator.dispose(),this._modulator=null,this._modulationNode.dispose(),this._modulation
|
||
|
var n,o;if(i=this.toSeconds(i),this.triggerAttack(t,i,s),this.isArray(e)&&this.isArray(t))for(n=0;n<t.length;n++)o=e[Math.min(n,e.length-1)],this.triggerRelease(t[n],i+this.toSeconds(o));else this.triggerRelease(t,i+this.toSeconds(e));return this},t.PolySynth.prototype.triggerRelease=function(t,e){var i,s,n,o;for(Array.isArray(t)||(t=[t]),e=this.toSeconds(e),i=0;i<t.length;i++)for(s=JSON.stringify(t[i]),n=0;n<this._triggers.length;n++)o=this._triggers[n],o.note===s&&o.release>e&&(o.voice.triggerRelease(e),o.release=e);return this},t.PolySynth.prototype.set=function(t,e,i){for(var s=0;s<this.voices.length;s++)this.voices[s].set(t,e,i);return this},t.PolySynth.prototype.get=function(t){return this.voices[0].get(t)},t.PolySynth.prototype.releaseAll=function(t){var e,i;for(t=this.toSeconds(t),e=0;e<this._triggers.length;e++)i=this._triggers[e],i.release>t&&(i.release=t,i.voice.triggerRelease(t));return this},t.PolySynth.prototype.dispose=function(){t.Instrument.prototype.dispose.call(this);for(var e=0;e<this.voices.length;e++)this.voices[e].dispose(),this.voices[e]=null;return this._writable("detune"),this.detune.dispose(),this.detune=null,this.voices=null,this._triggers=null,this},t.PolySynth.MAX_POLYPHONY=20,t.PolySynth}),e(function(t){return t.Player=function(e){var i;e instanceof t.Buffer?(e=e.get(),i=t.Player.defaults):i=this.optionsObject(arguments,["url","onload"],t.Player.defaults),t.Source.call(this,i),this._source=null,this.autostart=i.autostart,this._buffer=new t.Buffer({url:i.url,onload:this._onload.bind(this,i.onload),reverse:i.reverse}),e instanceof AudioBuffer&&this._buffer.set(e),this._loop=i.loop,this._loopStart=i.loopStart,this._loopEnd=i.loopEnd,this._playbackRate=i.playbackRate,this.retrigger=i.retrigger},t.extend(t.Player,t.Source),t.Player.defaults={onload:t.noOp,playbackRate:1,loop:!1,autostart:!1,loopStart:0,loopEnd:0,retrigger:!1,reverse:!1},t.Player.prototype.load=function(t,e){return this._buffer.load(t,this._onload.bind(this,e)),this},t.Player.prototype._onload=function(t){t(this),this.autostart&&this.start()},t.Player.prototype._start=function(e,i,s){if(!this._buffer.loaded)throw Error("Tone.Player: tried to start Player before the buffer was loaded");return i=this._loop?this.defaultArg(i,this._loopStart):this.defaultArg(i,0),i=this.toSeconds(i),s=this.defaultArg(s,this._buffer.duration-i),e=this.toSeconds(e),s=this.toSeconds(s),this._source=this.context.createBufferSource(),this._source.buffer=this._buffer.get(),this._loop?(this._source.loop=this._loop,this._source.loopStart=this.toSeconds(this._loopStart),this._source.loopEnd=this.toSeconds(this._loopEnd)):this._state.setStateAtTime(t.State.Stopped,e+s),this._source.playbackRate.value=this._playbackRate,this._source.connect(this.output),this._loop?this._source.start(e,i):this._source.start(e,i,s),this},t.Player.prototype._stop=function(t){return this._source&&(this._source.stop(this.toSeconds(t)),this._source=null),this},t.Player.prototype.setLoopPoints=function(t,e){return this.loopStart=t,this.loopEnd=e,this},Object.defineProperty(t.Player.prototype,"loopStart",{get:function(){return this._loopStart},set:function(t){this._loopStart=t,this._source&&(this._source.loopStart=this.toSeconds(t))}}),Object.defineProperty(t.Player.prototype,"loopEnd",{get:function(){return this._loopEnd},set:function(t){this._loopEnd=t,this._source&&(this._source.loopEnd=this.toSeconds(t))}}),Object.defineProperty(t.Player.prototype,"buffer",{get:function(){return this._buffer},set:function(t){this._buffer.set(t)}}),Object.defineProperty(t.Player.prototype,"loop",{get:function(){return this._loop},set:function(t){this._loop=t,this._source&&(this._source.loop=t)}}),Object.defineProperty(t.Player.prototype,"playbackRate",{get:function(){return this._playbackRate},set:function(t){this._playbackRate=t,this._source&&(this._source.playbackRate.value=t)}}),Object.defineProperty(t.Player.prototype,"reverse",{get:function(){return this._buffer.reverse},set:function(t){this._buffer.reverse=t}}),t.Player.prototype.dispose=function(){return t.Source.prototype.dispose.call(this)
|