@soundtouchjs/audio-worklet
Advanced tools
Comparing version 0.1.5 to 0.1.6
Changelog | ||
### 0.1.6 (2020-07-20) | ||
### 0.1.5 (2020-05-03) | ||
@@ -3,0 +5,0 @@ |
/* | ||
* SoundTouch Audio Worklet v0.1.5 AudioWorklet using the | ||
* SoundTouch Audio Worklet v0.1.6 AudioWorklet using the | ||
* SoundTouch audio processing library | ||
@@ -24,2 +24,506 @@ * | ||
*/ | ||
function e(e,t,n,i,r,a,o){try{var s=e[a](o),u=s.value}catch(e){return void n(e)}s.done?t(u):Promise.resolve(u).then(i,r)}function t(t){return function(){var n=this,i=arguments;return new Promise((function(r,a){var o=t.apply(n,i);function s(t){e(o,r,a,s,u,"next",t)}function u(t){e(o,r,a,s,u,"throw",t)}s(void 0)}))}}function n(e,t){for(var n=0;n<t.length;n++){var i=t[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}function i(e){return(i=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function r(e,t){return(r=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function a(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function o(e,t){return!t||"object"!=typeof t&&"function"!=typeof t?a(e):t}function s(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=i(e);if(t){var a=i(this).constructor;n=Reflect.construct(r,arguments,a)}else n=r.apply(this,arguments);return o(this,n)}}var u=function(e){var t,n,i,r=Math.floor(e/60),a=e-60*r;return"".concat(r,":").concat((t=parseInt(a),i=i||"0",(t+="").length>=(n=2)?t:new Array(n-t.length+1).join(i)+t))};export default function(e,i,o,f){return new(function(e){!function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&r(e,t)}(d,e);var i,o,f,c,h,l=s(d);function d(e,t,n){var i;return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,d),(i=l.call(this,e,"soundtouch-worklet",n))._arrayBuffer=t.slice(0),i.listeners=[],i.port.onmessage=i._messageProcessor.bind(a(i)),i.sourcePosition=0,i.timePlayed=0,i._startTime=0,i._pauseTime=0,i._playHead=0,i._playing=!1,i._ready=!1,i._initialPlay=!0,i}return i=d,(o=[{key:"connectToBuffer",value:function(){return this.bufferNode=this.context.createBufferSource(),this.bufferNode.buffer=this.audioBuffer,this.bufferNode.onended=function(){return console.log("song ended")},this.bufferNode.connect(this),this.bufferNode}},{key:"disconnectFromBuffer",value:function(){this.bufferNode.disconnect()}},{key:"handleAudioData",value:function(e){this.audioBuffer=e,this.port.postMessage({message:"INITIALIZE_PROCESSOR",detail:this.createBaseArray(e)})}},{key:"createBaseArray",value:function(e){return[{sampleRate:this.sampleRate,duration:this.duration,bufferLength:this.bufferLength,numberOfChannels:this.numberOfChannels},e.getChannelData(0),this.numberOfChannels>1?e.getChannelData(1):e.getChannelData(0)]}},{key:"play",value:(h=t(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.ready){e.next=2;break}throw new Error("Your processor is not ready yet");case 2:return this.playing&&this.stop(!0),this._initialPlay&&(0===this._playHead&&(this.percentagePlayed=0),this._initialPlay=!1),e.next=6,this.context.resume();case 6:this._startTime=(new Date).getTime(),this.playing=!0;case 8:case"end":return e.stop()}}),e,this)}))),function(){return h.apply(this,arguments)})},{key:"pause",value:function(){var e=this.currentTime;this.stop(),this.currentTime=e}},{key:"stop",value:(c=t(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.context.suspend();case 2:this.currentTime=0,this._startTime=(new Date).getTime(),this.playing=!1;case 5:case"end":return e.stop()}}),e,this)}))),function(){return c.apply(this,arguments)})},{key:"on",value:function(e,t){this.listeners.push({name:e,cb:t}),this.addEventListener(e,(function(e){return t(e.detail)}))}},{key:"off",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null,n=this.listeners;t&&(n=n.filter((function(e){return e.name===t}))),n.forEach((function(t){e.removeEventListener(t.name,(function(e){return t.cb(e.detail)}))}))}},{key:"onprocessorerror",value:function(e){throw e}},{key:"_updatePipeProp",value:function(e,t){this.port.postMessage({message:"SET_PIPE_PROP",detail:{name:e,value:t}})}},{key:"_updateFilterProp",value:function(e,t){this.port.postMessage({message:"SET_FILTER_PROP",detail:{name:e,value:t}})}},{key:"_messageProcessor",value:function(e){var t=this,n=e.data,i=n.message,r=n.detail,a=this.sampleRate,o=this.timePlayed;if("SOURCEPOSITION"===i){this.sourcePosition=r;var s=r/a;if(o!==s){this.timePlayed=s;var u=new CustomEvent("play",{detail:{timePlayed:this.timePlayed,formattedTimePlayed:this.formattedTimePlayed,percentagePlayed:this.percentagePlayed}});this.dispatchEvent(u)}}if("PROCESSOR_CONSTRUCTOR"!==i)if("PROCESSOR_READY"!==i)if("PROCESSOR_END"!==i);else{this.stop(),this.percentagePlayed=0;var f=new CustomEvent("end",{detail:{timePlayed:this.currentTime,formattedTimePlayed:this.formattedTimePlayed,percentagePlayed:this.percentagePlayed}});this.dispatchEvent(f)}else{if(this.ready=!0,"function"==typeof this.onInitialized)return void this.onInitialized(r);var c=new CustomEvent("initialized",r);this.dispatchEvent(c)}else this.context.decodeAudioData(this._arrayBuffer,(function(e){return t.handleAudioData(e)}),(function(e){return console.log("[decodeAudioData ERROR] ",e)}))}},{key:"formattedDuration",get:function(){return u(this.duration)}},{key:"formattedTimePlayed",get:function(){return u(this.timePlayed)}},{key:"percentagePlayed",get:function(){return 100*this.sourcePosition/(this.duration*this.sampleRate)},set:function(e){var t=this.duration,n=this.sampleRate;this.sourcePosition=parseInt(t*n*(e/100)),this._updateFilterProp("sourcePosition",this.sourcePosition),this.currentTime=this.duration*e/100}},{key:"currentTime",get:function(){return this.playing?this._playHead+(e=this._startTime,((new Date).getTime()-e)/1e3):this._playHead;var e},set:function(e){this._playHead=e}},{key:"playing",get:function(){return this._playing},set:function(e){this._playing=Boolean(e)}},{key:"ready",get:function(){return this._ready},set:function(e){this._ready=Boolean(e)}},{key:"sampleRate",get:function(){if(this.audioBuffer)return this.audioBuffer.sampleRate}},{key:"duration",get:function(){if(this.audioBuffer)return this.audioBuffer.duration}},{key:"bufferLength",get:function(){if(this.audioBuffer)return this.audioBuffer.length}},{key:"numberOfChannels",get:function(){if(this.audioBuffer)return this.audioBuffer.numberOfChannels}},{key:"pitch",set:function(e){this._updatePipeProp("pitch",e)}},{key:"pitchSemitones",set:function(e){this._updatePipeProp("pitchSemitones",e)}},{key:"rate",set:function(e){this._updatePipeProp("rate",e)}},{key:"tempo",set:function(e){this._updatePipeProp("tempo",e)}}])&&n(i.prototype,o),f&&n(i,f),d}(i))(e,o,f)} | ||
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { | ||
try { | ||
var info = gen[key](arg); | ||
var value = info.value; | ||
} catch (error) { | ||
reject(error); | ||
return; | ||
} | ||
if (info.done) { | ||
resolve(value); | ||
} else { | ||
Promise.resolve(value).then(_next, _throw); | ||
} | ||
} | ||
function _asyncToGenerator(fn) { | ||
return function () { | ||
var self = this, | ||
args = arguments; | ||
return new Promise(function (resolve, reject) { | ||
var gen = fn.apply(self, args); | ||
function _next(value) { | ||
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); | ||
} | ||
function _throw(err) { | ||
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); | ||
} | ||
_next(undefined); | ||
}); | ||
}; | ||
} | ||
function _classCallCheck(instance, Constructor) { | ||
if (!(instance instanceof Constructor)) { | ||
throw new TypeError("Cannot call a class as a function"); | ||
} | ||
} | ||
function _defineProperties(target, props) { | ||
for (var i = 0; i < props.length; i++) { | ||
var descriptor = props[i]; | ||
descriptor.enumerable = descriptor.enumerable || false; | ||
descriptor.configurable = true; | ||
if ("value" in descriptor) descriptor.writable = true; | ||
Object.defineProperty(target, descriptor.key, descriptor); | ||
} | ||
} | ||
function _createClass(Constructor, protoProps, staticProps) { | ||
if (protoProps) _defineProperties(Constructor.prototype, protoProps); | ||
if (staticProps) _defineProperties(Constructor, staticProps); | ||
return Constructor; | ||
} | ||
function _inherits(subClass, superClass) { | ||
if (typeof superClass !== "function" && superClass !== null) { | ||
throw new TypeError("Super expression must either be null or a function"); | ||
} | ||
subClass.prototype = Object.create(superClass && superClass.prototype, { | ||
constructor: { | ||
value: subClass, | ||
writable: true, | ||
configurable: true | ||
} | ||
}); | ||
if (superClass) _setPrototypeOf(subClass, superClass); | ||
} | ||
function _getPrototypeOf(o) { | ||
_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { | ||
return o.__proto__ || Object.getPrototypeOf(o); | ||
}; | ||
return _getPrototypeOf(o); | ||
} | ||
function _setPrototypeOf(o, p) { | ||
_setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { | ||
o.__proto__ = p; | ||
return o; | ||
}; | ||
return _setPrototypeOf(o, p); | ||
} | ||
function _isNativeReflectConstruct() { | ||
if (typeof Reflect === "undefined" || !Reflect.construct) return false; | ||
if (Reflect.construct.sham) return false; | ||
if (typeof Proxy === "function") return true; | ||
try { | ||
Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); | ||
return true; | ||
} catch (e) { | ||
return false; | ||
} | ||
} | ||
function _assertThisInitialized(self) { | ||
if (self === void 0) { | ||
throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); | ||
} | ||
return self; | ||
} | ||
function _possibleConstructorReturn(self, call) { | ||
if (call && (typeof call === "object" || typeof call === "function")) { | ||
return call; | ||
} | ||
return _assertThisInitialized(self); | ||
} | ||
function _createSuper(Derived) { | ||
var hasNativeReflectConstruct = _isNativeReflectConstruct(); | ||
return function _createSuperInternal() { | ||
var Super = _getPrototypeOf(Derived), | ||
result; | ||
if (hasNativeReflectConstruct) { | ||
var NewTarget = _getPrototypeOf(this).constructor; | ||
result = Reflect.construct(Super, arguments, NewTarget); | ||
} else { | ||
result = Super.apply(this, arguments); | ||
} | ||
return _possibleConstructorReturn(this, result); | ||
}; | ||
} | ||
var pad = function pad(n, width, z) { | ||
z = z || '0'; | ||
n = n + ''; | ||
return n.length >= width ? n : new Array(width - n.length + 1).join(z) + n; | ||
}; | ||
var minsSecs = function minsSecs(secs) { | ||
var mins = Math.floor(secs / 60); | ||
var seconds = secs - mins * 60; | ||
return "".concat(mins, ":").concat(pad(parseInt(seconds), 2)); | ||
}; | ||
var diffSecs = function diffSecs(ms1, ms2) { | ||
return (ms2 - ms1) / 1000; | ||
}; | ||
var createSoundTouchNode = function createSoundTouchNode(audioCtx, AudioWorkletNode, arrayBuffer, options) { | ||
var SoundTouchNode = function (_AudioWorkletNode) { | ||
_inherits(SoundTouchNode, _AudioWorkletNode); | ||
var _super = _createSuper(SoundTouchNode); | ||
function SoundTouchNode(context, arrayBuffer, options) { | ||
var _this; | ||
_classCallCheck(this, SoundTouchNode); | ||
_this = _super.call(this, context, 'soundtouch-worklet', options); | ||
_this._arrayBuffer = arrayBuffer.slice(0); | ||
_this.listeners = []; | ||
_this.port.onmessage = _this._messageProcessor.bind(_assertThisInitialized(_this)); | ||
_this.sourcePosition = 0; | ||
_this.timePlayed = 0; | ||
_this._startTime = 0; | ||
_this._pauseTime = 0; | ||
_this._playHead = 0; | ||
_this._playing = false; | ||
_this._ready = false; | ||
_this._initialPlay = true; | ||
return _this; | ||
} | ||
_createClass(SoundTouchNode, [{ | ||
key: "connectToBuffer", | ||
value: function connectToBuffer() { | ||
this.bufferNode = this.context.createBufferSource(); | ||
this.bufferNode.buffer = this.audioBuffer; | ||
this.bufferNode.onended = function () { | ||
return console.log('song ended'); | ||
}; | ||
this.bufferNode.connect(this); | ||
return this.bufferNode; | ||
} | ||
}, { | ||
key: "disconnectFromBuffer", | ||
value: function disconnectFromBuffer() { | ||
this.bufferNode.disconnect(); | ||
} | ||
}, { | ||
key: "handleAudioData", | ||
value: function handleAudioData(audioBuffer) { | ||
this.audioBuffer = audioBuffer; | ||
this.port.postMessage({ | ||
message: 'INITIALIZE_PROCESSOR', | ||
detail: this.createBaseArray(audioBuffer) | ||
}); | ||
} | ||
}, { | ||
key: "createBaseArray", | ||
value: function createBaseArray(audioBuffer) { | ||
return [{ | ||
sampleRate: this.sampleRate, | ||
duration: this.duration, | ||
bufferLength: this.bufferLength, | ||
numberOfChannels: this.numberOfChannels | ||
}, audioBuffer.getChannelData(0), this.numberOfChannels > 1 ? audioBuffer.getChannelData(1) : audioBuffer.getChannelData(0)]; | ||
} | ||
}, { | ||
key: "play", | ||
value: function () { | ||
var _play = _asyncToGenerator( regeneratorRuntime.mark(function _callee() { | ||
return regeneratorRuntime.wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
if (this.ready) { | ||
_context.next = 2; | ||
break; | ||
} | ||
throw new Error('Your processor is not ready yet'); | ||
case 2: | ||
if (this.playing) { | ||
this.stop(true); | ||
} | ||
if (this._initialPlay) { | ||
if (this._playHead === 0) { | ||
this.percentagePlayed = 0; | ||
} | ||
this._initialPlay = false; | ||
} | ||
_context.next = 6; | ||
return this.context.resume(); | ||
case 6: | ||
this._startTime = new Date().getTime(); | ||
this.playing = true; | ||
case 8: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
} | ||
}, _callee, this); | ||
})); | ||
function play() { | ||
return _play.apply(this, arguments); | ||
} | ||
return play; | ||
}() | ||
}, { | ||
key: "pause", | ||
value: function pause() { | ||
var currTime = this.currentTime; | ||
this.stop(); | ||
this.currentTime = currTime; | ||
} | ||
}, { | ||
key: "stop", | ||
value: function () { | ||
var _stop = _asyncToGenerator( regeneratorRuntime.mark(function _callee2() { | ||
return regeneratorRuntime.wrap(function _callee2$(_context2) { | ||
while (1) { | ||
switch (_context2.prev = _context2.next) { | ||
case 0: | ||
_context2.next = 2; | ||
return this.context.suspend(); | ||
case 2: | ||
this.currentTime = 0; | ||
this._startTime = new Date().getTime(); | ||
this.playing = false; | ||
case 5: | ||
case "end": | ||
return _context2.stop(); | ||
} | ||
} | ||
}, _callee2, this); | ||
})); | ||
function stop() { | ||
return _stop.apply(this, arguments); | ||
} | ||
return stop; | ||
}() | ||
}, { | ||
key: "on", | ||
value: function on(eventName, cb) { | ||
this.listeners.push({ | ||
name: eventName, | ||
cb: cb | ||
}); | ||
this.addEventListener(eventName, function (event) { | ||
return cb(event.detail); | ||
}); | ||
} | ||
}, { | ||
key: "off", | ||
value: function off() { | ||
var _this2 = this; | ||
var eventName = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null; | ||
var listeners = this.listeners; | ||
if (eventName) { | ||
listeners = listeners.filter(function (e) { | ||
return e.name === eventName; | ||
}); | ||
} | ||
listeners.forEach(function (e) { | ||
_this2.removeEventListener(e.name, function (event) { | ||
return e.cb(event.detail); | ||
}); | ||
}); | ||
} | ||
}, { | ||
key: "onprocessorerror", | ||
value: function onprocessorerror(err) { | ||
throw err; | ||
} | ||
}, { | ||
key: "_updatePipeProp", | ||
value: function _updatePipeProp(name, value) { | ||
this.port.postMessage({ | ||
message: 'SET_PIPE_PROP', | ||
detail: { | ||
name: name, | ||
value: value | ||
} | ||
}); | ||
} | ||
}, { | ||
key: "_updateFilterProp", | ||
value: function _updateFilterProp(name, value) { | ||
this.port.postMessage({ | ||
message: 'SET_FILTER_PROP', | ||
detail: { | ||
name: name, | ||
value: value | ||
} | ||
}); | ||
} | ||
}, { | ||
key: "_messageProcessor", | ||
value: function _messageProcessor(eventFromWorker) { | ||
var _this3 = this; | ||
var _eventFromWorker$data = eventFromWorker.data, | ||
message = _eventFromWorker$data.message, | ||
detail = _eventFromWorker$data.detail; | ||
var sampleRate = this.sampleRate, | ||
currentTime = this.timePlayed; | ||
if (message === 'SOURCEPOSITION') { | ||
this.sourcePosition = detail; | ||
var timePlayed = detail / sampleRate; | ||
if (currentTime !== timePlayed) { | ||
this.timePlayed = timePlayed; | ||
var timeEvent = new CustomEvent('play', { | ||
detail: { | ||
timePlayed: this.timePlayed, | ||
formattedTimePlayed: this.formattedTimePlayed, | ||
percentagePlayed: this.percentagePlayed | ||
} | ||
}); | ||
this.dispatchEvent(timeEvent); | ||
} | ||
} | ||
if (message === 'PROCESSOR_CONSTRUCTOR') { | ||
this.context.decodeAudioData(this._arrayBuffer, function (audioData) { | ||
return _this3.handleAudioData(audioData); | ||
}, function (err) { | ||
return console.log('[decodeAudioData ERROR] ', err); | ||
}); | ||
return; | ||
} | ||
if (message === 'PROCESSOR_READY') { | ||
this.ready = true; | ||
if (typeof this.onInitialized === 'function') { | ||
this.onInitialized(detail); | ||
return; | ||
} | ||
var init = new CustomEvent('initialized', detail); | ||
this.dispatchEvent(init); | ||
return; | ||
} | ||
if (message === 'PROCESSOR_END') { | ||
this.stop(); | ||
this.percentagePlayed = 0; | ||
var endOfPlay = new CustomEvent('end', { | ||
detail: { | ||
timePlayed: this.currentTime, | ||
formattedTimePlayed: this.formattedTimePlayed, | ||
percentagePlayed: this.percentagePlayed | ||
} | ||
}); | ||
this.dispatchEvent(endOfPlay); | ||
return; | ||
} | ||
} | ||
}, { | ||
key: "formattedDuration", | ||
get: function get() { | ||
return minsSecs(this.duration); | ||
} | ||
}, { | ||
key: "formattedTimePlayed", | ||
get: function get() { | ||
return minsSecs(this.timePlayed); | ||
} | ||
}, { | ||
key: "percentagePlayed", | ||
get: function get() { | ||
return 100 * this.sourcePosition / (this.duration * this.sampleRate); | ||
} | ||
, | ||
set: function set(percentage) { | ||
var duration = this.duration, | ||
sampleRate = this.sampleRate; | ||
this.sourcePosition = parseInt(duration * sampleRate * (percentage / 100)); | ||
this._updateFilterProp('sourcePosition', this.sourcePosition); | ||
this.currentTime = this.duration * percentage / 100; | ||
} | ||
}, { | ||
key: "currentTime", | ||
get: function get() { | ||
if (!this.playing) { | ||
return this._playHead; | ||
} | ||
return this._playHead + diffSecs(this._startTime, new Date().getTime()); | ||
} | ||
, | ||
set: function set(val) { | ||
this._playHead = val; | ||
} | ||
}, { | ||
key: "playing", | ||
get: function get() { | ||
return this._playing; | ||
} | ||
, | ||
set: function set(val) { | ||
this._playing = Boolean(val); | ||
} | ||
}, { | ||
key: "ready", | ||
get: function get() { | ||
return this._ready; | ||
} | ||
, | ||
set: function set(val) { | ||
this._ready = Boolean(val); | ||
} | ||
}, { | ||
key: "sampleRate", | ||
get: function get() { | ||
if (this.audioBuffer) { | ||
return this.audioBuffer.sampleRate; | ||
} | ||
return undefined; | ||
} | ||
}, { | ||
key: "duration", | ||
get: function get() { | ||
if (this.audioBuffer) { | ||
return this.audioBuffer.duration; | ||
} | ||
return undefined; | ||
} | ||
}, { | ||
key: "bufferLength", | ||
get: function get() { | ||
if (this.audioBuffer) { | ||
return this.audioBuffer.length; | ||
} | ||
return undefined; | ||
} | ||
}, { | ||
key: "numberOfChannels", | ||
get: function get() { | ||
if (this.audioBuffer) { | ||
return this.audioBuffer.numberOfChannels; | ||
} | ||
return undefined; | ||
} | ||
}, { | ||
key: "pitch", | ||
set: function set(pitch) { | ||
this._updatePipeProp('pitch', pitch); | ||
} | ||
}, { | ||
key: "pitchSemitones", | ||
set: function set(semitone) { | ||
this._updatePipeProp('pitchSemitones', semitone); | ||
} | ||
}, { | ||
key: "rate", | ||
set: function set(rate) { | ||
this._updatePipeProp('rate', rate); | ||
} | ||
}, { | ||
key: "tempo", | ||
set: function set(tempo) { | ||
this._updatePipeProp('tempo', tempo); | ||
} | ||
}]); | ||
return SoundTouchNode; | ||
}(AudioWorkletNode); | ||
return new SoundTouchNode(audioCtx, arrayBuffer, options); | ||
}; | ||
export default createSoundTouchNode; | ||
//# sourceMappingURL=soundtouch-audio-node.js.map |
/* | ||
* SoundTouch Audio Worklet v0.1.5 AudioWorklet using the | ||
* SoundTouch Audio Worklet v0.1.6 AudioWorklet using the | ||
* SoundTouch audio processing library | ||
@@ -24,2 +24,1848 @@ * | ||
*/ | ||
"use strict";function t(e){return(t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(e)}function e(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function r(t,e){for(var r=0;r<e.length;r++){var i=e[r];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}function i(t,e,i){return e&&r(t.prototype,e),i&&r(t,i),t}function n(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&s(t,e)}function o(t){return(o=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function s(t,e){return(s=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function u(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(t){return!1}}function a(t,e,r){return(a=u()?Reflect.construct:function(t,e,r){var i=[null];i.push.apply(i,e);var n=new(Function.bind.apply(t,i));return r&&s(n,r.prototype),n}).apply(null,arguments)}function h(t){var e="function"==typeof Map?new Map:void 0;return(h=function(t){if(null===t||(r=t,-1===Function.toString.call(r).indexOf("[native code]")))return t;var r;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==e){if(e.has(t))return e.get(t);e.set(t,i)}function i(){return a(t,arguments,o(this).constructor)}return i.prototype=Object.create(t.prototype,{constructor:{value:i,enumerable:!1,writable:!0,configurable:!0}}),s(i,t)})(t)}function f(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}function c(t,e){return!e||"object"!=typeof e&&"function"!=typeof e?f(t):e}function l(t){var e=u();return function(){var r,i=o(t);if(e){var n=o(this).constructor;r=Reflect.construct(i,arguments,n)}else r=i.apply(this,arguments);return c(this,r)}}function p(t,e,r){return(p="undefined"!=typeof Reflect&&Reflect.get?Reflect.get:function(t,e,r){var i=function(t,e){for(;!Object.prototype.hasOwnProperty.call(t,e)&&null!==(t=o(t)););return t}(t,e);if(i){var n=Object.getOwnPropertyDescriptor(i,e);return n.get?n.get.call(r):n.value}})(t,e,r||t)}function v(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){if("undefined"==typeof Symbol||!(Symbol.iterator in Object(t)))return;var r=[],i=!0,n=!1,o=void 0;try{for(var s,u=t[Symbol.iterator]();!(i=(s=u.next()).done)&&(r.push(s.value),!e||r.length!==e);i=!0);}catch(t){n=!0,o=t}finally{try{i||null==u.return||u.return()}finally{if(n)throw o}}return r}(t,e)||function(t,e){if(!t)return;if("string"==typeof t)return y(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);"Object"===r&&t.constructor&&(r=t.constructor.name);if("Map"===r||"Set"===r)return Array.from(t);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return y(t,e)}(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function y(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,i=new Array(e);r<e;r++)i[r]=t[r];return i}var d=function(e){var r=Object.prototype,i=r.hasOwnProperty,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",s=n.asyncIterator||"@@asyncIterator",u=n.toStringTag||"@@toStringTag";function a(t,e,r,i){var n=e&&e.prototype instanceof c?e:c,o=Object.create(n.prototype),s=new S(i||[]);return o._invoke=function(t,e,r){var i="suspendedStart";return function(n,o){if("executing"===i)throw new Error("Generator is already running");if("completed"===i){if("throw"===n)throw o;return b()}for(r.method=n,r.arg=o;;){var s=r.delegate;if(s){var u=k(s,r);if(u){if(u===f)continue;return u}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if("suspendedStart"===i)throw i="completed",r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);i="executing";var a=h(t,e,r);if("normal"===a.type){if(i=r.done?"completed":"suspendedYield",a.arg===f)continue;return{value:a.arg,done:r.done}}"throw"===a.type&&(i="completed",r.method="throw",r.arg=a.arg)}}}(t,r,s),o}function h(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}e.wrap=a;var f={};function c(){}function l(){}function p(){}var v={};v[o]=function(){return this};var y=Object.getPrototypeOf,d=y&&y(y(P([])));d&&d!==r&&i.call(d,o)&&(v=d);var m=p.prototype=c.prototype=Object.create(v);function g(t){["next","throw","return"].forEach((function(e){t[e]=function(t){return this._invoke(e,t)}}))}function _(e,r){var n;this._invoke=function(o,s){function u(){return new r((function(n,u){!function n(o,s,u,a){var f=h(e[o],e,s);if("throw"!==f.type){var c=f.arg,l=c.value;return l&&"object"===t(l)&&i.call(l,"__await")?r.resolve(l.__await).then((function(t){n("next",t,u,a)}),(function(t){n("throw",t,u,a)})):r.resolve(l).then((function(t){c.value=t,u(c)}),(function(t){return n("throw",t,u,a)}))}a(f.arg)}(o,s,n,u)}))}return n=n?n.then(u,u):u()}}function k(t,e){var r=t.iterator[e.method];if(void 0===r){if(e.delegate=null,"throw"===e.method){if(t.iterator.return&&(e.method="return",e.arg=void 0,k(t,e),"throw"===e.method))return f;e.method="throw",e.arg=new TypeError("The iterator does not provide a 'throw' method")}return f}var i=h(r,t.iterator,e.arg);if("throw"===i.type)return e.method="throw",e.arg=i.arg,e.delegate=null,f;var n=i.arg;return n?n.done?(e[t.resultName]=n.value,e.next=t.nextLoc,"return"!==e.method&&(e.method="next",e.arg=void 0),e.delegate=null,f):n:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,f)}function B(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function w(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function S(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(B,this),this.reset(!0)}function P(t){if(t){var e=t[o];if(e)return e.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var r=-1,n=function e(){for(;++r<t.length;)if(i.call(t,r))return e.value=t[r],e.done=!1,e;return e.value=void 0,e.done=!0,e};return n.next=n}}return{next:b}}function b(){return{value:void 0,done:!0}}return l.prototype=m.constructor=p,p.constructor=l,p[u]=l.displayName="GeneratorFunction",e.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===l||"GeneratorFunction"===(e.displayName||e.name))},e.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,p):(t.__proto__=p,u in t||(t[u]="GeneratorFunction")),t.prototype=Object.create(m),t},e.awrap=function(t){return{__await:t}},g(_.prototype),_.prototype[s]=function(){return this},e.AsyncIterator=_,e.async=function(t,r,i,n,o){void 0===o&&(o=Promise);var s=new _(a(t,r,i,n),o);return e.isGeneratorFunction(r)?s:s.next().then((function(t){return t.done?t.value:s.next()}))},g(m),m[u]="Generator",m[o]=function(){return this},m.toString=function(){return"[object Generator]"},e.keys=function(t){var e=[];for(var r in t)e.push(r);return e.reverse(),function r(){for(;e.length;){var i=e.pop();if(i in t)return r.value=i,r.done=!1,r}return r.done=!0,r}},e.values=P,S.prototype={constructor:S,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(w),!t)for(var e in this)"t"===e.charAt(0)&&i.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=void 0)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var e=this;function r(r,i){return s.type="throw",s.arg=t,e.next=r,i&&(e.method="next",e.arg=void 0),!!i}for(var n=this.tryEntries.length-1;n>=0;--n){var o=this.tryEntries[n],s=o.completion;if("root"===o.tryLoc)return r("end");if(o.tryLoc<=this.prev){var u=i.call(o,"catchLoc"),a=i.call(o,"finallyLoc");if(u&&a){if(this.prev<o.catchLoc)return r(o.catchLoc,!0);if(this.prev<o.finallyLoc)return r(o.finallyLoc)}else if(u){if(this.prev<o.catchLoc)return r(o.catchLoc,!0)}else{if(!a)throw new Error("try statement without catch or finally");if(this.prev<o.finallyLoc)return r(o.finallyLoc)}}}},abrupt:function(t,e){for(var r=this.tryEntries.length-1;r>=0;--r){var n=this.tryEntries[r];if(n.tryLoc<=this.prev&&i.call(n,"finallyLoc")&&this.prev<n.finallyLoc){var o=n;break}}o&&("break"===t||"continue"===t)&&o.tryLoc<=e&&e<=o.finallyLoc&&(o=null);var s=o?o.completion:{};return s.type=t,s.arg=e,o?(this.method="next",this.next=o.finallyLoc,f):this.complete(s)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),f},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),w(r),f}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var i=r.completion;if("throw"===i.type){var n=i.arg;w(r)}return n}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,r){return this.delegate={iterator:P(t),resultName:e,nextLoc:r},"next"===this.method&&(this.arg=void 0),f}},e}("object"===("undefined"==typeof module?"undefined":t(module))?module.exports:{});try{regeneratorRuntime=d}catch(t){Function("r","regeneratorRuntime = r")(d)}var m=function(){function t(){e(this,t),this._vector=new Float32Array,this._position=0,this._frameCount=0}return i(t,[{key:"clear",value:function(){this.receive(this._frameCount),this.rewind()}},{key:"put",value:function(t){this._frameCount+=t}},{key:"putSamples",value:function(t,e){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,i=2*(e=e||0);r>=0||(r=(t.length-i)/2);var n=2*r;this.ensureCapacity(r+this._frameCount);var o=this.endIndex;this.vector.set(t.subarray(i,i+n),o),this._frameCount+=r}},{key:"putBuffer",value:function(t,e){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0;e=e||0,r>=0||(r=t.frameCount-e),this.putSamples(t.vector,t.position+e,r)}},{key:"receive",value:function(t){t>=0&&!(t>this._frameCount)||(t=this.frameCount),this._frameCount-=t,this._position+=t}},{key:"receiveSamples",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,r=2*e,i=this.startIndex;t.set(this._vector.subarray(i,i+r)),this.receive(e)}},{key:"extract",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,i=this.startIndex+2*e,n=2*r;t.set(this._vector.subarray(i,i+n))}},{key:"ensureCapacity",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,e=parseInt(2*t);if(this._vector.length<e){var r=new Float32Array(e);r.set(this._vector.subarray(this.startIndex,this.endIndex)),this._vector=r,this._position=0}else this.rewind()}},{key:"ensureAdditionalCapacity",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0;this.ensureCapacity(this._frameCount+t)}},{key:"rewind",value:function(){this._position>0&&(this._vector.set(this._vector.subarray(this.startIndex,this.endIndex)),this._position=0)}},{key:"vector",get:function(){return this._vector}},{key:"position",get:function(){return this._position}},{key:"startIndex",get:function(){return 2*this._position}},{key:"frameCount",get:function(){return this._frameCount}},{key:"endIndex",get:function(){return 2*(this._position+this._frameCount)}}]),t}(),g=function(){function t(r){e(this,t),r?(this._inputBuffer=new m,this._outputBuffer=new m):this._inputBuffer=this._outputBuffer=null}return i(t,[{key:"clear",value:function(){this._inputBuffer.clear(),this._outputBuffer.clear()}},{key:"inputBuffer",get:function(){return this._inputBuffer},set:function(t){this._inputBuffer=t}},{key:"outputBuffer",get:function(){return this._outputBuffer},set:function(t){this._outputBuffer=t}}]),t}(),_=function(t){n(o,g);var r=l(o);function o(t){var i;return e(this,o),(i=r.call(this,t)).reset(),i._rate=1,i}return i(o,[{key:"reset",value:function(){this.slopeCount=0,this.prevSampleL=0,this.prevSampleR=0}},{key:"clone",value:function(){var t=new o;return t.rate=this._rate,t}},{key:"process",value:function(){var t=this._inputBuffer.frameCount;this._outputBuffer.ensureAdditionalCapacity(t/this._rate+1);var e=this.transpose(t);this._inputBuffer.receive(),this._outputBuffer.put(e)}},{key:"transpose",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0;if(0===t)return 0;for(var e=this._inputBuffer.vector,r=this._inputBuffer.startIndex,i=this._outputBuffer.vector,n=this._outputBuffer.endIndex,o=0,s=0;this.slopeCount<1;)i[n+2*s]=(1-this.slopeCount)*this.prevSampleL+this.slopeCount*e[r],i[n+2*s+1]=(1-this.slopeCount)*this.prevSampleR+this.slopeCount*e[r+1],s+=1,this.slopeCount+=this._rate;if(this.slopeCount-=1,1!==t)t:for(;;){for(;this.slopeCount>1;)if(this.slopeCount-=1,(o+=1)>=t-1)break t;var u=r+2*o;i[n+2*s]=(1-this.slopeCount)*e[u]+this.slopeCount*e[u+2],i[n+2*s+1]=(1-this.slopeCount)*e[u+1]+this.slopeCount*e[u+3],s+=1,this.slopeCount+=this._rate}return this.prevSampleL=e[r+2*t-2],this.prevSampleR=e[r+2*t-1],s}},{key:"rate",set:function(t){this._rate=t}}]),o}(),k=function(){function t(r){e(this,t),this._pipe=r}return i(t,[{key:"fillInputBuffer",value:function(){throw new Error("fillInputBuffer() not overridden")}},{key:"fillOutputBuffer",value:function(){for(var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0;this.outputBuffer.frameCount<t;){var e=16384-this.inputBuffer.frameCount;if(this.fillInputBuffer(e),this.inputBuffer.frameCount<16384)break;this._pipe.process()}}},{key:"clear",value:function(){this._pipe.clear()}},{key:"pipe",get:function(){return this._pipe}},{key:"inputBuffer",get:function(){return this._pipe.inputBuffer}},{key:"outputBuffer",get:function(){return this._pipe.outputBuffer}}]),t}(),B=function(){},w=function(t){n(s,k);var r=l(s);function s(t,i){var n,o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:B;return e(this,s),(n=r.call(this,i)).callback=o,n.sourceSound=t,n.historyBufferSize=22050,n._sourcePosition=0,n.outputBufferPosition=0,n._position=0,n}return i(s,[{key:"onEnd",value:function(){this.callback()}},{key:"fillInputBuffer",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,e=new Float32Array(2*t),r=this.sourceSound.extract(e,t,this._sourcePosition);this._sourcePosition+=r,this.inputBuffer.putSamples(e,0,r)}},{key:"extract",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;this.fillOutputBuffer(this.outputBufferPosition+e);var r=Math.min(e,this.outputBuffer.frameCount-this.outputBufferPosition);this.outputBuffer.extract(t,this.outputBufferPosition,r);var i=this.outputBufferPosition+r;return this.outputBufferPosition=Math.min(this.historyBufferSize,i),this.outputBuffer.receive(Math.max(i-this.historyBufferSize,0)),this._position+=r,r}},{key:"handleSampleData",value:function(t){this.extract(t.data,4096)}},{key:"clear",value:function(){p(o(s.prototype),"clear",this).call(this),this.outputBufferPosition=0}},{key:"position",get:function(){return this._position},set:function(t){if(t>this._position)throw new RangeError("New position may not be greater than current position");var e=this.outputBufferPosition-(this._position-t);if(e<0)throw new RangeError("New position falls outside of history buffer");this.outputBufferPosition=e,this._position=t}},{key:"sourcePosition",get:function(){return this._sourcePosition},set:function(t){this.clear(),this._sourcePosition=t}}]),s}(),S=[[124,186,248,310,372,434,496,558,620,682,744,806,868,930,992,1054,1116,1178,1240,1302,1364,1426,1488,0],[-100,-75,-50,-25,25,50,75,100,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[-20,-15,-10,-5,5,10,15,20,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[-4,-3,-2,-1,1,2,3,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]],P=function(t){n(s,g);var r=l(s);function s(t){var i;return e(this,s),(i=r.call(this,t))._quickSeek=!0,i.midBufferDirty=!1,i.midBuffer=null,i.overlapLength=0,i.autoSeqSetting=!0,i.autoSeekSetting=!0,i._tempo=1,i.setParameters(44100,0,0,8),i}return i(s,[{key:"clear",value:function(){p(o(s.prototype),"clear",this).call(this),this.clearMidBuffer()}},{key:"clearMidBuffer",value:function(){this.midBufferDirty&&(this.midBufferDirty=!1,this.midBuffer=null)}},{key:"setParameters",value:function(t,e,r,i){t>0&&(this.sampleRate=t),i>0&&(this.overlapMs=i),e>0?(this.sequenceMs=e,this.autoSeqSetting=!1):this.autoSeqSetting=!0,r>0?(this.seekWindowMs=r,this.autoSeekSetting=!1):this.autoSeekSetting=!0,this.calculateSequenceParameters(),this.calculateOverlapLength(this.overlapMs),this.tempo=this._tempo}},{key:"calculateOverlapLength",value:function(){var t,e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0;t=(t=this.sampleRate*e/1e3)<16?16:t,t-=t%8,this.overlapLength=t,this.refMidBuffer=new Float32Array(2*this.overlapLength),this.midBuffer=new Float32Array(2*this.overlapLength)}},{key:"checkLimits",value:function(t,e,r){return t<e?e:t>r?r:t}},{key:"calculateSequenceParameters",value:function(){var t,e;this.autoSeqSetting&&(t=150+-50*this._tempo,t=this.checkLimits(t,50,125),this.sequenceMs=Math.floor(t+.5)),this.autoSeekSetting&&(e=25- -10/1.5*.5+-10/1.5*this._tempo,e=this.checkLimits(e,15,25),this.seekWindowMs=Math.floor(e+.5)),this.seekWindowLength=Math.floor(this.sampleRate*this.sequenceMs/1e3),this.seekLength=Math.floor(this.sampleRate*this.seekWindowMs/1e3)}},{key:"clone",value:function(){var t=new s;return t.tempo=this._tempo,t.setParameters(this.sampleRate,this.sequenceMs,this.seekWindowMs,this.overlapMs),t}},{key:"seekBestOverlapPosition",value:function(){return this._quickSeek?this.seekBestOverlapPositionStereoQuick():this.seekBestOverlapPositionStereo()}},{key:"seekBestOverlapPositionStereo",value:function(){var t,e,r,i=0;for(this.preCalculateCorrelationReferenceStereo(),t=0,e=Number.MIN_VALUE;i<this.seekLength;i+=1)(r=this.calculateCrossCorrelationStereo(2*i,this.refMidBuffer))>e&&(e=r,t=i);return t}},{key:"seekBestOverlapPositionStereoQuick",value:function(){var t,e,r,i,n,o=0;for(this.preCalculateCorrelationReferenceStereo(),e=Number.MIN_VALUE,t=0,i=0,n=0;o<4;o+=1){for(var s=0;S[o][s]&&!((n=i+S[o][s])>=this.seekLength);)(r=this.calculateCrossCorrelationStereo(2*n,this.refMidBuffer))>e&&(e=r,t=n),s+=1;i=t}return t}},{key:"preCalculateCorrelationReferenceStereo",value:function(){for(var t,e,r=0;r<this.overlapLength;r+=1)e=r*(this.overlapLength-r),t=2*r,this.refMidBuffer[t]=this.midBuffer[t]*e,this.refMidBuffer[t+1]=this.midBuffer[t+1]*e}},{key:"calculateCrossCorrelationStereo",value:function(t,e){var r=this._inputBuffer.vector;t+=this._inputBuffer.startIndex;for(var i,n=0,o=2,s=2*this.overlapLength;o<s;o+=2)n+=r[i=o+t]*e[o]+r[i+1]*e[o+1];return n}},{key:"overlap",value:function(t){this.overlapStereo(2*t)}},{key:"overlapStereo",value:function(t){var e=this._inputBuffer.vector;t+=this._inputBuffer.startIndex;for(var r,i,n,o,s,u=this._outputBuffer.vector,a=this._outputBuffer.endIndex,h=0,f=1/this.overlapLength;h<this.overlapLength;h+=1)i=(this.overlapLength-h)*f,n=h*f,o=(r=2*h)+t,u[(s=r+a)+0]=e[o+0]*n+this.midBuffer[r+0]*i,u[s+1]=e[o+1]*n+this.midBuffer[r+1]*i}},{key:"process",value:function(){var t,e,r;if(null===this.midBuffer){if(this._inputBuffer.frameCount<this.overlapLength)return;this.midBuffer=new Float32Array(2*this.overlapLength),this._inputBuffer.receiveSamples(this.midBuffer,this.overlapLength)}for(;this._inputBuffer.frameCount>=this.sampleReq;){t=this.seekBestOverlapPosition(),this._outputBuffer.ensureAdditionalCapacity(this.overlapLength),this.overlap(Math.floor(t)),this._outputBuffer.put(this.overlapLength),(e=this.seekWindowLength-2*this.overlapLength)>0&&this._outputBuffer.putBuffer(this._inputBuffer,t+this.overlapLength,e);var i=this._inputBuffer.startIndex+2*(t+this.seekWindowLength-this.overlapLength);this.midBuffer.set(this._inputBuffer.vector.subarray(i,i+2*this.overlapLength)),this.skipFract+=this.nominalSkip,r=Math.floor(this.skipFract),this.skipFract-=r,this._inputBuffer.receive(r)}}},{key:"tempo",set:function(t){var e;this._tempo=t,this.calculateSequenceParameters(),this.nominalSkip=this._tempo*(this.seekWindowLength-this.overlapLength),this.skipFract=0,e=Math.floor(this.nominalSkip+.5),this.sampleReq=Math.max(e+this.overlapLength,this.seekWindowLength)+this.seekLength},get:function(){return this._tempo}},{key:"inputChunkSize",get:function(){return this.sampleReq}},{key:"outputChunkSize",get:function(){return this.overlapLength+Math.max(0,this.seekWindowLength-2*this.overlapLength)}},{key:"quickSeek",set:function(t){this._quickSeek=t}}]),s}(),b=function(t,e){return(t>e?t-e:e-t)>1e-10},C=function(){function t(){e(this,t),this.transposer=new _(!1),this.stretch=new P(!1),this._inputBuffer=new m,this._intermediateBuffer=new m,this._outputBuffer=new m,this._rate=0,this._tempo=0,this.virtualPitch=1,this.virtualRate=1,this.virtualTempo=1,this.calculateEffectiveRateAndTempo()}return i(t,[{key:"clear",value:function(){this.transposer.clear(),this.stretch.clear()}},{key:"clone",value:function(){var e=new t;return e.rate=this.rate,e.tempo=this.tempo,e}},{key:"calculateEffectiveRateAndTempo",value:function(){var t=this._tempo,e=this._rate;this._tempo=this.virtualTempo/this.virtualPitch,this._rate=this.virtualRate*this.virtualPitch,b(this._tempo,t)&&(this.stretch.tempo=this._tempo),b(this._rate,e)&&(this.transposer.rate=this._rate),this._rate>1?this._outputBuffer!=this.transposer.outputBuffer&&(this.stretch.inputBuffer=this._inputBuffer,this.stretch.outputBuffer=this._intermediateBuffer,this.transposer.inputBuffer=this._intermediateBuffer,this.transposer.outputBuffer=this._outputBuffer):this._outputBuffer!=this.stretch.outputBuffer&&(this.transposer.inputBuffer=this._inputBuffer,this.transposer.outputBuffer=this._intermediateBuffer,this.stretch.inputBuffer=this._intermediateBuffer,this.stretch.outputBuffer=this._outputBuffer)}},{key:"process",value:function(){this._rate>1?(this.stretch.process(),this.transposer.process()):(this.transposer.process(),this.stretch.process())}},{key:"rate",get:function(){return this._rate},set:function(t){this.virtualRate=t,this.calculateEffectiveRateAndTempo()}},{key:"rateChange",set:function(t){this._rate=1+.01*t}},{key:"tempo",get:function(){return this._tempo},set:function(t){this.virtualTempo=t,this.calculateEffectiveRateAndTempo()}},{key:"tempoChange",set:function(t){this.tempo=1+.01*t}},{key:"pitch",set:function(t){this.virtualPitch=t,this.calculateEffectiveRateAndTempo()}},{key:"pitchOctaves",set:function(t){this.pitch=Math.exp(.69314718056*t),this.calculateEffectiveRateAndTempo()}},{key:"pitchSemitones",set:function(t){this.pitchOctaves=t/12}},{key:"inputBuffer",get:function(){return this._inputBuffer}},{key:"outputBuffer",get:function(){return this._outputBuffer}}]),t}(),L=function(){function t(r){e(this,t),this.buffer=r,this._position=0}return i(t,[{key:"extract",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0;this.position=r;for(var i=this.buffer.getChannelData(0),n=this.dualChannel?this.buffer.getChannelData(1):this.buffer.getChannelData(0),o=0;o<e;o++)t[2*o]=i[o+r],t[2*o+1]=n[o+r];return Math.min(e,i.length-r)}},{key:"dualChannel",get:function(){return this.buffer.numberOfChannels>1}},{key:"position",get:function(){return this._position},set:function(t){this._position=t}}]),t}(),E=function(t,e){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:B,i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:4096,n=t.createScriptProcessor(i,2,2),o=new Float32Array(2*i);return n.onaudioprocess=function(t){var n=t.outputBuffer.getChannelData(0),s=t.outputBuffer.getChannelData(1),u=e.extract(o,i);r(e.sourcePosition),0===u&&e.onEnd();for(var a=0;a<u;a++)n[a]=o[2*a],s[a]=o[2*a+1]},n},O=function(t){var e,r,i,n=Math.floor(t/60),o=t-60*n;return"".concat(n,":").concat((e=parseInt(o),i=i||"0",(e+="").length>=(r=2)?e:new Array(r-e.length+1).join(i)+e))},R=function(t){var e=this.timePlayed,r=this.sampleRate;if(this.sourcePosition=t,this.timePlayed=t/r,e!==this.timePlayed){var i=new CustomEvent("play",{detail:{timePlayed:this.timePlayed,formattedTimePlayed:this.formattedTimePlayed,percentagePlayed:this.percentagePlayed}});this._node.dispatchEvent(i)}},x=(function(){function t(r,i,n){var o=this,s=arguments.length>3&&void 0!==arguments[3]?arguments[3]:B;e(this,t),this._soundtouch=new C;var u=new L(i);this.timePlayed=0,this.sourcePosition=0,this._filter=new w(u,this._soundtouch,s),this._node=E(r,this._filter,(function(t){return R.call(o,t)}),n),this.tempo=1,this.rate=1,this.duration=i.duration,this.sampleRate=r.sampleRate,this.listeners=[]}i(t,[{key:"connect",value:function(t){this._node.connect(t)}},{key:"disconnect",value:function(){this._node.disconnect()}},{key:"on",value:function(t,e){this.listeners.push({name:t,cb:e}),this._node.addEventListener(t,(function(t){return e(t.detail)}))}},{key:"off",value:function(){var t=this,e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null,r=this.listeners;e&&(r=r.filter((function(t){return t.name===e}))),r.forEach((function(e){t._node.removeEventListener(e.name,(function(t){return e.cb(t.detail)}))}))}},{key:"formattedDuration",get:function(){return O(this.duration)}},{key:"formattedTimePlayed",get:function(){return O(this.timePlayed)}},{key:"percentagePlayed",get:function(){return 100*this._filter.sourcePosition/(this.duration*this.sampleRate)},set:function(t){this._filter.sourcePosition=parseInt(t*this.duration*this.sampleRate),this.sourcePosition=this._filter.sourcePosition,this.timePlayed=this.sourcePosition/this.sampleRate}},{key:"node",get:function(){return this._node}},{key:"pitch",set:function(t){this._soundtouch.pitch=t}},{key:"pitchSemitones",set:function(t){this._soundtouch.pitchSemitones=t}},{key:"rate",set:function(t){this._soundtouch.rate=t}},{key:"tempo",set:function(t){this._soundtouch.tempo=t}}])}(),function(){function t(r,i,n){e(this,t),Object.assign(this,r),this.leftChannel=i,this.rightChannel=n,this._position=0}return i(t,[{key:"extract",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0;this.position=r;for(var i=0;i<e;i++)t[2*i]=this.leftChannel[i+r],t[2*i+1]=this.rightChannel[i+r];return Math.min(e,this.leftChannel.length-r)}},{key:"position",get:function(){return this._position},set:function(t){this._position=t}}]),t}()),M=function(r){n(s,h(AudioWorkletProcessor));var o=l(s);function s(t){var r;return e(this,s),(r=o.call(this))._initialized=!1,r.bufferSize=128,r.port.onmessage=r._messageProcessor.bind(f(r)),r.port.postMessage({message:"PROCESSOR_CONSTRUCTOR",detail:t}),r}return i(s,[{key:"_messageProcessor",value:function(e){var r=e.data,i=r.message,n=r.detail;if("INITIALIZE_PROCESSOR"===i){var o=v(n,3),s=o[0],u=o[1],a=o[2];return this.bufferSource=new x(s,u,a),this._samples=new Float32Array(2*this.bufferSize),this._pipe=new C,this._filter=new w(this.bufferSource,this._pipe),this.port.postMessage({message:"PROCESSOR_READY"}),this._initialized=!0,!0}if("SET_PIPE_PROP"===i&&n){var h=n.name,f=n.value;return this._pipe[h]=f,void this.port.postMessage({message:"PIPE_PROP_CHANGED",detail:"Updated ".concat(h," to ").concat(this._pipe[h],"\ntypeof ").concat(t(f))})}if("SET_FILTER_PROP"===i&&n){var c=n.name,l=n.value;return this._filter[c]=l,void this.port.postMessage({message:"FILTER_PROP_CHANGED",detail:"Updated ".concat(c," to ").concat(this._filter[c],"\ntypeof ").concat(t(l))})}console.log("[PitchShifterWorkletProcessor] Unknown message: ",e)}},{key:"_sendMessage",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;t&&this.port.postMessage({message:t,detail:e})}},{key:"process",value:function(t,e){if(!this._initialized||!t[0].length)return!0;var r=e[0][0],i=e[0][1],n=this._samples;if(!r||r&&!r.length)return!1;var o=this._filter.extract(n,t[0][0].length);if(!o)return this._sendMessage("PROCESSOR_END"),!1;this._sendMessage("SOURCEPOSITION",this._filter.sourcePosition);for(var s=0;s<o;s+=1)r[s]=n[2*s],i[s]=n[2*s+1];return!0}}]),s}();registerProcessor("soundtouch-worklet",M); | ||
'use strict'; | ||
function _typeof(obj) { | ||
"@babel/helpers - typeof"; | ||
if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { | ||
_typeof = function (obj) { | ||
return typeof obj; | ||
}; | ||
} else { | ||
_typeof = function (obj) { | ||
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; | ||
}; | ||
} | ||
return _typeof(obj); | ||
} | ||
function _classCallCheck(instance, Constructor) { | ||
if (!(instance instanceof Constructor)) { | ||
throw new TypeError("Cannot call a class as a function"); | ||
} | ||
} | ||
function _defineProperties(target, props) { | ||
for (var i = 0; i < props.length; i++) { | ||
var descriptor = props[i]; | ||
descriptor.enumerable = descriptor.enumerable || false; | ||
descriptor.configurable = true; | ||
if ("value" in descriptor) descriptor.writable = true; | ||
Object.defineProperty(target, descriptor.key, descriptor); | ||
} | ||
} | ||
function _createClass(Constructor, protoProps, staticProps) { | ||
if (protoProps) _defineProperties(Constructor.prototype, protoProps); | ||
if (staticProps) _defineProperties(Constructor, staticProps); | ||
return Constructor; | ||
} | ||
function _inherits(subClass, superClass) { | ||
if (typeof superClass !== "function" && superClass !== null) { | ||
throw new TypeError("Super expression must either be null or a function"); | ||
} | ||
subClass.prototype = Object.create(superClass && superClass.prototype, { | ||
constructor: { | ||
value: subClass, | ||
writable: true, | ||
configurable: true | ||
} | ||
}); | ||
if (superClass) _setPrototypeOf(subClass, superClass); | ||
} | ||
function _getPrototypeOf(o) { | ||
_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { | ||
return o.__proto__ || Object.getPrototypeOf(o); | ||
}; | ||
return _getPrototypeOf(o); | ||
} | ||
function _setPrototypeOf(o, p) { | ||
_setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { | ||
o.__proto__ = p; | ||
return o; | ||
}; | ||
return _setPrototypeOf(o, p); | ||
} | ||
function _isNativeReflectConstruct() { | ||
if (typeof Reflect === "undefined" || !Reflect.construct) return false; | ||
if (Reflect.construct.sham) return false; | ||
if (typeof Proxy === "function") return true; | ||
try { | ||
Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); | ||
return true; | ||
} catch (e) { | ||
return false; | ||
} | ||
} | ||
function _construct(Parent, args, Class) { | ||
if (_isNativeReflectConstruct()) { | ||
_construct = Reflect.construct; | ||
} else { | ||
_construct = function _construct(Parent, args, Class) { | ||
var a = [null]; | ||
a.push.apply(a, args); | ||
var Constructor = Function.bind.apply(Parent, a); | ||
var instance = new Constructor(); | ||
if (Class) _setPrototypeOf(instance, Class.prototype); | ||
return instance; | ||
}; | ||
} | ||
return _construct.apply(null, arguments); | ||
} | ||
function _isNativeFunction(fn) { | ||
return Function.toString.call(fn).indexOf("[native code]") !== -1; | ||
} | ||
function _wrapNativeSuper(Class) { | ||
var _cache = typeof Map === "function" ? new Map() : undefined; | ||
_wrapNativeSuper = function _wrapNativeSuper(Class) { | ||
if (Class === null || !_isNativeFunction(Class)) return Class; | ||
if (typeof Class !== "function") { | ||
throw new TypeError("Super expression must either be null or a function"); | ||
} | ||
if (typeof _cache !== "undefined") { | ||
if (_cache.has(Class)) return _cache.get(Class); | ||
_cache.set(Class, Wrapper); | ||
} | ||
function Wrapper() { | ||
return _construct(Class, arguments, _getPrototypeOf(this).constructor); | ||
} | ||
Wrapper.prototype = Object.create(Class.prototype, { | ||
constructor: { | ||
value: Wrapper, | ||
enumerable: false, | ||
writable: true, | ||
configurable: true | ||
} | ||
}); | ||
return _setPrototypeOf(Wrapper, Class); | ||
}; | ||
return _wrapNativeSuper(Class); | ||
} | ||
function _assertThisInitialized(self) { | ||
if (self === void 0) { | ||
throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); | ||
} | ||
return self; | ||
} | ||
function _possibleConstructorReturn(self, call) { | ||
if (call && (typeof call === "object" || typeof call === "function")) { | ||
return call; | ||
} | ||
return _assertThisInitialized(self); | ||
} | ||
function _createSuper(Derived) { | ||
var hasNativeReflectConstruct = _isNativeReflectConstruct(); | ||
return function _createSuperInternal() { | ||
var Super = _getPrototypeOf(Derived), | ||
result; | ||
if (hasNativeReflectConstruct) { | ||
var NewTarget = _getPrototypeOf(this).constructor; | ||
result = Reflect.construct(Super, arguments, NewTarget); | ||
} else { | ||
result = Super.apply(this, arguments); | ||
} | ||
return _possibleConstructorReturn(this, result); | ||
}; | ||
} | ||
function _superPropBase(object, property) { | ||
while (!Object.prototype.hasOwnProperty.call(object, property)) { | ||
object = _getPrototypeOf(object); | ||
if (object === null) break; | ||
} | ||
return object; | ||
} | ||
function _get(target, property, receiver) { | ||
if (typeof Reflect !== "undefined" && Reflect.get) { | ||
_get = Reflect.get; | ||
} else { | ||
_get = function _get(target, property, receiver) { | ||
var base = _superPropBase(target, property); | ||
if (!base) return; | ||
var desc = Object.getOwnPropertyDescriptor(base, property); | ||
if (desc.get) { | ||
return desc.get.call(receiver); | ||
} | ||
return desc.value; | ||
}; | ||
} | ||
return _get(target, property, receiver || target); | ||
} | ||
function _slicedToArray(arr, i) { | ||
return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); | ||
} | ||
function _arrayWithHoles(arr) { | ||
if (Array.isArray(arr)) return arr; | ||
} | ||
function _iterableToArrayLimit(arr, i) { | ||
if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return; | ||
var _arr = []; | ||
var _n = true; | ||
var _d = false; | ||
var _e = undefined; | ||
try { | ||
for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { | ||
_arr.push(_s.value); | ||
if (i && _arr.length === i) break; | ||
} | ||
} catch (err) { | ||
_d = true; | ||
_e = err; | ||
} finally { | ||
try { | ||
if (!_n && _i["return"] != null) _i["return"](); | ||
} finally { | ||
if (_d) throw _e; | ||
} | ||
} | ||
return _arr; | ||
} | ||
function _unsupportedIterableToArray(o, minLen) { | ||
if (!o) return; | ||
if (typeof o === "string") return _arrayLikeToArray(o, minLen); | ||
var n = Object.prototype.toString.call(o).slice(8, -1); | ||
if (n === "Object" && o.constructor) n = o.constructor.name; | ||
if (n === "Map" || n === "Set") return Array.from(o); | ||
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); | ||
} | ||
function _arrayLikeToArray(arr, len) { | ||
if (len == null || len > arr.length) len = arr.length; | ||
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; | ||
return arr2; | ||
} | ||
function _nonIterableRest() { | ||
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); | ||
} | ||
var runtime = function (exports) { | ||
var Op = Object.prototype; | ||
var hasOwn = Op.hasOwnProperty; | ||
var undefined$1; | ||
var $Symbol = typeof Symbol === "function" ? Symbol : {}; | ||
var iteratorSymbol = $Symbol.iterator || "@@iterator"; | ||
var asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator"; | ||
var toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; | ||
function wrap(innerFn, outerFn, self, tryLocsList) { | ||
var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator; | ||
var generator = Object.create(protoGenerator.prototype); | ||
var context = new Context(tryLocsList || []); | ||
generator._invoke = makeInvokeMethod(innerFn, self, context); | ||
return generator; | ||
} | ||
exports.wrap = wrap; | ||
function tryCatch(fn, obj, arg) { | ||
try { | ||
return { | ||
type: "normal", | ||
arg: fn.call(obj, arg) | ||
}; | ||
} catch (err) { | ||
return { | ||
type: "throw", | ||
arg: err | ||
}; | ||
} | ||
} | ||
var GenStateSuspendedStart = "suspendedStart"; | ||
var GenStateSuspendedYield = "suspendedYield"; | ||
var GenStateExecuting = "executing"; | ||
var GenStateCompleted = "completed"; | ||
var ContinueSentinel = {}; | ||
function Generator() {} | ||
function GeneratorFunction() {} | ||
function GeneratorFunctionPrototype() {} | ||
var IteratorPrototype = {}; | ||
IteratorPrototype[iteratorSymbol] = function () { | ||
return this; | ||
}; | ||
var getProto = Object.getPrototypeOf; | ||
var NativeIteratorPrototype = getProto && getProto(getProto(values([]))); | ||
if (NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol)) { | ||
IteratorPrototype = NativeIteratorPrototype; | ||
} | ||
var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); | ||
GeneratorFunction.prototype = Gp.constructor = GeneratorFunctionPrototype; | ||
GeneratorFunctionPrototype.constructor = GeneratorFunction; | ||
GeneratorFunctionPrototype[toStringTagSymbol] = GeneratorFunction.displayName = "GeneratorFunction"; | ||
function defineIteratorMethods(prototype) { | ||
["next", "throw", "return"].forEach(function (method) { | ||
prototype[method] = function (arg) { | ||
return this._invoke(method, arg); | ||
}; | ||
}); | ||
} | ||
exports.isGeneratorFunction = function (genFun) { | ||
var ctor = typeof genFun === "function" && genFun.constructor; | ||
return ctor ? ctor === GeneratorFunction || | ||
(ctor.displayName || ctor.name) === "GeneratorFunction" : false; | ||
}; | ||
exports.mark = function (genFun) { | ||
if (Object.setPrototypeOf) { | ||
Object.setPrototypeOf(genFun, GeneratorFunctionPrototype); | ||
} else { | ||
genFun.__proto__ = GeneratorFunctionPrototype; | ||
if (!(toStringTagSymbol in genFun)) { | ||
genFun[toStringTagSymbol] = "GeneratorFunction"; | ||
} | ||
} | ||
genFun.prototype = Object.create(Gp); | ||
return genFun; | ||
}; | ||
exports.awrap = function (arg) { | ||
return { | ||
__await: arg | ||
}; | ||
}; | ||
function AsyncIterator(generator, PromiseImpl) { | ||
function invoke(method, arg, resolve, reject) { | ||
var record = tryCatch(generator[method], generator, arg); | ||
if (record.type === "throw") { | ||
reject(record.arg); | ||
} else { | ||
var result = record.arg; | ||
var value = result.value; | ||
if (value && _typeof(value) === "object" && hasOwn.call(value, "__await")) { | ||
return PromiseImpl.resolve(value.__await).then(function (value) { | ||
invoke("next", value, resolve, reject); | ||
}, function (err) { | ||
invoke("throw", err, resolve, reject); | ||
}); | ||
} | ||
return PromiseImpl.resolve(value).then(function (unwrapped) { | ||
result.value = unwrapped; | ||
resolve(result); | ||
}, function (error) { | ||
return invoke("throw", error, resolve, reject); | ||
}); | ||
} | ||
} | ||
var previousPromise; | ||
function enqueue(method, arg) { | ||
function callInvokeWithMethodAndArg() { | ||
return new PromiseImpl(function (resolve, reject) { | ||
invoke(method, arg, resolve, reject); | ||
}); | ||
} | ||
return previousPromise = | ||
previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, | ||
callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); | ||
} | ||
this._invoke = enqueue; | ||
} | ||
defineIteratorMethods(AsyncIterator.prototype); | ||
AsyncIterator.prototype[asyncIteratorSymbol] = function () { | ||
return this; | ||
}; | ||
exports.AsyncIterator = AsyncIterator; | ||
exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { | ||
if (PromiseImpl === void 0) PromiseImpl = Promise; | ||
var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); | ||
return exports.isGeneratorFunction(outerFn) ? iter | ||
: iter.next().then(function (result) { | ||
return result.done ? result.value : iter.next(); | ||
}); | ||
}; | ||
function makeInvokeMethod(innerFn, self, context) { | ||
var state = GenStateSuspendedStart; | ||
return function invoke(method, arg) { | ||
if (state === GenStateExecuting) { | ||
throw new Error("Generator is already running"); | ||
} | ||
if (state === GenStateCompleted) { | ||
if (method === "throw") { | ||
throw arg; | ||
} | ||
return doneResult(); | ||
} | ||
context.method = method; | ||
context.arg = arg; | ||
while (true) { | ||
var delegate = context.delegate; | ||
if (delegate) { | ||
var delegateResult = maybeInvokeDelegate(delegate, context); | ||
if (delegateResult) { | ||
if (delegateResult === ContinueSentinel) continue; | ||
return delegateResult; | ||
} | ||
} | ||
if (context.method === "next") { | ||
context.sent = context._sent = context.arg; | ||
} else if (context.method === "throw") { | ||
if (state === GenStateSuspendedStart) { | ||
state = GenStateCompleted; | ||
throw context.arg; | ||
} | ||
context.dispatchException(context.arg); | ||
} else if (context.method === "return") { | ||
context.abrupt("return", context.arg); | ||
} | ||
state = GenStateExecuting; | ||
var record = tryCatch(innerFn, self, context); | ||
if (record.type === "normal") { | ||
state = context.done ? GenStateCompleted : GenStateSuspendedYield; | ||
if (record.arg === ContinueSentinel) { | ||
continue; | ||
} | ||
return { | ||
value: record.arg, | ||
done: context.done | ||
}; | ||
} else if (record.type === "throw") { | ||
state = GenStateCompleted; | ||
context.method = "throw"; | ||
context.arg = record.arg; | ||
} | ||
} | ||
}; | ||
} | ||
function maybeInvokeDelegate(delegate, context) { | ||
var method = delegate.iterator[context.method]; | ||
if (method === undefined$1) { | ||
context.delegate = null; | ||
if (context.method === "throw") { | ||
if (delegate.iterator["return"]) { | ||
context.method = "return"; | ||
context.arg = undefined$1; | ||
maybeInvokeDelegate(delegate, context); | ||
if (context.method === "throw") { | ||
return ContinueSentinel; | ||
} | ||
} | ||
context.method = "throw"; | ||
context.arg = new TypeError("The iterator does not provide a 'throw' method"); | ||
} | ||
return ContinueSentinel; | ||
} | ||
var record = tryCatch(method, delegate.iterator, context.arg); | ||
if (record.type === "throw") { | ||
context.method = "throw"; | ||
context.arg = record.arg; | ||
context.delegate = null; | ||
return ContinueSentinel; | ||
} | ||
var info = record.arg; | ||
if (!info) { | ||
context.method = "throw"; | ||
context.arg = new TypeError("iterator result is not an object"); | ||
context.delegate = null; | ||
return ContinueSentinel; | ||
} | ||
if (info.done) { | ||
context[delegate.resultName] = info.value; | ||
context.next = delegate.nextLoc; | ||
if (context.method !== "return") { | ||
context.method = "next"; | ||
context.arg = undefined$1; | ||
} | ||
} else { | ||
return info; | ||
} | ||
context.delegate = null; | ||
return ContinueSentinel; | ||
} | ||
defineIteratorMethods(Gp); | ||
Gp[toStringTagSymbol] = "Generator"; | ||
Gp[iteratorSymbol] = function () { | ||
return this; | ||
}; | ||
Gp.toString = function () { | ||
return "[object Generator]"; | ||
}; | ||
function pushTryEntry(locs) { | ||
var entry = { | ||
tryLoc: locs[0] | ||
}; | ||
if (1 in locs) { | ||
entry.catchLoc = locs[1]; | ||
} | ||
if (2 in locs) { | ||
entry.finallyLoc = locs[2]; | ||
entry.afterLoc = locs[3]; | ||
} | ||
this.tryEntries.push(entry); | ||
} | ||
function resetTryEntry(entry) { | ||
var record = entry.completion || {}; | ||
record.type = "normal"; | ||
delete record.arg; | ||
entry.completion = record; | ||
} | ||
function Context(tryLocsList) { | ||
this.tryEntries = [{ | ||
tryLoc: "root" | ||
}]; | ||
tryLocsList.forEach(pushTryEntry, this); | ||
this.reset(true); | ||
} | ||
exports.keys = function (object) { | ||
var keys = []; | ||
for (var key in object) { | ||
keys.push(key); | ||
} | ||
keys.reverse(); | ||
return function next() { | ||
while (keys.length) { | ||
var key = keys.pop(); | ||
if (key in object) { | ||
next.value = key; | ||
next.done = false; | ||
return next; | ||
} | ||
} | ||
next.done = true; | ||
return next; | ||
}; | ||
}; | ||
function values(iterable) { | ||
if (iterable) { | ||
var iteratorMethod = iterable[iteratorSymbol]; | ||
if (iteratorMethod) { | ||
return iteratorMethod.call(iterable); | ||
} | ||
if (typeof iterable.next === "function") { | ||
return iterable; | ||
} | ||
if (!isNaN(iterable.length)) { | ||
var i = -1, | ||
next = function next() { | ||
while (++i < iterable.length) { | ||
if (hasOwn.call(iterable, i)) { | ||
next.value = iterable[i]; | ||
next.done = false; | ||
return next; | ||
} | ||
} | ||
next.value = undefined$1; | ||
next.done = true; | ||
return next; | ||
}; | ||
return next.next = next; | ||
} | ||
} | ||
return { | ||
next: doneResult | ||
}; | ||
} | ||
exports.values = values; | ||
function doneResult() { | ||
return { | ||
value: undefined$1, | ||
done: true | ||
}; | ||
} | ||
Context.prototype = { | ||
constructor: Context, | ||
reset: function reset(skipTempReset) { | ||
this.prev = 0; | ||
this.next = 0; | ||
this.sent = this._sent = undefined$1; | ||
this.done = false; | ||
this.delegate = null; | ||
this.method = "next"; | ||
this.arg = undefined$1; | ||
this.tryEntries.forEach(resetTryEntry); | ||
if (!skipTempReset) { | ||
for (var name in this) { | ||
if (name.charAt(0) === "t" && hasOwn.call(this, name) && !isNaN(+name.slice(1))) { | ||
this[name] = undefined$1; | ||
} | ||
} | ||
} | ||
}, | ||
stop: function stop() { | ||
this.done = true; | ||
var rootEntry = this.tryEntries[0]; | ||
var rootRecord = rootEntry.completion; | ||
if (rootRecord.type === "throw") { | ||
throw rootRecord.arg; | ||
} | ||
return this.rval; | ||
}, | ||
dispatchException: function dispatchException(exception) { | ||
if (this.done) { | ||
throw exception; | ||
} | ||
var context = this; | ||
function handle(loc, caught) { | ||
record.type = "throw"; | ||
record.arg = exception; | ||
context.next = loc; | ||
if (caught) { | ||
context.method = "next"; | ||
context.arg = undefined$1; | ||
} | ||
return !!caught; | ||
} | ||
for (var i = this.tryEntries.length - 1; i >= 0; --i) { | ||
var entry = this.tryEntries[i]; | ||
var record = entry.completion; | ||
if (entry.tryLoc === "root") { | ||
return handle("end"); | ||
} | ||
if (entry.tryLoc <= this.prev) { | ||
var hasCatch = hasOwn.call(entry, "catchLoc"); | ||
var hasFinally = hasOwn.call(entry, "finallyLoc"); | ||
if (hasCatch && hasFinally) { | ||
if (this.prev < entry.catchLoc) { | ||
return handle(entry.catchLoc, true); | ||
} else if (this.prev < entry.finallyLoc) { | ||
return handle(entry.finallyLoc); | ||
} | ||
} else if (hasCatch) { | ||
if (this.prev < entry.catchLoc) { | ||
return handle(entry.catchLoc, true); | ||
} | ||
} else if (hasFinally) { | ||
if (this.prev < entry.finallyLoc) { | ||
return handle(entry.finallyLoc); | ||
} | ||
} else { | ||
throw new Error("try statement without catch or finally"); | ||
} | ||
} | ||
} | ||
}, | ||
abrupt: function abrupt(type, arg) { | ||
for (var i = this.tryEntries.length - 1; i >= 0; --i) { | ||
var entry = this.tryEntries[i]; | ||
if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { | ||
var finallyEntry = entry; | ||
break; | ||
} | ||
} | ||
if (finallyEntry && (type === "break" || type === "continue") && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc) { | ||
finallyEntry = null; | ||
} | ||
var record = finallyEntry ? finallyEntry.completion : {}; | ||
record.type = type; | ||
record.arg = arg; | ||
if (finallyEntry) { | ||
this.method = "next"; | ||
this.next = finallyEntry.finallyLoc; | ||
return ContinueSentinel; | ||
} | ||
return this.complete(record); | ||
}, | ||
complete: function complete(record, afterLoc) { | ||
if (record.type === "throw") { | ||
throw record.arg; | ||
} | ||
if (record.type === "break" || record.type === "continue") { | ||
this.next = record.arg; | ||
} else if (record.type === "return") { | ||
this.rval = this.arg = record.arg; | ||
this.method = "return"; | ||
this.next = "end"; | ||
} else if (record.type === "normal" && afterLoc) { | ||
this.next = afterLoc; | ||
} | ||
return ContinueSentinel; | ||
}, | ||
finish: function finish(finallyLoc) { | ||
for (var i = this.tryEntries.length - 1; i >= 0; --i) { | ||
var entry = this.tryEntries[i]; | ||
if (entry.finallyLoc === finallyLoc) { | ||
this.complete(entry.completion, entry.afterLoc); | ||
resetTryEntry(entry); | ||
return ContinueSentinel; | ||
} | ||
} | ||
}, | ||
"catch": function _catch(tryLoc) { | ||
for (var i = this.tryEntries.length - 1; i >= 0; --i) { | ||
var entry = this.tryEntries[i]; | ||
if (entry.tryLoc === tryLoc) { | ||
var record = entry.completion; | ||
if (record.type === "throw") { | ||
var thrown = record.arg; | ||
resetTryEntry(entry); | ||
} | ||
return thrown; | ||
} | ||
} | ||
throw new Error("illegal catch attempt"); | ||
}, | ||
delegateYield: function delegateYield(iterable, resultName, nextLoc) { | ||
this.delegate = { | ||
iterator: values(iterable), | ||
resultName: resultName, | ||
nextLoc: nextLoc | ||
}; | ||
if (this.method === "next") { | ||
this.arg = undefined$1; | ||
} | ||
return ContinueSentinel; | ||
} | ||
}; | ||
return exports; | ||
}( | ||
(typeof module === "undefined" ? "undefined" : _typeof(module)) === "object" ? module.exports : {}); | ||
try { | ||
regeneratorRuntime = runtime; | ||
} catch (accidentalStrictMode) { | ||
Function("r", "regeneratorRuntime = r")(runtime); | ||
} | ||
var FifoSampleBuffer = function () { | ||
function FifoSampleBuffer() { | ||
_classCallCheck(this, FifoSampleBuffer); | ||
this._vector = new Float32Array(); | ||
this._position = 0; | ||
this._frameCount = 0; | ||
} | ||
_createClass(FifoSampleBuffer, [{ | ||
key: "clear", | ||
value: function clear() { | ||
this.receive(this._frameCount); | ||
this.rewind(); | ||
} | ||
}, { | ||
key: "put", | ||
value: function put(numFrames) { | ||
this._frameCount += numFrames; | ||
} | ||
}, { | ||
key: "putSamples", | ||
value: function putSamples(samples, position) { | ||
var numFrames = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0; | ||
position = position || 0; | ||
var sourceOffset = position * 2; | ||
if (!(numFrames >= 0)) { | ||
numFrames = (samples.length - sourceOffset) / 2; | ||
} | ||
var numSamples = numFrames * 2; | ||
this.ensureCapacity(numFrames + this._frameCount); | ||
var destOffset = this.endIndex; | ||
this.vector.set(samples.subarray(sourceOffset, sourceOffset + numSamples), destOffset); | ||
this._frameCount += numFrames; | ||
} | ||
}, { | ||
key: "putBuffer", | ||
value: function putBuffer(buffer, position) { | ||
var numFrames = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0; | ||
position = position || 0; | ||
if (!(numFrames >= 0)) { | ||
numFrames = buffer.frameCount - position; | ||
} | ||
this.putSamples(buffer.vector, buffer.position + position, numFrames); | ||
} | ||
}, { | ||
key: "receive", | ||
value: function receive(numFrames) { | ||
if (!(numFrames >= 0) || numFrames > this._frameCount) { | ||
numFrames = this.frameCount; | ||
} | ||
this._frameCount -= numFrames; | ||
this._position += numFrames; | ||
} | ||
}, { | ||
key: "receiveSamples", | ||
value: function receiveSamples(output) { | ||
var numFrames = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0; | ||
var numSamples = numFrames * 2; | ||
var sourceOffset = this.startIndex; | ||
output.set(this._vector.subarray(sourceOffset, sourceOffset + numSamples)); | ||
this.receive(numFrames); | ||
} | ||
}, { | ||
key: "extract", | ||
value: function extract(output) { | ||
var position = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0; | ||
var numFrames = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0; | ||
var sourceOffset = this.startIndex + position * 2; | ||
var numSamples = numFrames * 2; | ||
output.set(this._vector.subarray(sourceOffset, sourceOffset + numSamples)); | ||
} | ||
}, { | ||
key: "ensureCapacity", | ||
value: function ensureCapacity() { | ||
var numFrames = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0; | ||
var minLength = parseInt(numFrames * 2); | ||
if (this._vector.length < minLength) { | ||
var newVector = new Float32Array(minLength); | ||
newVector.set(this._vector.subarray(this.startIndex, this.endIndex)); | ||
this._vector = newVector; | ||
this._position = 0; | ||
} else { | ||
this.rewind(); | ||
} | ||
} | ||
}, { | ||
key: "ensureAdditionalCapacity", | ||
value: function ensureAdditionalCapacity() { | ||
var numFrames = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0; | ||
this.ensureCapacity(this._frameCount + numFrames); | ||
} | ||
}, { | ||
key: "rewind", | ||
value: function rewind() { | ||
if (this._position > 0) { | ||
this._vector.set(this._vector.subarray(this.startIndex, this.endIndex)); | ||
this._position = 0; | ||
} | ||
} | ||
}, { | ||
key: "vector", | ||
get: function get() { | ||
return this._vector; | ||
} | ||
}, { | ||
key: "position", | ||
get: function get() { | ||
return this._position; | ||
} | ||
}, { | ||
key: "startIndex", | ||
get: function get() { | ||
return this._position * 2; | ||
} | ||
}, { | ||
key: "frameCount", | ||
get: function get() { | ||
return this._frameCount; | ||
} | ||
}, { | ||
key: "endIndex", | ||
get: function get() { | ||
return (this._position + this._frameCount) * 2; | ||
} | ||
}]); | ||
return FifoSampleBuffer; | ||
}(); | ||
var AbstractFifoSamplePipe = function () { | ||
function AbstractFifoSamplePipe(createBuffers) { | ||
_classCallCheck(this, AbstractFifoSamplePipe); | ||
if (createBuffers) { | ||
this._inputBuffer = new FifoSampleBuffer(); | ||
this._outputBuffer = new FifoSampleBuffer(); | ||
} else { | ||
this._inputBuffer = this._outputBuffer = null; | ||
} | ||
} | ||
_createClass(AbstractFifoSamplePipe, [{ | ||
key: "clear", | ||
value: function clear() { | ||
this._inputBuffer.clear(); | ||
this._outputBuffer.clear(); | ||
} | ||
}, { | ||
key: "inputBuffer", | ||
get: function get() { | ||
return this._inputBuffer; | ||
}, | ||
set: function set(inputBuffer) { | ||
this._inputBuffer = inputBuffer; | ||
} | ||
}, { | ||
key: "outputBuffer", | ||
get: function get() { | ||
return this._outputBuffer; | ||
}, | ||
set: function set(outputBuffer) { | ||
this._outputBuffer = outputBuffer; | ||
} | ||
}]); | ||
return AbstractFifoSamplePipe; | ||
}(); | ||
var RateTransposer = function (_AbstractFifoSamplePi) { | ||
_inherits(RateTransposer, _AbstractFifoSamplePi); | ||
var _super = _createSuper(RateTransposer); | ||
function RateTransposer(createBuffers) { | ||
var _this; | ||
_classCallCheck(this, RateTransposer); | ||
_this = _super.call(this, createBuffers); | ||
_this.reset(); | ||
_this._rate = 1; | ||
return _this; | ||
} | ||
_createClass(RateTransposer, [{ | ||
key: "reset", | ||
value: function reset() { | ||
this.slopeCount = 0; | ||
this.prevSampleL = 0; | ||
this.prevSampleR = 0; | ||
} | ||
}, { | ||
key: "clone", | ||
value: function clone() { | ||
var result = new RateTransposer(); | ||
result.rate = this._rate; | ||
return result; | ||
} | ||
}, { | ||
key: "process", | ||
value: function process() { | ||
var numFrames = this._inputBuffer.frameCount; | ||
this._outputBuffer.ensureAdditionalCapacity(numFrames / this._rate + 1); | ||
var numFramesOutput = this.transpose(numFrames); | ||
this._inputBuffer.receive(); | ||
this._outputBuffer.put(numFramesOutput); | ||
} | ||
}, { | ||
key: "transpose", | ||
value: function transpose() { | ||
var numFrames = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0; | ||
if (numFrames === 0) { | ||
return 0; | ||
} | ||
var src = this._inputBuffer.vector; | ||
var srcOffset = this._inputBuffer.startIndex; | ||
var dest = this._outputBuffer.vector; | ||
var destOffset = this._outputBuffer.endIndex; | ||
var used = 0; | ||
var i = 0; | ||
while (this.slopeCount < 1.0) { | ||
dest[destOffset + 2 * i] = (1.0 - this.slopeCount) * this.prevSampleL + this.slopeCount * src[srcOffset]; | ||
dest[destOffset + 2 * i + 1] = (1.0 - this.slopeCount) * this.prevSampleR + this.slopeCount * src[srcOffset + 1]; | ||
i = i + 1; | ||
this.slopeCount += this._rate; | ||
} | ||
this.slopeCount -= 1.0; | ||
if (numFrames !== 1) { | ||
out: while (true) { | ||
while (this.slopeCount > 1.0) { | ||
this.slopeCount -= 1.0; | ||
used = used + 1; | ||
if (used >= numFrames - 1) { | ||
break out; | ||
} | ||
} | ||
var srcIndex = srcOffset + 2 * used; | ||
dest[destOffset + 2 * i] = (1.0 - this.slopeCount) * src[srcIndex] + this.slopeCount * src[srcIndex + 2]; | ||
dest[destOffset + 2 * i + 1] = (1.0 - this.slopeCount) * src[srcIndex + 1] + this.slopeCount * src[srcIndex + 3]; | ||
i = i + 1; | ||
this.slopeCount += this._rate; | ||
} | ||
} | ||
this.prevSampleL = src[srcOffset + 2 * numFrames - 2]; | ||
this.prevSampleR = src[srcOffset + 2 * numFrames - 1]; | ||
return i; | ||
} | ||
}, { | ||
key: "rate", | ||
set: function set(rate) { | ||
this._rate = rate; | ||
} | ||
}]); | ||
return RateTransposer; | ||
}(AbstractFifoSamplePipe); | ||
var FilterSupport = function () { | ||
function FilterSupport(pipe) { | ||
_classCallCheck(this, FilterSupport); | ||
this._pipe = pipe; | ||
} | ||
_createClass(FilterSupport, [{ | ||
key: "fillInputBuffer", | ||
value: function fillInputBuffer() { | ||
throw new Error('fillInputBuffer() not overridden'); | ||
} | ||
}, { | ||
key: "fillOutputBuffer", | ||
value: function fillOutputBuffer() { | ||
var numFrames = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0; | ||
while (this.outputBuffer.frameCount < numFrames) { | ||
var numInputFrames = 8192 * 2 - this.inputBuffer.frameCount; | ||
this.fillInputBuffer(numInputFrames); | ||
if (this.inputBuffer.frameCount < 8192 * 2) { | ||
break; | ||
} | ||
this._pipe.process(); | ||
} | ||
} | ||
}, { | ||
key: "clear", | ||
value: function clear() { | ||
this._pipe.clear(); | ||
} | ||
}, { | ||
key: "pipe", | ||
get: function get() { | ||
return this._pipe; | ||
} | ||
}, { | ||
key: "inputBuffer", | ||
get: function get() { | ||
return this._pipe.inputBuffer; | ||
} | ||
}, { | ||
key: "outputBuffer", | ||
get: function get() { | ||
return this._pipe.outputBuffer; | ||
} | ||
}]); | ||
return FilterSupport; | ||
}(); | ||
var noop = function noop() { | ||
return; | ||
}; | ||
var SimpleFilter = function (_FilterSupport) { | ||
_inherits(SimpleFilter, _FilterSupport); | ||
var _super2 = _createSuper(SimpleFilter); | ||
function SimpleFilter(sourceSound, pipe) { | ||
var _this2; | ||
var callback = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : noop; | ||
_classCallCheck(this, SimpleFilter); | ||
_this2 = _super2.call(this, pipe); | ||
_this2.callback = callback; | ||
_this2.sourceSound = sourceSound; | ||
_this2.historyBufferSize = 22050; | ||
_this2._sourcePosition = 0; | ||
_this2.outputBufferPosition = 0; | ||
_this2._position = 0; | ||
return _this2; | ||
} | ||
_createClass(SimpleFilter, [{ | ||
key: "onEnd", | ||
value: function onEnd() { | ||
this.callback(); | ||
} | ||
}, { | ||
key: "fillInputBuffer", | ||
value: function fillInputBuffer() { | ||
var numFrames = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0; | ||
var samples = new Float32Array(numFrames * 2); | ||
var numFramesExtracted = this.sourceSound.extract(samples, numFrames, this._sourcePosition); | ||
this._sourcePosition += numFramesExtracted; | ||
this.inputBuffer.putSamples(samples, 0, numFramesExtracted); | ||
} | ||
}, { | ||
key: "extract", | ||
value: function extract(target) { | ||
var numFrames = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0; | ||
this.fillOutputBuffer(this.outputBufferPosition + numFrames); | ||
var numFramesExtracted = Math.min(numFrames, this.outputBuffer.frameCount - this.outputBufferPosition); | ||
this.outputBuffer.extract(target, this.outputBufferPosition, numFramesExtracted); | ||
var currentFrames = this.outputBufferPosition + numFramesExtracted; | ||
this.outputBufferPosition = Math.min(this.historyBufferSize, currentFrames); | ||
this.outputBuffer.receive(Math.max(currentFrames - this.historyBufferSize, 0)); | ||
this._position += numFramesExtracted; | ||
return numFramesExtracted; | ||
} | ||
}, { | ||
key: "handleSampleData", | ||
value: function handleSampleData(event) { | ||
this.extract(event.data, 4096); | ||
} | ||
}, { | ||
key: "clear", | ||
value: function clear() { | ||
_get(_getPrototypeOf(SimpleFilter.prototype), "clear", this).call(this); | ||
this.outputBufferPosition = 0; | ||
} | ||
}, { | ||
key: "position", | ||
get: function get() { | ||
return this._position; | ||
}, | ||
set: function set(position) { | ||
if (position > this._position) { | ||
throw new RangeError('New position may not be greater than current position'); | ||
} | ||
var newOutputBufferPosition = this.outputBufferPosition - (this._position - position); | ||
if (newOutputBufferPosition < 0) { | ||
throw new RangeError('New position falls outside of history buffer'); | ||
} | ||
this.outputBufferPosition = newOutputBufferPosition; | ||
this._position = position; | ||
} | ||
}, { | ||
key: "sourcePosition", | ||
get: function get() { | ||
return this._sourcePosition; | ||
}, | ||
set: function set(sourcePosition) { | ||
this.clear(); | ||
this._sourcePosition = sourcePosition; | ||
} | ||
}]); | ||
return SimpleFilter; | ||
}(FilterSupport); | ||
var USE_AUTO_SEQUENCE_LEN = 0; | ||
var DEFAULT_SEQUENCE_MS = USE_AUTO_SEQUENCE_LEN; | ||
var USE_AUTO_SEEKWINDOW_LEN = 0; | ||
var DEFAULT_SEEKWINDOW_MS = USE_AUTO_SEEKWINDOW_LEN; | ||
var DEFAULT_OVERLAP_MS = 8; | ||
var _SCAN_OFFSETS = [[124, 186, 248, 310, 372, 434, 496, 558, 620, 682, 744, 806, 868, 930, 992, 1054, 1116, 1178, 1240, 1302, 1364, 1426, 1488, 0], [-100, -75, -50, -25, 25, 50, 75, 100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [-20, -15, -10, -5, 5, 10, 15, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [-4, -3, -2, -1, 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]; | ||
var AUTOSEQ_TEMPO_LOW = 0.5; | ||
var AUTOSEQ_TEMPO_TOP = 2.0; | ||
var AUTOSEQ_AT_MIN = 125.0; | ||
var AUTOSEQ_AT_MAX = 50.0; | ||
var AUTOSEQ_K = (AUTOSEQ_AT_MAX - AUTOSEQ_AT_MIN) / (AUTOSEQ_TEMPO_TOP - AUTOSEQ_TEMPO_LOW); | ||
var AUTOSEQ_C = AUTOSEQ_AT_MIN - AUTOSEQ_K * AUTOSEQ_TEMPO_LOW; | ||
var AUTOSEEK_AT_MIN = 25.0; | ||
var AUTOSEEK_AT_MAX = 15.0; | ||
var AUTOSEEK_K = (AUTOSEEK_AT_MAX - AUTOSEEK_AT_MIN) / (AUTOSEQ_TEMPO_TOP - AUTOSEQ_TEMPO_LOW); | ||
var AUTOSEEK_C = AUTOSEEK_AT_MIN - AUTOSEEK_K * AUTOSEQ_TEMPO_LOW; | ||
var Stretch = function (_AbstractFifoSamplePi2) { | ||
_inherits(Stretch, _AbstractFifoSamplePi2); | ||
var _super3 = _createSuper(Stretch); | ||
function Stretch(createBuffers) { | ||
var _this3; | ||
_classCallCheck(this, Stretch); | ||
_this3 = _super3.call(this, createBuffers); | ||
_this3._quickSeek = true; | ||
_this3.midBufferDirty = false; | ||
_this3.midBuffer = null; | ||
_this3.overlapLength = 0; | ||
_this3.autoSeqSetting = true; | ||
_this3.autoSeekSetting = true; | ||
_this3._tempo = 1; | ||
_this3.setParameters(44100, DEFAULT_SEQUENCE_MS, DEFAULT_SEEKWINDOW_MS, DEFAULT_OVERLAP_MS); | ||
return _this3; | ||
} | ||
_createClass(Stretch, [{ | ||
key: "clear", | ||
value: function clear() { | ||
_get(_getPrototypeOf(Stretch.prototype), "clear", this).call(this); | ||
this.clearMidBuffer(); | ||
} | ||
}, { | ||
key: "clearMidBuffer", | ||
value: function clearMidBuffer() { | ||
if (this.midBufferDirty) { | ||
this.midBufferDirty = false; | ||
this.midBuffer = null; | ||
} | ||
} | ||
}, { | ||
key: "setParameters", | ||
value: function setParameters(sampleRate, sequenceMs, seekWindowMs, overlapMs) { | ||
if (sampleRate > 0) { | ||
this.sampleRate = sampleRate; | ||
} | ||
if (overlapMs > 0) { | ||
this.overlapMs = overlapMs; | ||
} | ||
if (sequenceMs > 0) { | ||
this.sequenceMs = sequenceMs; | ||
this.autoSeqSetting = false; | ||
} else { | ||
this.autoSeqSetting = true; | ||
} | ||
if (seekWindowMs > 0) { | ||
this.seekWindowMs = seekWindowMs; | ||
this.autoSeekSetting = false; | ||
} else { | ||
this.autoSeekSetting = true; | ||
} | ||
this.calculateSequenceParameters(); | ||
this.calculateOverlapLength(this.overlapMs); | ||
this.tempo = this._tempo; | ||
} | ||
}, { | ||
key: "calculateOverlapLength", | ||
value: function calculateOverlapLength() { | ||
var overlapInMsec = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0; | ||
var newOvl; | ||
newOvl = this.sampleRate * overlapInMsec / 1000; | ||
newOvl = newOvl < 16 ? 16 : newOvl; | ||
newOvl -= newOvl % 8; | ||
this.overlapLength = newOvl; | ||
this.refMidBuffer = new Float32Array(this.overlapLength * 2); | ||
this.midBuffer = new Float32Array(this.overlapLength * 2); | ||
} | ||
}, { | ||
key: "checkLimits", | ||
value: function checkLimits(x, mi, ma) { | ||
return x < mi ? mi : x > ma ? ma : x; | ||
} | ||
}, { | ||
key: "calculateSequenceParameters", | ||
value: function calculateSequenceParameters() { | ||
var seq; | ||
var seek; | ||
if (this.autoSeqSetting) { | ||
seq = AUTOSEQ_C + AUTOSEQ_K * this._tempo; | ||
seq = this.checkLimits(seq, AUTOSEQ_AT_MAX, AUTOSEQ_AT_MIN); | ||
this.sequenceMs = Math.floor(seq + 0.5); | ||
} | ||
if (this.autoSeekSetting) { | ||
seek = AUTOSEEK_C + AUTOSEEK_K * this._tempo; | ||
seek = this.checkLimits(seek, AUTOSEEK_AT_MAX, AUTOSEEK_AT_MIN); | ||
this.seekWindowMs = Math.floor(seek + 0.5); | ||
} | ||
this.seekWindowLength = Math.floor(this.sampleRate * this.sequenceMs / 1000); | ||
this.seekLength = Math.floor(this.sampleRate * this.seekWindowMs / 1000); | ||
} | ||
}, { | ||
key: "clone", | ||
value: function clone() { | ||
var result = new Stretch(); | ||
result.tempo = this._tempo; | ||
result.setParameters(this.sampleRate, this.sequenceMs, this.seekWindowMs, this.overlapMs); | ||
return result; | ||
} | ||
}, { | ||
key: "seekBestOverlapPosition", | ||
value: function seekBestOverlapPosition() { | ||
return this._quickSeek ? this.seekBestOverlapPositionStereoQuick() : this.seekBestOverlapPositionStereo(); | ||
} | ||
}, { | ||
key: "seekBestOverlapPositionStereo", | ||
value: function seekBestOverlapPositionStereo() { | ||
var bestOffset; | ||
var bestCorrelation; | ||
var correlation; | ||
var i = 0; | ||
this.preCalculateCorrelationReferenceStereo(); | ||
bestOffset = 0; | ||
bestCorrelation = Number.MIN_VALUE; | ||
for (; i < this.seekLength; i = i + 1) { | ||
correlation = this.calculateCrossCorrelationStereo(2 * i, this.refMidBuffer); | ||
if (correlation > bestCorrelation) { | ||
bestCorrelation = correlation; | ||
bestOffset = i; | ||
} | ||
} | ||
return bestOffset; | ||
} | ||
}, { | ||
key: "seekBestOverlapPositionStereoQuick", | ||
value: function seekBestOverlapPositionStereoQuick() { | ||
var bestOffset; | ||
var bestCorrelation; | ||
var correlation; | ||
var scanCount = 0; | ||
var correlationOffset; | ||
var tempOffset; | ||
this.preCalculateCorrelationReferenceStereo(); | ||
bestCorrelation = Number.MIN_VALUE; | ||
bestOffset = 0; | ||
correlationOffset = 0; | ||
tempOffset = 0; | ||
for (; scanCount < 4; scanCount = scanCount + 1) { | ||
var j = 0; | ||
while (_SCAN_OFFSETS[scanCount][j]) { | ||
tempOffset = correlationOffset + _SCAN_OFFSETS[scanCount][j]; | ||
if (tempOffset >= this.seekLength) { | ||
break; | ||
} | ||
correlation = this.calculateCrossCorrelationStereo(2 * tempOffset, this.refMidBuffer); | ||
if (correlation > bestCorrelation) { | ||
bestCorrelation = correlation; | ||
bestOffset = tempOffset; | ||
} | ||
j = j + 1; | ||
} | ||
correlationOffset = bestOffset; | ||
} | ||
return bestOffset; | ||
} | ||
}, { | ||
key: "preCalculateCorrelationReferenceStereo", | ||
value: function preCalculateCorrelationReferenceStereo() { | ||
var i = 0; | ||
var context; | ||
var temp; | ||
for (; i < this.overlapLength; i = i + 1) { | ||
temp = i * (this.overlapLength - i); | ||
context = i * 2; | ||
this.refMidBuffer[context] = this.midBuffer[context] * temp; | ||
this.refMidBuffer[context + 1] = this.midBuffer[context + 1] * temp; | ||
} | ||
} | ||
}, { | ||
key: "calculateCrossCorrelationStereo", | ||
value: function calculateCrossCorrelationStereo(mixingPosition, compare) { | ||
var mixing = this._inputBuffer.vector; | ||
mixingPosition += this._inputBuffer.startIndex; | ||
var correlation = 0; | ||
var i = 2; | ||
var calcLength = 2 * this.overlapLength; | ||
var mixingOffset; | ||
for (; i < calcLength; i = i + 2) { | ||
mixingOffset = i + mixingPosition; | ||
correlation += mixing[mixingOffset] * compare[i] + mixing[mixingOffset + 1] * compare[i + 1]; | ||
} | ||
return correlation; | ||
} | ||
}, { | ||
key: "overlap", | ||
value: function overlap(overlapPosition) { | ||
this.overlapStereo(2 * overlapPosition); | ||
} | ||
}, { | ||
key: "overlapStereo", | ||
value: function overlapStereo(inputPosition) { | ||
var input = this._inputBuffer.vector; | ||
inputPosition += this._inputBuffer.startIndex; | ||
var output = this._outputBuffer.vector; | ||
var outputPosition = this._outputBuffer.endIndex; | ||
var i = 0; | ||
var context; | ||
var tempFrame; | ||
var frameScale = 1 / this.overlapLength; | ||
var fi; | ||
var inputOffset; | ||
var outputOffset; | ||
for (; i < this.overlapLength; i = i + 1) { | ||
tempFrame = (this.overlapLength - i) * frameScale; | ||
fi = i * frameScale; | ||
context = 2 * i; | ||
inputOffset = context + inputPosition; | ||
outputOffset = context + outputPosition; | ||
output[outputOffset + 0] = input[inputOffset + 0] * fi + this.midBuffer[context + 0] * tempFrame; | ||
output[outputOffset + 1] = input[inputOffset + 1] * fi + this.midBuffer[context + 1] * tempFrame; | ||
} | ||
} | ||
}, { | ||
key: "process", | ||
value: function process() { | ||
var offset; | ||
var temp; | ||
var overlapSkip; | ||
if (this.midBuffer === null) { | ||
if (this._inputBuffer.frameCount < this.overlapLength) { | ||
return; | ||
} | ||
this.midBuffer = new Float32Array(this.overlapLength * 2); | ||
this._inputBuffer.receiveSamples(this.midBuffer, this.overlapLength); | ||
} | ||
while (this._inputBuffer.frameCount >= this.sampleReq) { | ||
offset = this.seekBestOverlapPosition(); | ||
this._outputBuffer.ensureAdditionalCapacity(this.overlapLength); | ||
this.overlap(Math.floor(offset)); | ||
this._outputBuffer.put(this.overlapLength); | ||
temp = this.seekWindowLength - 2 * this.overlapLength; | ||
if (temp > 0) { | ||
this._outputBuffer.putBuffer(this._inputBuffer, offset + this.overlapLength, temp); | ||
} | ||
var start = this._inputBuffer.startIndex + 2 * (offset + this.seekWindowLength - this.overlapLength); | ||
this.midBuffer.set(this._inputBuffer.vector.subarray(start, start + 2 * this.overlapLength)); | ||
this.skipFract += this.nominalSkip; | ||
overlapSkip = Math.floor(this.skipFract); | ||
this.skipFract -= overlapSkip; | ||
this._inputBuffer.receive(overlapSkip); | ||
} | ||
} | ||
}, { | ||
key: "tempo", | ||
set: function set(newTempo) { | ||
var intskip; | ||
this._tempo = newTempo; | ||
this.calculateSequenceParameters(); | ||
this.nominalSkip = this._tempo * (this.seekWindowLength - this.overlapLength); | ||
this.skipFract = 0; | ||
intskip = Math.floor(this.nominalSkip + 0.5); | ||
this.sampleReq = Math.max(intskip + this.overlapLength, this.seekWindowLength) + this.seekLength; | ||
}, | ||
get: function get() { | ||
return this._tempo; | ||
} | ||
}, { | ||
key: "inputChunkSize", | ||
get: function get() { | ||
return this.sampleReq; | ||
} | ||
}, { | ||
key: "outputChunkSize", | ||
get: function get() { | ||
return this.overlapLength + Math.max(0, this.seekWindowLength - 2 * this.overlapLength); | ||
} | ||
}, { | ||
key: "quickSeek", | ||
set: function set(enable) { | ||
this._quickSeek = enable; | ||
} | ||
}]); | ||
return Stretch; | ||
}(AbstractFifoSamplePipe); | ||
var testFloatEqual = function testFloatEqual(a, b) { | ||
return (a > b ? a - b : b - a) > 1e-10; | ||
}; | ||
var SoundTouch = function () { | ||
function SoundTouch() { | ||
_classCallCheck(this, SoundTouch); | ||
this.transposer = new RateTransposer(false); | ||
this.stretch = new Stretch(false); | ||
this._inputBuffer = new FifoSampleBuffer(); | ||
this._intermediateBuffer = new FifoSampleBuffer(); | ||
this._outputBuffer = new FifoSampleBuffer(); | ||
this._rate = 0; | ||
this._tempo = 0; | ||
this.virtualPitch = 1.0; | ||
this.virtualRate = 1.0; | ||
this.virtualTempo = 1.0; | ||
this.calculateEffectiveRateAndTempo(); | ||
} | ||
_createClass(SoundTouch, [{ | ||
key: "clear", | ||
value: function clear() { | ||
this.transposer.clear(); | ||
this.stretch.clear(); | ||
} | ||
}, { | ||
key: "clone", | ||
value: function clone() { | ||
var result = new SoundTouch(); | ||
result.rate = this.rate; | ||
result.tempo = this.tempo; | ||
return result; | ||
} | ||
}, { | ||
key: "calculateEffectiveRateAndTempo", | ||
value: function calculateEffectiveRateAndTempo() { | ||
var previousTempo = this._tempo; | ||
var previousRate = this._rate; | ||
this._tempo = this.virtualTempo / this.virtualPitch; | ||
this._rate = this.virtualRate * this.virtualPitch; | ||
if (testFloatEqual(this._tempo, previousTempo)) { | ||
this.stretch.tempo = this._tempo; | ||
} | ||
if (testFloatEqual(this._rate, previousRate)) { | ||
this.transposer.rate = this._rate; | ||
} | ||
if (this._rate > 1.0) { | ||
if (this._outputBuffer != this.transposer.outputBuffer) { | ||
this.stretch.inputBuffer = this._inputBuffer; | ||
this.stretch.outputBuffer = this._intermediateBuffer; | ||
this.transposer.inputBuffer = this._intermediateBuffer; | ||
this.transposer.outputBuffer = this._outputBuffer; | ||
} | ||
} else { | ||
if (this._outputBuffer != this.stretch.outputBuffer) { | ||
this.transposer.inputBuffer = this._inputBuffer; | ||
this.transposer.outputBuffer = this._intermediateBuffer; | ||
this.stretch.inputBuffer = this._intermediateBuffer; | ||
this.stretch.outputBuffer = this._outputBuffer; | ||
} | ||
} | ||
} | ||
}, { | ||
key: "process", | ||
value: function process() { | ||
if (this._rate > 1.0) { | ||
this.stretch.process(); | ||
this.transposer.process(); | ||
} else { | ||
this.transposer.process(); | ||
this.stretch.process(); | ||
} | ||
} | ||
}, { | ||
key: "rate", | ||
get: function get() { | ||
return this._rate; | ||
}, | ||
set: function set(rate) { | ||
this.virtualRate = rate; | ||
this.calculateEffectiveRateAndTempo(); | ||
} | ||
}, { | ||
key: "rateChange", | ||
set: function set(rateChange) { | ||
this._rate = 1.0 + 0.01 * rateChange; | ||
} | ||
}, { | ||
key: "tempo", | ||
get: function get() { | ||
return this._tempo; | ||
}, | ||
set: function set(tempo) { | ||
this.virtualTempo = tempo; | ||
this.calculateEffectiveRateAndTempo(); | ||
} | ||
}, { | ||
key: "tempoChange", | ||
set: function set(tempoChange) { | ||
this.tempo = 1.0 + 0.01 * tempoChange; | ||
} | ||
}, { | ||
key: "pitch", | ||
set: function set(pitch) { | ||
this.virtualPitch = pitch; | ||
this.calculateEffectiveRateAndTempo(); | ||
} | ||
}, { | ||
key: "pitchOctaves", | ||
set: function set(pitchOctaves) { | ||
this.pitch = Math.exp(0.69314718056 * pitchOctaves); | ||
this.calculateEffectiveRateAndTempo(); | ||
} | ||
}, { | ||
key: "pitchSemitones", | ||
set: function set(pitchSemitones) { | ||
this.pitchOctaves = pitchSemitones / 12.0; | ||
} | ||
}, { | ||
key: "inputBuffer", | ||
get: function get() { | ||
return this._inputBuffer; | ||
} | ||
}, { | ||
key: "outputBuffer", | ||
get: function get() { | ||
return this._outputBuffer; | ||
} | ||
}]); | ||
return SoundTouch; | ||
}(); | ||
var WebAudioBufferSource = function () { | ||
function WebAudioBufferSource(buffer) { | ||
_classCallCheck(this, WebAudioBufferSource); | ||
this.buffer = buffer; | ||
this._position = 0; | ||
} | ||
_createClass(WebAudioBufferSource, [{ | ||
key: "extract", | ||
value: function extract(target) { | ||
var numFrames = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0; | ||
var position = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0; | ||
this.position = position; | ||
var left = this.buffer.getChannelData(0); | ||
var right = this.dualChannel ? this.buffer.getChannelData(1) : this.buffer.getChannelData(0); | ||
var i = 0; | ||
for (; i < numFrames; i++) { | ||
target[i * 2] = left[i + position]; | ||
target[i * 2 + 1] = right[i + position]; | ||
} | ||
return Math.min(numFrames, left.length - position); | ||
} | ||
}, { | ||
key: "dualChannel", | ||
get: function get() { | ||
return this.buffer.numberOfChannels > 1; | ||
} | ||
}, { | ||
key: "position", | ||
get: function get() { | ||
return this._position; | ||
}, | ||
set: function set(value) { | ||
this._position = value; | ||
} | ||
}]); | ||
return WebAudioBufferSource; | ||
}(); | ||
var getWebAudioNode = function getWebAudioNode(context, filter) { | ||
var sourcePositionCallback = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : noop; | ||
var bufferSize = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 4096; | ||
var node = context.createScriptProcessor(bufferSize, 2, 2); | ||
var samples = new Float32Array(bufferSize * 2); | ||
node.onaudioprocess = function (event) { | ||
var left = event.outputBuffer.getChannelData(0); | ||
var right = event.outputBuffer.getChannelData(1); | ||
var framesExtracted = filter.extract(samples, bufferSize); | ||
sourcePositionCallback(filter.sourcePosition); | ||
if (framesExtracted === 0) { | ||
filter.onEnd(); | ||
} | ||
var i = 0; | ||
for (; i < framesExtracted; i++) { | ||
left[i] = samples[i * 2]; | ||
right[i] = samples[i * 2 + 1]; | ||
} | ||
}; | ||
return node; | ||
}; | ||
var pad = function pad(n, width, z) { | ||
z = z || '0'; | ||
n = n + ''; | ||
return n.length >= width ? n : new Array(width - n.length + 1).join(z) + n; | ||
}; | ||
var minsSecs = function minsSecs(secs) { | ||
var mins = Math.floor(secs / 60); | ||
var seconds = secs - mins * 60; | ||
return "".concat(mins, ":").concat(pad(parseInt(seconds), 2)); | ||
}; | ||
var onUpdate = function onUpdate(sourcePosition) { | ||
var currentTimePlayed = this.timePlayed; | ||
var sampleRate = this.sampleRate; | ||
this.sourcePosition = sourcePosition; | ||
this.timePlayed = sourcePosition / sampleRate; | ||
if (currentTimePlayed !== this.timePlayed) { | ||
var timePlayed = new CustomEvent('play', { | ||
detail: { | ||
timePlayed: this.timePlayed, | ||
formattedTimePlayed: this.formattedTimePlayed, | ||
percentagePlayed: this.percentagePlayed | ||
} | ||
}); | ||
this._node.dispatchEvent(timePlayed); | ||
} | ||
}; | ||
var PitchShifter = function () { | ||
function PitchShifter(context, buffer, bufferSize) { | ||
var _this4 = this; | ||
var onEnd = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : noop; | ||
_classCallCheck(this, PitchShifter); | ||
this._soundtouch = new SoundTouch(); | ||
var source = new WebAudioBufferSource(buffer); | ||
this.timePlayed = 0; | ||
this.sourcePosition = 0; | ||
this._filter = new SimpleFilter(source, this._soundtouch, onEnd); | ||
this._node = getWebAudioNode(context, this._filter, function (sourcePostion) { | ||
return onUpdate.call(_this4, sourcePostion); | ||
}, bufferSize); | ||
this.tempo = 1; | ||
this.rate = 1; | ||
this.duration = buffer.duration; | ||
this.sampleRate = context.sampleRate; | ||
this.listeners = []; | ||
} | ||
_createClass(PitchShifter, [{ | ||
key: "connect", | ||
value: function connect(toNode) { | ||
this._node.connect(toNode); | ||
} | ||
}, { | ||
key: "disconnect", | ||
value: function disconnect() { | ||
this._node.disconnect(); | ||
} | ||
}, { | ||
key: "on", | ||
value: function on(eventName, cb) { | ||
this.listeners.push({ | ||
name: eventName, | ||
cb: cb | ||
}); | ||
this._node.addEventListener(eventName, function (event) { | ||
return cb(event.detail); | ||
}); | ||
} | ||
}, { | ||
key: "off", | ||
value: function off() { | ||
var _this5 = this; | ||
var eventName = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null; | ||
var listeners = this.listeners; | ||
if (eventName) { | ||
listeners = listeners.filter(function (e) { | ||
return e.name === eventName; | ||
}); | ||
} | ||
listeners.forEach(function (e) { | ||
_this5._node.removeEventListener(e.name, function (event) { | ||
return e.cb(event.detail); | ||
}); | ||
}); | ||
} | ||
}, { | ||
key: "formattedDuration", | ||
get: function get() { | ||
return minsSecs(this.duration); | ||
} | ||
}, { | ||
key: "formattedTimePlayed", | ||
get: function get() { | ||
return minsSecs(this.timePlayed); | ||
} | ||
}, { | ||
key: "percentagePlayed", | ||
get: function get() { | ||
return 100 * this._filter.sourcePosition / (this.duration * this.sampleRate); | ||
}, | ||
set: function set(perc) { | ||
this._filter.sourcePosition = parseInt(perc * this.duration * this.sampleRate); | ||
this.sourcePosition = this._filter.sourcePosition; | ||
this.timePlayed = this.sourcePosition / this.sampleRate; | ||
} | ||
}, { | ||
key: "node", | ||
get: function get() { | ||
return this._node; | ||
} | ||
}, { | ||
key: "pitch", | ||
set: function set(pitch) { | ||
this._soundtouch.pitch = pitch; | ||
} | ||
}, { | ||
key: "pitchSemitones", | ||
set: function set(semitone) { | ||
this._soundtouch.pitchSemitones = semitone; | ||
} | ||
}, { | ||
key: "rate", | ||
set: function set(rate) { | ||
this._soundtouch.rate = rate; | ||
} | ||
}, { | ||
key: "tempo", | ||
set: function set(tempo) { | ||
this._soundtouch.tempo = tempo; | ||
} | ||
}]); | ||
return PitchShifter; | ||
}(); | ||
var ProcessAudioBufferSource = function () { | ||
function ProcessAudioBufferSource(bufferProps, leftChannel, rightChannel) { | ||
_classCallCheck(this, ProcessAudioBufferSource); | ||
Object.assign(this, bufferProps); | ||
this.leftChannel = leftChannel; | ||
this.rightChannel = rightChannel; | ||
this._position = 0; | ||
} | ||
_createClass(ProcessAudioBufferSource, [{ | ||
key: "extract", | ||
value: function extract(target) { | ||
var numFrames = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0; | ||
var position = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0; | ||
this.position = position; | ||
var i = 0; | ||
for (; i < numFrames; i++) { | ||
target[i * 2] = this.leftChannel[i + position]; | ||
target[i * 2 + 1] = this.rightChannel[i + position]; | ||
} | ||
return Math.min(numFrames, this.leftChannel.length - position); | ||
} | ||
}, { | ||
key: "position", | ||
get: function get() { | ||
return this._position; | ||
}, | ||
set: function set(value) { | ||
this._position = value; | ||
} | ||
}]); | ||
return ProcessAudioBufferSource; | ||
}(); | ||
var SoundTouchWorklet = function (_AudioWorkletProcesso) { | ||
_inherits(SoundTouchWorklet, _AudioWorkletProcesso); | ||
var _super = _createSuper(SoundTouchWorklet); | ||
function SoundTouchWorklet(nodeOptions) { | ||
var _this; | ||
_classCallCheck(this, SoundTouchWorklet); | ||
_this = _super.call(this); | ||
_this._initialized = false; | ||
_this.bufferSize = 128; | ||
_this.port.onmessage = _this._messageProcessor.bind(_assertThisInitialized(_this)); | ||
_this.port.postMessage({ | ||
message: 'PROCESSOR_CONSTRUCTOR', | ||
detail: nodeOptions | ||
}); | ||
return _this; | ||
} | ||
_createClass(SoundTouchWorklet, [{ | ||
key: "_messageProcessor", | ||
value: function _messageProcessor(eventFromWorker) { | ||
var _eventFromWorker$data = eventFromWorker.data, | ||
message = _eventFromWorker$data.message, | ||
detail = _eventFromWorker$data.detail; | ||
if (message === 'INITIALIZE_PROCESSOR') { | ||
var _detail = _slicedToArray(detail, 3), | ||
bufferProps = _detail[0], | ||
leftChannel = _detail[1], | ||
rightChannel = _detail[2]; | ||
this.bufferSource = new ProcessAudioBufferSource(bufferProps, leftChannel, rightChannel); | ||
this._samples = new Float32Array(this.bufferSize * 2); | ||
this._pipe = new SoundTouch(); | ||
this._filter = new SimpleFilter(this.bufferSource, this._pipe); | ||
this.port.postMessage({ | ||
message: 'PROCESSOR_READY' | ||
}); | ||
this._initialized = true; | ||
return true; | ||
} | ||
if (message === 'SET_PIPE_PROP' && detail) { | ||
var name = detail.name, | ||
value = detail.value; | ||
this._pipe[name] = value; | ||
this.port.postMessage({ | ||
message: 'PIPE_PROP_CHANGED', | ||
detail: "Updated ".concat(name, " to ").concat(this._pipe[name], "\ntypeof ").concat(_typeof(value)) | ||
}); | ||
return; | ||
} | ||
if (message === 'SET_FILTER_PROP' && detail) { | ||
var _name = detail.name, | ||
_value = detail.value; | ||
this._filter[_name] = _value; | ||
this.port.postMessage({ | ||
message: 'FILTER_PROP_CHANGED', | ||
detail: "Updated ".concat(_name, " to ").concat(this._filter[_name], "\ntypeof ").concat(_typeof(_value)) | ||
}); | ||
return; | ||
} | ||
console.log('[PitchShifterWorkletProcessor] Unknown message: ', eventFromWorker); | ||
} | ||
}, { | ||
key: "_sendMessage", | ||
value: function _sendMessage(message) { | ||
var detail = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; | ||
if (!message) { | ||
return; | ||
} | ||
this.port.postMessage({ | ||
message: message, | ||
detail: detail | ||
}); | ||
} | ||
}, { | ||
key: "process", | ||
value: function process(inputs, outputs) { | ||
if (!this._initialized || !inputs[0].length) { | ||
return true; | ||
} | ||
var left = outputs[0][0]; | ||
var right = outputs[0][1]; | ||
var samples = this._samples; | ||
if (!left || left && !left.length) { | ||
return false; | ||
} | ||
var framesExtracted = this._filter.extract(samples, inputs[0][0].length); | ||
if (!framesExtracted) { | ||
this._sendMessage('PROCESSOR_END'); | ||
return false; | ||
} | ||
this._sendMessage('SOURCEPOSITION', this._filter.sourcePosition); | ||
var i = 0; | ||
for (; i < framesExtracted; i = i + 1) { | ||
left[i] = samples[i * 2]; | ||
right[i] = samples[i * 2 + 1]; | ||
} | ||
return true; | ||
} | ||
}]); | ||
return SoundTouchWorklet; | ||
}( _wrapNativeSuper(AudioWorkletProcessor)); | ||
registerProcessor('soundtouch-worklet', SoundTouchWorklet); |
{ | ||
"name": "@soundtouchjs/audio-worklet", | ||
"version": "0.1.5", | ||
"version": "0.1.6", | ||
"description": "An ES2015+ AudioWorklet implementation of the SoundTouchJS library", | ||
@@ -41,24 +41,24 @@ "module": "dist/soundtouch-audio-node.js", | ||
"devDependencies": { | ||
"@babel/cli": "^7.8.4", | ||
"@babel/core": "7.9.6", | ||
"@babel/plugin-external-helpers": "7.8.3", | ||
"@babel/preset-env": "7.9.6", | ||
"@commitlint/cli": "8.3.5", | ||
"@commitlint/config-conventional": "8.3.4", | ||
"@rollup/plugin-babel": "5.0.0", | ||
"@rollup/plugin-commonjs": "11.1.0", | ||
"@rollup/plugin-node-resolve": "7.1.3", | ||
"@babel/cli": "7.10.5", | ||
"@babel/core": "7.10.5", | ||
"@babel/plugin-external-helpers": "7.10.4", | ||
"@babel/preset-env": "7.10.4", | ||
"@commitlint/cli": "9.1.1", | ||
"@commitlint/config-conventional": "9.1.1", | ||
"@rollup/plugin-babel": "5.1.0", | ||
"@rollup/plugin-commonjs": "14.0.0", | ||
"@rollup/plugin-node-resolve": "8.4.0", | ||
"connect": "3.7.0", | ||
"git-branch-is": "3.1.0", | ||
"husky": "4.2.5", | ||
"open": "7.1.0", | ||
"prettier": "2.0.5", | ||
"regenerator-runtime": "0.13.5", | ||
"rollup": "^2.7.5", | ||
"rollup": "2.22.1", | ||
"rollup-plugin-cleanup": "3.1.1", | ||
"rollup-plugin-clear": "2.0.7", | ||
"rollup-plugin-eslint": "7.0.0", | ||
"rollup-plugin-terser": "5.3.0", | ||
"serve-static": "1.14.1", | ||
"soundtouchjs": "0.1.20", | ||
"standard-version": "7.1.0" | ||
"soundtouchjs": "0.1.22", | ||
"standard-version": "8.0.2" | ||
}, | ||
@@ -65,0 +65,0 @@ "prettier": { |
@@ -7,3 +7,2 @@ import path from 'path'; | ||
import cleanup from 'rollup-plugin-cleanup'; | ||
import { terser } from 'rollup-plugin-terser'; | ||
import pkg from '../package.json'; | ||
@@ -43,3 +42,3 @@ | ||
banner: banner, | ||
sourcemap: false, | ||
sourcemap: true, | ||
exports: 'named', | ||
@@ -58,7 +57,2 @@ }, | ||
}), | ||
terser({ | ||
module: true, | ||
sourcemap: true, | ||
output: { comments: 'all' }, | ||
}), | ||
cleanup(), | ||
@@ -87,7 +81,2 @@ ], | ||
}), | ||
terser({ | ||
toplevel: true, | ||
sourcemap: true, | ||
output: { comments: 'all' }, | ||
}), | ||
cleanup(), | ||
@@ -94,0 +83,0 @@ ], |
const connect = require('connect'); | ||
const path = require('path'); | ||
const serveStatic = require('serve-static'); | ||
const open = require('open'); | ||
@@ -20,4 +21,5 @@ const port = 8081; | ||
.use(serveStatic(path.join(__dirname, '../public'))) | ||
.listen(8081, function () { | ||
.listen(port, function () { | ||
console.log(`Go to http://localhost:${port}`); | ||
open(`http://localhost:${port}`); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1873970
13
2576
4