Skip to main content

Speaker

Struct Speaker 

Source
pub struct Speaker { /* private fields */ }
Expand description

The headless backend’s sound device: it records what the last frame played, works out which music “sounds” from the music commands and the clock, and keeps the sounds started with a handle until they stop (one that plays once too: it knows no lengths). Like shuyi-app, it mutes rather than pauses: while suspended its music clock runs on. It keeps the sounds the game added at run time, and hears every play of them (added_plays). A voice clip sounds from its request until it is stopped or replaced, or until the length a test gave clips has passed (set_voice_length).

Implementations§

Source§

impl Speaker

Source

pub fn set_load_delay(&mut self, seconds: f64)

Makes music take seconds to load: a track sounds that long after the game starts it (at once by default). Negative or NaN counts as 0.

Source

pub fn set_voice_length(&mut self, seconds: f64)

Makes every voice clip last seconds: it stops sounding that long after it was asked for. Until this is called a clip sounds until it is stopped or replaced. Negative or NaN counts as 0.

Source

pub fn set_silent(&mut self)

Makes no music ever sound, as when the music files are missing.

Source

pub fn requests(&self) -> &[SoundRequest]

The sound and voice requests of the last frame that played any audio.

Source

pub fn music(&self) -> &[MusicCommand]

The music commands of the last frame that played audio.

Source

pub fn volumes(&self) -> (f32, f32, f32)

The music, sound and voice volumes the last frame played at, 0–1; full before any.

Source

pub fn stopped(&self) -> bool

Whether the game stopped all its audio (it quit).

Source

pub fn sounds_playing(&self) -> &[PlayingSound]

The sounds started with a handle and not yet stopped, in id order.

Source

pub fn suspended(&self) -> bool

Whether the audio is held because the system suspended the game.

Source

pub fn added_sounds(&self) -> &BTreeMap<String, SharedSamples>

The sounds the game added at run time and hasn’t removed, by cue.

Source

pub fn added_plays(&self) -> &[AddedPlay]

Every play and start of a sound the game added, in order, since the speaker was made: what each played.

Trait Implementations§

Source§

impl Audio for Speaker

Source§

fn music_playing(&self, now: Millis) -> Option<(&str, f64)>

The music sounding at now: its cue and the seconds since it really started (once its file had loaded), or None in silence: nothing asked for, a track still loading or whose file failed. Of two tracks sounding (a crossfade), the newest: the old one until the new one has loaded.
Source§

fn voice_playing(&self, now: Millis) -> Option<&str>

The voice clip sounding at now, by its file (SoundRequest::Voice), or asked for and still loading: None once it has ended, and for a clip stopped, replaced, whose file failed or that loaded too late to be played. A clip held by suspend still sounds. None by default, for a device that plays no voices.
Source§

fn play(&mut self, frame: &AudioFrame<'_>, now: Millis)

Plays one frame’s frame of audio at now: the volumes first, then the requests and the music commands in order. It also checks on what is still loading, so it is called every frame, with nothing to play too.
Source§

fn stop_all(&mut self)

Stops the music, the voice and the sounds started with a handle: the game has quit.
Source§

fn suspend(&mut self)

Holds everything sounding (the sounds started with a handle, the voice and the music) while the system suspends the game (SystemEvent::Suspend); sound cues played once finish. Pauses, or mutes where the backend can’t pause. A second call does nothing. Read more
Source§

fn resume(&mut self)

Brings back what suspend held, and leaves a SoundRequest::PauseSounds pause in place. A call while not suspended does nothing.
Source§

impl Clone for Speaker

Source§

fn clone(&self) -> Speaker

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Speaker

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Speaker

Source§

fn default() -> Speaker

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

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

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.