Struct Sound

Source
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

Source

pub fn wav(bytes: &[u8]) -> Option<Sound>

Decode a validated PCM16 WAV once; playback reuses the owned sample Arc.

Source

pub fn new(clip: Clip) -> Option<Sound>

Source

pub fn clip(&self) -> &Clip

Source§

impl Sound

Source

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

Trait Implementations§

Source§

impl Clone for Sound

Source§

fn clone(&self) -> Sound

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 Sound

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Sound

§

impl RefUnwindSafe for Sound

§

impl Send for Sound

§

impl Sync for Sound

§

impl Unpin for Sound

§

impl UnwindSafe for Sound

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.