Skip to content

Commit 8219ecc

Browse files
committed
fix audio fade in never ending when using Replay Gain
1 parent 14a75cb commit 8219ecc

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/player/audio.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -150,13 +150,13 @@ export class AudioController {
150150
}
151151

152152
private fadeFromTo(from: number, to: number, duration: number) {
153-
console.info(`AudioController: start fade (${from}, ${to}, ${duration})`)
154-
const startTime = Date.now()
155-
156153
const replayGainFactor = this.replayGainFactor()
157154
from *= replayGainFactor
158155
to *= replayGainFactor
159156

157+
console.info(`AudioController: start fade (${from}, ${to}, ${duration})`)
158+
const startTime = Date.now()
159+
160160
const step = (to - from) / duration
161161
if (duration <= 0.0) {
162162
this.audio.volume = to
@@ -173,7 +173,7 @@ export class AudioController {
173173
return
174174
}
175175
const elapsed = Date.now() - startTime
176-
this.audio.volume = clamp(0.0, this.volume, from + (elapsed * step))
176+
this.audio.volume = clamp(0.0, Math.max(from, to), from + (elapsed * step))
177177
this.handle = setTimeout(run, 10)
178178
}
179179
run()

0 commit comments

Comments
 (0)