diff --git a/packages/csound/index.mjs b/packages/csound/index.mjs index a00be74f..1eeaf6fa 100644 --- a/packages/csound/index.mjs +++ b/packages/csound/index.mjs @@ -23,7 +23,7 @@ export const csound = register('csound', (instrument, pat) => { instrument = instrument || 'triangle'; init(); // not async to support csound inside other patterns + to be able to call pattern methods after it // TODO: find a alternative way to wait for csound to load (to wait with first time playback) - return pat.onTrigger((time, hap) => { + return pat.onTrigger((time_deprecate, hap, currentTime, _cps, targetTime) => { if (!_csound) { logger('[csound] not loaded yet', 'warning'); return; @@ -38,9 +38,11 @@ export const csound = register('csound', (instrument, pat) => { .join('/'); // TODO: find out how to send a precise ctx based time // http://www.csounds.com/manual/html/i.html + const timeOffset = targetTime - currentTime; // latency ? + //const timeOffset = time_deprecate - getAudioContext().currentTime const params = [ `"${instrument}"`, // p1: instrument name - time - getAudioContext().currentTime, //.toFixed(precision), // p2: starting time in arbitrary unit called beats + timeOffset, // p2: starting time in arbitrary unit called beats hap.duration + 0, // p3: duration in beats // instrument specific params: freq, //.toFixed(precision), // p4: frequency diff --git a/packages/superdough/dspworklet.mjs b/packages/superdough/dspworklet.mjs index deff485a..ed5c1e7e 100644 --- a/packages/superdough/dspworklet.mjs +++ b/packages/superdough/dspworklet.mjs @@ -74,6 +74,6 @@ export const dough = async (code) => { worklet.node.connect(ac.destination); }; -export function doughTrigger(t, hap, currentTime, duration, cps) { - window.postMessage({ time: t, dough: hap.value, currentTime, duration, cps }); +export function doughTrigger(time_deprecate, hap, currentTime, cps, targetTime) { + window.postMessage({ time: targetTime, dough: hap.value, currentTime, duration: hap.duration, cps }); }