From 38c631d03fde74b8415533e29174e1a136825b78 Mon Sep 17 00:00:00 2001 From: gabriellsh Date: Tue, 28 Oct 2025 16:20:36 -0300 Subject: [PATCH] Fix tone player --- packages/ui-voip/src/v2/useTonePlayer.ts | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/packages/ui-voip/src/v2/useTonePlayer.ts b/packages/ui-voip/src/v2/useTonePlayer.ts index 76ba9cf931d05..09d0d80231fbb 100644 --- a/packages/ui-voip/src/v2/useTonePlayer.ts +++ b/packages/ui-voip/src/v2/useTonePlayer.ts @@ -26,8 +26,8 @@ class TonePlayer { // This filter makes the sound more natural this.filter = this.audioContext.createBiquadFilter(); - this.filter.type = 'lowpass'; - this.filter.frequency.value = 8000; + this.filter.type = 'bandpass'; + this.filter.frequency.value = 4000; this.gainNode.connect(this.filter); this.filter.connect(this.destination); @@ -54,8 +54,10 @@ class TonePlayer { lowFrequencyOscillator.frequency.value = lowFreq; highFrequencyOscillator.frequency.value = highFreq; - lowFrequencyOscillator.start(); - highFrequencyOscillator.start(); + const startTime = this.audioContext.currentTime; + + lowFrequencyOscillator.start(startTime); + highFrequencyOscillator.start(startTime); // Ensure audio element is playing if (this.audioElement.paused) { @@ -64,12 +66,8 @@ class TonePlayer { }); } - setTimeout(() => { - lowFrequencyOscillator.stop(); - highFrequencyOscillator.stop(); - highFrequencyOscillator.disconnect(); - lowFrequencyOscillator.disconnect(); - }, durationMs ?? 400); + highFrequencyOscillator.stop(startTime + (durationMs ?? 400) / 1000); + lowFrequencyOscillator.stop(startTime + (durationMs ?? 400) / 1000); } public destroy() {