From 2885236707b1cc5a5cb993510f691c0578a02665 Mon Sep 17 00:00:00 2001 From: Dorian Date: Wed, 18 Feb 2026 10:39:10 +0000 Subject: [PATCH] Refactor keyboard input sound implementation in useLoginSounds.ts - Updated the keyboard typing sound function to use a synthesized click instead of preloaded audio files, enhancing performance and responsiveness. - Removed the previous audio pool logic for keyboard input sounds to streamline the code. - Ensured audio context is properly managed to prevent playback issues. --- neode-ui/src/composables/useLoginSounds.ts | 44 ++++++++++++---------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/neode-ui/src/composables/useLoginSounds.ts b/neode-ui/src/composables/useLoginSounds.ts index 6483b476..f4c9a990 100644 --- a/neode-ui/src/composables/useLoginSounds.ts +++ b/neode-ui/src/composables/useLoginSounds.ts @@ -172,27 +172,31 @@ export function playTypingTick() { a.play().catch(() => {}) } -/** Keyboard input sound - plays on any character typed in inputs. Separate from typing tick/intro typing. */ -let keyboardInputPool: HTMLAudioElement[] = [] -const KEYBOARD_INPUT_POOL_SIZE = 5 - -function getKeyboardInputSound(): HTMLAudioElement { - if (keyboardInputPool.length === 0) { - for (let i = 0; i < KEYBOARD_INPUT_POOL_SIZE; i++) { - const a = new Audio('/assets/audio/typing.mp3') - a.volume = 0.5 - keyboardInputPool.push(a) - } - } - const a = keyboardInputPool.shift()! - keyboardInputPool.push(a) - return a -} - +/** Keyboard input sound - short synthesized click per key. Does NOT use typing.mp3 or intro-typing.mp3. */ export function playKeyboardTypingSound() { - const a = getKeyboardInputSound() - a.currentTime = 0 - a.play().catch(() => {}) + const ctx = getContext() + if (!ctx) return + + try { + if (ctx.state === 'suspended') ctx.resume() + } catch { + return + } + + const t = ctx.currentTime + const osc = ctx.createOscillator() + const gain = ctx.createGain() + + osc.type = 'sine' + osc.frequency.setValueAtTime(1200, t) + gain.gain.setValueAtTime(0, t) + gain.gain.linearRampToValueAtTime(0.06, t + 0.002) + gain.gain.exponentialRampToValueAtTime(0.001, t + 0.04) + + osc.connect(gain) + gain.connect(ctx.destination) + osc.start(t) + osc.stop(t + 0.04) } /** Gaming-style boot thud - soft impact when dashboard loads */