Skip to content

Commit

Permalink
fix initial conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
dweymouth committed Jul 23, 2024
1 parent 4d635d8 commit fdeb33f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
8 changes: 7 additions & 1 deletion ui/controller/visualizations.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"fyne.io/fyne/v2"
"fyne.io/fyne/v2/lang"
"github.com/dweymouth/supersonic/backend/player"
"github.com/dweymouth/supersonic/ui/util"
"github.com/dweymouth/supersonic/ui/visualizations"
)
Expand Down Expand Up @@ -47,7 +48,12 @@ func (c *Controller) ShowPeakMeter() {
}
c.peakMeter = visualizations.NewPeakMeter()
win.SetContent(c.peakMeter)
c.startVisualizationAnim()
if c.App.LocalPlayer.GetStatus().State == player.Playing {
c.startVisualizationAnim()
} else {
// TODO: why is this needed?
c.peakMeter.Refresh()
}
win.Show()
}

Expand Down
16 changes: 13 additions & 3 deletions ui/visualizations/peakmeter.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ const (
meterRangeDB = 62
rmsSmoothingFactor = 0.8
peakHoldFrames = 60

noiseFloorDB = -96
)

type PeakMeter struct {
Expand All @@ -33,7 +35,14 @@ type PeakMeter struct {
}

func NewPeakMeter() *PeakMeter {
p := &PeakMeter{}
p := &PeakMeter{
lPeak: noiseFloorDB,
rPeak: noiseFloorDB,
lRMS: noiseFloorDB,
rRMS: noiseFloorDB,
lPeakHold: noiseFloorDB,
rPeakHold: noiseFloorDB,
}
p.ExtendBaseWidget(p)
return p
}
Expand All @@ -44,8 +53,8 @@ func NewPeakMeter() *PeakMeter {
func (p *PeakMeter) UpdatePeaks(lPeak, rPeak, lRMS, rRMS float64) {
p.lPeak = lPeak
p.rPeak = rPeak
lRMS = math.Max(-96, lRMS)
rRMS = math.Max(-96, rRMS)
lRMS = math.Max(noiseFloorDB, lRMS)
rRMS = math.Max(noiseFloorDB, rRMS)
p.lRMS = rmsSmoothingFactor*p.lRMS + (1-rmsSmoothingFactor)*lRMS
p.rRMS = rmsSmoothingFactor*p.rRMS + (1-rmsSmoothingFactor)*rRMS

Expand Down Expand Up @@ -99,6 +108,7 @@ func newPeakMeterRenderer(pm *PeakMeter) *peakMeterRenderer {
p.rulerLabels[i].Resize(p.rulerLabels[i].MinSize())
x -= 10
}
p.Layout(pm.Size())

return p
}
Expand Down

0 comments on commit fdeb33f

Please sign in to comment.