Skip to content

Commit

Permalink
fix some window and math stuffs
Browse files Browse the repository at this point in the history
  • Loading branch information
noriah committed Apr 3, 2023
1 parent eb6d142 commit 5fb151a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
12 changes: 6 additions & 6 deletions graphic/display.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package graphic

import (
"context"
"sync"
"sync/atomic"

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

// ScalingWindow in seconds
ScalingWindow = 5
ScalingWindow = 2.5
// PeakThreshold is the threshold to not draw if the peak is less.
PeakThreshold = 0.01
)
Expand Down Expand Up @@ -97,7 +96,6 @@ type Display struct {
drawType DrawType
styles Styles
styleBuffer []termbox.Attribute
wg sync.WaitGroup
ctx context.Context
cancel context.CancelFunc
}
Expand Down Expand Up @@ -302,7 +300,11 @@ func (d *Display) Write(buffers [][]float64, channels int) error {
if peak >= PeakThreshold {
vMean, vSD := d.window.Update(peak)

if t := vMean + (1.5 * vSD); peak > t {
if t := vMean + (1.25 * vSD); peak > t {
vMean, vSD = d.window.Drop(5)
}

if t := vMean - (1.5 * vSD); peak < t {
vMean, vSD = d.window.Drop(5)
}

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

d.wg.Add(channels)

switch d.drawType {
case DrawUp:
d.drawUp(buffers, channels, scale)
Expand Down
2 changes: 1 addition & 1 deletion util/window.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ func (mw *MovingWindow) Drop(count int) (mean float64, stddev float64) {

old := mw.data[idx]

mw.variance -= math.Pow(old-mw.average, 2.0)
mw.average -= old / float64(mw.length)
mw.variance -= old * old

mw.length--
count--
Expand Down

0 comments on commit 5fb151a

Please sign in to comment.