[−][src]Struct tetra::audio::Sound
Sound data that can be played back.
Supports WAV, Ogg Vorbis, MP3 and FLAC (in other words, everything that Rodio provides support for).
All of the playback methods on this type return a SoundInstance
that
can be used to control the sound after it has started. If you just want
to 'fire and forget' a sound, you can discard it - the sound will
continue playing regardless.
This type acts as a lightweight handle to the associated audio data, and so can be cloned with little overhead.
Methods
impl Sound
[src]
pub fn new<P>(path: P) -> Result<Sound> where
P: AsRef<Path>,
[src]
P: AsRef<Path>,
Creates a new sound from the given file.
Errors
If the file path is invalid, a TetraError::Io
will be returned. Note that the data
is not decoded until playback begins, so this function will not validate
that the data being read is formatted correctly.
pub fn from_file_data(data: &[u8]) -> Sound
[src]
Creates a new sound from a slice of binary data, encoded in one of Tetra's supported file formats.
This is useful in combination with include_bytes
, as it allows you to include
your audio data directly in the binary.
Note that the data is not decoded until playback begins, so this function will not validate that the data being read is formatted correctly.
pub fn from_data(data: &[u8]) -> Sound
[src]
Renamed to from_file_data
to disambiguate from other sound data formats (e.g. PCM).
pub fn play(&self, ctx: &Context) -> Result<SoundInstance>
[src]
Plays the sound.
Errors
If there is no active audio device, a TetraError::NoAudioDevice
will be returned.
If the sound data could not be decoded, a TetraError::FailedToDecodeAudio
will be returned.
pub fn repeat(&self, ctx: &Context) -> Result<SoundInstance>
[src]
Plays the sound repeatedly.
Errors
If there is no active audio device, a TetraError::NoAudioDevice
will be returned.
If the sound data could not be decoded, a TetraError::FailedToDecodeAudio
will be returned.
pub fn spawn(&self, ctx: &Context) -> Result<SoundInstance>
[src]
Spawns a new instance of the sound that is not playing yet.
Errors
If there is no active audio device, a TetraError::NoAudioDevice
will be returned.
If the sound data could not be decoded, a TetraError::FailedToDecodeAudio
will be returned.
pub fn play_with(
&self,
ctx: &Context,
volume: f32,
speed: f32
) -> Result<SoundInstance>
[src]
&self,
ctx: &Context,
volume: f32,
speed: f32
) -> Result<SoundInstance>
Plays the sound, with the provided settings.
Errors
If there is no active audio device, a TetraError::NoAudioDevice
will be returned.
If the sound data could not be decoded, a TetraError::FailedToDecodeAudio
will be returned.
pub fn repeat_with(
&self,
ctx: &Context,
volume: f32,
speed: f32
) -> Result<SoundInstance>
[src]
&self,
ctx: &Context,
volume: f32,
speed: f32
) -> Result<SoundInstance>
Plays the sound repeatedly, with the provided settings.
Errors
If there is no active audio device, a TetraError::NoAudioDevice
will be returned.
If the sound data could not be decoded, a TetraError::FailedToDecodeAudio
will be returned.
pub fn spawn_with(
&self,
ctx: &Context,
volume: f32,
speed: f32
) -> Result<SoundInstance>
[src]
&self,
ctx: &Context,
volume: f32,
speed: f32
) -> Result<SoundInstance>
Spawns a new instance of the sound that is not playing yet, with the provided settings.
Errors
If there is no active audio device, a TetraError::NoAudioDevice
will be returned.
If the sound data could not be decoded, a TetraError::FailedToDecodeAudio
will be returned.
Trait Implementations
impl PartialEq<Sound> for Sound
[src]
impl Clone for Sound
[src]
fn clone(&self) -> Sound
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl Debug for Sound
[src]
Auto Trait Implementations
Blanket Implementations
impl<T, U> Into for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
impl<T> From for T
[src]
impl<T, U> TryFrom for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T> Borrow for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Same for T
type Output = T
Should always be Self
impl<SS, SP> SupersetOf for SP where
SS: SubsetOf<SP>,
SS: SubsetOf<SP>,
fn to_subset(&self) -> Option<SS>
fn is_in_subset(&self) -> bool
unsafe fn to_subset_unchecked(&self) -> SS
fn from_subset(element: &SS) -> SP
impl<T> SetParameter for T
fn set<T>(&mut self, value: T) -> <T as Parameter<Self>>::Result where
T: Parameter<Self>,
T: Parameter<Self>,
Sets value
as a parameter of self
.