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
impl AcousticTransition
Sourcepub fn new(
profile: AcousticProfile,
) -> Result<AcousticTransition, AcousticTransitionError>
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());Sourcepub fn current(&self) -> AcousticProfile
pub fn current(&self) -> AcousticProfile
Current finite profile, without advancing time. See Self::new.
Sourcepub fn target(&self) -> AcousticProfile
pub fn target(&self) -> AcousticProfile
Last accepted destination profile. See Self::new.
Sourcepub fn is_transitioning(&self) -> bool
pub fn is_transitioning(&self) -> bool
Whether transition time remains. See AcousticTransition.
Sourcepub fn transition_to(
&mut self,
target: AcousticProfile,
duration_seconds: f64,
) -> Result<(), AcousticTransitionError>
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());Sourcepub fn advance(
&mut self,
elapsed_seconds: f64,
) -> Result<AcousticProfile, AcousticTransitionError>
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.
Sourcepub fn reset(
&mut self,
profile: AcousticProfile,
) -> Result<(), AcousticTransitionError>
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
impl Clone for AcousticTransition
Source§fn clone(&self) -> AcousticTransition
fn clone(&self) -> AcousticTransition
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more