Skip to content

Commit

Permalink
Handle negative values on gain calculation (#834)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffvli committed Nov 19, 2024
1 parent 8ec4551 commit b65c972
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/renderer/components/audio-player/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -341,15 +341,18 @@ 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
// Attempt to prevent pop-in for web audio.
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,
Expand Down

0 comments on commit b65c972

Please sign in to comment.