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>
impl<V> AudioQueue<V>
Sourcepub fn set_manifest(&mut self, manifest: &AudioManifest)
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.
Sourcepub fn add_sound(
&mut self,
cue: &str,
samples: Samples,
) -> Result<(), AddSoundError>
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 cue the audio manifest has (
AddSoundError::InManifest): a checked cue isn’t replaced by accident; - a sound longer than
ADDED_SECONDS_MAX(AddSoundError::TooLong); - a sound that would make the sounds added hold more than
ADDED_BYTES_MAX(AddSoundError::TooMuch).
// 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);Sourcepub fn remove_sound(&mut self, cue: &str)
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.
Sourcepub fn added_bytes(&self) -> u64
pub fn added_bytes(&self) -> u64
The bytes of samples the sounds added hold now, all together: at most
ADDED_BYTES_MAX.
Sourcepub fn take_problems(&mut self) -> Vec<String>
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>
impl<V> AudioQueue<V>
Sourcepub fn start_sound(&mut self, cue: &str) -> SoundId
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.
Sourcepub fn start_sound_at(&mut self, cue: &str, volume: f32) -> SoundId
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.
Sourcepub fn stop_sound(&mut self, id: SoundId, fade_ms: u32)
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.
Sourcepub fn set_sound_volume(&mut self, id: SoundId, volume: f32)
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.
Sourcepub fn sound_is_live(&self, id: SoundId) -> bool
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.
Sourcepub fn advance(&mut self, dt: f32)
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.
Sourcepub fn pause_sounds(&mut self)
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.
Sourcepub fn resume_sounds(&mut self)
pub fn resume_sounds(&mut self)
Ends the calling screen’s pause_sounds. A
screen that isn’t pausing does nothing.
Sourcepub fn sounds_paused(&self) -> bool
pub fn sounds_paused(&self) -> bool
Whether some screen is pausing the sounds.
Source§impl<V> AudioQueue<V>
impl<V> AudioQueue<V>
Sourcepub fn new(config: AudioConfig) -> Self
pub fn new(config: AudioConfig) -> Self
An empty queue that plays the MenuSounds with config’s cues.
Sourcepub fn config(&self) -> AudioConfig
pub fn config(&self) -> AudioConfig
Which cues the MenuSounds are.
Plays a menu sound: its cue in the config.
Sourcepub fn cursor_tick(&mut self)
pub fn cursor_tick(&mut self)
Plays the cursor’s tick, once per step it moves.
Sourcepub fn play_sound(&mut self, cue: &str)
pub fn play_sound(&mut self, cue: &str)
Plays sound cue once at its own volume.
Sourcepub fn play_sound_at(&mut self, cue: &str, volume: f32)
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.
Sourcepub fn play_music(&mut self, cue: &str)
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.
Sourcepub fn play_music_with(&mut self, cue: &str, switch: MusicSwitch)
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.
Sourcepub fn stop_music(&mut self)
pub fn stop_music(&mut self)
Fades the music out over the audio manifest’s default fade-out.
Sourcepub fn stop_music_with(&mut self, fade_ms: u32)
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.
Sourcepub fn play_voice(&mut self, line: &LineId, variant: V)
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.
Sourcepub fn stop_voice(&mut self)
pub fn stop_voice(&mut self)
Stops the voice that is playing, if any.
Sourcepub fn preload_voices(&mut self, lines: Vec<(LineId, V)>)
pub fn preload_voices(&mut self, lines: Vec<(LineId, V)>)
Tells the platform which clips are coming, in order
(Ctx::preload_voices).
Sourcepub fn pending(&self) -> &[AudioRequest<V>]
pub fn pending(&self) -> &[AudioRequest<V>]
The requests made since the last take, in order.
Sourcepub fn take(&mut self) -> Vec<AudioRequest<V>>
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>
impl<V: Clone> Clone for AudioQueue<V>
Source§fn clone(&self) -> AudioQueue<V>
fn clone(&self) -> AudioQueue<V>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more