pub struct SoundData { /* private fields */ }Expand description
Decoded PCM audio kept in memory: interleaved f32 samples.
You normally never touch this directly; the engine loads files for you.
It is public so you can generate sounds in code and register them with
Audio::register.
Implementations§
Source§impl SoundData
impl SoundData
Sourcepub fn from_samples(
samples: Vec<f32>,
channels: usize,
sample_rate: u32,
) -> Self
pub fn from_samples( samples: Vec<f32>, channels: usize, sample_rate: u32, ) -> Self
Creates sound data from interleaved samples in the range -1.0..=1.0.
§Panics
If channels is 0 or sample_rate is 0.
Sourcepub fn tone(frequency: f32, seconds: f32, volume: f32) -> Self
pub fn tone(frequency: f32, seconds: f32, volume: f32) -> Self
Generates a sine tone with short fades, handy for prototypes and beeps.
frequency is the pitch in hertz (440 = A, 880 = one octave higher), seconds the
length and volume the linear loudness from 0.0 to 1.0.
Sourcepub fn generate(seconds: f32, f: impl FnMut(f32) -> f32) -> Self
pub fn generate(seconds: f32, f: impl FnMut(f32) -> f32) -> Self
Generates mono sound from a function of time in seconds. Adds 5 ms fades at both ends to avoid clicks.
Sourcepub fn sample_rate(&self) -> u32
pub fn sample_rate(&self) -> u32
Sample rate in Hz.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for SoundData
impl RefUnwindSafe for SoundData
impl Send for SoundData
impl Sync for SoundData
impl Unpin for SoundData
impl UnsafeUnpin for SoundData
impl UnwindSafe for SoundData
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
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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>
Convert
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>
Convert
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)
Convert
&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)
Convert
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.