Skip to content

Commit c736131

Browse files
committed
changes
1 parent e16e20e commit c736131

File tree

6 files changed

+36
-55
lines changed

6 files changed

+36
-55
lines changed

catnip.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@ func Run(cfg *Config, ctx context.Context) error {
4141
vis = processor.New(procConfig)
4242
}
4343

44-
// INPUT SETUP
45-
4644
backend, err := input.InitBackend(cfg.Backend)
4745
if err != nil {
4846
return err
@@ -65,8 +63,6 @@ func Run(cfg *Config, ctx context.Context) error {
6563
return errors.Wrap(err, "failed to start the input backend")
6664
}
6765

68-
// DISPLAY SETUP
69-
7066
if cfg.SetupFunc != nil {
7167
if err := cfg.SetupFunc(); err != nil {
7268
return err
@@ -90,7 +86,6 @@ func Run(cfg *Config, ctx context.Context) error {
9086

9187
mu := &sync.Mutex{}
9288

93-
// Start the processor
9489
go vis.Process(ctx, kickChan, mu)
9590

9691
if err := audio.Start(ctx, inputBuffers, kickChan, mu); err != nil {

cmd/catnip/config.go

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,23 +51,17 @@ type config struct {
5151

5252
// NewZeroConfig returns a zero config
5353
// it is the "default"
54-
//
55-
// nori's defaults:
56-
// - sampleRate: 122880
57-
// - sampleSize: 2048
58-
// - smoothFactor: 80.15
59-
// - super smooth detail view
6054
func newZeroConfig() config {
6155
return config{
6256
backend: input.DefaultBackend(),
6357
sampleRate: 44100,
6458
sampleSize: 1024,
65-
smoothFactor: 74.15,
66-
smoothingMethod: dsp.SmoothSimpleAverage,
59+
smoothFactor: 64.15,
60+
smoothingMethod: int(dsp.SmoothDefault),
6761
smoothingAverageWindowSize: 0, // if zero, will be calculated
6862
frameRate: 0,
6963
baseSize: 1,
70-
barSize: 2,
64+
barSize: 1,
7165
spaceSize: 1,
7266
channelCount: 2,
7367
drawType: int(graphic.DrawDefault),

cmd/catnip/main.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const AppDesc = "Continuous Automatic Terminal Number Interpretation Printer"
2727
// AppSite is the app website
2828
const AppSite = "https://github.com/noriah/catnip"
2929

30-
var version = "unknown"
30+
var version = "git"
3131

3232
func main() {
3333
log.SetFlags(0)
@@ -66,7 +66,6 @@ func main() {
6666
},
6767
StartFunc: func(ctx context.Context) (context.Context, error) {
6868
ctx = display.Start(ctx)
69-
7069
return ctx, nil
7170
},
7271
CleanupFunc: func() error {

dsp/smoother.go

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,23 @@ import (
99
type SmoothingMethod int
1010

1111
const (
12-
SmoothUnspecified = iota // 0
13-
SmoothSimple // 1
14-
SmoothAverage // 2
15-
SmoothSimpleAverage // 3
16-
SmoothNew // 5
17-
SmoothNewAverage // 4
12+
SmoothUnspecified SmoothingMethod = iota // 0
13+
SmoothSimple // 1
14+
SmoothAverage // 2
15+
SmoothSimpleAverage // 3
16+
SmoothNew // 5
17+
SmoothNewAverage // 4
18+
19+
SmoothDefault = SmoothSimpleAverage
1820
)
1921

2022
type SmootherConfig struct {
23+
AverageSize int // size of window for average methods
24+
ChannelCount int // number of channels
2125
SampleSize int // number of samples per slice
2226
SampleRate float64 // sample rate
23-
ChannelCount int // number of channels
2427
SmoothingFactor float64 // smoothing factor
2528
SmoothingMethod SmoothingMethod // smoothing method
26-
AverageSize int // size of window for average methods
2729
}
2830

2931
type Smoother interface {
@@ -39,9 +41,14 @@ type smoother struct {
3941
}
4042

4143
func NewSmoother(cfg SmootherConfig) Smoother {
44+
if cfg.SmoothingFactor <= 0.0 {
45+
cfg.SmoothingFactor = math.SmallestNonzeroFloat64
46+
}
47+
4248
sm := &smoother{
4349
values: make([][]float64, cfg.ChannelCount),
4450
averages: make([][]*util.MovingWindow, cfg.ChannelCount),
51+
smoothFactor: cfg.SmoothingFactor,
4552
smoothMethod: cfg.SmoothingMethod,
4653
}
4754

@@ -65,8 +72,6 @@ func NewSmoother(cfg SmootherConfig) Smoother {
6572
}
6673
}
6774

68-
sm.setSmoothing(cfg.SmoothingFactor)
69-
7075
return sm
7176
}
7277

@@ -91,13 +96,6 @@ func (sm *smoother) SmoothBin(ch, idx int, value float64) float64 {
9196
return sm.switchSmoothing(ch, idx, value, 0.0)
9297
}
9398

94-
func (sm *smoother) setSmoothing(factor float64) {
95-
if factor <= 0.0 {
96-
factor = math.SmallestNonzeroFloat64
97-
}
98-
sm.smoothFactor = factor
99-
}
100-
10199
func (sm *smoother) switchSmoothing(ch, idx int, value, peak float64) float64 {
102100
switch sm.smoothMethod {
103101
default:

graphic/display.go

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -311,22 +311,22 @@ func (d *Display) Write(buffers [][]float64, channels int) error {
311311

312312
switch d.drawType {
313313
case DrawUp:
314-
d.DrawUp(buffers, channels, scale)
314+
d.drawUp(buffers, channels, scale)
315315

316316
case DrawUpDown:
317-
d.DrawUpDown(buffers, channels, scale)
317+
d.drawUpDown(buffers, channels, scale)
318318

319319
case DrawDown:
320-
d.DrawDown(buffers, channels, scale)
320+
d.drawDown(buffers, channels, scale)
321321

322322
case DrawLeft:
323-
d.DrawLeft(buffers, channels, scale)
323+
d.drawLeft(buffers, channels, scale)
324324

325325
case DrawLeftRight:
326-
d.DrawLeftRight(buffers, channels, scale)
326+
d.drawLeftRight(buffers, channels, scale)
327327

328328
case DrawRight:
329-
d.DrawRight(buffers, channels, scale)
329+
d.drawRight(buffers, channels, scale)
330330

331331
default:
332332
return nil
@@ -433,8 +433,8 @@ func sizeAndCap(value float64, space int, zeroBase bool, baseRune rune) (int, ru
433433

434434
// DRAWING METHODS
435435

436-
// DrawUp will draw up.
437-
func (d *Display) DrawUp(bins [][]float64, channelCount int, scale float64) {
436+
// drawUp will draw up.
437+
func (d *Display) drawUp(bins [][]float64, channelCount int, scale float64) {
438438
binCount := d.Bins(channelCount)
439439
barSpace := intMax(d.termHeight-d.baseSize, 0)
440440
scale = float64(barSpace) / scale
@@ -474,8 +474,8 @@ func (d *Display) DrawUp(bins [][]float64, channelCount int, scale float64) {
474474
}
475475
}
476476

477-
// DrawUpDown will draw up and down.
478-
func (d *Display) DrawUpDown(bins [][]float64, channelCount int, scale float64) {
477+
// drawUpDown will draw up and down.
478+
func (d *Display) drawUpDown(bins [][]float64, channelCount int, scale float64) {
479479
binCount := d.Bins(channelCount)
480480
centerStart := intMax((d.termHeight-d.baseSize)/2, 0)
481481
centerStop := centerStart + d.baseSize
@@ -521,8 +521,8 @@ func (d *Display) DrawUpDown(bins [][]float64, channelCount int, scale float64)
521521
}
522522
}
523523

524-
// DrawDown will draw down.
525-
func (d *Display) DrawDown(bins [][]float64, channelCount int, scale float64) {
524+
// drawDown will draw down.
525+
func (d *Display) drawDown(bins [][]float64, channelCount int, scale float64) {
526526
binCount := d.Bins(channelCount)
527527
barSpace := intMax(d.termHeight-d.baseSize, 0)
528528
scale = float64(barSpace) / scale
@@ -566,7 +566,7 @@ func (d *Display) DrawDown(bins [][]float64, channelCount int, scale float64) {
566566
}
567567
}
568568

569-
func (d *Display) DrawLeft(bins [][]float64, channelCount int, scale float64) {
569+
func (d *Display) drawLeft(bins [][]float64, channelCount int, scale float64) {
570570
binCount := d.Bins(channelCount)
571571
barSpace := intMax(d.termWidth-d.baseSize, 0)
572572
scale = float64(barSpace) / scale
@@ -606,8 +606,8 @@ func (d *Display) DrawLeft(bins [][]float64, channelCount int, scale float64) {
606606
}
607607
}
608608

609-
// DrawLeftRight will draw left and right.
610-
func (d *Display) DrawLeftRight(bins [][]float64, channelCount int, scale float64) {
609+
// drawLeftRight will draw left and right.
610+
func (d *Display) drawLeftRight(bins [][]float64, channelCount int, scale float64) {
611611
binCount := d.Bins(channelCount)
612612
centerStart := intMax((d.termWidth-d.baseSize)/2, 0)
613613
centerStop := centerStart + d.baseSize
@@ -656,7 +656,7 @@ func (d *Display) DrawLeftRight(bins [][]float64, channelCount int, scale float6
656656
}
657657
}
658658

659-
func (d *Display) DrawRight(bins [][]float64, channelCount int, scale float64) {
659+
func (d *Display) drawRight(bins [][]float64, channelCount int, scale float64) {
660660
binCount := d.Bins(channelCount)
661661
barSpace := intMax(d.termWidth-d.baseSize, 0)
662662
scale = float64(barSpace) / scale

input/backend.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,7 @@ func FindBackend(name string) Backend {
9595
}
9696

9797
func HasBackend(name string) bool {
98-
for _, backend := range Backends {
99-
if backend.Name == name {
100-
return true
101-
}
102-
}
103-
return false
98+
return FindBackend(name) != nil
10499
}
105100

106101
func InitBackend(bknd string) (Backend, error) {

0 commit comments

Comments
 (0)