pub struct AudioEngine<G = ()>{ /* private fields */ }
Expand description
The main struct of the crate.
This hold all existing SoundSource
s 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§
Source§impl<G> AudioEngine<G>
impl<G> AudioEngine<G>
Sourcepub fn new_sound<T>(&self, source: T) -> Result<Sound<G>, &'static str>where
T: SoundSource + Send + 'static,
pub fn new_sound<T>(&self, source: T) -> Result<Sound<G>, &'static str>where
T: SoundSource + Send + 'static,
Add a new Sound in the default Group.
Same as calling new_sound_with_group(G::default(), source)
.
See Self::new_sound_with_group, for more information.
Source§impl AudioEngine
impl AudioEngine
Sourcepub fn new() -> Result<AudioEngine, &'static str>
pub fn new() -> Result<AudioEngine, &'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>() -> Result<AudioEngine<G>, &'static str>
pub fn with_groups<G>() -> 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);
Source§impl<G> AudioEngine<G>
impl<G> 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>(
&self,
group: G,
source: T,
) -> Result<Sound<G>, &'static str>where
T: SoundSource + Send + 'static,
pub fn new_sound_with_group<T>(
&self,
group: G,
source: T,
) -> Result<Sound<G>, &'static str>where
T: SoundSource + Send + 'static,
Add a new Sound with the given Group.
The added sound starts in the stopped state, and play
must be called to
start playing it.
If the number of channels of source
mismatch the output number of
channel, source
will be 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.
Trait Implementations§
Source§impl NewSoundEffect for AudioEngine
impl NewSoundEffect for AudioEngine
fn load_from_bytes( &self, bytes: &'static [u8], duration: f64, ) -> Result<SoundEffect, GameUtilError>
Auto Trait Implementations§
impl<G> Freeze for AudioEngine<G>
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§
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
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.