Skip to content

Commit 5fb151a

Browse files
committed
fix some window and math stuffs
1 parent eb6d142 commit 5fb151a

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

graphic/display.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package graphic
22

33
import (
44
"context"
5-
"sync"
65
"sync/atomic"
76

87
"github.com/noriah/catnip/util"
@@ -27,7 +26,7 @@ const (
2726
NumRunes = 8
2827

2928
// ScalingWindow in seconds
30-
ScalingWindow = 5
29+
ScalingWindow = 2.5
3130
// PeakThreshold is the threshold to not draw if the peak is less.
3231
PeakThreshold = 0.01
3332
)
@@ -97,7 +96,6 @@ type Display struct {
9796
drawType DrawType
9897
styles Styles
9998
styleBuffer []termbox.Attribute
100-
wg sync.WaitGroup
10199
ctx context.Context
102100
cancel context.CancelFunc
103101
}
@@ -302,7 +300,11 @@ func (d *Display) Write(buffers [][]float64, channels int) error {
302300
if peak >= PeakThreshold {
303301
vMean, vSD := d.window.Update(peak)
304302

305-
if t := vMean + (1.5 * vSD); peak > t {
303+
if t := vMean + (1.25 * vSD); peak > t {
304+
vMean, vSD = d.window.Drop(5)
305+
}
306+
307+
if t := vMean - (1.5 * vSD); peak < t {
306308
vMean, vSD = d.window.Drop(5)
307309
}
308310

@@ -311,8 +313,6 @@ func (d *Display) Write(buffers [][]float64, channels int) error {
311313
}
312314
}
313315

314-
d.wg.Add(channels)
315-
316316
switch d.drawType {
317317
case DrawUp:
318318
d.drawUp(buffers, channels, scale)

util/window.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ func (mw *MovingWindow) Drop(count int) (mean float64, stddev float64) {
7777

7878
old := mw.data[idx]
7979

80+
mw.variance -= math.Pow(old-mw.average, 2.0)
8081
mw.average -= old / float64(mw.length)
81-
mw.variance -= old * old
8282

8383
mw.length--
8484
count--

0 commit comments

Comments
 (0)