Struct awedio::sounds::SoundMixer

source ·
pub struct SoundMixer { /* private fields */ }
Expand description

Mix multiple sounds together to be played simultaneously.

The Manager contains a SoundMixer so you might not need to crate one yourself but instead add multiple sounds on the Manager.

If a Sound returns an Error from next_sample, the error is logged and the Sound is dropped but other sounds keep playing.

Implementations§

source§

impl SoundMixer

source

pub fn new(output_channel_count: u16, output_sample_rate: u32) -> Self

Create a new empty sound mixer with an output channel count and sample rate that all added sounds will be converted to.

source

pub fn set_output_channel_count_and_sample_rate( &mut self, output_channel_count: u16, output_sample_rate: u32 )

Set the output channel count and sample rate. Added sounds will be converted to the output values. Must only be called when the next sample is for the first channel in the frame.

Trait Implementations§

source§

impl AddSound for SoundMixer

source§

fn add(&mut self, sound: Box<dyn Sound>)

Add a sound to be played. When or how the sound is played is implementation specific.
source§

impl ClearSounds for SoundMixer

source§

fn clear(&mut self)

Remove all audio sounds.

source§

impl Sound for SoundMixer

source§

fn next_sample(&mut self) -> Result<NextSample, Error>

Guaranteed to not return an Error.

source§

fn channel_count(&self) -> u16

Returns the number of channels.
source§

fn sample_rate(&self) -> u32

Returns the number of samples per second for each channel for this sound (e.g. 44,100).
source§

fn on_start_of_batch(&mut self)

Called whenever a new batch of audio samples is requested by the backend. Read more
source§

fn next_frame(&mut self) -> Result<Vec<i16>, Result<NextSample, Error>>

Returns the next sample for all channels. Read more
source§

fn append_next_frame_to( &mut self, samples: &mut Vec<i16> ) -> Result<(), Result<NextSample, Error>>

Same as next_frame but samples are appended into an existing Vec. Read more
source§

fn into_memory_sound(self) -> Result<MemorySound, Error>
where Self: Sized,

Read the entire sound into memory. MemorySound can be cloned for efficient reuse. See MemorySound::from_sound.
source§

fn loop_from_memory(self) -> Result<MemorySound, Error>
where Self: Sized,

Read the entire sound into memory and loop indefinitely. Read more
source§

fn controllable(self) -> (Controllable<Self>, Controller<Self>)
where Self: Sized,

Allow this sound to be controlled after it has started playing with a Controller. Read more
source§

fn with_async_completion_notifier( self ) -> (AsyncCompletionNotifier<Self>, Receiver<()>)
where Self: Sized,

Get notified via a tokio::sync::oneshot::Receiver when this sound has Finished.
source§

fn with_completion_notifier(self) -> (CompletionNotifier<Self>, Receiver<()>)
where Self: Sized,

Get notified via a std::sync::mpsc::Receiver when this sound has Finished.
source§

fn with_adjustable_volume(self) -> AdjustableVolume<Self>
where Self: Sized,

Allow the volume of the sound to be adjustable with set_volume.
source§

fn with_adjustable_volume_of( self, volume_adjustment: f32 ) -> AdjustableVolume<Self>
where Self: Sized,

Allow the volume of the sound to be adjustable with set_volume and set the initial volume adjustment.
source§

fn with_adjustable_speed(self) -> AdjustableSpeed<Self>
where Self: Sized,

Allow the speed of the sound to be adjustable with set_speed. Read more
source§

fn with_adjustable_speed_of( self, speed_adjustment: f32 ) -> AdjustableSpeed<Self>
where Self: Sized,

Allow the speed of the sound to be adjustable with set_speed and set the initial speed adjustment. Read more
source§

fn pausable(self) -> Pausable<Self>
where Self: Sized,

Allow for the sound to be pausable with set_paused. Starts unpaused.
source§

fn paused(self) -> Pausable<Self>
where Self: Sized,

Allow for the sound to be pausable with set_paused. Starts paused.
source§

fn finish_after(self, duration: Duration) -> FinishAfter<Self>
where Self: Sized,

Play the first duration of the sound, then finish even if samples remain. Read more
source§

fn skip(&mut self, duration: Duration) -> Result<bool, Error>

Skip the next duration of samples. 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<S> FromSample<S> for S

source§

fn from_sample_(s: S) -> S

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<F, T> IntoSample<T> for F
where T: FromSample<F>,

source§

fn into_sample(self) -> T

source§

impl<T, U> ToSample<U> for T
where U: FromSample<T>,

source§

fn to_sample_(self) -> U

source§

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

§

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>,

§

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.
source§

impl<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,