simplify webaudio replaygain to reduce pop-in
This commit is contained in:
parent
616fd45734
commit
37b0407188
1 changed files with 25 additions and 9 deletions
|
@ -277,18 +277,34 @@ export const AudioPlayer = forwardRef(
|
||||||
}, [audioDeviceId, webAudio]);
|
}, [audioDeviceId, webAudio]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (webAudio && player1Source && player1 && currentPlayer === 1) {
|
if (!webAudio) return;
|
||||||
const newVolume = calculateReplayGain(player1) * volume;
|
|
||||||
webAudio.gain.gain.setValueAtTime(newVolume, 0);
|
|
||||||
}
|
|
||||||
}, [calculateReplayGain, currentPlayer, player1, player1Source, volume, webAudio]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
const sources = [player1Source ? player1 : null, player2Source ? player2 : null];
|
||||||
if (webAudio && player2Source && player2 && currentPlayer === 2) {
|
const current = sources[currentPlayer - 1];
|
||||||
const newVolume = calculateReplayGain(player2) * volume;
|
|
||||||
|
// Set the current replaygain
|
||||||
|
if (current) {
|
||||||
|
const newVolume = calculateReplayGain(current) * volume;
|
||||||
webAudio.gain.gain.setValueAtTime(newVolume, 0);
|
webAudio.gain.gain.setValueAtTime(newVolume, 0);
|
||||||
}
|
}
|
||||||
}, [calculateReplayGain, currentPlayer, player2, player2Source, volume, webAudio]);
|
|
||||||
|
// 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);
|
||||||
|
}
|
||||||
|
}, [
|
||||||
|
calculateReplayGain,
|
||||||
|
currentPlayer,
|
||||||
|
player1,
|
||||||
|
player1Source,
|
||||||
|
player2,
|
||||||
|
player2Source,
|
||||||
|
volume,
|
||||||
|
webAudio,
|
||||||
|
]);
|
||||||
|
|
||||||
const handlePlayer1Start = useCallback(
|
const handlePlayer1Start = useCallback(
|
||||||
async (player: ReactPlayer) => {
|
async (player: ReactPlayer) => {
|
||||||
|
|
Reference in a new issue