Skip to content

Commit e7e7b3c

Browse files
committed
idk
1 parent 9b18673 commit e7e7b3c

File tree

7 files changed

+264
-32
lines changed

7 files changed

+264
-32
lines changed

CatnipJulia/src/run_catnip.jl

Lines changed: 40 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,30 @@
1-
GLMakie.activate!()
1+
using Colors
2+
using DataStructures: CircularBuffer
3+
using GLMakie
24

3-
# set_theme!(theme_black())
5+
set_theme!(theme_black())
46

5-
set_window_config!(;
7+
GLMakie.activate!(;
68
vsync=false,
79
framerate=60.0,
8-
float=true,
10+
float=false,
911
pause_renderloop=false,
1012
focus_on_show=false,
1113
decorated=true,
1214
title="catnip"
1315
)
1416

1517
function run_catnip(; timeout=false)
16-
# 5 seconds at 60 samples per second out of catnip
18+
# 6 seconds at 60 samples per second out of catnip
1719
numSets = 300
20+
# numSets = 120
1821

19-
fig = Figure(resolution=(1200, 800), fontsize=14)
22+
fig = Figure(fontsize=14; size=(1200, 888))
2023
ax1 = Axis3(fig[1, 1]; aspect=(2, 1, 0.25), elevation=pi / 6, perspectiveness=0.5)
2124

25+
hidedecorations!(ax1)
26+
hidespines!(ax1)
27+
2228
data = CircularBuffer{Vector{Float64}}(numSets)
2329

2430
push!(data, [0.0, 0.0])
@@ -58,27 +64,31 @@ function run_catnip(; timeout=false)
5864
return mat
5965
end
6066

61-
function makeColorMap2(z, s, b, x)
62-
d = z[:]
67+
function makeColorMap2(data, sets, bars, idx)
68+
d = data[:]
6369

64-
maxValue = reduce(d) do left, right
65-
left > right ? left : right
70+
for n in eachindex(d)
71+
d[n] > 100.0 && (d[n] = 100.0)
72+
# d[n] < 1.0 && (d[n] = 100.0)
6673
end
6774

68-
maxValue = max(maxValue, 100.0)
75+
# for j = 0:bars-1
76+
# d[idx+(j*sets)] = 100.0
77+
# end
6978

70-
for j = 0:b-1
71-
d[x+(j*s)] = maxValue
79+
for j = 0:bars-1
80+
d[idx+(j*sets)] = 100.0
7281
end
7382

74-
d[1] = 0.0
83+
d[idx] = 0.0
84+
d[idx+((bars-1)*sets)] = 100.0
7585

7686
return d
7787
end
7888

7989
zC = @lift($z[:])
8090

81-
staticColorMap = @lift(makeColorMap2($z, $sets, $bars, $idx)[:])
91+
staticColorMap = @lift(makeColorMap2($z, $sets, $bars, $idx))
8292

8393

8494
function updateZ()
@@ -89,7 +99,12 @@ function run_catnip(; timeout=false)
8999

90100
display(fig)
91101

92-
command = `catnip -d spotify -r 122880 -n 2048 -sas 6 -sf 45 -i -nw -nwb 60`
102+
mymagma = GLMakie.to_colormap(:magma)
103+
# mymagma = GLMakie.to_colormap(:BuPu_9)
104+
mymagma[1] = RGBA(0.0,0.0,0.0,0.0)
105+
106+
command = `catnip -d spotify -r 122880 -n 2048 -sas 6 -sf 45 -i -nw -nwb 81`
107+
# command = `catnip -d "Google Chrome" -r 122880 -n 2048 -sas 6 -sf 45 -i -nw -nwb 60`
93108
#command = `go run ./cmd/catnip -d spotify -r 122880 -n 2048 -sas 5 -sf 45 -i -nw -nwb 50`
94109

95110

@@ -113,9 +128,11 @@ function run_catnip(; timeout=false)
113128
limits!(ax1, 0, sets[], 0, bars[], 0, 100)
114129

115130
meshscatter!(ax1, x, y, zZ; marker=rectMesh, color=staticColorMap,
116-
markersize=mSize, colormap=:plasma,
117-
shading=true)
131+
markersize=mSize, colormap=mymagma,
132+
# markersize=mSize, colormap=:plasma,
133+
shading=MultiLightShading)
118134

135+
idx[] = numSets
119136

120137

121138
#while !eof(io) && (count < numSets + 4 || !timeout)
@@ -132,12 +149,12 @@ function run_catnip(; timeout=false)
132149
nums = map(x -> parse(Float64, strip(x)), elms)
133150
nums = reverse(nums)
134151

135-
idx[] = numSets - count
152+
# idx[] = numSets - count
136153
#println(nums)
137154

138-
data[idx[]] = nums
155+
# data[idx[]] = nums
139156

140-
# pushfirst!(data, nums)
157+
pushfirst!(data, nums)
141158

142159
updateZ()
143160
end
@@ -146,3 +163,5 @@ function run_catnip(; timeout=false)
146163
@show e
147164
end
148165
end
166+
167+
run_catnip()

dsp/analyzer.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,10 @@ func (az *analyzer) ProcessBin(idx int, src []complex128) float64 {
127127
fftCeil = az.fftSize
128128
}
129129

130+
if fftFloor >= fftCeil {
131+
fftFloor = fftCeil - 1
132+
}
133+
130134
src = src[fftFloor:fftCeil]
131135
mag := 0.0
132136
count := len(src)

graphic/display.go

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ func (d *Display) Stop() error {
168168
func (d *Display) Write(buffers [][]float64, channels int) error {
169169

170170
peak := 0.0
171-
bins := d.Bins(channels)
171+
bins := d.binsInternal(channels, bufferLength(buffers))
172172

173173
for i := 0; i < channels; i++ {
174174
for _, val := range buffers[i][:bins] {
@@ -311,6 +311,18 @@ func (d *Display) Bins(chCount int) int {
311311
}
312312
}
313313

314+
func bufferLength(buffers [][]float64) int {
315+
return len(buffers[0])
316+
}
317+
318+
func (d *Display) binsInternal(chCount, bufLen int) int {
319+
bins := d.Bins(chCount)
320+
if bins >= bufLen {
321+
bins = bufLen - 1
322+
}
323+
return bins
324+
}
325+
314326
func (d *Display) inputProcessor() {
315327
if d.cancel != nil {
316328
defer d.cancel()
@@ -474,7 +486,7 @@ func sizeAndCap(value float64, space int, zeroBase bool, baseRune rune) (int, ru
474486

475487
// drawUp will draw up.
476488
func (d *Display) drawUp(bins [][]float64, channelCount int, scale float64) {
477-
binCount := d.Bins(channelCount)
489+
binCount := d.binsInternal(channelCount, bufferLength(bins))
478490
barSpace := intMax(d.termHeight-d.baseSize, 0)
479491
scale = float64(barSpace) / scale
480492

@@ -515,7 +527,7 @@ func (d *Display) drawUp(bins [][]float64, channelCount int, scale float64) {
515527

516528
// drawUpDown will draw up and down.
517529
func (d *Display) drawUpDown(bins [][]float64, channelCount int, scale float64) {
518-
binCount := d.Bins(channelCount)
530+
binCount := d.binsInternal(channelCount, bufferLength(bins))
519531
centerStart := intMax((d.termHeight-d.baseSize)/2, 0)
520532
centerStop := centerStart + d.baseSize
521533

@@ -563,7 +575,7 @@ func (d *Display) drawUpDown(bins [][]float64, channelCount int, scale float64)
563575
// drawUpDownSplit will draw up and down split down the middle for left and
564576
// right channels.
565577
func (d *Display) drawUpDownSplit(bins [][]float64, channelCount int, scale float64) {
566-
binCount := d.Bins(2)
578+
binCount := d.binsInternal(2, bufferLength(bins))
567579
centerStart := intMax((d.termHeight-d.baseSize)/2, 0)
568580
centerStop := centerStart + d.baseSize
569581

@@ -616,7 +628,7 @@ func (d *Display) drawUpDownSplit(bins [][]float64, channelCount int, scale floa
616628
// drawUpDownSplitVert will draw up and down split down the middle for left and
617629
// right channels.
618630
func (d *Display) drawUpDownSplitVert(bins [][]float64, channelCount int, scale float64) {
619-
binCount := d.Bins(2)
631+
binCount := d.binsInternal(2, bufferLength(bins))
620632
centerStart := intMax((d.termHeight-d.baseSize)/2, 0)
621633
centerStop := centerStart + d.baseSize
622634

@@ -668,7 +680,7 @@ func (d *Display) drawUpDownSplitVert(bins [][]float64, channelCount int, scale
668680

669681
// drawDown will draw down.
670682
func (d *Display) drawDown(bins [][]float64, channelCount int, scale float64) {
671-
binCount := d.Bins(channelCount)
683+
binCount := d.binsInternal(channelCount, bufferLength(bins))
672684
barSpace := intMax(d.termHeight-d.baseSize, 0)
673685
scale = float64(barSpace) / scale
674686

@@ -712,7 +724,7 @@ func (d *Display) drawDown(bins [][]float64, channelCount int, scale float64) {
712724
}
713725

714726
func (d *Display) drawLeft(bins [][]float64, channelCount int, scale float64) {
715-
binCount := d.Bins(channelCount)
727+
binCount := d.binsInternal(channelCount, bufferLength(bins))
716728
barSpace := intMax(d.termWidth-d.baseSize, 0)
717729
scale = float64(barSpace) / scale
718730

@@ -753,7 +765,7 @@ func (d *Display) drawLeft(bins [][]float64, channelCount int, scale float64) {
753765

754766
// drawLeftRight will draw left and right.
755767
func (d *Display) drawLeftRight(bins [][]float64, channelCount int, scale float64) {
756-
binCount := d.Bins(channelCount)
768+
binCount := d.binsInternal(channelCount, bufferLength(bins))
757769
centerStart := intMax((d.termWidth-d.baseSize)/2, 0)
758770
centerStop := centerStart + d.baseSize
759771

@@ -803,7 +815,7 @@ func (d *Display) drawLeftRight(bins [][]float64, channelCount int, scale float6
803815

804816
// drawLeftRight will draw left and right.
805817
func (d *Display) drawLeftRightSplit(bins [][]float64, channelCount int, scale float64) {
806-
binCount := d.Bins(2)
818+
binCount := d.binsInternal(2, bufferLength(bins))
807819
centerStart := intMax((d.termWidth-d.baseSize)/2, 0)
808820
centerStop := centerStart + d.baseSize
809821

@@ -854,7 +866,7 @@ func (d *Display) drawLeftRightSplit(bins [][]float64, channelCount int, scale f
854866
}
855867

856868
func (d *Display) drawRight(bins [][]float64, channelCount int, scale float64) {
857-
binCount := d.Bins(channelCount)
869+
binCount := d.binsInternal(channelCount, bufferLength(bins))
858870
barSpace := intMax(d.termWidth-d.baseSize, 0)
859871
scale = float64(barSpace) / scale
860872

input/all/all.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ import (
55
_ "github.com/noriah/catnip/input/ffmpeg"
66
_ "github.com/noriah/catnip/input/parec"
77
_ "github.com/noriah/catnip/input/pipewire"
8+
_ "github.com/noriah/catnip/input/stdinput"
89
)

input/common/execread/execread.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ func (s *Session) Start(ctx context.Context, dst [][]input.Sample, kickChan chan
100100
// to the buffer.
101101
timeout := sampleDuration
102102
if !readExpired {
103-
timeout *= 2
103+
timeout *= 6
104104
}
105105
if err := of.SetReadDeadline(time.Now().Add(timeout)); err != nil {
106106
return errors.Wrap(err, "failed to set read deadline")

0 commit comments

Comments
 (0)