pub struct VoiceAllocator<const N: usize> { /* private fields */ }Expand description
Fixed pool of N voices. All state is inline; no allocation on any path.
Implementations§
Source§impl<const N: usize> VoiceAllocator<N>
impl<const N: usize> VoiceAllocator<N>
Sourcepub fn new(sample_rate: f32, waveform: Waveform, env: AdsrEnvelope) -> Self
pub fn new(sample_rate: f32, waveform: Waveform, env: AdsrEnvelope) -> Self
Build a pool of N idle voices sharing a waveform + envelope template.
Sourcepub fn freq_12tet(note: u8) -> f32
pub fn freq_12tet(note: u8) -> f32
Equal-temperament frequency (Hz) for a MIDI note (A4 = 69 = 440 Hz).
Sourcepub fn note_on(&mut self, note: u8, velocity: u8, freq_hz: f32)
pub fn note_on(&mut self, note: u8, velocity: u8, freq_hz: f32)
Start a note at an explicit frequency (Hz). Assigns a free voice, or steals the
oldest voice when the pool is full. The active voice count never exceeds N.
Sourcepub fn note_on_12tet(&mut self, note: u8, velocity: u8)
pub fn note_on_12tet(&mut self, note: u8, velocity: u8)
Start a note using the default 12-TET frequency for note.
Sourcepub fn active_count(&self) -> usize
pub fn active_count(&self) -> usize
Number of voices currently producing signal.
Sourcepub fn voices(&self) -> &[Voice]
pub fn voices(&self) -> &[Voice]
Immutable view of the voice array (for rendering / inspection).
Sourcepub fn voices_mut(&mut self) -> &mut [Voice]
pub fn voices_mut(&mut self) -> &mut [Voice]
Mutable view of the voice array (used by the render path).
Trait Implementations§
Source§impl<const N: usize> Clone for VoiceAllocator<N>
impl<const N: usize> Clone for VoiceAllocator<N>
impl<const N: usize> Copy for VoiceAllocator<N>
Auto Trait Implementations§
impl<const N: usize> Freeze for VoiceAllocator<N>
impl<const N: usize> RefUnwindSafe for VoiceAllocator<N>
impl<const N: usize> Send for VoiceAllocator<N>
impl<const N: usize> Sync for VoiceAllocator<N>
impl<const N: usize> Unpin for VoiceAllocator<N>
impl<const N: usize> UnsafeUnpin for VoiceAllocator<N>
impl<const N: usize> UnwindSafe for VoiceAllocator<N>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more