pub struct BasicMixer { /* private fields */ }Expand description
A mixer that combines multiple AudioSources.
This simple mixer adds the samples from the given sources together, and optionally multiplies by a coefficient to give some headroom.
§Examples
let sin1 = SineWave::new(0.5, 440.0);
let sin2 = SineWave::new(0.5, 220.0);
let mut mixer = BasicMixer::new();
let sin1 = mixer.add_source(sin1.into_shared());
mixer.add_source(sin2.into_shared());
mixer.remove_source(sin1);Implementations§
Source§impl BasicMixer
impl BasicMixer
Sourcepub fn new() -> Self
pub fn new() -> Self
Construct a BasicMixer that simply adds samples and doesn’t multiply by anything.
Sourcepub fn with_coefficient(coefficient: f32) -> Self
pub fn with_coefficient(coefficient: f32) -> Self
Construct a BasicMixer that adds samples together, then multiplies by the given
coefficient to reduce the chance of clipping.
§Arguments
coefficient– A number to multiply the final resulting samples by.
Sourcepub fn add_source(&mut self, source: SharedAudioSource) -> BasicMixerSource
pub fn add_source(&mut self, source: SharedAudioSource) -> BasicMixerSource
Add a source to this mixer.
§Arguments
source– The audio source to add to this mixer.
§Returns
A key to be used in remove_source to remove this source.
Sourcepub fn remove_source(&mut self, source: BasicMixerSource)
pub fn remove_source(&mut self, source: BasicMixerSource)
Removes the source indicated by source, if present.
§Examples
let sin = SineWave::new(1.0, 440.0);
let mut mixer = BasicMixer::new();
let sin = mixer.add_source(sin.into_shared());
mixer.remove_source(sin);Trait Implementations§
Source§impl AudioSource for BasicMixer
impl AudioSource for BasicMixer
Source§fn read(&mut self, buffer: &mut AudioBuffer<'_>) -> ReadResult
fn read(&mut self, buffer: &mut AudioBuffer<'_>) -> ReadResult
Consume audio data and attempt to fill the given buffer. Read more
Source§impl Default for BasicMixer
impl Default for BasicMixer
Source§fn default() -> BasicMixer
fn default() -> BasicMixer
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for BasicMixer
impl RefUnwindSafe for BasicMixer
impl Send for BasicMixer
impl Sync for BasicMixer
impl Unpin for BasicMixer
impl UnsafeUnpin for BasicMixer
impl UnwindSafe for BasicMixer
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Move this audio source into an
Arc<Mutex<...>> so that it can be
shared between threads.