mirror of
https://github.com/vsariola/sointu.git
synced 2026-02-12 11:13:03 -05:00
drafting
This commit is contained in:
parent
f765d75fde
commit
2303e89bbd
@ -37,7 +37,7 @@ 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
|
||||
ToSpecAn chan MsgToSpecAn
|
||||
|
||||
CloseDetector chan struct{}
|
||||
CloseGUI chan struct{}
|
||||
@ -53,7 +53,7 @@ type (
|
||||
mIDIEventsToGUI atomic.Bool
|
||||
|
||||
bufferPool sync.Pool
|
||||
f32slicePool sync.Pool
|
||||
spectrumPool sync.Pool
|
||||
}
|
||||
|
||||
// MsgToModel is a message sent to the model. The most often sent data
|
||||
@ -97,6 +97,12 @@ type (
|
||||
Param int
|
||||
}
|
||||
|
||||
MsgToSpecAn struct {
|
||||
SpecSettings SpecAnSettings
|
||||
HasSettings bool
|
||||
Data any
|
||||
}
|
||||
|
||||
GUIMessageKind int
|
||||
)
|
||||
|
||||
@ -112,7 +118,7 @@ func NewBroker() *Broker {
|
||||
ToModel: make(chan MsgToModel, 1024),
|
||||
ToDetector: make(chan MsgToDetector, 1024),
|
||||
ToGUI: make(chan any, 1024),
|
||||
ToSpecAn: make(chan any, 1024),
|
||||
ToSpecAn: make(chan MsgToSpecAn, 1024),
|
||||
CloseDetector: make(chan struct{}, 1),
|
||||
CloseGUI: make(chan struct{}, 1),
|
||||
CloseSpecAn: make(chan struct{}, 1),
|
||||
@ -120,7 +126,7 @@ func NewBroker() *Broker {
|
||||
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{} }},
|
||||
spectrumPool: sync.Pool{New: func() any { return &Spectrum{} }},
|
||||
}
|
||||
}
|
||||
|
||||
@ -148,15 +154,18 @@ 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) GetSpectrum() *Spectrum {
|
||||
return b.spectrumPool.Get().(*Spectrum)
|
||||
}
|
||||
|
||||
func (b *Broker) PutF32Slice(s *[]float32) {
|
||||
if len(*s) > 0 {
|
||||
*s = (*s)[:0]
|
||||
func (b *Broker) PutSpectrum(s *Spectrum) {
|
||||
if len((*s)[0]) > 0 {
|
||||
(*s)[0] = (*s)[0][:0]
|
||||
}
|
||||
b.f32slicePool.Put(s)
|
||||
if len((*s)[1]) > 0 {
|
||||
(*s)[1] = (*s)[1][:0]
|
||||
}
|
||||
b.spectrumPool.Put(s)
|
||||
}
|
||||
|
||||
// TrySend is a helper function to send a value to a channel if it is not full.
|
||||
|
||||
Reference in New Issue
Block a user