diff --git a/src/worker/worker.ts b/src/worker/worker.ts index 3db7e90c..b5398294 100644 --- a/src/worker/worker.ts +++ b/src/worker/worker.ts @@ -1,2 +1,2 @@ // This is the minified and stringified code of the web-audio-beat-detector-worker package. -export const worker = `(()=>{"use strict";const e=(e,t,o)=>{const s=e.length,n=[];let a=!1;for(let r=0;rt?a=!0:a&&(a=!1,n.push(r-1),r+=o/4-1);return a&&n.push(s-1),n},t=(t,o,s)=>{const n=(e=>{let t=0;const o=e.length;for(let s=0;st&&(t=e[s]);return t})(t),a=.3*n;let r=[],l=n-.05*n;if(n>.25)for(;r.length<30&&l>=a;)r=e(t,l,o),l-=.05*n;const p=(e=>{const t=[];return e.forEach(((o,s)=>{const n=Math.min(e.length-s,10);for(let a=1;ae.interval===n&&(e.peaks.push(o),!0)))||t.push({interval:n,peaks:[o]})}})),t})(r),h=function(e,t){let o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};var s,n;const a=Math.max(0,null!==(s=o.maxTempo)&&void 0!==s?s:180),r=Math.max(0,null!==(n=o.minTempo)&&void 0!==n?n:90),l=[];return e.forEach((e=>{let o=60/(e.interval/t);for(;oa;)o/=2;if(o{if(t.tempo===o&&(t.score+=e.peaks.length,t.peaks=[...t.peaks,...e.peaks],s=!0),t.tempo>o-.5&&t.tempot.score-e.score)),h};addEventListener("message",(e=>{let{data:o}=e;try{if("analyze"===o.method){const{id:e,params:{channelData:s,sampleRate:n,tempoSettings:a}}=o,r=((e,o,s)=>{const n=t(e,o,s);if(0===n.length)throw new Error("The given channelData does not contain any detectable beats.");return n[0].tempo})(s,n,a);postMessage({error:null,id:e,result:{tempo:r}})}else{if("guess"!==o.method)throw new Error('The given method "'.concat(o.method,'" is not supported'));{const{id:e,params:{channelData:s,sampleRate:n,tempoSettings:a}}=o,{bpm:r,offset:l,tempo:p}=((e,o,s)=>{const n=t(e,o,s);if(0===n.length)throw new Error("The given channelData does not contain any detectable beats.");const{peaks:a,tempo:r}=n[0],l=Math.round(r),p=60/l;a.sort(((e,t)=>e-t));let h=a[0]/o;for(;h>p;)h-=p;return{bpm:l,offset:h,tempo:r}})(s,n,a);postMessage({error:null,id:e,result:{bpm:r,offset:l,tempo:p}})}}}catch(e){postMessage({error:{message:e.message},id:o.id,result:null})}}))})();`; // tslint:disable-line:max-line-length +export const worker = `(()=>{"use strict";const e=(e,t,s)=>{const o=e.length,n=[];let a=!1;for(let r=0;rt?a=!0:a&&(a=!1,n.push(r-1),r+=s/4-1);return a&&n.push(o-1),n},t=(t,s,o)=>{const n=(e=>{let t=0;const s=e.length;for(let o=0;ot&&(t=e[o]);return t})(t),a=.3*n;let r=[],l=n-.05*n;if(n>.25)for(;r.length<30&&l>=a;)r=e(t,l,s),l-=.05*n;const p=(e=>{const t=[];return e.forEach(((s,o)=>{const n=Math.min(e.length-o,10);for(let a=1;ae.interval===n&&(e.peaks.push(s),!0)))||t.push({interval:n,peaks:[s]})}})),t})(r),h=((e,t,s={})=>{var o,n;const a=Math.max(0,null!==(o=s.maxTempo)&&void 0!==o?o:180),r=Math.max(0,null!==(n=s.minTempo)&&void 0!==n?n:90),l=[];return e.forEach((e=>{let s=60/(e.interval/t);for(;sa;)s/=2;if(s{if(t.tempo===s&&(t.score+=e.peaks.length,t.peaks=[...t.peaks,...e.peaks],o=!0),t.tempo>s-.5&&t.tempot.score-e.score)),h};addEventListener("message",(({data:e})=>{try{if("analyze"===e.method){const{id:s,params:{channelData:o,sampleRate:n,tempoSettings:a}}=e,r=((e,s,o)=>{const n=t(e,s,o);if(0===n.length)throw new Error("The given channelData does not contain any detectable beats.");return n[0].tempo})(o,n,a);postMessage({error:null,id:s,result:{tempo:r}})}else{if("guess"!==e.method)throw new Error('The given method "'.concat(e.method,'" is not supported'));{const{id:s,params:{channelData:o,sampleRate:n,tempoSettings:a}}=e,{bpm:r,offset:l,tempo:p}=((e,s,o)=>{const n=t(e,s,o);if(0===n.length)throw new Error("The given channelData does not contain any detectable beats.");const{peaks:a,tempo:r}=n[0],l=Math.round(r),p=60/l;a.sort(((e,t)=>e-t));let h=a[0]/s;for(;h>p;)h-=p;return{bpm:l,offset:h,tempo:r}})(o,n,a);postMessage({error:null,id:s,result:{bpm:r,offset:l,tempo:p}})}}}catch(t){postMessage({error:{message:t.message},id:e.id,result:null})}}))})();`; // tslint:disable-line:max-line-length