pub struct AudioEngine<'a, const N: usize = 2> { /* private fields */ }Expand description
N-voice mixer with bank playback, dynamic voice allocation, and duty-modulated PWM output.
Implementations§
Source§impl<'a> AudioEngine<'a, 2>
impl<'a> AudioEngine<'a, 2>
Sourcepub fn new(config: AudioConfig) -> Self
pub fn new(config: AudioConfig) -> Self
Create a standard 2-voice audio engine.
pub fn from_sample_rate( sample_rate_hz: u32, pwm_period: u16, duty_mode: DutyMode, ) -> Self
Source§impl<'a, const N: usize> AudioEngine<'a, N>
impl<'a, const N: usize> AudioEngine<'a, N>
Sourcepub fn with_voice_count(config: AudioConfig) -> Self
pub fn with_voice_count(config: AudioConfig) -> Self
Create an audio engine with generic voice count N.
pub fn config(&self) -> AudioConfig
pub fn set_stealing_policy(&mut self, policy: VoiceStealingPolicy)
pub fn stealing_policy(&self) -> VoiceStealingPolicy
pub fn voice_count(&self) -> usize
pub fn active_voice_count(&self) -> usize
pub fn voice(&self, idx: usize) -> Option<&Voice<'a>>
pub fn voice_mut(&mut self, idx: usize) -> Option<&mut Voice<'a>>
pub fn set_bank(&mut self, bank: SoundBank<'a>)
pub fn set_master_gain_q8(&mut self, gain: u8)
pub fn stop_all(&mut self)
pub fn is_playing(&self) -> bool
Sourcepub fn allocate_voice(&mut self, priority: u8) -> Option<usize>
pub fn allocate_voice(&mut self, priority: u8) -> Option<usize>
Dynamically allocate a voice channel based on priority and stealing policy.
Sourcepub fn play(
&mut self,
effect_id: u16,
adsr: AdsrSpec,
) -> Result<usize, AudioError>
pub fn play( &mut self, effect_id: u16, adsr: AdsrSpec, ) -> Result<usize, AudioError>
Play effect on an automatically allocated voice channel.
Sourcepub fn play_with_priority(
&mut self,
effect_id: u16,
adsr: AdsrSpec,
priority: u8,
) -> Result<usize, AudioError>
pub fn play_with_priority( &mut self, effect_id: u16, adsr: AdsrSpec, priority: u8, ) -> Result<usize, AudioError>
Play with custom priority on an allocated voice channel.
Sourcepub fn play_wavetable(
&mut self,
table: &'a [u8],
freq_hz: u32,
adsr: AdsrSpec,
) -> Result<usize, AudioError>
pub fn play_wavetable( &mut self, table: &'a [u8], freq_hz: u32, adsr: AdsrSpec, ) -> Result<usize, AudioError>
Play custom wavetable on an automatically allocated voice channel.
Sourcepub fn play_wavetable_with_priority(
&mut self,
table: &'a [u8],
freq_hz: u32,
adsr: AdsrSpec,
priority: u8,
) -> Result<usize, AudioError>
pub fn play_wavetable_with_priority( &mut self, table: &'a [u8], freq_hz: u32, adsr: AdsrSpec, priority: u8, ) -> Result<usize, AudioError>
Play custom wavetable with custom priority on an allocated voice channel.
Sourcepub fn crossfade_to(
&mut self,
effect_id: u16,
duration_ms: u16,
adsr: AdsrSpec,
) -> Result<(), AudioError>
pub fn crossfade_to( &mut self, effect_id: u16, duration_ms: u16, adsr: AdsrSpec, ) -> Result<(), AudioError>
Crossfade voice 0 → effect_id on voice 1 over duration_ms.
pub fn start_on_voice( &mut self, idx: usize, bank: &SoundBank<'a>, entry: EffectEntry, adsr: AdsrSpec, priority: u8, ) -> Result<(), AudioError>
Sourcepub fn tick_pcm(&mut self) -> i8
pub fn tick_pcm(&mut self) -> i8
Mixed PCM sample after envelopes (before PWM mapping). Useful for WAV preview.
Sourcepub fn fill_duty_buffer(&mut self, out: &mut [u16]) -> usize
pub fn fill_duty_buffer(&mut self, out: &mut [u16]) -> usize
Fill a DMA buffer with consecutive duty values (one per sample tick).
Returns how many slots were written (out.len()).
Sourcepub fn fill_pcm_i8_buffer(&mut self, out: &mut [i8]) -> usize
pub fn fill_pcm_i8_buffer(&mut self, out: &mut [i8]) -> usize
Fill a DMA buffer with consecutive signed 8-bit PCM samples (-128..=127).
Sourcepub fn fill_pcm_i16_buffer(&mut self, out: &mut [i16]) -> usize
pub fn fill_pcm_i16_buffer(&mut self, out: &mut [i16]) -> usize
Fill a DMA buffer with consecutive signed 16-bit PCM samples (-32768..=32767).
Sourcepub fn fill_pcm_i32_buffer(&mut self, out: &mut [i32]) -> usize
pub fn fill_pcm_i32_buffer(&mut self, out: &mut [i32]) -> usize
Fill a DMA buffer with consecutive signed 32-bit PCM samples (24-bit aligned).
Sourcepub fn fill_dac_u8_buffer(&mut self, out: &mut [u8]) -> usize
pub fn fill_dac_u8_buffer(&mut self, out: &mut [u8]) -> usize
Fill a DMA buffer with consecutive unsigned 8-bit DAC values (0..=255).
Sourcepub fn fill_dac_u12_buffer(&mut self, out: &mut [u16]) -> usize
pub fn fill_dac_u12_buffer(&mut self, out: &mut [u16]) -> usize
Fill a DMA buffer with consecutive unsigned 12-bit DAC values (0..=4095, e.g. STM32 DAC1).
Sourcepub fn fill_dac_u16_buffer(&mut self, out: &mut [u16]) -> usize
pub fn fill_dac_u16_buffer(&mut self, out: &mut [u16]) -> usize
Fill a DMA buffer with consecutive unsigned 16-bit DAC values (0..=65535).
Sourcepub fn fill_stereo_i16_buffer(&mut self, out: &mut [i16]) -> usize
pub fn fill_stereo_i16_buffer(&mut self, out: &mut [i16]) -> usize
Fill an interleaved stereo 16-bit PCM buffer (duplicating mono mixed sample to L and R channels).
Sourcepub fn fill_stereo_i32_buffer(&mut self, out: &mut [i32]) -> usize
pub fn fill_stereo_i32_buffer(&mut self, out: &mut [i32]) -> usize
Fill an interleaved stereo 32-bit PCM buffer (for 24-bit / 32-bit SAI / I2S DMA peripherals).
Sourcepub fn fill_custom_buffer<T>(
&mut self,
out: &mut [T],
map_fn: impl FnMut(i8) -> T,
) -> usize
pub fn fill_custom_buffer<T>( &mut self, out: &mut [T], map_fn: impl FnMut(i8) -> T, ) -> usize
Generic buffer filling using a custom sample mapping closure.
Sourcepub fn tick_pwm(&mut self) -> u16
pub fn tick_pwm(&mut self) -> u16
Alias for Self::tick.