Skip to content

Commit 51054ce

Browse files
committed
Yay working again
1 parent 890af28 commit 51054ce

File tree

5 files changed

+36
-52
lines changed

5 files changed

+36
-52
lines changed

dsp/spectrum.go

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ func NewSpectrum(hz float64, size int) *Spectrum {
8686
sampleSize: size,
8787
sampleRate: hz,
8888
smoothFactor: 0.1969,
89-
winVar: 1.0,
89+
winVar: 0.5,
9090
fftBuf: make([]complex128, fftSize),
9191
bins: make([]bin, size+1),
9292
streams: make([]*stream, 0, 2),
@@ -220,10 +220,6 @@ func (sp *Spectrum) Recalculate(bins int) int {
220220

221221
// set widths
222222
for xB := 0; xB < bins; xB++ {
223-
if sp.bins[xB].ceilFFT == sp.bins[xB].floorFFT {
224-
sp.bins[xB].widthFFT = 1
225-
continue
226-
}
227223

228224
sp.bins[xB].widthFFT = sp.bins[xB].ceilFFT - sp.bins[xB].floorFFT
229225
}
@@ -248,9 +244,7 @@ func (sp *Spectrum) distributeLog(bins int) {
248244

249245
var cCoef = 100.0 / float64(bins+1)
250246

251-
sp.bins[0].floorFFT = lo &
252-
253-
for xB := 0; xB < bins; xB++ {
247+
for xB := 0; xB <= bins; xB++ {
254248

255249
sp.bins[xB].floorFFT = getBinBase(xB)
256250
sp.bins[xB].eqVal = math.Log2(float64(xB)+2) * cCoef
@@ -269,7 +263,7 @@ func (sp *Spectrum) distributeEqual(bins int) {
269263
var loF = Frequencies[0]
270264
var hiF = math.Min(Frequencies[4], sp.sampleRate/2)
271265
var minIdx = sp.freqToIdx(loF, math.Floor)
272-
var maxIdx = sp.freqToIdx(hiF, math.Round)
266+
var maxIdx = sp.freqToIdx(hiF, math.Ceil)
273267

274268
var size = maxIdx - minIdx
275269

graphic/display.go

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -328,28 +328,23 @@ func (d *Display) Draw(bufs [][]float64, channels, bins int) error {
328328

329329
termbox.Flush()
330330

331-
termbox.Clear(termbox.ColorDefault, termbox.ColorDefault)
331+
termbox.Clear(StyleDefault, StyleDefaultBack)
332332

333333
return nil
334334
}
335335

336336
func stopAndTop(value float64, height int, up bool) (int, rune) {
337337
if stop := int(value * NumRunes); stop < height*NumRunes {
338-
if up {
339-
top := BarRuneR + rune(stop%NumRunes)
340-
stop = height - (stop / NumRunes)
341338

342-
return stop, top
339+
if up {
340+
return height - (stop / NumRunes), BarRuneR + rune(stop%NumRunes)
343341
}
344342

345-
top := BarRune - rune(stop%NumRunes)
346-
stop /= NumRunes
347-
348-
return stop, top
343+
return stop / NumRunes, BarRune - rune(stop%NumRunes)
349344
}
350345

351346
if up {
352-
return 0, BarRune
347+
return 0, BarRuneR
353348
}
354349

355350
return height, BarRune

graphic/draw_down.go

Lines changed: 24 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,36 +3,50 @@ package graphic
33
import "github.com/nsf/termbox-go"
44

55
func drawDown(bins [][]float64, count int, cfg Config, scale float64) error {
6-
var cSetCount = len(bins)
7-
86
var cWidth, cHeight = termbox.Size()
97

10-
var cChanWidth = (cfg.BinWidth * count) - cfg.SpaceWidth
11-
var cPaddedWidth = (cfg.BinWidth * count * cSetCount) - cfg.SpaceWidth
12-
var cOffset = (cWidth - cPaddedWidth) / 2
13-
148
var vHeight = cHeight - cfg.BaseThick
9+
if vHeight < 0 {
10+
vHeight = 0
11+
}
1512

1613
scale = float64(vHeight) / scale
1714

15+
var cPaddedWidth = (cfg.BinWidth * count * len(bins)) - cfg.SpaceWidth
16+
17+
if cPaddedWidth > cWidth || cPaddedWidth < 0 {
18+
cPaddedWidth = cWidth
19+
}
20+
1821
var xBin int
19-
var xCol = cOffset
22+
var xCol = (cWidth - cPaddedWidth) / 2
2023
var delta = 1
2124

2225
for xCh := range bins {
2326
var stop, top = stopAndTop(bins[xCh][xBin]*scale, vHeight, false)
27+
if stop += cfg.BaseThick; stop >= cHeight {
28+
stop = cHeight
29+
top = BarRune
30+
}
2431

2532
var lCol = xCol + cfg.BarWidth
26-
var lColMax = xCol + cChanWidth
27-
28-
for xCol < lColMax {
33+
var lColMax = xCol + (cfg.BinWidth * count) - cfg.SpaceWidth
2934

35+
for {
3036
if xCol >= lCol {
37+
if xCol >= lColMax {
38+
break
39+
}
40+
3141
if xBin += delta; xBin >= count || xBin < 0 {
3242
break
3343
}
3444

3545
stop, top = stopAndTop(bins[xCh][xBin]*scale, vHeight, false)
46+
if stop += cfg.BaseThick; stop >= cHeight {
47+
stop = cHeight
48+
top = BarRune
49+
}
3650

3751
xCol += cfg.SpaceWidth
3852
lCol = xCol + cfg.BarWidth
@@ -65,20 +79,3 @@ func drawDown(bins [][]float64, count int, cfg Config, scale float64) error {
6579

6680
return nil
6781
}
68-
69-
// var stopAndTop = func(value float64) (stop int, top int) {
70-
// if value *= scale; value < float64(vHeight) {
71-
// top = int(value * NumRunes)
72-
// } else {
73-
// top = vHeight * NumRunes
74-
// }
75-
// stop = (top / NumRunes) + cfg.BaseThick
76-
// top %= NumRunes
77-
78-
// if stop > cHeight {
79-
// stop = cHeight
80-
// top = 0
81-
// }
82-
83-
// return
84-
// }

graphic/draw_up.go

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

33
import "github.com/nsf/termbox-go"
44

5-
// DrawUp takes data and draws
65
func drawUp(bins [][]float64, count int, cfg Config, scale float64) error {
76
var cWidth, cHeight = termbox.Size()
87

graphic/draw_updown.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ func drawUpDown(bins [][]float64, count int, cfg Config, scale float64) error {
3030

3131
var lStop, lTop = stopAndTop(bins[0][xBin]*scale, centerStart, true)
3232
var rStop, rTop = stopAndTop(bins[1%cSetCount][xBin]*scale, centerStart, false)
33-
if rStop += centerStop; rStop > cHeight {
33+
if rStop += centerStop; rStop >= cHeight {
3434
rStop = cHeight
35-
rTop = 0
35+
rTop = BarRune
3636
}
3737

3838
var lCol = xCol + cfg.BarWidth
@@ -51,10 +51,9 @@ func drawUpDown(bins [][]float64, count int, cfg Config, scale float64) error {
5151

5252
lStop, lTop = stopAndTop(bins[0][xBin]*scale, centerStart, true)
5353
rStop, rTop = stopAndTop(bins[1%cSetCount][xBin]*scale, centerStart, false)
54-
55-
if rStop += centerStop; rStop > cHeight {
54+
if rStop += centerStop; rStop >= cHeight {
5655
rStop = cHeight
57-
rTop = 0
56+
rTop = BarRune
5857
}
5958

6059
xCol += cfg.SpaceWidth

0 commit comments

Comments
 (0)