From b65c972da1f4e9b900a597f06170aff69b612bce Mon Sep 17 00:00:00 2001 From: jeffvli Date: Mon, 18 Nov 2024 20:16:20 -0800 Subject: [PATCH] Handle negative values on gain calculation (#834) --- src/renderer/components/audio-player/index.tsx | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/renderer/components/audio-player/index.tsx b/src/renderer/components/audio-player/index.tsx index 5bc4863f..87e0e20e 100644 --- a/src/renderer/components/audio-player/index.tsx +++ b/src/renderer/components/audio-player/index.tsx @@ -341,7 +341,7 @@ export const AudioPlayer = forwardRef( // Set the current replaygain if (current) { const newVolume = calculateReplayGain(current) * volume; - webAudio.gain.gain.setValueAtTime(newVolume, 0); + webAudio.gain.gain.setValueAtTime(Math.max(0, newVolume), 0); } // Set the next track replaygain right before the end of this track @@ -349,7 +349,10 @@ export const AudioPlayer = forwardRef( const next = sources[3 - currentPlayer]; if (next && current) { const newVolume = calculateReplayGain(next) * volume; - webAudio.gain.gain.setValueAtTime(newVolume, (current.duration - 1) / 1000); + webAudio.gain.gain.setValueAtTime( + Math.max(0, newVolume), + Math.max(0, (current.duration - 1) / 1000), + ); } }, [ calculateReplayGain,