Skip to main content

BasicMixer

Struct BasicMixer 

Source
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

Source

pub fn new() -> Self

Construct a BasicMixer that simply adds samples and doesn’t multiply by anything.

Source

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.
Source

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.

Source

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

Source§

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

Source§

fn default() -> BasicMixer

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoShared for T
where T: AudioSource + Send + 'static,

Source§

fn into_shared(self) -> Arc<Mutex<dyn AudioSource + Send>>

Move this audio source into an Arc<Mutex<...>> so that it can be shared between threads.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.