UNPKG

synth-js

Version:

high performance MIDI parser and WAV encoder

4 lines (3 loc) 39.9 kB
!function(t){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var e;e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,e.synth=t()}}(function(){return function(){function t(e,r,n){function i(a,s){if(!r[a]){if(!e[a]){var u="function"==typeof require&&require;if(!s&&u)return u(a,!0);if(o)return o(a,!0);var f=new Error("Cannot find module '"+a+"'");throw f.code="MODULE_NOT_FOUND",f}var h=r[a]={exports:{}};e[a][0].call(h.exports,function(t){return i(e[a][1][t]||t)},h,h.exports,t,e,r,n)}return r[a].exports}for(var o="function"==typeof require&&require,a=0;a<n.length;a++)i(n[a]);return i}return t}()({1:[function(t,e,r){"use strict";e.exports={WAV:t("./src/wav"),MIDIStream:t("./src/midi"),midiToWav:t("./src/midi2wav")}},{"./src/midi":5,"./src/midi2wav":6,"./src/wav":8}],2:[function(t,e,r){"use strict";function n(t){var e=t.length;if(e%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var r=t.indexOf("=");return-1===r&&(r=e),[r,r===e?0:4-r%4]}function i(t){var e=n(t),r=e[0],i=e[1];return 3*(r+i)/4-i}function o(t,e,r){return 3*(e+r)/4-r}function a(t){var e,r,i=n(t),a=i[0],s=i[1],u=new c(o(t,a,s)),f=0,h=s>0?a-4:a;for(r=0;r<h;r+=4)e=l[t.charCodeAt(r)]<<18|l[t.charCodeAt(r+1)]<<12|l[t.charCodeAt(r+2)]<<6|l[t.charCodeAt(r+3)],u[f++]=e>>16&255,u[f++]=e>>8&255,u[f++]=255&e;return 2===s&&(e=l[t.charCodeAt(r)]<<2|l[t.charCodeAt(r+1)]>>4,u[f++]=255&e),1===s&&(e=l[t.charCodeAt(r)]<<10|l[t.charCodeAt(r+1)]<<4|l[t.charCodeAt(r+2)]>>2,u[f++]=e>>8&255,u[f++]=255&e),u}function s(t){return h[t>>18&63]+h[t>>12&63]+h[t>>6&63]+h[63&t]}function u(t,e,r){for(var n,i=[],o=e;o<r;o+=3)n=(t[o]<<16&16711680)+(t[o+1]<<8&65280)+(255&t[o+2]),i.push(s(n));return i.join("")}function f(t){for(var e,r=t.length,n=r%3,i=[],o=0,a=r-n;o<a;o+=16383)i.push(u(t,o,o+16383>a?a:o+16383));return 1===n?(e=t[r-1],i.push(h[e>>2]+h[e<<4&63]+"==")):2===n&&(e=(t[r-2]<<8)+t[r-1],i.push(h[e>>10]+h[e>>4&63]+h[e<<2&63]+"=")),i.join("")}r.byteLength=i,r.toByteArray=a,r.fromByteArray=f;for(var h=[],l=[],c="undefined"!=typeof Uint8Array?Uint8Array:Array,p="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",y=0,d=p.length;y<d;++y)h[y]=p[y],l[p.charCodeAt(y)]=y;l["-".charCodeAt(0)]=62,l["_".charCodeAt(0)]=63},{}],3:[function(t,e,r){(function(e){"use strict";function n(t){if(t>J)throw new RangeError('The value "'+t+'" is invalid for option "size"');var r=new Uint8Array(t);return Object.setPrototypeOf(r,e.prototype),r}function e(t,e,r){if("number"==typeof t){if("string"==typeof e)throw new TypeError('The "string" argument must be of type string. Received type number');return s(t)}return i(t,e,r)}function i(t,r,n){if("string"==typeof t)return u(t,r);if(ArrayBuffer.isView(t))return f(t);if(null==t)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof t);if(q(t,ArrayBuffer)||t&&q(t.buffer,ArrayBuffer))return h(t,r,n);if("undefined"!=typeof SharedArrayBuffer&&(q(t,SharedArrayBuffer)||t&&q(t.buffer,SharedArrayBuffer)))return h(t,r,n);if("number"==typeof t)throw new TypeError('The "value" argument must not be of type number. Received type number');var i=t.valueOf&&t.valueOf();if(null!=i&&i!==t)return e.from(i,r,n);var o=l(t);if(o)return o;if("undefined"!=typeof Symbol&&null!=Symbol.toPrimitive&&"function"==typeof t[Symbol.toPrimitive])return e.from(t[Symbol.toPrimitive]("string"),r,n);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof t)}function o(t){if("number"!=typeof t)throw new TypeError('"size" argument must be of type number');if(t<0)throw new RangeError('The value "'+t+'" is invalid for option "size"')}function a(t,e,r){return o(t),t<=0?n(t):void 0!==e?"string"==typeof r?n(t).fill(e,r):n(t).fill(e):n(t)}function s(t){return o(t),n(t<0?0:0|c(t))}function u(t,r){if("string"==typeof r&&""!==r||(r="utf8"),!e.isEncoding(r))throw new TypeError("Unknown encoding: "+r);var i=0|y(t,r),o=n(i),a=o.write(t,r);return a!==i&&(o=o.slice(0,a)),o}function f(t){for(var e=t.length<0?0:0|c(t.length),r=n(e),i=0;i<e;i+=1)r[i]=255&t[i];return r}function h(t,r,n){if(r<0||t.byteLength<r)throw new RangeError('"offset" is outside of buffer bounds');if(t.byteLength<r+(n||0))throw new RangeError('"length" is outside of buffer bounds');var i;return i=void 0===r&&void 0===n?new Uint8Array(t):void 0===n?new Uint8Array(t,r):new Uint8Array(t,r,n),Object.setPrototypeOf(i,e.prototype),i}function l(t){if(e.isBuffer(t)){var r=0|c(t.length),i=n(r);return 0===i.length?i:(t.copy(i,0,0,r),i)}return void 0!==t.length?"number"!=typeof t.length||W(t.length)?n(0):f(t):"Buffer"===t.type&&Array.isArray(t.data)?f(t.data):void 0}function c(t){if(t>=J)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+J.toString(16)+" bytes");return 0|t}function p(t){return+t!=t&&(t=0),e.alloc(+t)}function y(t,r){if(e.isBuffer(t))return t.length;if(ArrayBuffer.isView(t)||q(t,ArrayBuffer))return t.byteLength;if("string"!=typeof t)throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof t);var n=t.length,i=arguments.length>2&&!0===arguments[2];if(!i&&0===n)return 0;for(var o=!1;;)switch(r){case"ascii":case"latin1":case"binary":return n;case"utf8":case"utf-8":return j(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*n;case"hex":return n>>>1;case"base64":return _(t).length;default:if(o)return i?-1:j(t).length;r=(""+r).toLowerCase(),o=!0}}function d(t,e,r){var n=!1;if((void 0===e||e<0)&&(e=0),e>this.length)return"";if((void 0===r||r>this.length)&&(r=this.length),r<=0)return"";if(r>>>=0,e>>>=0,r<=e)return"";for(t||(t="utf8");;)switch(t){case"hex":return I(this,e,r);case"utf8":case"utf-8":return B(this,e,r);case"ascii":return C(this,e,r);case"latin1":case"binary":return O(this,e,r);case"base64":return A(this,e,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return M(this,e,r);default:if(n)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),n=!0}}function g(t,e,r){var n=t[e];t[e]=t[r],t[r]=n}function v(t,r,n,i,o){if(0===t.length)return-1;if("string"==typeof n?(i=n,n=0):n>2147483647?n=2147483647:n<-2147483648&&(n=-2147483648),n=+n,W(n)&&(n=o?0:t.length-1),n<0&&(n=t.length+n),n>=t.length){if(o)return-1;n=t.length-1}else if(n<0){if(!o)return-1;n=0}if("string"==typeof r&&(r=e.from(r,i)),e.isBuffer(r))return 0===r.length?-1:b(t,r,n,i,o);if("number"==typeof r)return r&=255,"function"==typeof Uint8Array.prototype.indexOf?o?Uint8Array.prototype.indexOf.call(t,r,n):Uint8Array.prototype.lastIndexOf.call(t,r,n):b(t,[r],n,i,o);throw new TypeError("val must be string, number or Buffer")}function b(t,e,r,n,i){function o(t,e){return 1===a?t[e]:t.readUInt16BE(e*a)}var a=1,s=t.length,u=e.length;if(void 0!==n&&("ucs2"===(n=String(n).toLowerCase())||"ucs-2"===n||"utf16le"===n||"utf-16le"===n)){if(t.length<2||e.length<2)return-1;a=2,s/=2,u/=2,r/=2}var f;if(i){var h=-1;for(f=r;f<s;f++)if(o(t,f)===o(e,-1===h?0:f-h)){if(-1===h&&(h=f),f-h+1===u)return h*a}else-1!==h&&(f-=f-h),h=-1}else for(r+u>s&&(r=s-u),f=r;f>=0;f--){for(var l=!0,c=0;c<u;c++)if(o(t,f+c)!==o(e,c)){l=!1;break}if(l)return f}return-1}function w(t,e,r,n){r=Number(r)||0;var i=t.length-r;n?(n=Number(n))>i&&(n=i):n=i;var o=e.length;n>o/2&&(n=o/2);for(var a=0;a<n;++a){var s=parseInt(e.substr(2*a,2),16);if(W(s))return a;t[r+a]=s}return a}function m(t,e,r,n){return V(j(e,t.length-r),t,r,n)}function k(t,e,r,n){return V(z(e),t,r,n)}function E(t,e,r,n){return k(t,e,r,n)}function S(t,e,r,n){return V(_(e),t,r,n)}function U(t,e,r,n){return V(F(e,t.length-r),t,r,n)}function A(t,e,r){return 0===e&&r===t.length?Y.fromByteArray(t):Y.fromByteArray(t.slice(e,r))}function B(t,e,r){r=Math.min(t.length,r);for(var n=[],i=e;i<r;){var o=t[i],a=null,s=o>239?4:o>223?3:o>191?2:1;if(i+s<=r){var u,f,h,l;switch(s){case 1:o<128&&(a=o);break;case 2:u=t[i+1],128==(192&u)&&(l=(31&o)<<6|63&u)>127&&(a=l);break;case 3:u=t[i+1],f=t[i+2],128==(192&u)&&128==(192&f)&&(l=(15&o)<<12|(63&u)<<6|63&f)>2047&&(l<55296||l>57343)&&(a=l);break;case 4:u=t[i+1],f=t[i+2],h=t[i+3],128==(192&u)&&128==(192&f)&&128==(192&h)&&(l=(15&o)<<18|(63&u)<<12|(63&f)<<6|63&h)>65535&&l<1114112&&(a=l)}}null===a?(a=65533,s=1):a>65535&&(a-=65536,n.push(a>>>10&1023|55296),a=56320|1023&a),n.push(a),i+=s}return T(n)}function T(t){var e=t.length;if(e<=Z)return String.fromCharCode.apply(String,t);for(var r="",n=0;n<e;)r+=String.fromCharCode.apply(String,t.slice(n,n+=Z));return r}function C(t,e,r){var n="";r=Math.min(t.length,r);for(var i=e;i<r;++i)n+=String.fromCharCode(127&t[i]);return n}function O(t,e,r){var n="";r=Math.min(t.length,r);for(var i=e;i<r;++i)n+=String.fromCharCode(t[i]);return n}function I(t,e,r){var n=t.length;(!e||e<0)&&(e=0),(!r||r<0||r>n)&&(r=n);for(var i="",o=e;o<r;++o)i+=H[t[o]];return i}function M(t,e,r){for(var n=t.slice(e,r),i="",o=0;o<n.length;o+=2)i+=String.fromCharCode(n[o]+256*n[o+1]);return i}function P(t,e,r){if(t%1!=0||t<0)throw new RangeError("offset is not uint");if(t+e>r)throw new RangeError("Trying to access beyond buffer length")}function R(t,r,n,i,o,a){if(!e.isBuffer(t))throw new TypeError('"buffer" argument must be a Buffer instance');if(r>o||r<a)throw new RangeError('"value" argument is out of bounds');if(n+i>t.length)throw new RangeError("Index out of range")}function x(t,e,r,n,i,o){if(r+n>t.length)throw new RangeError("Index out of range");if(r<0)throw new RangeError("Index out of range")}function L(t,e,r,n,i){return e=+e,r>>>=0,i||x(t,e,r,4,3.4028234663852886e38,-3.4028234663852886e38),G.write(t,e,r,n,23,4),r+4}function N(t,e,r,n,i){return e=+e,r>>>=0,i||x(t,e,r,8,1.7976931348623157e308,-1.7976931348623157e308),G.write(t,e,r,n,52,8),r+8}function D(t){if(t=t.split("=")[0],t=t.trim().replace($,""),t.length<2)return"";for(;t.length%4!=0;)t+="=";return t}function j(t,e){e=e||1/0;for(var r,n=t.length,i=null,o=[],a=0;a<n;++a){if((r=t.charCodeAt(a))>55295&&r<57344){if(!i){if(r>56319){(e-=3)>-1&&o.push(239,191,189);continue}if(a+1===n){(e-=3)>-1&&o.push(239,191,189);continue}i=r;continue}if(r<56320){(e-=3)>-1&&o.push(239,191,189),i=r;continue}r=65536+(i-55296<<10|r-56320)}else i&&(e-=3)>-1&&o.push(239,191,189);if(i=null,r<128){if((e-=1)<0)break;o.push(r)}else if(r<2048){if((e-=2)<0)break;o.push(r>>6|192,63&r|128)}else if(r<65536){if((e-=3)<0)break;o.push(r>>12|224,r>>6&63|128,63&r|128)}else{if(!(r<1114112))throw new Error("Invalid code point");if((e-=4)<0)break;o.push(r>>18|240,r>>12&63|128,r>>6&63|128,63&r|128)}}return o}function z(t){for(var e=[],r=0;r<t.length;++r)e.push(255&t.charCodeAt(r));return e}function F(t,e){for(var r,n,i,o=[],a=0;a<t.length&&!((e-=2)<0);++a)r=t.charCodeAt(a),n=r>>8,i=r%256,o.push(i),o.push(n);return o}function _(t){return Y.toByteArray(D(t))}function V(t,e,r,n){for(var i=0;i<n&&!(i+r>=e.length||i>=t.length);++i)e[i+r]=t[i];return i}function q(t,e){return t instanceof e||null!=t&&null!=t.constructor&&null!=t.constructor.name&&t.constructor.name===e.name}function W(t){return t!==t}var Y=t("base64-js"),G=t("ieee754"),X="function"==typeof Symbol&&"function"==typeof Symbol.for?Symbol.for("nodejs.util.inspect.custom"):null;r.Buffer=e,r.SlowBuffer=p,r.INSPECT_MAX_BYTES=50;var J=2147483647;r.kMaxLength=J,e.TYPED_ARRAY_SUPPORT=function(){try{var t=new Uint8Array(1),e={foo:function(){return 42}};return Object.setPrototypeOf(e,Uint8Array.prototype),Object.setPrototypeOf(t,e),42===t.foo()}catch(t){return!1}}(),e.TYPED_ARRAY_SUPPORT||"undefined"==typeof console||"function"!=typeof console.error||console.error("This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support."),Object.defineProperty(e.prototype,"parent",{enumerable:!0,get:function(){if(e.isBuffer(this))return this.buffer}}),Object.defineProperty(e.prototype,"offset",{enumerable:!0,get:function(){if(e.isBuffer(this))return this.byteOffset}}),e.poolSize=8192,e.from=function(t,e,r){return i(t,e,r)},Object.setPrototypeOf(e.prototype,Uint8Array.prototype),Object.setPrototypeOf(e,Uint8Array),e.alloc=function(t,e,r){return a(t,e,r)},e.allocUnsafe=function(t){return s(t)},e.allocUnsafeSlow=function(t){return s(t)},e.isBuffer=function(t){return null!=t&&!0===t._isBuffer&&t!==e.prototype},e.compare=function(t,r){if(q(t,Uint8Array)&&(t=e.from(t,t.offset,t.byteLength)),q(r,Uint8Array)&&(r=e.from(r,r.offset,r.byteLength)),!e.isBuffer(t)||!e.isBuffer(r))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(t===r)return 0;for(var n=t.length,i=r.length,o=0,a=Math.min(n,i);o<a;++o)if(t[o]!==r[o]){n=t[o],i=r[o];break}return n<i?-1:i<n?1:0},e.isEncoding=function(t){switch(String(t).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},e.concat=function(t,r){if(!Array.isArray(t))throw new TypeError('"list" argument must be an Array of Buffers');if(0===t.length)return e.alloc(0);var n;if(void 0===r)for(r=0,n=0;n<t.length;++n)r+=t[n].length;var i=e.allocUnsafe(r),o=0;for(n=0;n<t.length;++n){var a=t[n];if(q(a,Uint8Array)&&(a=e.from(a)),!e.isBuffer(a))throw new TypeError('"list" argument must be an Array of Buffers');a.copy(i,o),o+=a.length}return i},e.byteLength=y,e.prototype._isBuffer=!0,e.prototype.swap16=function(){var t=this.length;if(t%2!=0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(var e=0;e<t;e+=2)g(this,e,e+1);return this},e.prototype.swap32=function(){var t=this.length;if(t%4!=0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(var e=0;e<t;e+=4)g(this,e,e+3),g(this,e+1,e+2);return this},e.prototype.swap64=function(){var t=this.length;if(t%8!=0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(var e=0;e<t;e+=8)g(this,e,e+7),g(this,e+1,e+6),g(this,e+2,e+5),g(this,e+3,e+4);return this},e.prototype.toString=function(){var t=this.length;return 0===t?"":0===arguments.length?B(this,0,t):d.apply(this,arguments)},e.prototype.toLocaleString=e.prototype.toString,e.prototype.equals=function(t){if(!e.isBuffer(t))throw new TypeError("Argument must be a Buffer");return this===t||0===e.compare(this,t)},e.prototype.inspect=function(){var t="",e=r.INSPECT_MAX_BYTES;return t=this.toString("hex",0,e).replace(/(.{2})/g,"$1 ").trim(),this.length>e&&(t+=" ... "),"<Buffer "+t+">"},X&&(e.prototype[X]=e.prototype.inspect),e.prototype.compare=function(t,r,n,i,o){if(q(t,Uint8Array)&&(t=e.from(t,t.offset,t.byteLength)),!e.isBuffer(t))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof t);if(void 0===r&&(r=0),void 0===n&&(n=t?t.length:0),void 0===i&&(i=0),void 0===o&&(o=this.length),r<0||n>t.length||i<0||o>this.length)throw new RangeError("out of range index");if(i>=o&&r>=n)return 0;if(i>=o)return-1;if(r>=n)return 1;if(r>>>=0,n>>>=0,i>>>=0,o>>>=0,this===t)return 0;for(var a=o-i,s=n-r,u=Math.min(a,s),f=this.slice(i,o),h=t.slice(r,n),l=0;l<u;++l)if(f[l]!==h[l]){a=f[l],s=h[l];break}return a<s?-1:s<a?1:0},e.prototype.includes=function(t,e,r){return-1!==this.indexOf(t,e,r)},e.prototype.indexOf=function(t,e,r){return v(this,t,e,r,!0)},e.prototype.lastIndexOf=function(t,e,r){return v(this,t,e,r,!1)},e.prototype.write=function(t,e,r,n){if(void 0===e)n="utf8",r=this.length,e=0;else if(void 0===r&&"string"==typeof e)n=e,r=this.length,e=0;else{if(!isFinite(e))throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");e>>>=0,isFinite(r)?(r>>>=0,void 0===n&&(n="utf8")):(n=r,r=void 0)}var i=this.length-e;if((void 0===r||r>i)&&(r=i),t.length>0&&(r<0||e<0)||e>this.length)throw new RangeError("Attempt to write outside buffer bounds");n||(n="utf8");for(var o=!1;;)switch(n){case"hex":return w(this,t,e,r);case"utf8":case"utf-8":return m(this,t,e,r);case"ascii":return k(this,t,e,r);case"latin1":case"binary":return E(this,t,e,r);case"base64":return S(this,t,e,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return U(this,t,e,r);default:if(o)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),o=!0}},e.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};var Z=4096;e.prototype.slice=function(t,r){var n=this.length;t=~~t,r=void 0===r?n:~~r,t<0?(t+=n)<0&&(t=0):t>n&&(t=n),r<0?(r+=n)<0&&(r=0):r>n&&(r=n),r<t&&(r=t);var i=this.subarray(t,r);return Object.setPrototypeOf(i,e.prototype),i},e.prototype.readUIntLE=function(t,e,r){t>>>=0,e>>>=0,r||P(t,e,this.length);for(var n=this[t],i=1,o=0;++o<e&&(i*=256);)n+=this[t+o]*i;return n},e.prototype.readUIntBE=function(t,e,r){t>>>=0,e>>>=0,r||P(t,e,this.length);for(var n=this[t+--e],i=1;e>0&&(i*=256);)n+=this[t+--e]*i;return n},e.prototype.readUInt8=function(t,e){return t>>>=0,e||P(t,1,this.length),this[t]},e.prototype.readUInt16LE=function(t,e){return t>>>=0,e||P(t,2,this.length),this[t]|this[t+1]<<8},e.prototype.readUInt16BE=function(t,e){return t>>>=0,e||P(t,2,this.length),this[t]<<8|this[t+1]},e.prototype.readUInt32LE=function(t,e){return t>>>=0,e||P(t,4,this.length),(this[t]|this[t+1]<<8|this[t+2]<<16)+16777216*this[t+3]},e.prototype.readUInt32BE=function(t,e){return t>>>=0,e||P(t,4,this.length),16777216*this[t]+(this[t+1]<<16|this[t+2]<<8|this[t+3])},e.prototype.readIntLE=function(t,e,r){t>>>=0,e>>>=0,r||P(t,e,this.length);for(var n=this[t],i=1,o=0;++o<e&&(i*=256);)n+=this[t+o]*i;return i*=128,n>=i&&(n-=Math.pow(2,8*e)),n},e.prototype.readIntBE=function(t,e,r){t>>>=0,e>>>=0,r||P(t,e,this.length);for(var n=e,i=1,o=this[t+--n];n>0&&(i*=256);)o+=this[t+--n]*i;return i*=128,o>=i&&(o-=Math.pow(2,8*e)),o},e.prototype.readInt8=function(t,e){return t>>>=0,e||P(t,1,this.length),128&this[t]?-1*(255-this[t]+1):this[t]},e.prototype.readInt16LE=function(t,e){t>>>=0,e||P(t,2,this.length);var r=this[t]|this[t+1]<<8;return 32768&r?4294901760|r:r},e.prototype.readInt16BE=function(t,e){t>>>=0,e||P(t,2,this.length);var r=this[t+1]|this[t]<<8;return 32768&r?4294901760|r:r},e.prototype.readInt32LE=function(t,e){return t>>>=0,e||P(t,4,this.length),this[t]|this[t+1]<<8|this[t+2]<<16|this[t+3]<<24},e.prototype.readInt32BE=function(t,e){return t>>>=0,e||P(t,4,this.length),this[t]<<24|this[t+1]<<16|this[t+2]<<8|this[t+3]},e.prototype.readFloatLE=function(t,e){return t>>>=0,e||P(t,4,this.length),G.read(this,t,!0,23,4)},e.prototype.readFloatBE=function(t,e){return t>>>=0,e||P(t,4,this.length),G.read(this,t,!1,23,4)},e.prototype.readDoubleLE=function(t,e){return t>>>=0,e||P(t,8,this.length),G.read(this,t,!0,52,8)},e.prototype.readDoubleBE=function(t,e){return t>>>=0,e||P(t,8,this.length),G.read(this,t,!1,52,8)},e.prototype.writeUIntLE=function(t,e,r,n){if(t=+t,e>>>=0,r>>>=0,!n){R(this,t,e,r,Math.pow(2,8*r)-1,0)}var i=1,o=0;for(this[e]=255&t;++o<r&&(i*=256);)this[e+o]=t/i&255;return e+r},e.prototype.writeUIntBE=function(t,e,r,n){if(t=+t,e>>>=0,r>>>=0,!n){R(this,t,e,r,Math.pow(2,8*r)-1,0)}var i=r-1,o=1;for(this[e+i]=255&t;--i>=0&&(o*=256);)this[e+i]=t/o&255;return e+r},e.prototype.writeUInt8=function(t,e,r){return t=+t,e>>>=0,r||R(this,t,e,1,255,0),this[e]=255&t,e+1},e.prototype.writeUInt16LE=function(t,e,r){return t=+t,e>>>=0,r||R(this,t,e,2,65535,0),this[e]=255&t,this[e+1]=t>>>8,e+2},e.prototype.writeUInt16BE=function(t,e,r){return t=+t,e>>>=0,r||R(this,t,e,2,65535,0),this[e]=t>>>8,this[e+1]=255&t,e+2},e.prototype.writeUInt32LE=function(t,e,r){return t=+t,e>>>=0,r||R(this,t,e,4,4294967295,0),this[e+3]=t>>>24,this[e+2]=t>>>16,this[e+1]=t>>>8,this[e]=255&t,e+4},e.prototype.writeUInt32BE=function(t,e,r){return t=+t,e>>>=0,r||R(this,t,e,4,4294967295,0),this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t,e+4},e.prototype.writeIntLE=function(t,e,r,n){if(t=+t,e>>>=0,!n){var i=Math.pow(2,8*r-1);R(this,t,e,r,i-1,-i)}var o=0,a=1,s=0;for(this[e]=255&t;++o<r&&(a*=256);)t<0&&0===s&&0!==this[e+o-1]&&(s=1),this[e+o]=(t/a>>0)-s&255;return e+r},e.prototype.writeIntBE=function(t,e,r,n){if(t=+t,e>>>=0,!n){var i=Math.pow(2,8*r-1);R(this,t,e,r,i-1,-i)}var o=r-1,a=1,s=0;for(this[e+o]=255&t;--o>=0&&(a*=256);)t<0&&0===s&&0!==this[e+o+1]&&(s=1),this[e+o]=(t/a>>0)-s&255;return e+r},e.prototype.writeInt8=function(t,e,r){return t=+t,e>>>=0,r||R(this,t,e,1,127,-128),t<0&&(t=255+t+1),this[e]=255&t,e+1},e.prototype.writeInt16LE=function(t,e,r){return t=+t,e>>>=0,r||R(this,t,e,2,32767,-32768),this[e]=255&t,this[e+1]=t>>>8,e+2},e.prototype.writeInt16BE=function(t,e,r){return t=+t,e>>>=0,r||R(this,t,e,2,32767,-32768),this[e]=t>>>8,this[e+1]=255&t,e+2},e.prototype.writeInt32LE=function(t,e,r){return t=+t,e>>>=0,r||R(this,t,e,4,2147483647,-2147483648),this[e]=255&t,this[e+1]=t>>>8,this[e+2]=t>>>16,this[e+3]=t>>>24,e+4},e.prototype.writeInt32BE=function(t,e,r){return t=+t,e>>>=0,r||R(this,t,e,4,2147483647,-2147483648),t<0&&(t=4294967295+t+1),this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t,e+4},e.prototype.writeFloatLE=function(t,e,r){return L(this,t,e,!0,r)},e.prototype.writeFloatBE=function(t,e,r){return L(this,t,e,!1,r)},e.prototype.writeDoubleLE=function(t,e,r){return N(this,t,e,!0,r)},e.prototype.writeDoubleBE=function(t,e,r){return N(this,t,e,!1,r)},e.prototype.copy=function(t,r,n,i){if(!e.isBuffer(t))throw new TypeError("argument should be a Buffer");if(n||(n=0),i||0===i||(i=this.length),r>=t.length&&(r=t.length),r||(r=0),i>0&&i<n&&(i=n),i===n)return 0;if(0===t.length||0===this.length)return 0;if(r<0)throw new RangeError("targetStart out of bounds");if(n<0||n>=this.length)throw new RangeError("Index out of range");if(i<0)throw new RangeError("sourceEnd out of bounds");i>this.length&&(i=this.length),t.length-r<i-n&&(i=t.length-r+n);var o=i-n;if(this===t&&"function"==typeof Uint8Array.prototype.copyWithin)this.copyWithin(r,n,i);else if(this===t&&n<r&&r<i)for(var a=o-1;a>=0;--a)t[a+r]=this[a+n];else Uint8Array.prototype.set.call(t,this.subarray(n,i),r);return o},e.prototype.fill=function(t,r,n,i){if("string"==typeof t){if("string"==typeof r?(i=r,r=0,n=this.length):"string"==typeof n&&(i=n,n=this.length),void 0!==i&&"string"!=typeof i)throw new TypeError("encoding must be a string");if("string"==typeof i&&!e.isEncoding(i))throw new TypeError("Unknown encoding: "+i);if(1===t.length){var o=t.charCodeAt(0);("utf8"===i&&o<128||"latin1"===i)&&(t=o)}}else"number"==typeof t?t&=255:"boolean"==typeof t&&(t=Number(t));if(r<0||this.length<r||this.length<n)throw new RangeError("Out of range index");if(n<=r)return this;r>>>=0,n=void 0===n?this.length:n>>>0,t||(t=0);var a;if("number"==typeof t)for(a=r;a<n;++a)this[a]=t;else{var s=e.isBuffer(t)?t:e.from(t,i),u=s.length;if(0===u)throw new TypeError('The value "'+t+'" is invalid for argument "value"');for(a=0;a<n-r;++a)this[a+r]=s[a%u]}return this};var $=/[^+\/0-9A-Za-z-_]/g,H=function(){for(var t=new Array(256),e=0;e<16;++e)for(var r=16*e,n=0;n<16;++n)t[r+n]="0123456789abcdef"[e]+"0123456789abcdef"[n];return t}()}).call(this,t("buffer").Buffer)},{"base64-js":2,buffer:3,ieee754:4}],4:[function(t,e,r){r.read=function(t,e,r,n,i){var o,a,s=8*i-n-1,u=(1<<s)-1,f=u>>1,h=-7,l=r?i-1:0,c=r?-1:1,p=t[e+l];for(l+=c,o=p&(1<<-h)-1,p>>=-h,h+=s;h>0;o=256*o+t[e+l],l+=c,h-=8);for(a=o&(1<<-h)-1,o>>=-h,h+=n;h>0;a=256*a+t[e+l],l+=c,h-=8);if(0===o)o=1-f;else{if(o===u)return a?NaN:1/0*(p?-1:1);a+=Math.pow(2,n),o-=f}return(p?-1:1)*a*Math.pow(2,o-n)},r.write=function(t,e,r,n,i,o){var a,s,u,f=8*o-i-1,h=(1<<f)-1,l=h>>1,c=23===i?Math.pow(2,-24)-Math.pow(2,-77):0,p=n?0:o-1,y=n?1:-1,d=e<0||0===e&&1/e<0?1:0;for(e=Math.abs(e),isNaN(e)||e===1/0?(s=isNaN(e)?1:0,a=h):(a=Math.floor(Math.log(e)/Math.LN2),e*(u=Math.pow(2,-a))<1&&(a--,u*=2),e+=a+l>=1?c/u:c*Math.pow(2,1-l),e*u>=2&&(a++,u/=2),a+l>=h?(s=0,a=h):a+l>=1?(s=(e*u-1)*Math.pow(2,i),a+=l):(s=e*Math.pow(2,l-1)*Math.pow(2,i),a=0));i>=8;t[r+p]=255&s,p+=y,s/=256,i-=8);for(a=a<<i|s,f+=i;f>0;t[r+p]=255&a,p+=y,a/=256,f-=8);t[r+p-y]|=128*d}},{}],5:[function(t,e,r){"use strict";function n(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}var i=function(){function t(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}return function(e,r,n){return r&&t(e.prototype,r),n&&t(e,n),e}}(),o=function(){function t(e){n(this,t),this.data=new Uint8Array(e),this.byteOffset=0,this.lastEventTypeByte=0}return i(t,[{key:"readString",value:function(t){for(var e=this.byteOffset,r=0,n="";r<t;r++)n+=String.fromCharCode(this.data[e+r]);return this.byteOffset+=t,n}},{key:"readUint32",value:function(){var t=this.byteOffset,e=this.data[t]<<24|this.data[t+1]<<16|this.data[t+2]<<8|this.data[t+3];return this.byteOffset+=4,e}},{key:"readUint24",value:function(){var t=this.byteOffset,e=this.data[t]<<16|this.data[t+1]<<8|this.data[t+2];return this.byteOffset+=3,e}},{key:"readUint16",value:function(){var t=this.byteOffset,e=this.data[t]<<8|this.data[t+1];return this.byteOffset+=2,e}},{key:"readUint8",value:function(){var t=this.byteOffset,e=this.data[t];return this.byteOffset+=1,e}},{key:"readInt8",value:function(){var t=this.byteOffset,e=this.data[t];return!0&e&&(e^=4294967040),this.byteOffset+=1,e}},{key:"readVarUint",value:function(){var t,e=0;do{t=this.readUint8(),e=(e<<7)+(127&t)}while(128==(128&t));return e}},{key:"skip",value:function(t){this.byteOffset+=t}},{key:"readChunk",value:function(){var t=this.readString(4),e=this.readUint32(),r=this.byteOffset;return this.byteOffset+=e,{id:t,length:e,data:this.data.slice(r,this.byteOffset).buffer}}},{key:"readEvent",value:function(){var t={};t.delta=this.readVarUint();var e=this.readUint8();if(240==(240&e))switch(e){case 255:t.type="meta";var r=this.readUint8(),n=this.readVarUint();switch(r){case 0:t.subType="sequenceNumber",2===n?t.value=this.readUint16():this.skip(n);break;case 1:t.subType="text",t.value=this.readString(n);break;case 2:t.subType="copyrightNotice",t.value=this.readString(n);break;case 3:t.subType="trackName",t.value=this.readString(n);break;case 4:t.subType="instrumentName",t.value=this.readString(n);break;case 5:t.subType="lyrics",t.value=this.readString(n);break;case 6:t.subType="marker",t.value=this.readString(n);break;case 7:t.subType="cuePoint",t.value=this.readString(n);break;case 32:t.subType="midiChannelPrefix",1===n?t.value=this.readUint8():this.skip(n);break;case 47:t.subType="endOfTrack",n>0&&this.skip(n);break;case 81:t.subType="setTempo",3===n?t.value=this.readUint24():this.skip(n);break;case 84:if(t.subType="smpteOffset",5===n){var i=this.readUint8();t.value={frameRate:{0:24,1:25,2:29.97,3:30}[i>>>6],hour:63&i,minute:this.readUint8(),second:this.readUint8(),frame:this.readUint8(),subFrame:this.readUint8()}}else this.skip(n);break;case 88:t.subType="timeSignature",4===n?t.value={numerator:this.readUint8(),denominator:1<<this.readUint8(),metronome:this.readUint8(),thirtyseconds:this.readUint8()}:this.skip(n);break;case 89:t.subType="keySignature",2===n?t.value={key:this.readInt8(),scale:this.readUint8()}:this.skip(n);break;case 127:t.subType="sequencerSpecific",t.value=this.readString(n);break;default:t.subType="unknown",t.value=this.readString(n)}break;case 240:t.type="sysEx";var n=this.readVarUint();t.value=this.readString(n);break;case 247:t.type="dividedSysEx";var n=this.readVarUint();t.value=this.readString(n);break;default:t.type="unknown";var n=this.readVarUint();t.value=this.readString(n)}else{var o;0==(128&e)?(o=e,e=this.lastEventTypeByte):(o=this.readUint8(),this.lastEventTypeByte=e);var a=e>>4;switch(t.channel=15&e,t.type="channel",a){case 8:t.subType="noteOff",t.value={noteNumber:o,velocity:this.readUint8()};break;case 9:t.value={noteNumber:o,velocity:this.readUint8()},0===t.value.velocity?t.subType="noteOff":t.subType="noteOn";break;case 10:t.subType="noteAftertouch",t.value={noteNumber:o,amount:this.readUint8()};break;case 11:t.subType="controller",t.value={controllerNumber:o,controllerValue:this.readUint8()};break;case 12:t.subType="programChange",t.value=o;break;case 13:t.subType="channelAftertouch",t.value=o;break;case 14:t.subType="pitchBend",t.value=o+(this.readUint8()<<7);break;default:t.subType="unknown",t.value=(o<<8)+this.readUint8()}}return t}}]),t}();e.exports=o},{}],6:[function(t,e,r){"use strict";var n=t("./wav"),i=t("./midi"),o=t("./utils/timer");e.exports=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};e.verbose&&console.log("parsing MIDI header...");var r=new i(t),a=r.readChunk();if("MThd"!==a.id||6!==a.length)throw new SyntaxError("malformed header");for(var s=new i(a.data),u=(s.readUint16(),s.readUint16()),f=s.readUint16(),h=[],l=[],c=[],p=void 0,y=0;y<u;y++){e.verbose&&console.log("parsing track "+(y+1)+"...");var d=r.readChunk();if("MTrk"===d.id){for(var g=new i(d.data),v=[],b=!0;b&&g.byteOffset<d.length;){var w=g.readEvent();if(v.push(w),"string"==typeof w.value&&(e.verbose&&console.log('{"'+w.subType+'":"'+w.value+'"}'),Array.isArray(e.Skip)))for(var m=0;m<e.Skip.length;m++)if(e.Skip[m][w.subType]===w.value){e.verbose&&console.log('skip match found: {"'+w.subType+'":"'+w.value+'"}'),b=!1;break}}"function"==typeof e.Skip&&(b=!e.Skip(v)),b?h.push(v):e.verbose&&console.log("skipping track "+(y+1)+"...")}}if(f>>>15!=0)return console.log("Detected unsupported MIDI timing mode"),null;var k=new o(f);e.verbose&&console.log("initializing timer...");for(var E,S=0,U=0,A=0;S<h[0].length;S++)E=h[0][S],U+=E.delta,A+=E.delta,"setTempo"===E.subType&&(k.addCriticalPoint(U,E.value),U=0);for(var B=0;B<h.length;B++){e.verbose&&console.log("generating progression from track "+(B+1)+"...");for(var T=h[B],C=0,O=new Map,I=0;I<T.length;I++){var M=T[I];if(C+=M.delta,"channel"===M.type){var P=M.value.noteNumber;if("noteOn"===M.subType){var R=M.value.velocity,x=k.getTime(C);O.has(P)?O.get(P).push({offset:x,velocity:R}):O.set(P,[{offset:x,velocity:R}]),c.push({velocity:R,delta:C,note:!0})}else if("noteOff"===M.subType){var L=O.get(P),N=L?L.pop():{offset:0,velocity:0};l.push({note:n.note(P),time:k.getTime(C)-N.offset,amplitude:N.velocity/128,offset:N.offset}),c.push({velocity:N.velocity,delta:C,note:!1})}}else e.verbose&&"meta"===M.type&&"string"==typeof M.value&&console.log(k.getTime(C).toFixed(2)+"s "+M.subType+": "+M.value)}}e.verbose&&console.log("normalizing volume..."),c.sort(function(t,e){return t.delta-e.delta||t.note-e.note}),e.verbose&&(console.log("total notes:",l.length),console.log("total time:",k.getTime(c[c.length-1].delta),"seconds"));var D=1,j=0,z=1,F=0,_=0,V=0,q=!0,W=!1,Y=void 0;try{for(var G,X=c[Symbol.iterator]();!(q=(G=X.next()).done);q=!0){var J=G.value;J.note?(z+=J.velocity,V++,z>D&&(D=z,j=k.getTime(J.delta)),V>F&&(F=V,_=k.getTime(J.delta))):(z-=J.velocity,V--)}}catch(t){W=!0,Y=t}finally{try{!q&&X.return&&X.return()}finally{if(W)throw Y}}p=128/D,e.verbose&&(console.log("setting volume to",p),console.log(" maximum chord of",F,"at",_,"seconds"),console.log(" maximum velocity of",D-1,"at",j,"seconds")),e.channels=1,e.verbose&&console.log("generating WAV buffer...");var Z=new n(e.channels,e.sampleRate,e.bitsPerSample);return Z.writeProgression(l,p,[0],!0,!0,e.duration),Z}},{"./midi":5,"./utils/timer":7,"./wav":8}],7:[function(t,e,r){"use strict";function n(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}var i=function(){function t(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}return function(e,r,n){return r&&t(e.prototype,r),n&&t(e,n),e}}(),o=function(){function t(e){n(this,t),this.ticksPerBeat=e,this.criticalPoints=[]}return i(t,[{key:"addCriticalPoint",value:function(t,e){this.criticalPoints.push({delta:t,microsecondsPerBeat:e})}},{key:"getTime",value:function(t){for(var e,r=0,n=5e5,i=0;i<this.criticalPoints.length&&t>0;i++)e=this.criticalPoints[i],t>=e.delta?(r+=e.delta*n/this.ticksPerBeat/1e6,t-=e.delta):(r+=t*n/this.ticksPerBeat/1e6,t=0), n=e.microsecondsPerBeat;return r+=t*n/this.ticksPerBeat/1e6}}]),t}();e.exports=o},{}],8:[function(t,e,r){(function(t){"use strict";function r(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}var n=function(){function t(t,e){var r=[],n=!0,i=!1,o=void 0;try{for(var a,s=t[Symbol.iterator]();!(n=(a=s.next()).done)&&(r.push(a.value),!e||r.length!==e);n=!0);}catch(t){i=!0,o=t}finally{try{!n&&s.return&&s.return()}finally{if(i)throw o}}return r}return function(e,r){if(Array.isArray(e))return e;if(Symbol.iterator in Object(e))return t(e,r);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),i=function(){function t(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}return function(e,r,n){return r&&t(e.prototype,r),n&&t(e,n),e}}(),o=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:44100,i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:16,o=!(arguments.length>3&&void 0!==arguments[3])||arguments[3],a=arguments.length>4&&void 0!==arguments[4]?arguments[4]:[];r(this,e);var s=i>>>3;this.header=new ArrayBuffer(44),this.view=new DataView(this.header),this.data=a,Object.defineProperty(this,"littleEndian",{configurable:!1,enumerable:!0,value:o,writable:!1}),this.pointer=0,this.ChunkID=o?"RIFF":"RIFX",this.ChunkSize=this.header.byteLength-8,this.Format="WAVE",this.SubChunk1ID="fmt ",this.SubChunk1Size=16,this.AudioFormat=1,this.NumChannels=t,this.SampleRate=n,this.ByteRate=t*n*s,this.BlockAlign=t*s,this.BitsPerSample=i,this.SubChunk2ID="data",this.SubChunk2Size=a.length*s}return i(e,null,[{key:"semitone",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"REST",e=/^([A-G])(\-?\d+)(b{0,2}|#{0,2})$/;if(!e.test(t))return-1/0;var r=t.match(e),i=n(r,4),o=i[1],a=i[2],s=i[3],u={C:0,D:2,E:4,F:5,G:7,A:9,B:11},f={"-1":0,0:1,1:2,2:3,3:4,4:5,5:6,6:7,7:8,8:9,9:10,10:11},h={bb:-2,b:-1,"":0,"#":1,"##":2};return void 0===u[o]||void 0===f[a]||void 0===h[s]?-1/0:u[o]+12*f[a]+h[s]}},{key:"note",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:-1/0,e=[-1,0,1,2,3,4,5,6,7,8,9,10],r=["C","C#","D","D#","E","F","F#","G","G#","A","A#","B"],n=Math.floor(t/12),i=Math.floor(t-12*n),o=e[n],a=r[i];return void 0===o||void 0===a?"REST":a.charAt(0)+o.toString()+a.charAt(1)}},{key:"frequency",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:-1/0;return 440*Math.pow(2,(t-69)/12)}}]),i(e,[{key:"setString",value:function(t){for(var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:t.length,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,n=0;n<e;n++)this.view.setUint8(r+n,t.charCodeAt(n))}},{key:"getString",value:function(t){for(var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,r=0,n="";r<t;r++)n+=String.fromCharCode(this.view.getUint8(e+r));return n}},{key:"toBlob",value:function(){return new Blob([this.header,this.typedData],{type:"audio/wav"})}},{key:"toBuffer",value:function(){return t.concat([t.from(this.header),t.from(this.typedData)])}},{key:"tell",value:function(){return this.pointer/this.NumChannels/this.SampleRate}},{key:"seek",value:function(t){var e=!(arguments.length>1&&void 0!==arguments[1])||arguments[1],r=this.data,n=Math.round(this.SampleRate*t);if(this.pointer=this.NumChannels*n,e)for(;r.length<this.pointer;)r[r.length]=0;else this.pointer=r.length}},{key:"writeNote",value:function(t){var r,n,i,o,a=t.note,s=t.time,u=t.amplitude,f=void 0===u?1:u,h=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[],l=!(arguments.length>2&&void 0!==arguments[2])||arguments[2],c=arguments.length>3&&void 0!==arguments[3]&&arguments[3],p=this.data,y=this.NumChannels,d=this.SampleRate,g=e.semitone(a),v=e.frequency(g)*Math.PI*2/d,b=(Math.PI,Math.round(d*s)),w=b-.001*d,m=b-w+1,k=this.pointer,E=p.length,S=Math.min(Math.floor((E-k)/y),b);if(0===h.length)for(h=[],r=0;r<y;r++)h[r]=r;var U=[];for(r=0;r<y;r++)U[r]=-1===h.indexOf(r);for(r=0;r<S;r++)for(n=0;n<h.length;n++)i=k+r*y+h[n],o=0,v>0&&(o=f*Math.sin(v*r)*(r<m?r:r>w?b-r+1:m)/m),p[i]=o+(l?p[i]:0);for(r=S;r<b;r++)for(i=k+r*y,n=0;n<y;n++)o=0,(v>0||!U[n])&&(o=f*Math.sin(v*r)*(r<m?r:r>w?b-r+1:m)/m),p[i+n]=o;var A=Math.max(k+b*y,E)*this.BitsPerSample>>>3;this.ChunkSize=A+this.header.byteLength-8,this.SubChunk2Size=A,c||(this.pointer=k+b*y)}},{key:"writeProgression",value:function(t){for(var e,r,n,i,o,a,s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1,u=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[],f=!(arguments.length>3&&void 0!==arguments[3])||arguments[3],h=arguments.length>4&&void 0!==arguments[4]&&arguments[4],l=arguments.length>5&&void 0!==arguments[5]?arguments[5]:1,c=this.pointer,p=0;p<t.length;p++){var y=t[p];e=y.note,r=y.time,n=y.amplitude,i=y.offset,void 0!==i&&this.seek(i),1===l||"REST"===e?this.writeNote({note:e,time:r,amplitude:void 0===n?s:n*s},u,f,!1):(o=r*l,a=r-o,this.writeNote({note:e,time:o,amplitude:void 0===n?s:n*s},u,f,!1),this.writeNote({note:"REST",time:a},u,f,!1))}h&&(this.pointer=c)}},{key:"ChunkID",set:function(t){this.setString(t,4,0)},get:function(){return this.getString(4,0)}},{key:"ChunkSize",set:function(t){this.view.setUint32(4,t,this.littleEndian)},get:function(){return this.view.getUint32(4,this.littleEndian)}},{key:"Format",set:function(t){this.setString(t,4,8)},get:function(){return this.getString(4,8)}},{key:"SubChunk1ID",set:function(t){this.setString(t,4,12)},get:function(){return this.getString(4,12)}},{key:"SubChunk1Size",set:function(t){this.view.setUint32(16,t,this.littleEndian)},get:function(){return this.view.getUint32(16,this.littleEndian)}},{key:"AudioFormat",set:function(t){this.view.setUint16(20,t,this.littleEndian)},get:function(){return this.view.getUint16(20,this.littleEndian)}},{key:"NumChannels",set:function(t){this.view.setUint16(22,t,this.littleEndian)},get:function(){return this.view.getUint16(22,this.littleEndian)}},{key:"SampleRate",set:function(t){this.view.setUint32(24,t,this.littleEndian)},get:function(){return this.view.getUint32(24,this.littleEndian)}},{key:"ByteRate",set:function(t){this.view.setUint32(28,t,this.littleEndian)},get:function(){return this.view.getUint32(28,this.littleEndian)}},{key:"BlockAlign",set:function(t){this.view.setUint16(32,t,this.littleEndian)},get:function(){return this.view.getUint16(32,this.littleEndian)}},{key:"BitsPerSample",set:function(t){this.view.setUint16(34,t,this.littleEndian)},get:function(){return this.view.getUint16(34,this.littleEndian)}},{key:"SubChunk2ID",set:function(t){this.setString(t,4,36)},get:function(){return this.getString(4,36)}},{key:"SubChunk2Size",set:function(t){this.view.setUint32(40,t,this.littleEndian)},get:function(){return this.view.getUint32(40,this.littleEndian)}},{key:"typedData",get:function(){var t,e,r=this.BitsPerSample>>>3,n=this.data,i=this.SubChunk2Size,o=i/r,a=new ArrayBuffer(i),s=new Uint8Array(a),u=Math.pow(2,(r<<3)-1)-1;switch(r){case 1:for(t=0;t<o;t++)s[t]=n[t]*u+128&255;break;case 2:if(this.littleEndian)for(t=0;t<o;t++)e=n[t]*u+65536&65535,s[2*t]=255&e,s[2*t+1]=e>>>8;else for(t=0;t<o;t++)e=n[t]*u+65536&65535,s[2*t]=e>>>8,s[2*t+1]=255&e;break;case 3:if(this.littleEndian)for(t=0;t<o;t++)e=n[t]*u+16777216&16777215,s[3*t]=255&e,s[3*t+1]=e>>>8&255,s[3*t+2]=e>>>16;else for(t=0;t<o;t++)e=n[t]*u+16777216&16777215,s[3*t]=e>>>16,s[3*t+1]=e>>>8&255,s[3*t+2]=255&e;case 4:if(this.littleEndian)for(t=0;t<o;t++)e=n[t]*u+4294967296&4294967295,s[4*t]=255&e,s[4*t+1]=e>>>8&255,s[4*t+2]=e>>>16&255,s[4*t+3]=e>>>24;else for(t=0;t<o;t++)e=n[t]*u+4294967296&4294967295,s[4*t]=e>>>24,s[4*t+1]=e>>>16&255,s[4*t+2]=e>>>8&255,s[4*t+3]=255&e}return a}}]),e}();e.exports=o}).call(this,t("buffer").Buffer)},{buffer:3}]},{},[1])(1)}); //# sourceMappingURL=synth.min.js.map