summaryrefslogtreecommitdiff
path: root/tools/mq_editor/app.js
diff options
context:
space:
mode:
Diffstat (limited to 'tools/mq_editor/app.js')
-rw-r--r--tools/mq_editor/app.js8
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();