From 8219ecc8e2b9f75315df7e5a535e15482ea8fb56 Mon Sep 17 00:00:00 2001 From: Thomas Amland Date: Mon, 30 Dec 2024 17:00:59 +0100 Subject: [PATCH] fix audio fade in never ending when using Replay Gain --- src/player/audio.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/player/audio.ts b/src/player/audio.ts index ac2bf3f..6d15ae8 100644 --- a/src/player/audio.ts +++ b/src/player/audio.ts @@ -150,13 +150,13 @@ export class AudioController { } private fadeFromTo(from: number, to: number, duration: number) { - console.info(`AudioController: start fade (${from}, ${to}, ${duration})`) - const startTime = Date.now() - const replayGainFactor = this.replayGainFactor() from *= replayGainFactor to *= replayGainFactor + console.info(`AudioController: start fade (${from}, ${to}, ${duration})`) + const startTime = Date.now() + const step = (to - from) / duration if (duration <= 0.0) { this.audio.volume = to @@ -173,7 +173,7 @@ export class AudioController { return } const elapsed = Date.now() - startTime - this.audio.volume = clamp(0.0, this.volume, from + (elapsed * step)) + this.audio.volume = clamp(0.0, Math.max(from, to), from + (elapsed * step)) this.handle = setTimeout(run, 10) } run()