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> </span>
</li> </li>
<li>volume (global): {playQueue.volume.toFixed(2)}</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>volumeFade: {playQueue.volumeFade ? 'true' : 'false'}</li>
<li>shuffle: {playQueue.shuffle ? 'true' : 'false'}</li> <li>shuffle: {playQueue.shuffle ? 'true' : 'false'}</li>
<li>repeat: {playQueue.repeat}</li> <li>repeat: {playQueue.repeat}</li>

16
src/components/player/Player.tsx

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

4
src/components/player/PlayerBar.tsx

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

4
src/hooks/usePlayerControls.ts

@ -63,7 +63,7 @@ const usePlayerControls = (
dispatch(fixPlayer2Index()); dispatch(fixPlayer2Index());
} else if (currentPlayer === 1) { } else if (currentPlayer === 1) {
playersRef.current.player1.audioEl.current.currentTime = 0; 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 // Reset the alt player if reset during fade
playersRef.current.player2.audioEl.current.currentTime = 0; playersRef.current.player2.audioEl.current.currentTime = 0;
@ -86,7 +86,7 @@ const usePlayerControls = (
} }
} else { } else {
playersRef.current.player2.audioEl.current.currentTime = 0; 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 // Reset the alt player if reset during fade
playersRef.current.player1.audioEl.current.currentTime = 0; playersRef.current.player1.audioEl.current.currentTime = 0;

Loading…
Cancel
Save