pub struct Sound(/* private fields */);Expand description
A clip whose sample and metadata validation is complete. Keep a bank owner alive during real-time playback if the last Arc must not free in render.
Implementations§
Source§impl Sound
impl Sound
Sourcepub fn with_release(
&self,
start_frame: usize,
release_frames: usize,
) -> Option<Sound>
pub fn with_release( &self, start_frame: usize, release_frames: usize, ) -> Option<Sound>
Returns a shortened copy with a quadratic release ending in exact silence.
Frames before start_frame are copied unchanged. The release spans
release_frames stereo frames: its first frame retains full source gain,
and its last frame is exactly [0.0; 2]. Between them, gain follows the
quadratic decay used by the bank’s chirps, without restarting their phase
or noise sequence. The returned clip contains start_frame + release_frames
frames at the original sample rate. The source sound remains unchanged.
Returns None if the release has fewer than two frames, its end overflows,
or it extends past the source. Requiring both endpoints avoids a forced
one-frame gain jump; very short releases can still be audible.
This is a preparation/export operation: it allocates a new clip and takes
linear work in its length, bounded by the already validated source length.
Call it outside audio render callbacks and reuse the resulting Sound.
use ferravex_play::audio::{Cue, SoundBank};
let bank = SoundBank::procedural(8_000).unwrap();
let source = bank.get(Cue::Success);
let short = source.with_release(400, 800).unwrap();
assert_eq!(short.clip().sample_rate, 8_000);
assert_eq!(short.clip().samples.len(), 1_200);
assert_eq!(&short.clip().samples[..400], &source.clip().samples[..400]);
assert_eq!(short.clip().samples.last(), Some(&[0.0; 2]));
assert!(source.with_release(400, 1).is_none());