Fix equalizer audio filter string construction (#834)

* Fix equalizer audio filter string construction

* some code style cleanup

* import strings

---------

Co-authored-by: Drew Weymouth <dweymouth@users.noreply.github.com>
This commit is contained in:
Gianluca Boiano
2026-01-28 19:32:16 -08:00
committed by GitHub
co-authored by Drew Weymouth
parent aeec889e40
commit 6c038df537
+11 -14
View File
@@ -6,6 +6,7 @@ import (
"fmt" "fmt"
"math" "math"
"strconv" "strconv"
"strings"
"sync" "sync"
"time" "time"
@@ -503,23 +504,19 @@ func (p *Player) setState(s player.State) {
} }
func (p *Player) setAF() error { func (p *Player) setAF() error {
af := "" var filters []string
if p.peaksEnabled { 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 := p.equalizer; eq != nil && eq.IsEnabled() {
if eq == nil || !eq.IsEnabled() { if math.Abs(eq.Preamp()) > 0.01 {
return p.mpv.SetPropertyString("af", af) filters = append(filters, fmt.Sprintf("volume=volume=%0.1fdB", eq.Preamp()))
} else if p.peaksEnabled { }
af = af + "," if eqAF := eq.Curve().String(); eqAF != "" {
filters = append(filters, eqAF)
}
} }
if math.Abs(eq.Preamp()) > 0.01 { return p.mpv.SetPropertyString("af", strings.Join(filters, ","))
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)
} }
func (p *Player) eventHandler(ctx context.Context) { func (p *Player) eventHandler(ctx context.Context) {