From 6c038df5374891b935e6c8abc34a0314a714975a Mon Sep 17 00:00:00 2001 From: Gianluca Boiano <491117+M0Rf30@users.noreply.github.com> Date: Thu, 29 Jan 2026 04:32:16 +0100 Subject: [PATCH] Fix equalizer audio filter string construction (#834) * Fix equalizer audio filter string construction * some code style cleanup * import strings --------- Co-authored-by: Drew Weymouth --- backend/player/mpv/player.go | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/backend/player/mpv/player.go b/backend/player/mpv/player.go index a6a9cf6..89140ed 100644 --- a/backend/player/mpv/player.go +++ b/backend/player/mpv/player.go @@ -6,6 +6,7 @@ import ( "fmt" "math" "strconv" + "strings" "sync" "time" @@ -503,23 +504,19 @@ func (p *Player) setState(s player.State) { } func (p *Player) setAF() error { - af := "" + var filters []string if p.peaksEnabled { - af = "@astats:astats=metadata=1:reset=1:measure_overall=none" + filters = append(filters, "@astats:astats=metadata=1:reset=1:measure_overall=none") } - eq := p.equalizer - if eq == nil || !eq.IsEnabled() { - return p.mpv.SetPropertyString("af", af) - } else if p.peaksEnabled { - af = af + "," + if eq := p.equalizer; eq != nil && eq.IsEnabled() { + if math.Abs(eq.Preamp()) > 0.01 { + filters = append(filters, fmt.Sprintf("volume=volume=%0.1fdB", eq.Preamp())) + } + if eqAF := eq.Curve().String(); eqAF != "" { + filters = append(filters, eqAF) + } } - if math.Abs(eq.Preamp()) > 0.01 { - af = fmt.Sprintf("%svolume=volume=%0.1fdB", af, eq.Preamp()) - } - if eqAF := eq.Curve().String(); eqAF != "" { - af = fmt.Sprintf("%s,%s", af, eqAF) - } - return p.mpv.SetPropertyString("af", af) + return p.mpv.SetPropertyString("af", strings.Join(filters, ",")) } func (p *Player) eventHandler(ctx context.Context) {