pub struct Mixer<G: Eq + Hash + Send + 'static = ()> { /* private fields */ }
Expand description
Keep track of each Sound, and mix they output together.
Implementations§
Source§impl<G: Eq + Hash + Send + 'static> Mixer<G>
impl<G: Eq + Hash + Send + 'static> Mixer<G>
Sourcepub fn new(channels: u16, sample_rate: SampleRate) -> Self
pub fn new(channels: u16, sample_rate: SampleRate) -> Self
Create a new Mixer.
The created Mixer output samples with given sample rate and number of channels. This
configuration can be changed by calling set_config
.
Sourcepub fn set_config(&mut self, channels: u16, sample_rate: SampleRate)
pub fn set_config(&mut self, channels: u16, sample_rate: SampleRate)
Change the number of channels and the sample rate.
This keep also keep all currently playing sounds, and convert them to the new config, if necessary.
Sourcepub fn add_sound(&mut self, group: G, sound: Box<dyn SoundSource + Send>) -> u64
pub fn add_sound(&mut self, group: G, sound: Box<dyn SoundSource + Send>) -> u64
Add new sound to the Mixer.
Return the SoundId associated with that sound. This Id is globally unique.
The added sound is started in stopped state, and play
must be called to start playing
it. mark_to_remove
is true by default.
Sourcepub fn play(&mut self, id: u64)
pub fn play(&mut self, id: u64)
Start playing the sound associated with the given id.
If the sound was paused or stop, it will start playing again. Otherwise, does nothing.
Sourcepub fn pause(&mut self, id: u64)
pub fn pause(&mut self, id: u64)
Pause the sound associated with the given id.
If the sound is playing, it will pause. If play is called, this sound will continue from where it was when paused. If the sound is not playing, does nothing.
Sourcepub fn stop(&mut self, id: u64)
pub fn stop(&mut self, id: u64)
Stop the sound associated with the given id.
If the sound is playing, it will pause and reset the song. When play is called, this sound will start from the begging.
Even if the sound is not playing, it will reset the sound to the start. If the sound is marked to be removed, this sound will be removed from the Mixer.
Sourcepub fn reset(&mut self, id: u64)
pub fn reset(&mut self, id: u64)
Reset the sound associated with the given id.
This reset the sound to the start, the sound being playing or not.
Sourcepub fn set_loop(&mut self, id: u64, looping: bool)
pub fn set_loop(&mut self, id: u64, looping: bool)
Set if the sound associated with the given id will loop.
If true, ever time the sound reachs its end, it will reset, and continue to play in a loop.
This also set mark_to_remove
to false.
Sourcepub fn set_volume(&mut self, id: u64, volume: f32)
pub fn set_volume(&mut self, id: u64, volume: f32)
Set the volume of the sound associated with the given id.
The output samples of the SoundSource assicociated with the given id will be multiplied by this volume.
Sourcepub fn set_group_volume(&mut self, group: G, volume: f32)
pub fn set_group_volume(&mut self, group: G, volume: f32)
Set the volume of the given group.
The volume of all sounds associated with this group is multiplied by this volume.
Sourcepub fn mark_to_remove(&mut self, id: u64, drop: bool)
pub fn mark_to_remove(&mut self, id: u64, drop: bool)
Mark if the sound will be removed after it reachs its end.
If false, it will be possible to reset the sound and play it again after it has already reached its end. Otherwise, the sound will be removed when it reachs its end, even if it is marked to loop.
Sourcepub fn sound_count(&self) -> usize
pub fn sound_count(&self) -> usize
The number of sounds in the mixer.
This include the sounds that are currently stopped.
Sourcepub fn playing_count(&self) -> usize
pub fn playing_count(&self) -> usize
The number of sounds being played currently.
Does not include the sounds that are currently stopped.