Handle negative values on gain calculation (#834)

This commit is contained in:
jeffvli 2024-11-18 20:16:20 -08:00
parent 8ec4551b46
commit b65c972da1

View File

@ -341,7 +341,7 @@ export const AudioPlayer = forwardRef(
// Set the current replaygain // Set the current replaygain
if (current) { if (current) {
const newVolume = calculateReplayGain(current) * volume; 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 // 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]; const next = sources[3 - currentPlayer];
if (next && current) { if (next && current) {
const newVolume = calculateReplayGain(next) * volume; 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, calculateReplayGain,