diff options
| author | skal <pascal.massimino@gmail.com> | 2026-02-19 07:47:17 +0100 |
|---|---|---|
| committer | skal <pascal.massimino@gmail.com> | 2026-02-19 07:47:17 +0100 |
| commit | 7554f59a328acc706119d0952b50ab9fdee8c623 (patch) | |
| tree | 697512edd40d440c39b1680ea9fb6b23b325c356 /tools/mq_editor/app.js | |
| parent | 07538091b1fac417104c273bd9dc117af8afdb9e (diff) | |
handoff(Claude): playhead offset fix for single partial playback
Diffstat (limited to 'tools/mq_editor/app.js')
| -rw-r--r-- | tools/mq_editor/app.js | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/tools/mq_editor/app.js b/tools/mq_editor/app.js index 1c6d548..55b8d25 100644 --- a/tools/mq_editor/app.js +++ b/tools/mq_editor/app.js @@ -388,7 +388,7 @@ for (const el of [birthPersistenceEl, deathAgeEl, phaseErrorWeightEl, minLengthE el.addEventListener('change', () => { if (stftCache) runExtraction(); }); } -function playAudioBuffer(buffer, statusMsg) { +function playAudioBuffer(buffer, statusMsg, timeOffset = 0) { const startTime = audioContext.currentTime; currentSource = audioContext.createBufferSource(); currentSource.buffer = buffer; @@ -406,7 +406,7 @@ function playAudioBuffer(buffer, statusMsg) { setStatus(statusMsg, 'info'); function tick() { if (!currentSource) return; - viewer.setPlayheadTime(audioContext.currentTime - startTime); + viewer.setPlayheadTime(timeOffset + audioContext.currentTime - startTime); requestAnimationFrame(tick); } tick(); @@ -530,7 +530,9 @@ document.addEventListener('keydown', (e) => { const partial = extractedPartials[sel]; if (!partial) return; stopAudio(); - playAudioBuffer(getAudioBuffer([partial], 0.05), `Playing partial #${sel}...`); + const tStart = Math.min(...partial.times); + const offset = Math.max(0, tStart - 0.05); + playAudioBuffer(getAudioBuffer([partial], 0.05), `Playing partial #${sel}...`, offset); } else if (e.code === 'KeyP') { e.preventDefault(); if (viewer) viewer.togglePeaks(); |
