Struct audio_engine::AudioEngine
source · [−]Expand description
The main struct of the crate.
This hold all existing SoundSources and cpal::platform::Stream.
Each sound is associated with a group, which is purely used by
set_group_volume, to allow mixing multiple sounds together.
Implementations
sourceimpl<G: Default + Eq + Hash + Send> AudioEngine<G>
impl<G: Default + Eq + Hash + Send> AudioEngine<G>
sourcepub fn new_sound<T: SoundSource + Send + 'static>(
&self,
source: T
) -> Result<Sound<G>, &'static str>
pub fn new_sound<T: SoundSource + Send + 'static>(
&self,
source: T
) -> Result<Sound<G>, &'static str>
Create a new Sound in the default Group.
Same as calling new_sound_with_group(G::default(), source).
The added sound is started in stopped state, and play must be called to start playing
it.
Return a Err if the number of channels doesn’t match the output number of channels. If
the ouput number of channels is 1, or the number of channels of source is 1, source
will be automatic wrapped in a ChannelConverter. If the sample_rate of source
mismatch the output sample_rate, source will be wrapped in a SampleRateConverter.
sourceimpl AudioEngine
impl AudioEngine
sourcepub fn new() -> Result<Self, &'static str>
pub fn new() -> Result<Self, &'static str>
Tries to create a new AudioEngine.
cpal will spawn a new thread where the sound samples will be sampled, mixed, and outputed
to the output stream.
sourcepub fn with_groups<G: Eq + Hash + Send>(
) -> Result<AudioEngine<G>, &'static str>
pub fn with_groups<G: Eq + Hash + Send>(
) -> Result<AudioEngine<G>, &'static str>
Tries to create a new AudioEngine, with the given type to represent sound groups.
cpal will spawn a new thread where the sound samples will be sampled, mixed, and outputed
to the output stream.
Example
use audio_engine::{AudioEngine, WavDecoder};
#[derive(Eq, Hash, PartialEq)]
enum Group {
Effect,
Music,
}
let audio_engine = AudioEngine::with_groups::<Group>()?;
let mut fx = audio_engine.new_sound_with_group(Group::Effect, my_fx)?;
let mut music = audio_engine.new_sound_with_group(Group::Music, my_music)?;
fx.play();
music.play();
// decrease music volume, for example
audio_engine.set_group_volume(Group::Music, 0.1);sourceimpl<G: Eq + Hash + Send> AudioEngine<G>
impl<G: Eq + Hash + Send> AudioEngine<G>
sourcepub fn sample_rate(&self) -> u32
pub fn sample_rate(&self) -> u32
The sample rate that is currently being outputed to the device.
sourcepub fn channels(&self) -> u16
pub fn channels(&self) -> u16
The sample rate of the current output device.
May change when the device changes.
sourcepub fn new_sound_with_group<T: SoundSource + Send + 'static>(
&self,
group: G,
source: T
) -> Result<Sound<G>, &'static str>
pub fn new_sound_with_group<T: SoundSource + Send + 'static>(
&self,
group: G,
source: T
) -> Result<Sound<G>, &'static str>
Create a new Sound with the given Group.
Return a Err if the number of channels doesn’t match the output number of channels. If
the ouput number of channels is 1, or the number of channels of source is 1, source
will be automatic wrapped in a ChannelConverter.
If the sample_rate of source mismatch the output sample_rate, source will be
wrapped in a SampleRateConverter.
sourcepub fn set_group_volume(&self, group: G, volume: f32)
pub fn set_group_volume(&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.
Auto Trait Implementations
impl<G = ()> !RefUnwindSafe for AudioEngine<G>
impl<G> Send for AudioEngine<G>
impl<G = ()> !Sync for AudioEngine<G>
impl<G> Unpin for AudioEngine<G>
impl<G = ()> !UnwindSafe for AudioEngine<G>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more