mirror of
https://github.com/vsariola/sointu.git
synced 2026-02-08 00:30:18 -05:00
drafting spectrum analyzer
This commit is contained in:
parent
4d09e04a49
commit
f765d75fde
@ -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:]
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user