mirror of
https://github.com/jeffvli/feishin.git
synced 2024-11-20 06:27:09 +01:00
simplify webaudio replaygain to reduce pop-in
This commit is contained in:
parent
616fd45734
commit
37b0407188
@ -277,18 +277,34 @@ export const AudioPlayer = forwardRef(
|
||||
}, [audioDeviceId, webAudio]);
|
||||
|
||||
useEffect(() => {
|
||||
if (webAudio && player1Source && player1 && currentPlayer === 1) {
|
||||
const newVolume = calculateReplayGain(player1) * volume;
|
||||
webAudio.gain.gain.setValueAtTime(newVolume, 0);
|
||||
}
|
||||
}, [calculateReplayGain, currentPlayer, player1, player1Source, volume, webAudio]);
|
||||
if (!webAudio) return;
|
||||
|
||||
useEffect(() => {
|
||||
if (webAudio && player2Source && player2 && currentPlayer === 2) {
|
||||
const newVolume = calculateReplayGain(player2) * volume;
|
||||
const sources = [player1Source ? player1 : null, player2Source ? player2 : null];
|
||||
const current = sources[currentPlayer - 1];
|
||||
|
||||
// Set the current replaygain
|
||||
if (current) {
|
||||
const newVolume = calculateReplayGain(current) * volume;
|
||||
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(
|
||||
async (player: ReactPlayer) => {
|
||||
|
Loading…
Reference in New Issue
Block a user