Skip to content

Commit

Permalink
fix audio fade in never ending when using Replay Gain
Browse files Browse the repository at this point in the history
  • Loading branch information
tamland committed Dec 30, 2024
1 parent 14a75cb commit 8219ecc
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/player/audio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand Down

0 comments on commit 8219ecc

Please sign in to comment.