drafting spectrum analyzer

This commit is contained in:
5684185+vsariola@users.noreply.github.com
2025-12-29 23:57:08 +02:00
parent 4d09e04a49
commit f765d75fde
3 changed files with 190 additions and 2 deletions

View File

@ -62,6 +62,10 @@ type (
history [11]float32
tmp, tmp2 []float32
}
chunker struct {
buffer sointu.AudioBuffer
}
)
const (
@ -132,7 +136,7 @@ func (s *Detector) handleMsg(msg MsgToDetector) {
switch data := msg.Data.(type) {
case *sointu.AudioBuffer:
buf := *data
for {
for len(buf) > 0 {
var chunk sointu.AudioBuffer
if len(s.chunkHistory) > 0 && len(s.chunkHistory) < 4410 {
l := min(len(buf), 4410-len(s.chunkHistory))
@ -160,6 +164,7 @@ func (s *Detector) handleMsg(msg MsgToDetector) {
},
})
}
s.broker.PutAudioBuffer(data)
}
}
@ -432,3 +437,21 @@ func (d *peakDetector) reset() {
d.maxPower[chn] = 0
}
}
func (c *chunker) Process(input sointu.AudioBuffer, windowLength, overlap int, cb func(sointu.AudioBuffer)) sointu.AudioBuffer {
b := c.buffer
for len(b) >= windowLength {
cb(b[:windowLength])
b = b[windowLength-overlap:]
}
copy(c.buffer, b)
c.buffer = c.buffer[:len(b)]
for {
if len(c.buffer) > 0 {
l := min(len(input), windowLength-len(c.buffer))
c.buffer = append(c.buffer, input[:l]...)
input = input[l:]
}
}
}