pub struct AudioMixer {
pub sample_rate: u32,
pub channels: u16,
/* private fields */
}Expand description
Multi-track, constant-power-panned stereo mixer.
Combines N mono tracks into a single interleaved stereo f32 output at
48 kHz. Per-track volume and pan adjustments take effect on the next call
to mix.
§Pan law
For a pan position p ∈ [-1.0, +1.0]:
p_norm = (p + 1.0) * π / 4
l_gain = volume * cos(p_norm)
r_gain = volume * sin(p_norm)At p = 0 (center): l_gain == r_gain ≈ 0.707 × volume (constant-power
law — equal loudness in both ears).
§Example
ⓘ
let mut mixer = AudioMixer::new(48_000);
let track = mixer.add_track();
// Background audio-decode thread:
track.push_samples(&mono_pcm_chunk);
// Audio-device output callback:
let stereo = mixer.mix(output_buf.len());
output_buf[..stereo.len()].copy_from_slice(&stereo);Fields§
§sample_rate: u32Output sample rate in Hz.
channels: u16Number of output channels — always 2 (stereo).
Implementations§
Source§impl AudioMixer
impl AudioMixer
Sourcepub fn add_track(&mut self) -> AudioTrackHandle
pub fn add_track(&mut self) -> AudioTrackHandle
Add a new mono track and return a cloneable handle.
The track starts with volume = 1.0 and pan = 0.0 (center).
Auto Trait Implementations§
impl Freeze for AudioMixer
impl RefUnwindSafe for AudioMixer
impl Send for AudioMixer
impl Sync for AudioMixer
impl Unpin for AudioMixer
impl UnsafeUnpin for AudioMixer
impl UnwindSafe for AudioMixer
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