Struct tetra::audio::Sound[][src]

pub struct Sound { /* fields omitted */ }
Expand description

Sound data that can be played back.

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.

Supported Formats

Various file formats are supported, and can be enabled or disabled via Cargo features:

FormatCargo featureEnabled by default?
WAVaudio_wavYes
OGG Vorbisaudio_vorbisYes
MP3audio_mp3Yes
FLACaudio_flacNo

Performance

When you create an instance of Sound, the audio data is loaded into memory. It is not decoded until playback begins.

You can clone a sound cheaply, as it is reference-counted internally. The underlying data will be shared by all of the clones (and, by extension, all of the SoundInstances created from them).

Examples

The audio example demonstrates how to play several different kinds of sound.

Implementations

Creates a new sound from the given file.

Note that the data is not decoded until playback begins, so this function will not validate that the data being read is formatted correctly.

Errors

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.

Plays the sound.

Errors

Plays the sound repeatedly.

Errors

Spawns a new instance of the sound that is not playing yet.

Errors

Plays the sound, with the provided settings.

Errors

Plays the sound repeatedly, with the provided settings.

Errors

Spawns a new instance of the sound that is not playing yet, with the provided settings.

Errors

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.