Browse Source

Make volume scaling logarithmic

master
Gelaechter 3 years ago
committed by Jeff
parent
commit
2d2b938a48
  1. 1
      src/components/debug/DebugWindow.tsx
  2. 16
      src/components/player/Player.tsx
  3. 4
      src/components/player/PlayerBar.tsx
  4. 4
      src/hooks/usePlayerControls.ts

1
src/components/debug/DebugWindow.tsx

@ -132,6 +132,7 @@ const DebugWindow = ({ ...rest }) => {
</span>
</li>
<li>volume (global): {playQueue.volume.toFixed(2)}</li>
<li>actual volume: {(playQueue.volume ** 2).toFixed(2)}</li>
<li>volumeFade: {playQueue.volumeFade ? 'true' : 'false'}</li>
<li>shuffle: {playQueue.shuffle ? 'true' : 'false'}</li>
<li>repeat: {playQueue.repeat}</li>

16
src/components/player/Player.tsx

@ -50,7 +50,7 @@ const gaplessListenHandler = (
return;
}
nextPlayerRef.current.audioEl.current.volume = playQueue.volume;
nextPlayerRef.current.audioEl.current.volume = playQueue.volume ** 2;
nextPlayerRef.current.audioEl.current.play();
}
@ -175,8 +175,8 @@ const listenHandler = (
: playQueue.volume;
if (player === 1) {
currentPlayerRef.current.audioEl.current.volume = currentPlayerVolume;
nextPlayerRef.current.audioEl.current.volume = nextPlayerVolume;
currentPlayerRef.current.audioEl.current.volume = currentPlayerVolume ** 2;
nextPlayerRef.current.audioEl.current.volume = nextPlayerVolume ** 2;
if (debug) {
dispatch(
setFadeData({
@ -194,8 +194,8 @@ const listenHandler = (
);
}
} else {
currentPlayerRef.current.audioEl.current.volume = currentPlayerVolume;
nextPlayerRef.current.audioEl.current.volume = nextPlayerVolume;
currentPlayerRef.current.audioEl.current.volume = currentPlayerVolume ** 2;
nextPlayerRef.current.audioEl.current.volume = nextPlayerVolume ** 2;
if (debug) {
dispatch(
setFadeData({
@ -214,7 +214,7 @@ const listenHandler = (
}
}
} else {
nextPlayerRef.current.audioEl.current.volume = playQueue.volume;
nextPlayerRef.current.audioEl.current.volume = playQueue.volume ** 2;
}
}
}
@ -719,10 +719,10 @@ const Player = ({ currentEntryList, muted, children }: any, ref: any) => {
useEffect(() => {
if (!playQueue.isFading || !(playQueue.fadeDuration === 0)) {
if (playQueue.currentPlayer === 1) {
player1Ref.current.audioEl.current.volume = playQueue.volume;
player1Ref.current.audioEl.current.volume = playQueue.volume ** 2;
player2Ref.current.audioEl.current.volume = 0;
} else {
player2Ref.current.audioEl.current.volume = playQueue.volume;
player2Ref.current.audioEl.current.volume = playQueue.volume ** 2;
player1Ref.current.audioEl.current.volume = 0;
}
}

4
src/components/player/PlayerBar.tsx

@ -242,9 +242,9 @@ const PlayerBar = () => {
if (isDraggingVolume) {
dispatch(setVolume(localVolume));
if (playQueue.currentPlayer === 1) {
playersRef.current.player1.audioEl.current.volume = localVolume;
playersRef.current.player1.audioEl.current.volume = localVolume ** 2;
} else {
playersRef.current.player2.audioEl.current.volume = localVolume;
playersRef.current.player2.audioEl.current.volume = localVolume ** 2;
}
settings.setSync('volume', localVolume);

4
src/hooks/usePlayerControls.ts

@ -63,7 +63,7 @@ const usePlayerControls = (
dispatch(fixPlayer2Index());
} else if (currentPlayer === 1) {
playersRef.current.player1.audioEl.current.currentTime = 0;
playersRef.current.player1.audioEl.current.volume = playQueue.volume;
playersRef.current.player1.audioEl.current.volume = playQueue.volume ** 2;
// Reset the alt player if reset during fade
playersRef.current.player2.audioEl.current.currentTime = 0;
@ -86,7 +86,7 @@ const usePlayerControls = (
}
} else {
playersRef.current.player2.audioEl.current.currentTime = 0;
playersRef.current.player2.audioEl.current.volume = playQueue.volume;
playersRef.current.player2.audioEl.current.volume = playQueue.volume ** 2;
// Reset the alt player if reset during fade
playersRef.current.player1.audioEl.current.currentTime = 0;

Loading…
Cancel
Save