pub struct GameAudio { /* private fields */ }Expand description
Local gameplay audio with explicit suspension, independent of simulation time.
Pause/reset discard only this instance’s gameplay voices. Non-positional
Cue::Click voices use the UI bus and remain independent of this lifecycle,
as do other instances, music and the user’s mute/bus/master settings. There
is no pending-cue queue. Admission describes the mixer, not device audibility.
Runtime replacement discards stale voice ownership and cadence history.
Controllers belong to their creating thread, like the runtime mixer:
let audio = ferravex_render::audio::GameAudio::new();
std::thread::spawn(move || drop(audio));use ferravex_render::audio::{Cue, GameAudio};
let mut audio = GameAudio::new();
audio.pause();
assert!(audio.is_paused());
assert_eq!(audio.cue_with_outcome(Cue::Jump, 0.5), None);
audio.reset(); // Reset during a menu stays paused.
assert!(audio.is_paused());
audio.resume();
assert!(!audio.is_paused());
assert!(audio.cue_with_outcome(Cue::Jump, 0.5).unwrap().handle().is_some());Implementations§
Source§impl GameAudio
impl GameAudio
Sourcepub fn reset(&mut self)
pub fn reset(&mut self)
Immediately discard this instance’s gameplay voices and restart its
footfall history/pitch sequence, retaining acoustics and pause state.
UI clicks and shared mixer settings are unchanged. See Self.
Sourcepub fn pause(&mut self)
pub fn pause(&mut self)
Immediately discard gameplay voices (including releasing motors) and
footfall history, then suppress new gameplay cues until Self::resume.
Repeated calls are harmless; UI clicks remain usable. See Self.
Sourcepub fn resume(&mut self)
pub fn resume(&mut self)
Accept fresh gameplay cues again. Does not replay suppressed events or
restart the motor: the next active Self::motor call supplies its state.
The first valid walk sample establishes a new origin. See Self.
Sourcepub fn is_paused(&self) -> bool
pub fn is_paused(&self) -> bool
Whether gameplay cues are locally suspended, regardless of device or
user mute state. See Self.
pub fn set_acoustics(&mut self, profile: AcousticProfile) -> bool
Sourcepub fn cue(&mut self, cue: Cue, gain: f32)
pub fn cue(&mut self, cue: Cue, gain: f32)
Play a cue, discarding its admission result for compatibility.
See Self::cue_with_outcome for validation and suspension semantics.
Sourcepub fn cue_with_outcome(
&mut self,
cue: Cue,
gain: f32,
) -> Option<VoiceAdmission>
pub fn cue_with_outcome( &mut self, cue: Cue, gain: f32, ) -> Option<VoiceAdmission>
Submit a non-positional cue using the existing mixer admission policy.
None means local pause suppressed the cue without touching the mixer.
Otherwise the result distinguishes a start, a steal and a rejection.
The mixer validates the resulting parameters, including the gain after
acoustics (finite, in 0..=4). Clicks bypass acoustics and local pause.
Muted, zero-gain and device-unavailable playback can still be admitted;
the host continues to render/skip these voices normally.
use ferravex_render::audio::{Cue, GameAudio, VoiceAdmission, VoiceRejection};
let mut audio = GameAudio::new();
assert_eq!(audio.cue_with_outcome(Cue::Fire, f32::NAN),
Some(VoiceAdmission::Rejected(VoiceRejection::InvalidParams)));
let admission = audio.cue_with_outcome(Cue::Fire, 0.5).unwrap();
assert!(admission.handle().is_some());
audio.pause();
assert_eq!(audio.cue_with_outcome(Cue::Fire, 0.5), None);
assert!(audio.cue_with_outcome(Cue::Click, 0.2).unwrap().handle().is_some());Sourcepub fn at(&mut self, cue: Cue, position: Vec3, gain: f32)
pub fn at(&mut self, cue: Cue, position: Vec3, gain: f32)
Play a positional gameplay cue, discarding its admission result.
See Self::at_with_outcome.
Sourcepub fn at_with_outcome(
&mut self,
cue: Cue,
position: Vec3,
gain: f32,
) -> Option<VoiceAdmission>
pub fn at_with_outcome( &mut self, cue: Cue, position: Vec3, gain: f32, ) -> Option<VoiceAdmission>
Submit a positional gameplay cue. All positional cues, including Click,
retain the original effects-bus/acoustics behavior and obey local pause.
Invalid positions or resulting gains are rejected without a voice change.
Outcomes have the same meaning as Self::cue_with_outcome.
use ferravex_render::{audio::{Cue, GameAudio, VoiceAdmission, VoiceRejection},
prelude::Vec3};
let mut audio = GameAudio::new();
assert_eq!(audio.at_with_outcome(Cue::Fire, Vec3::splat(f32::NAN), 0.5),
Some(VoiceAdmission::Rejected(VoiceRejection::InvalidParams)));
assert!(audio.at_with_outcome(Cue::Fire, Vec3::ZERO, 0.5)
.unwrap().handle().is_some());
audio.pause();
assert_eq!(audio.at_with_outcome(Cue::Click, Vec3::ZERO, 0.2), None);Sourcepub fn walk(
&mut self,
position: Vec3,
grounded: bool,
active: bool,
surface: Surface,
stride: f32,
)
pub fn walk( &mut self, position: Vec3, grounded: bool, active: bool, surface: Surface, stride: f32, )
Local footfall cadence follows actual ground travel, avoiding sounds from pushing into a wall. Teleports, air motion and menus reset accumulated travel. Local pause ignores samples; resume establishes a fresh origin.