Struct AcousticTransition

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

An allocation-free, opt-in transition between room/occlusion profiles.

Gain and cutoff interpolate linearly over seconds, reaching the exact target at completion. Time is supplied by the caller; there is no sample-rate, renderer or wall-clock dependency. For an unchanged target, splitting elapsed time into smaller updates gives the same profile within floating-point error. Advance once per chosen presentation interval, then share Self::current across voices. This does not advance or pause gameplay, network or replay time.

AcousticScene::sample remains instantaneous and retains its authored defaults. Apply the result to the original voice parameters each update; repeatedly applying it to already attenuated parameters compounds the gain. Mixer bus/master fades and user preferences remain independent.

use ferravex_math::Vec3;
use ferravex_play::audio::{AcousticScene, AcousticTransition, VoiceParams};
let scene = AcousticScene::<0>::new([]).unwrap();
let mut transition = AcousticTransition::default();
// A real host query supplies the occlusion flag.
let occluded = scene.sample(Vec3::ZERO, true).unwrap();
transition.transition_to(occluded, 0.2)?;
let halfway = transition.advance(0.1)?;
assert!(halfway.gain > occluded.gain && halfway.gain < 1.0);
let authored = VoiceParams { gain: 0.5, ..Default::default() };
let voice = halfway.apply(authored);
assert!(voice.gain < authored.gain);
assert_eq!(transition.advance(0.1)?, occluded);
assert!(!transition.is_transitioning());

Implementations§

Source§

impl AcousticTransition

Source

pub fn new( profile: AcousticProfile, ) -> Result<AcousticTransition, AcousticTransitionError>

Start settled at a checked profile, without an initial fade.

use ferravex_play::audio::{AcousticProfile, AcousticTransition};
let profile = AcousticProfile { gain: 0.8, low_pass_hz: 2500.0 };
let transition = AcousticTransition::new(profile)?;
assert_eq!(transition.current(), profile);
assert_eq!(transition.target(), profile);
assert!(!transition.is_transitioning());
Source

pub fn current(&self) -> AcousticProfile

Current finite profile, without advancing time. See Self::new.

Source

pub fn target(&self) -> AcousticProfile

Last accepted destination profile. See Self::new.

Source

pub fn is_transitioning(&self) -> bool

Whether transition time remains. See AcousticTransition.

Source

pub fn transition_to( &mut self, target: AcousticProfile, duration_seconds: f64, ) -> Result<(), AcousticTransitionError>

Retarget from the current profile without a value jump.

Duration must be finite and nonnegative. Zero snaps immediately, even to an existing target. Resubmitting the same target with a positive duration preserves the existing timeline (the new duration is ignored), so sampling an unchanged scene each tick cannot indefinitely postpone completion. A destination equal to the current profile settles immediately. All inputs are checked before mutation, including when the destination is unchanged.

use ferravex_play::audio::{AcousticProfile, AcousticTransition};
let mut transition = AcousticTransition::default();
transition.transition_to(AcousticProfile { gain: 0.0, low_pass_hz: 80.0 }, 1.0)?;
let current = transition.advance(0.5)?;
transition.transition_to(AcousticProfile::default(), 0.25)?;
assert_eq!(transition.current(), current);
assert_eq!(transition.advance(0.25)?, AcousticProfile::default());
Source

pub fn advance( &mut self, elapsed_seconds: f64, ) -> Result<AcousticProfile, AcousticTransitionError>

Advance by finite, nonnegative seconds, returning the current profile.

Zero freezes the transition. Time past completion is discarded and the target is returned exactly; it does not carry into later transitions. Elapsed time is accumulated in f64 rather than rounding each update’s profile, preserving small steps at audio callback/sample rates. See AcousticTransition for an example.

Source

pub fn reset( &mut self, profile: AcousticProfile, ) -> Result<(), AcousticTransitionError>

Immediately settle at a checked profile, clearing all transition history. Use on restart/teleport or to restore AcousticProfile::default.

use ferravex_play::audio::{AcousticProfile, AcousticTransition};
let mut transition = AcousticTransition::default();
transition.transition_to(AcousticProfile { gain: 0.2, low_pass_hz: 900.0 }, 1.0)?;
transition.advance(0.1)?;
transition.reset(AcousticProfile::default())?;
assert!(!transition.is_transitioning());
assert_eq!(transition.advance(10.0)?, AcousticProfile::default());

Trait Implementations§

Source§

impl Clone for AcousticTransition

Source§

fn clone(&self) -> AcousticTransition

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for AcousticTransition

Source§

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

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

impl Default for AcousticTransition

Source§

fn default() -> AcousticTransition

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

impl PartialEq for AcousticTransition

Source§

fn eq(&self, other: &AcousticTransition) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for AcousticTransition

Source§

impl StructuralPartialEq for AcousticTransition

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> 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.