Skip to content

Commit

Permalink
fix: update worker string
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisguttandin committed Jun 10, 2024
1 parent 4b13763 commit 9d739df
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/worker/worker.ts
Original file line number Diff line number Diff line change
@@ -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;r<s;r+=1)e[r]>t?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;s<o;s+=1)e[s]>t&&(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;a<n;a+=1){const n=e[s+a]-o;t.some((e=>e.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.minTempo)&&void 0!==s?s:90),r=Math.max(0,null!==(n=o.maxTempo)&&void 0!==n?n:180),l=[];return e.forEach((e=>{let o=60/(e.interval/t);for(;o<a;)o*=2;for(;o>r;)o/=2;let s=!1,n=e.peaks.length;l.forEach((t=>{if(t.tempo===o&&(t.score+=e.peaks.length,t.peaks=[...t.peaks,...e.peaks],s=!0),t.tempo>o-.5&&t.tempo<o+.5){const s=2*Math.abs(t.tempo-o);n+=(1-s)*t.peaks.length,t.score+=(1-s)*e.peaks.length}})),s||l.push({peaks:e.peaks,score:n,tempo:o})})),l}(p,o,s);return h.sort(((e,t)=>t.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,o)=>{const s=e.length,n=[];let a=!1;for(let r=0;r<s;r+=1)e[r]>t?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;s<o;s+=1)e[s]>t&&(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;a<n;a+=1){const n=e[s+a]-o;t.some((e=>e.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(;o<r;)o*=2;for(;o>a;)o/=2;if(o<r)return;let s=!1,n=e.peaks.length;l.forEach((t=>{if(t.tempo===o&&(t.score+=e.peaks.length,t.peaks=[...t.peaks,...e.peaks],s=!0),t.tempo>o-.5&&t.tempo<o+.5){const s=2*Math.abs(t.tempo-o);n+=(1-s)*t.peaks.length,t.score+=(1-s)*e.peaks.length}})),s||l.push({peaks:e.peaks,score:n,tempo:o})})),l}(p,o,s);return h.sort(((e,t)=>t.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

0 comments on commit 9d739df

Please sign in to comment.