mirror of
https://github.com/vsariola/sointu.git
synced 2026-02-13 19:53:16 -05:00
drafting spectrum analyzer
This commit is contained in:
parent
4d09e04a49
commit
f765d75fde
@ -37,19 +37,23 @@ type (
|
||||
ToPlayer chan any // TODO: consider using a sum type here, for a bit more type safety. See: https://www.jerf.org/iri/post/2917/
|
||||
ToDetector chan MsgToDetector
|
||||
ToGUI chan any
|
||||
ToSpecAn chan any
|
||||
|
||||
CloseDetector chan struct{}
|
||||
CloseGUI chan struct{}
|
||||
CloseSpecAn chan struct{}
|
||||
|
||||
FinishedGUI chan struct{}
|
||||
FinishedDetector chan struct{}
|
||||
FinishedSpecAn chan struct{}
|
||||
|
||||
// mIDIEventsToGUI is true if all MIDI events should be sent to the GUI,
|
||||
// for inputting notes to tracks. If false, they should be sent to the
|
||||
// player instead.
|
||||
mIDIEventsToGUI atomic.Bool
|
||||
|
||||
bufferPool sync.Pool
|
||||
bufferPool sync.Pool
|
||||
f32slicePool sync.Pool
|
||||
}
|
||||
|
||||
// MsgToModel is a message sent to the model. The most often sent data
|
||||
@ -108,11 +112,15 @@ func NewBroker() *Broker {
|
||||
ToModel: make(chan MsgToModel, 1024),
|
||||
ToDetector: make(chan MsgToDetector, 1024),
|
||||
ToGUI: make(chan any, 1024),
|
||||
ToSpecAn: make(chan any, 1024),
|
||||
CloseDetector: make(chan struct{}, 1),
|
||||
CloseGUI: make(chan struct{}, 1),
|
||||
CloseSpecAn: make(chan struct{}, 1),
|
||||
FinishedGUI: make(chan struct{}),
|
||||
FinishedDetector: make(chan struct{}),
|
||||
FinishedSpecAn: make(chan struct{}),
|
||||
bufferPool: sync.Pool{New: func() any { return &sointu.AudioBuffer{} }},
|
||||
f32slicePool: sync.Pool{New: func() any { return &[]float32{} }},
|
||||
}
|
||||
}
|
||||
|
||||
@ -140,6 +148,17 @@ func (b *Broker) PutAudioBuffer(buf *sointu.AudioBuffer) {
|
||||
b.bufferPool.Put(buf)
|
||||
}
|
||||
|
||||
func (b *Broker) GetF32Slice(size int) *[]float32 {
|
||||
return b.f32slicePool.Get().(*[]float32)
|
||||
}
|
||||
|
||||
func (b *Broker) PutF32Slice(s *[]float32) {
|
||||
if len(*s) > 0 {
|
||||
*s = (*s)[:0]
|
||||
}
|
||||
b.f32slicePool.Put(s)
|
||||
}
|
||||
|
||||
// TrySend is a helper function to send a value to a channel if it is not full.
|
||||
// It is guaranteed to be non-blocking. Return true if the value was sent, false
|
||||
// otherwise.
|
||||
|
||||
Reference in New Issue
Block a user