pub struct Mixer { /* private fields */ }Available on crate feature
audio only.Expand description
Multi-track audio mixer.
Combines multiple named audio tracks into a single output with per-track volume control. Missing tracks are treated as silence.
§Example
ⓘ
let mut mixer = Mixer::new(24000);
mixer.add_track("narration", 1.0);
mixer.add_track("music", 0.3);
mixer.push_frame("narration", narration_frame);
mixer.push_frame("music", music_frame);
let mixed = mixer.mix()?;Implementations§
Source§impl Mixer
impl Mixer
Sourcepub fn new(output_sample_rate: u32) -> Mixer
pub fn new(output_sample_rate: u32) -> Mixer
Create a new mixer with the given output sample rate.
Sourcepub fn add_track(&mut self, name: impl Into<String>, volume: f32)
pub fn add_track(&mut self, name: impl Into<String>, volume: f32)
Add a named track with the given volume (0.0–1.0).
Sourcepub fn set_volume(&mut self, name: &str, volume: f32)
pub fn set_volume(&mut self, name: &str, volume: f32)
Set the volume for a named track.
Sourcepub fn push_frame(&mut self, track: &str, frame: AudioFrame)
pub fn push_frame(&mut self, track: &str, frame: AudioFrame)
Push an audio frame to a named track.
Sourcepub fn mix(&mut self) -> Result<AudioFrame, AudioError>
pub fn mix(&mut self) -> Result<AudioFrame, AudioError>
Mix all tracks into a single output frame.
Tracks without buffered audio are treated as silence. All tracks are mixed at the output sample rate.
Trait Implementations§
Source§impl AudioProcessor for Mixer
impl AudioProcessor for Mixer
Source§fn process<'life0, 'life1, 'async_trait>(
&'life0 self,
frame: &'life1 AudioFrame,
) -> Pin<Box<dyn Future<Output = Result<AudioFrame, AudioError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Mixer: 'async_trait,
fn process<'life0, 'life1, 'async_trait>(
&'life0 self,
frame: &'life1 AudioFrame,
) -> Pin<Box<dyn Future<Output = Result<AudioFrame, AudioError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Mixer: 'async_trait,
Process a single audio frame, returning the transformed result.
Auto Trait Implementations§
impl Freeze for Mixer
impl RefUnwindSafe for Mixer
impl Send for Mixer
impl Sync for Mixer
impl Unpin for Mixer
impl UnsafeUnpin for Mixer
impl UnwindSafe for Mixer
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