Struct GameAudio

Source
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

Source

pub fn new() -> GameAudio

Preload the shared bank and start unpaused. See Self.

Source

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.

Source

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.

Source

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.

Source

pub fn is_paused(&self) -> bool

Whether gameplay cues are locally suspended, regardless of device or user mute state. See Self.

Source

pub fn set_acoustics(&mut self, profile: AcousticProfile) -> bool

Source

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.

Source

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());
Source

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.

Source

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);
Source

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.

Source

pub fn motor(&mut self, speed: f32, max_speed: f32, active: bool)

Local continuous motor/propeller loop. Speed changes pitch and loudness; inactive/invalid input releases the voice over 128 output frames. Explicit Self::pause discards it immediately, even without an output callback.

Trait Implementations§

Source§

impl Default for GameAudio

Source§

fn default() -> GameAudio

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

impl Drop for GameAudio

Source§

fn drop(&mut self)

Executes the destructor for this 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> 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, 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.