Skip to content

Commit db6872f

Browse files
committed
i think we are nearing v1.0.0
1 parent 39ddb20 commit db6872f

File tree

5 files changed

+139
-119
lines changed

5 files changed

+139
-119
lines changed

config.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,17 @@ type Config struct {
3939
}
4040

4141
// NewZeroConfig returns a zero config
42+
// it is the "default"
43+
//
44+
// nora's defaults:
45+
// - sampleRate: 122880
46+
// - sampleSize: 2048
47+
// - super smooth detail view
4248
func NewZeroConfig() Config {
4349
return Config{
4450
SampleRate: 44100,
45-
SmoothFactor: 65.5,
46-
WinVar: 0.5,
51+
SmoothFactor: 19.69,
52+
WinVar: 0.50,
4753
BaseThick: 1,
4854
BarWidth: 2,
4955
SpaceWidth: 1,
@@ -58,6 +64,8 @@ func sanitizeConfig(cfg *Config) error {
5864
switch {
5965
case cfg.WinVar > 1.0:
6066
cfg.WinVar = 1.0
67+
case cfg.WinVar < 0.0:
68+
cfg.WinVar = 0.0
6169
default:
6270
}
6371

dsp/spectrum.go

Lines changed: 49 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -10,39 +10,43 @@ import (
1010

1111
// Spectrum is an audio spectrum in a buffer
1212
type Spectrum struct {
13-
numBins int
14-
15-
fftSize int
16-
17-
sampleSize int
18-
sampleRate float64
19-
20-
winVar float64
21-
22-
smoothFactor float64
23-
24-
bins []bin
25-
26-
fftBuf []complex128
27-
28-
streams []*stream
13+
numBins int // number of bins we look at
14+
fftSize int // number of fft bins
15+
sampleSize int // number of samples per slice
16+
sampleRate float64 // audio sample rate
17+
winVar float64 // window variable
18+
smoothFactor float64 // smothing factor
19+
bins []bin // bins for processing
20+
fftBuf []complex128 // fft return buffer
21+
streams []*stream // streams of data
2922
}
3023

3124
type bin struct {
32-
eqVal float64
33-
34-
floorFFT int
35-
ceilFFT int
36-
widthFFT int
25+
eqVal float64 // equalizer value
26+
floorFFT int // floor fft index
27+
ceilFFT int // ceiling fft index
28+
widthFFT int // fft floor-ceiling index delta
3729
}
3830

3931
type stream struct {
40-
input []float64
41-
buf []float64
42-
pBuf []float64
43-
plan *fft.Plan
32+
input []float64 // input data buffer
33+
buf []float64 // bar bin buffer
34+
pBuf []float64 // previous run bin buffer
35+
plan *fft.Plan // fft plan
4436
}
4537

38+
// SpectrumType is the type of calculation we run
39+
type SpectrumType int
40+
41+
// Spectrum calculation types
42+
const (
43+
SpectrumLog SpectrumType = iota
44+
SpectrumEqual
45+
46+
// SpectrumDefault is the default spectrum type
47+
SpectrumDefault = SpectrumLog
48+
)
49+
4650
// Frequencies are the dividing frequencies
4751
var Frequencies = []float64{
4852
// sub sub bass
@@ -60,18 +64,6 @@ var Frequencies = []float64{
6064
// everything else
6165
}
6266

63-
// SpectrumType is the type of calculation we run
64-
type SpectrumType int
65-
66-
// Spectrum calculation types
67-
const (
68-
SpectrumLog SpectrumType = iota
69-
SpectrumEqual
70-
71-
// SpectrumDefault is the default spectrum type
72-
SpectrumDefault = SpectrumLog
73-
)
74-
7567
// Some notes:
7668
//
7769
// https://stackoverflow.com/questions/3694918/how-to-extract-frequency-associated-with-fft-values-in-python
@@ -90,7 +82,7 @@ func NewSpectrum(hz float64, size int) *Spectrum {
9082
fftSize: fftSize,
9183
sampleSize: size,
9284
sampleRate: hz,
93-
smoothFactor: 0.655,
85+
smoothFactor: 0.1969,
9486
winVar: 1.0,
9587
bins: make([]bin, size+1),
9688
fftBuf: make([]complex128, fftSize),
@@ -161,7 +153,7 @@ func (sp *Spectrum) Process(win window.Function) {
161153

162154
// mag /= float64(sp.bins[xB].widthFFT)
163155

164-
var pow = 0.6
156+
var pow = 0.65
165157

166158
switch {
167159
case mag < 0.0:
@@ -172,9 +164,10 @@ func (sp *Spectrum) Process(win window.Function) {
172164
pow *= math.Max(0.6, float64(xF)/fBassCut)
173165

174166
default:
175-
mag *= sp.bins[xB].eqVal
176167
}
177168

169+
mag *= sp.bins[xB].eqVal
170+
178171
mag = math.Pow(mag, pow)
179172

180173
// Smoothing
@@ -319,18 +312,28 @@ func (sp *Spectrum) freqToIdx(freq float64, round mathFunc) int {
319312

320313
// SetWinVar sets the winVar used for distribution spread
321314
func (sp *Spectrum) SetWinVar(g float64) {
322-
if g <= 0.0 {
323-
g = 1
315+
switch {
316+
317+
case g <= 0.0:
318+
sp.winVar = 1.0
319+
320+
default:
321+
sp.winVar = g
322+
324323
}
325324

326-
sp.winVar = g
327325
}
328326

329327
// SetSmoothing sets the smoothing parameters
330328
func (sp *Spectrum) SetSmoothing(factor float64) {
331-
if factor <= 0 {
332-
factor = math.SmallestNonzeroFloat64
329+
switch {
330+
331+
case factor <= 0.0:
332+
sp.smoothFactor = math.SmallestNonzeroFloat64
333+
334+
default:
335+
sp.smoothFactor = factor
336+
333337
}
334338

335-
sp.smoothFactor = factor
336339
}

dsp/window/window.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ package window
55

66
import "math"
77

8-
// Function is a function that will do window things for you
8+
// Function is a function that will do window things for you on a slice
99
type Function func(buf []float64)
1010

1111
// Rectangle is just do nothing

0 commit comments

Comments
 (0)