Problem 1 of 4
Lock-Free Messaging
The problem
Standard multi-threaded communication relies on Mutexes or channels that allocate heap memory. In an audio thread, acquiring a lock or triggering an allocation will cause priority inversion or garbage collection pauses, producing audible dropouts (buffer underruns).
How OMNi does it
All UI control changes and MIDI triggers are serialized into fixed-size enums and passed to the audio thread via lock-free ringbuffers (crossbeam-channel). The audio thread polls these queues using non-blocking calls (try_recv), guaranteeing zero locks and zero allocations.
pub struct AudioQueue {
sender: crossbeam_channel::Sender<AudioCommand>,
receiver: crossbeam_channel::Receiver<AudioCommand>,
}
impl AudioQueue {
// Called on the audio thread — zero alloc, zero locks
pub fn process_commands(&self, state: &mut AudioThreadState) {
while let Ok(cmd) = self.receiver.try_recv() {
match cmd {
AudioCommand::SetParam(id, val) => {
state.set_parameter(id, val);
},
AudioCommand::TriggerNote(note) => {
state.trigger_voice(note);
},
}
}
}
}









































































































