pub struct AudioMixer { /* private fields */ }Expand description
Multi-channel audio mixer with fixed-point arithmetic
Implementations§
Source§impl AudioMixer
impl AudioMixer
Sourcepub fn new(sample_rate: u32, channels: u8) -> Self
pub fn new(sample_rate: u32, channels: u8) -> Self
Create a new audio mixer
§Arguments
sample_rate- Output sample rate in Hz (e.g., 48000)channels- Number of output channels (1=mono, 2=stereo)
Sourcepub fn add_channel(&mut self, name: &str) -> u16
pub fn add_channel(&mut self, name: &str) -> u16
Add a new mixer channel and return its ID
Sourcepub fn remove_channel(&mut self, id: u16)
pub fn remove_channel(&mut self, id: u16)
Remove a mixer channel by ID
Sourcepub fn set_volume(&self, channel_id: u16, volume: u16)
pub fn set_volume(&self, channel_id: u16, volume: u16)
Set volume for a specific channel (0..65535)
Sourcepub fn set_master_volume(&self, volume: u16)
pub fn set_master_volume(&self, volume: u16)
Set the master volume (0..65535)
Sourcepub fn get_master_volume(&self) -> u16
pub fn get_master_volume(&self) -> u16
Get the master volume (0..65535)
Sourcepub fn mix_to_output(&mut self, output: &mut [i16])
pub fn mix_to_output(&mut self, output: &mut [i16])
Mix all active channels into the provided output buffer
For each sample position, reads from all channels, applies per-channel
volume and mute, sums with saturation, then applies master volume.
The result is written directly to output.
Sourcepub fn channel_count(&self) -> usize
pub fn channel_count(&self) -> usize
Return the number of active channels
Sourcepub fn get_channel_mut(&mut self, id: u16) -> Option<&mut MixerChannel>
pub fn get_channel_mut(&mut self, id: u16) -> Option<&mut MixerChannel>
Get a mutable reference to a channel by ID
Sourcepub fn write_channel_samples(&mut self, channel_id: u16, samples: &[i16])
pub fn write_channel_samples(&mut self, channel_id: u16, samples: &[i16])
Write samples to a specific channel