Skip to content

Commit aee9e07

Browse files
committed
zero value only for var
1 parent fa619fa commit aee9e07

File tree

23 files changed

+114
-154
lines changed

23 files changed

+114
-154
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
- ALSA (linux FFmpeg)
2020
- DirectShow (windblows FFmpeg)
2121

22-
*portaudio is difficult on windows, so by default it is disabled on windows.
22+
*portaudio is difficult on windows. by default it is disabled on windows.
2323

2424
## it depends on
2525

@@ -58,6 +58,9 @@ go install -tags noportaudio
5858

5959
# with portaudio on windows
6060
go install -tags portonwin
61+
62+
# with fftw3 on windows
63+
go install -tags fftwonwin
6164
```
6265

6366
## run it

catnip.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"github.com/noriah/catnip/dsp"
1010
"github.com/noriah/catnip/graphic"
1111
"github.com/noriah/catnip/input"
12-
"github.com/noriah/catnip/visualizer"
12+
"github.com/noriah/catnip/processor"
1313

1414
_ "github.com/noriah/catnip/input/ffmpeg"
1515
_ "github.com/noriah/catnip/input/parec"
@@ -32,7 +32,7 @@ var version = "unknown"
3232
func main() {
3333
log.SetFlags(0)
3434

35-
var cfg = newZeroConfig()
35+
cfg := newZeroConfig()
3636

3737
if doFlags(&cfg) {
3838
return
@@ -43,7 +43,7 @@ func main() {
4343
chk(catnip(&cfg), "failed to run catnip")
4444
}
4545

46-
// Catnip starts to draw the visualizer on the termbox screen.
46+
// Catnip starts to draw the processor on the termbox screen.
4747
func catnip(cfg *config) error {
4848

4949
display := &graphic.Display{}
@@ -58,7 +58,7 @@ func catnip(cfg *config) error {
5858
inputBuffers := input.MakeBuffers(cfg.channelCount, cfg.sampleSize)
5959
// visBuffers := input.MakeBuffers(cfg.channelCount, cfg.sampleSize)
6060

61-
procConfig := visualizer.Config{
61+
procConfig := processor.Config{
6262
SampleRate: cfg.sampleRate,
6363
SampleSize: cfg.sampleSize,
6464
ChannelCount: cfg.channelCount,
@@ -68,17 +68,17 @@ func catnip(cfg *config) error {
6868
Display: display,
6969
}
7070

71-
var vis visualizer.Visualizer
71+
var vis processor.Processor
7272

7373
if cfg.useThreaded {
74-
vis = visualizer.NewThreaded(procConfig)
74+
vis = processor.NewThreaded(procConfig)
7575
} else {
76-
vis = visualizer.New(procConfig)
76+
vis = processor.New(procConfig)
7777
}
7878

7979
// INPUT SETUP
8080

81-
var backend, err = input.InitBackend(cfg.backend)
81+
backend, err := input.InitBackend(cfg.backend)
8282
if err != nil {
8383
return err
8484
}
@@ -174,7 +174,7 @@ func catnip(cfg *config) error {
174174
// NewZeroConfig returns a zero config
175175
// it is the "default"
176176
//
177-
// nora's defaults:
177+
// nori's defaults:
178178
// - sampleRate: 122880
179179
// - sampleSize: 2048
180180
// - smoothFactor: 80.15
@@ -198,12 +198,12 @@ func newZeroConfig() config {
198198

199199
func doFlags(cfg *config) bool {
200200

201-
var parser = flaggy.NewParser(AppName)
201+
parser := flaggy.NewParser(AppName)
202202
parser.Description = AppDesc
203203
parser.AdditionalHelpPrepend = AppSite
204204
parser.Version = version
205205

206-
var listBackendsCmd = flaggy.Subcommand{
206+
listBackendsCmd := flaggy.Subcommand{
207207
Name: "list-backends",
208208
ShortName: "lb",
209209
Description: "list all supported backends",
@@ -212,7 +212,7 @@ func doFlags(cfg *config) bool {
212212

213213
parser.AttachSubcommand(&listBackendsCmd, 1)
214214

215-
var listDevicesCmd = flaggy.Subcommand{
215+
listDevicesCmd := flaggy.Subcommand{
216216
Name: "list-devices",
217217
ShortName: "ld",
218218
Description: "list all devices for a backend",
@@ -232,7 +232,7 @@ func doFlags(cfg *config) bool {
232232
parser.Int(&cfg.barSize, "bw", "bar", "bar width [1, +Inf)")
233233
parser.Int(&cfg.spaceSize, "sw", "space", "space width [0, +Inf)")
234234
parser.Int(&cfg.drawType, "dt", "draw", "draw type (1, 2, 3)")
235-
parser.Bool(&cfg.useThreaded, "t", "threaded", "use the threaded visualizer")
235+
parser.Bool(&cfg.useThreaded, "t", "threaded", "use the threaded processor")
236236

237237
fg, bg, center := graphic.DefaultStyles().AsUInt16s()
238238
parser.UInt16(&fg, "fg", "foreground",
@@ -268,7 +268,7 @@ func doFlags(cfg *config) bool {
268268
fmt.Printf("all devices for %q backend. '*' marks default\n", cfg.backend)
269269

270270
for idx := range devices {
271-
var star = ' '
271+
star := ' '
272272
if defaultDevice != nil && devices[idx].String() == defaultDevice.String() {
273273
star = '*'
274274
}

config.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ type config struct {
2222
// hiCutFreq float64
2323
// SmoothFactor factor of smooth
2424
smoothFactor float64
25+
// SampleSize is how much we draw. Play with it
26+
sampleSize int
2527
// FrameRate is the number of frames to draw every second (0 draws it every
2628
// perfect sample)
2729
frameRate int
@@ -31,8 +33,6 @@ type config struct {
3133
barSize int
3234
// SpaceSize is the size of spaces, in columns/rows
3335
spaceSize int
34-
// SampleSiz is how much we draw. Play with it
35-
sampleSize int
3636
// ChannelCount is the number of channels we want to look at. DO NOT TOUCH
3737
channelCount int
3838
// Combine determines if we merge streams (stereo -> mono)

dsp/analyzer.go

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@
1111
//
1212
package dsp
1313

14-
import (
15-
"math"
16-
)
14+
import "math"
1715

1816
type Config struct {
1917
SampleRate float64 // audio sample rate
@@ -47,8 +45,8 @@ type bin struct {
4745
// widthFFT int // fft floor-ceiling index delta
4846
}
4947

50-
// Frequencies are the dividing frequencies
51-
var Frequencies = []float64{
48+
// frequencies are the dividing frequencies
49+
var frequencies = []float64{
5250
// sub sub bass
5351
20.0, // 0
5452
// sub bass
@@ -140,8 +138,8 @@ func (az *analyzer) Recalculate(binCount int) int {
140138

141139
az.distribute(binCount)
142140

143-
var bassCut = az.freqToIdx(Frequencies[2], math.Floor)
144-
var fBassCut = float64(bassCut)
141+
bassCut := az.freqToIdx(frequencies[2], math.Floor)
142+
fBassCut := float64(bassCut)
145143

146144
// set widths
147145
for idx, b := range az.bins[:binCount] {
@@ -160,16 +158,19 @@ func (az *analyzer) Recalculate(binCount int) int {
160158
return binCount
161159
}
162160

161+
// This is some hot garbage.
162+
// It essentially is a lot of work to just increment from 0 for each next bin.
163+
// Working on replacing this with a real distribution.
163164
func (az *analyzer) distribute(bins int) {
164-
var lo = Frequencies[1]
165-
var hi = math.Min(az.cfg.SampleRate/2, Frequencies[4])
165+
lo := frequencies[1]
166+
hi := math.Min(az.cfg.SampleRate/2, frequencies[4])
166167

167-
var loLog = math.Log10(lo)
168-
var hiLog = math.Log10(hi)
168+
loLog := math.Log10(lo)
169+
hiLog := math.Log10(hi)
169170

170-
var cF = (hiLog - loLog) / float64(bins)
171+
cF := (hiLog - loLog) / float64(bins)
171172

172-
var cCoef = 100.0 / float64(bins+1)
173+
cCoef := 100.0 / float64(bins+1)
173174

174175
for idx := range az.bins[:bins+1] {
175176

@@ -193,7 +194,7 @@ func (az *analyzer) distribute(bins int) {
193194
type mathFunc func(float64) float64
194195

195196
func (az *analyzer) freqToIdx(freq float64, round mathFunc) int {
196-
var b = int(round(freq / (az.cfg.SampleRate / float64(az.cfg.SampleSize))))
197+
b := int(round(freq / (az.cfg.SampleRate / float64(az.cfg.SampleSize))))
197198

198199
if b < az.fftSize {
199200
return b
@@ -208,7 +209,7 @@ func (az *analyzer) setSmoothing(factor float64) {
208209
factor = math.SmallestNonzeroFloat64
209210
}
210211

211-
var sf = math.Pow(10.0, (1.0-factor)*(-25.0))
212+
sf := math.Pow(10.0, (1.0-factor)*(-25.0))
212213

213214
az.smoothFactor = math.Pow(sf, float64(az.cfg.SampleSize)/az.cfg.SampleRate)
214215
}

dsp/window/window.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ func Rectangle(buf []float64) {
1515

1616
// CosSum modifies the buffer to conform to a cosine sum window following a0
1717
func CosSum(buf []float64, a0 float64) {
18-
var size = len(buf)
19-
var a1 = 1.0 - a0
20-
var coef = 2.0 * math.Pi / float64(size)
18+
size := len(buf)
19+
a1 := 1.0 - a0
20+
coef := 2.0 * math.Pi / float64(size)
2121
for n := 0; n < size; n++ {
2222
buf[n] *= (a0 - (a1 * math.Cos(coef*float64(n))))
2323
}
@@ -65,7 +65,7 @@ func Hann(buf []float64) {
6565

6666
// Bartlett modifies the buffer to a Bartlett window
6767
func Bartlett(buf []float64) {
68-
var N = float64(len(buf))
68+
N := float64(len(buf))
6969
for n := range buf {
7070
buf[n] *= (1.0 - (math.Abs(((2.0 * float64(n)) - N) / N)))
7171
}
@@ -94,8 +94,8 @@ func Blackman(buf []float64) {
9494
//
9595
// not sure how i got this
9696
func PlanckTaper(buf []float64, e float64) {
97-
var size = len(buf)
98-
var eN = e * float64(size)
97+
size := len(buf)
98+
eN := e * float64(size)
9999

100100
buf[0] *= 0
101101
for n := 1; n < int(eN); n++ {

fft/fft_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ func Benchmark(b *testing.B) {
2828
const numReals = 44100
2929

3030
func generateReals() []float64 {
31-
var input = make([]float64, numReals)
31+
input := make([]float64, numReals)
3232

33-
var c = 3.1
33+
c := 3.1
3434
for i := range input {
3535
c += 0.3
3636
input[i] = 2*c - c*c

fft/fftw.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//go:build cgo && !windows && !nofftw
1+
//go:build cgo && ((!windows && !nofftw) || (windows && fftwonwin))
22

33
package fft
44

fft/gonum.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//go:build !cgo || nofftw || windows
1+
//go:build !cgo || nofftw || (windows && !fftwonwin)
22

33
package fft
44

go.mod

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
module github.com/noriah/catnip
22

3-
go 1.15
3+
go 1.18
44

55
require (
66
github.com/integrii/flaggy v1.4.4
7-
github.com/lawl/pulseaudio v0.0.0-20200802093727-ab0735955fd0
8-
github.com/mattn/go-runewidth v0.0.13 // indirect
9-
github.com/nsf/termbox-go v0.0.0-20200418040025-38ba6e5628f1
7+
github.com/lawl/pulseaudio v0.0.0-20210928141934-ed754c0c6618
8+
github.com/nsf/termbox-go v1.1.1
109
github.com/pkg/errors v0.9.1
11-
gonum.org/v1/gonum v0.8.1
10+
gonum.org/v1/gonum v0.11.0
1211
)
12+
13+
require github.com/mattn/go-runewidth v0.0.9 // indirect

go.sum

Lines changed: 8 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,13 @@
1-
github.com/ajstarks/svgo v0.0.0-20180226025133-644b8db467af/go.mod h1:K08gAheRH3/J6wwsYMMT4xOr94bZjxIelGM0+d/wbFw=
2-
github.com/fogleman/gg v1.2.1-0.20190220221249-0403632d5b90/go.mod h1:R/bRT+9gY/C5z7JzPU0zXsXHKM4/ayA+zqcVNZzPa1k=
3-
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k=
41
github.com/integrii/flaggy v1.4.4 h1:8fGyiC14o0kxhTqm2VBoN19fDKPZsKipP7yggreTMDc=
52
github.com/integrii/flaggy v1.4.4/go.mod h1:tnTxHeTJbah0gQ6/K0RW0J7fMUBk9MCF5blhm43LNpI=
6-
github.com/jung-kurt/gofpdf v1.0.3-0.20190309125859-24315acbbda5/go.mod h1:7Id9E/uU8ce6rXgefFLlgrJj/GYY22cpxn+r32jIOes=
7-
github.com/lawl/pulseaudio v0.0.0-20200802093727-ab0735955fd0 h1:JrvOwrr1teFiqsp0EQxgEPJsm0pet+YLTL+HdYmnMx0=
8-
github.com/lawl/pulseaudio v0.0.0-20200802093727-ab0735955fd0/go.mod h1:9h36x4KH7r2V8DOCKoPMt87IXZ++X90y8D5nnuwq290=
3+
github.com/lawl/pulseaudio v0.0.0-20210928141934-ed754c0c6618 h1:lktbhQBHluc1oWEDow4DEv13qkWJ8zm/dTUSKer2iKk=
4+
github.com/lawl/pulseaudio v0.0.0-20210928141934-ed754c0c6618/go.mod h1:9h36x4KH7r2V8DOCKoPMt87IXZ++X90y8D5nnuwq290=
5+
github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0=
96
github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
10-
github.com/mattn/go-runewidth v0.0.12 h1:Y41i/hVW3Pgwr8gV+J23B9YEY0zxjptBuCWEaxmAOow=
11-
github.com/mattn/go-runewidth v0.0.12/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk=
12-
github.com/mattn/go-runewidth v0.0.13 h1:lTGmDsbAYt5DmK6OnoV7EuIF1wEIFAcxld6ypU4OSgU=
13-
github.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
14-
github.com/noriah/termbox-go v1.1.1 h1:fFwcWznTCH33NHhbHWvR9of/opQa4YecWMU+cQKIyA0=
15-
github.com/noriah/termbox-go v1.1.1/go.mod h1:T0cTdVuOwf7pHQNtfhnEbzHbcNyCEcVU4YPpouCbVxo=
16-
github.com/nsf/termbox-go v0.0.0-20200418040025-38ba6e5628f1 h1:lh3PyZvY+B9nFliSGTn5uFuqQQJGuNrD0MLCokv09ag=
17-
github.com/nsf/termbox-go v0.0.0-20200418040025-38ba6e5628f1/go.mod h1:IuKpRQcYE1Tfu+oAQqaLisqDeXgjyyltCfsaoYN18NQ=
7+
github.com/nsf/termbox-go v1.1.1 h1:nksUPLCb73Q++DwbYUBEglYBRPZyoXJdrj5L+TkjyZY=
8+
github.com/nsf/termbox-go v1.1.1/go.mod h1:T0cTdVuOwf7pHQNtfhnEbzHbcNyCEcVU4YPpouCbVxo=
189
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
1910
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
20-
github.com/rivo/uniseg v0.1.0 h1:+2KBaVoUmb9XzDsrx/Ct0W/EYOSFf/nWTauy++DprtY=
21-
github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
22-
github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=
23-
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
24-
golang.org/x/exp v0.0.0-20180321215751-8460e604b9de/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
25-
golang.org/x/exp v0.0.0-20180807140117-3d87b88a115f/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
26-
golang.org/x/exp v0.0.0-20190125153040-c74c464bbbf2 h1:y102fOLFqhV41b+4GPiJoa0k/x+pJcEi2/HB1Y5T6fU=
27-
golang.org/x/exp v0.0.0-20190125153040-c74c464bbbf2/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
28-
golang.org/x/image v0.0.0-20180708004352-c73c2afc3b81/go.mod h1:ux5Hcp/YLpHSI86hEcLt0YII63i6oz57MZXIpbrjZUs=
29-
golang.org/x/tools v0.0.0-20180525024113-a5b4c53f6e8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
30-
golang.org/x/tools v0.0.0-20190206041539-40960b6deb8e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
31-
gonum.org/v1/gonum v0.0.0-20180816165407-929014505bf4/go.mod h1:Y+Yx5eoAFn32cQvJDxZx5Dpnq+c3wtXuadVZAcxbbBo=
32-
gonum.org/v1/gonum v0.8.1 h1:wGtP3yGpc5mCLOLeTeBdjeui9oZSz5De0eOjMLC/QuQ=
33-
gonum.org/v1/gonum v0.8.1/go.mod h1:oe/vMfY3deqTw+1EZJhuvEW2iwGF1bW9wwu7XCu0+v0=
34-
gonum.org/v1/netlib v0.0.0-20190313105609-8cb42192e0e0 h1:OE9mWmgKkjJyEmDAAtGMPjXu+YNeGvK9VTSHY6+Qihc=
35-
gonum.org/v1/netlib v0.0.0-20190313105609-8cb42192e0e0/go.mod h1:wa6Ws7BG/ESfp6dHfk7C6KdzKA7wR7u/rKwOGE66zvw=
36-
gonum.org/v1/plot v0.0.0-20190515093506-e2840ee46a6b/go.mod h1:Wt8AAjI+ypCyYX3nZBvf6cAIx93T+c/OS2HFAYskSZc=
37-
rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4=
11+
golang.org/x/exp v0.0.0-20191002040644-a1355ae1e2c3 h1:n9HxLrNxWWtEb1cA950nuEEj3QnKbtsCJ6KjcgisNUs=
12+
gonum.org/v1/gonum v0.11.0 h1:f1IJhK4Km5tBJmaiJXtk/PkL4cdVX6J+tGiM187uT5E=
13+
gonum.org/v1/gonum v0.11.0/go.mod h1:fSG4YDCxxUZQJ7rKsQrj0gMOg00Il0Z96/qMA4bVQhA=

0 commit comments

Comments
 (0)