From a3891a59f0e5438ef7ee3341725ee07446ecbddc Mon Sep 17 00:00:00 2001 From: Metacube Date: Mon, 10 Nov 2025 20:57:39 +0100 Subject: [PATCH] Resume audio context on pointer down --- index.php | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/index.php b/index.php index 377d785..a0fa968 100644 --- a/index.php +++ b/index.php @@ -283,9 +283,20 @@ $title = "MausSynth Lab"; setupAudio(); } if (!audioCtx) return; - masterGain.gain.cancelScheduledValues(audioCtx.currentTime); - masterGain.gain.setTargetAtTime(0.7, audioCtx.currentTime, 0.02); - lfoGain.gain.setTargetAtTime(900, audioCtx.currentTime, 0.08); + + const resumePromise = audioCtx.state === 'suspended' + ? audioCtx.resume() + : Promise.resolve(); + + resumePromise + .then(() => { + masterGain.gain.cancelScheduledValues(audioCtx.currentTime); + masterGain.gain.setTargetAtTime(0.7, audioCtx.currentTime, 0.02); + lfoGain.gain.setTargetAtTime(900, audioCtx.currentTime, 0.08); + }) + .catch((error) => { + console.error('Failed to resume AudioContext', error); + }); } function pointerUp() {