zyklus
Version:
Fuzz-Free Web Audio Scheduling
2 lines (1 loc) • 390 B
JavaScript
;AudioContext.prototype.createClock=function(p,e,c=.1,n=.1){let o=0,t=0,l=10**4,h=.01;const u=s=>e=s(e);n=n||c/2;const i=()=>{const s=this.currentTime,I=s+c+n;for(t===0&&(t=s+h);t<I;)t=Math.round(t*l)/l,t>=s&&p(t,e,o),t+=e,o++};let r;const k=()=>{i(),r=setInterval(i,c*1e3)},a=()=>clearInterval(r);return{setDuration:u,start:k,stop:()=>{o=0,t=0,a()},pause:()=>a(),duration:e}};