fix(tracker): avoid NaNs in volume analyzer better

This commit is contained in:
vsariola
2021-03-14 18:19:13 +02:00
parent b6283cd13e
commit 5daf81f331
3 changed files with 15 additions and 12 deletions

View File

@ -149,7 +149,7 @@ func New(audioContext sointu.AudioContext, synthService sointu.SynthService, syn
}
t.Model = tracker.NewModel()
vuBufferObserver := make(chan []float32)
go tracker.VuAnalyzer(0.3, 1e-4, 1, -100, vuBufferObserver, t.volumeChan)
go tracker.VuAnalyzer(0.3, 1e-4, 1, -100, 20, vuBufferObserver, t.volumeChan)
t.Theme.Palette.Fg = primaryColor
t.Theme.Palette.ContrastFg = black
t.SetEditMode(tracker.EditTracks)

View File

@ -21,7 +21,7 @@ func (v VuMeter) Layout(gtx C) D {
gtx.Constraints.Max.Y = gtx.Px(unit.Dp(12))
height := gtx.Px(unit.Dp(6))
for j := 0; j < 2; j++ {
value := v.Volume.Average[j] + v.Range
value := float32(v.Volume.Average[j]) + v.Range
if value > 0 {
x := int(value/v.Range*float32(gtx.Constraints.Max.X) + 0.5)
if x > gtx.Constraints.Max.X {
@ -29,7 +29,7 @@ func (v VuMeter) Layout(gtx C) D {
}
paint.FillShape(gtx.Ops, mediumEmphasisTextColor, clip.Rect(image.Rect(0, 0, x, height)).Op())
}
valueMax := v.Volume.Peak[j] + v.Range
valueMax := float32(v.Volume.Peak[j]) + v.Range
if valueMax > 0 {
color := white
if valueMax >= v.Range {