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

@ -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 {