Skip to main content

AudioQueue

Struct AudioQueue 

Source
pub struct AudioQueue<V> { /* private fields */ }
Expand description

The requests screens made this frame. Game empties it every frame. It knows which cues the MenuSounds are (AudioConfig), and the sounds started with a handle that haven’t stopped.

Implementations§

Source§

impl<V> AudioQueue<V>

Source

pub fn set_manifest(&mut self, manifest: &AudioManifest)

Tells the queue the sound cues of manifest, which add_sound refuses. The context tells it the game’s.

Source

pub fn add_sound( &mut self, cue: &str, samples: Samples, ) -> Result<(), AddSoundError>

Makes samples the sound cue cue: from now on play_sound and start_sound of cue play it as a cue of the manifest would, at its own volume, full, and once. Adding a cue added before replaces it. Refused, with a problem in the game’s log:

// A tenth of a second of a square wave, 8-bit, at 11,025 a second.
let bytes: Vec<u8> = (0..1102).map(|i| if i % 50 < 25 { 64 } else { 192 }).collect();
let beep = Samples::from_u8(11_025, 1, &bytes).unwrap();
let mut audio = AudioQueue::<()>::default();
audio.add_sound("beep", beep).unwrap();
audio.play_sound("beep");
assert_eq!(audio.pending().len(), 2);
Source

pub fn remove_sound(&mut self, cue: &str)

Removes the sound cue cue that add_sound made, stopping what plays it and freeing its samples. From then on a play of it plays nothing, and the first is a problem in the game’s log, until it is added again. A cue that wasn’t added is a problem in the log too.

Source

pub fn is_added(&self, cue: &str) -> bool

Whether cue was added and not removed.

Source

pub fn added_bytes(&self) -> u64

The bytes of samples the sounds added hold now, all together: at most ADDED_BYTES_MAX.

Source

pub fn take_problems(&mut self) -> Vec<String>

Takes the problems for the game’s log, oldest first: Game logs them every frame.

Source§

impl<V> AudioQueue<V>

Source

pub fn start_sound(&mut self, cue: &str) -> SoundId

Starts sound cue at its own volume, playing until it is stopped: looped if its cue says so, else once. The handle lives until stop_sound, or until the screen that started it leaves the stack. A sound nothing needs to stop is play_sound’s.

Source

pub fn start_sound_at(&mut self, cue: &str, volume: f32) -> SoundId

start_sound at volume (0–1, clamped) times the cue’s own volume. A cue remove_sound removed plays nothing: its id was never live.

Source

pub fn stop_sound(&mut self, id: SoundId, fade_ms: u32)

Stops the sound started as id: at once with a fade_ms of 0, else after its volume falls in a straight line to silence over fade_ms milliseconds (advance). A sound already fading keeps its fade, unless this stops it at once. An unknown or stopped id does nothing.

Source

pub fn set_sound_volume(&mut self, id: SoundId, volume: f32)

Sets the volume of the sound started as id (0–1, clamped). An unknown or stopped id, or a sound fading out, does nothing.

Source

pub fn sound_is_live(&self, id: SoundId) -> bool

Whether id was started and hasn’t been stopped (a sound fading out still counts). A cue that plays once counts until it is stopped, as the queue knows no lengths.

Source

pub fn advance(&mut self, dt: f32)

Advances the fades by dt seconds: each sends its volume, or the stop on the frame it ends. Game calls it every frame before it takes the requests. Nonsense frame times pass no time.

Source

pub fn pause_sounds(&mut self)

Pauses every sound started with a handle that is playing now, for a pause menu: one started after it plays, so the menu’s own sounds are heard. Sound cues played once, the music and the voice go on. The pause is the calling screen’s and lasts until it calls resume_sounds or leaves the stack. A screen pauses at most once, so calling it every frame is fine, and several screens pausing don’t stack further: the queue sends AudioRequest::PauseSounds when the first pause begins and AudioRequest::ResumeSounds when the last ends.

Source

pub fn resume_sounds(&mut self)

Ends the calling screen’s pause_sounds. A screen that isn’t pausing does nothing.

Source

pub fn sounds_paused(&self) -> bool

Whether some screen is pausing the sounds.

Source§

impl<V> AudioQueue<V>

Source

pub fn new(config: AudioConfig) -> Self

An empty queue that plays the MenuSounds with config’s cues.

Source

pub fn config(&self) -> AudioConfig

Which cues the MenuSounds are.

Source

pub fn menu(&mut self, sound: MenuSound)

Plays a menu sound: its cue in the config.

Source

pub fn cursor_tick(&mut self)

Plays the cursor’s tick, once per step it moves.

Source

pub fn play_sound(&mut self, cue: &str)

Plays sound cue once at its own volume.

Source

pub fn play_sound_at(&mut self, cue: &str, volume: f32)

Plays sound cue once at volume (0–1, clamped) times its own volume. A cue remove_sound removed plays nothing.

Source

pub fn play_music(&mut self, cue: &str)

Switches the music to cue (nothing happens if it’s already on), as the audio manifest’s default switch says.

Source

pub fn play_music_with(&mut self, cue: &str, switch: MusicSwitch)

Switches the music to cue as switch says (nothing happens if it’s already on): how long the old track fades out and the new one fades in, and whether the two overlap.

Source

pub fn stop_music(&mut self)

Fades the music out over the audio manifest’s default fade-out.

Source

pub fn stop_music_with(&mut self, fade_ms: u32)

Fades the music out over fade_ms instead of the default, for this stop only: the time from full gain to silence (0 stops at once). A quiet interval before the next track is the caller’s to time.

Source

pub fn play_voice(&mut self, line: &LineId, variant: V)

Plays the variant clip of line. Screens call Ctx::play_voice instead, which asks only for clips that exist and only while voices are on.

Source

pub fn stop_voice(&mut self)

Stops the voice that is playing, if any.

Source

pub fn preload_voices(&mut self, lines: Vec<(LineId, V)>)

Tells the platform which clips are coming, in order (Ctx::preload_voices).

Source

pub fn pending(&self) -> &[AudioRequest<V>]

The requests made since the last take, in order.

Source

pub fn take(&mut self) -> Vec<AudioRequest<V>>

Empties the queue, returning its requests in order.

Trait Implementations§

Source§

impl<V: Clone> Clone for AudioQueue<V>

Source§

fn clone(&self) -> AudioQueue<V>

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<V: Debug> Debug for AudioQueue<V>

Source§

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

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

impl<V> Default for AudioQueue<V>

Source§

fn default() -> Self

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

impl<V: PartialEq> PartialEq for AudioQueue<V>

Source§

fn eq(&self, other: &AudioQueue<V>) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl<V: PartialEq> StructuralPartialEq for AudioQueue<V>

Auto Trait Implementations§

§

impl<V> Freeze for AudioQueue<V>

§

impl<V> RefUnwindSafe for AudioQueue<V>
where V: RefUnwindSafe,

§

impl<V> Send for AudioQueue<V>
where V: Send,

§

impl<V> Sync for AudioQueue<V>
where V: Sync,

§

impl<V> Unpin for AudioQueue<V>
where V: Unpin,

§

impl<V> UnsafeUnpin for AudioQueue<V>

§

impl<V> UnwindSafe for AudioQueue<V>
where V: UnwindSafe,

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.