pub struct SoundData { /* private fields */ }Expand description
A sound’s samples, or the loaded bytes they are decoded from.
Build one by hand for computed audio; a loaded one comes from
Assets::sound.
Implementations§
Source§impl SoundData
impl SoundData
Sourcepub fn mono(rate: u32, samples: Vec<f32>) -> Self
pub fn mono(rate: u32, samples: Vec<f32>) -> Self
A sound of rate frames a second, one sample per frame.
The rate must be more than zero; checked only in debug builds.
Sourcepub fn stereo(rate: u32, samples: Vec<f32>) -> Self
pub fn stereo(rate: u32, samples: Vec<f32>) -> Self
A sound of rate frames a second, samples interleaved left then
right.
The rate must be more than zero and the length even; checked only in debug builds.
Sourcepub fn streamed(self) -> Self
pub fn streamed(self) -> Self
Decodes the sound while it plays, in place of keeping every sample in memory.
For music and other long loaded clips. A sound built by hand is already in memory, so this returns it as it is, with a debug log.
Examples found in repository?
examples/breakout-game.rs (line 213)
205 fn build(&self, assets: &Assets) -> SoundData {
206 match self {
207 Sound::Serve => assets.sound("serve"),
208 Sound::BallLost => assets.sound("lost"),
209 Sound::LevelClear => assets.sound("win"),
210 Sound::GameOver => assets.sound("gameover"),
211 Sound::Bounce => assets.sound("bounce"),
212 Sound::BrickBreak => assets.sound("break"),
213 Sound::Music => assets.sound("music").streamed(),
214 Sound::MenuMusic => assets.sound("menu_music").streamed(),
215 Sound::Click => assets.sound("click"),
216 }
217 }More examples
examples/sound-lab.rs (line 282)
273 fn build(&self, assets: &Assets) -> SoundData {
274 match self {
275 Sound::Bounce => assets.sound("bounce"),
276 Sound::Break => assets.sound("break"),
277 Sound::Serve => assets.sound("serve"),
278 Sound::GameOver => assets.sound("gameover"),
279 Sound::Lost => assets.sound("lost"),
280 Sound::Win => assets.sound("win"),
281 Sound::Click => assets.sound("click"),
282 Sound::Theme => assets.sound("music").streamed(),
283 Sound::ThemeDecoded => assets.sound("music"),
284 Sound::MenuTheme => assets.sound("menu_music").streamed(),
285 Sound::Pulse => assets.sound("break"),
286 }
287 }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.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
impl<S, T> Duplex<S> for Twhere
T: FromSample<S> + ToSample<S>,
Source§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more