Skip to main content

SampleResourceF32

Trait SampleResourceF32 

Source
pub trait SampleResourceF32 {
    // Required methods
    fn info(&self) -> SampleResourceInfo;
    fn channel(&self, i: usize) -> Option<&[f32]>;
}
Expand description

An immutable resource of audio samples which has its data stored in de-interleaved f32 format, and which has all of its data loaded into memory.

§Implementation example

struct MyResource {
    data: Vec<Vec<f32>>,
    frames: usize,
    sample_rate: Option<f64>,
}

impl SampleResourceF32 for MyResource {
    fn info(&self) -> SampleResourceInfo {
        SampleResourceInfo {
            num_channels: self.data.len(),
            len_frames: self.frames as u64,
            sample_rate: self.sample_rate,
        }
    }

    fn channel(&self, i: usize) -> Option<&[f32]> {
        self.data.get(i).map(|ch| ch.as_slice())
    }
}

§Realtime Safety

3rd party libraries that implement this trait should expect that all methods in this trait may be called in a realtime thread. For more information, see: http://www.rossbencina.com/code/real-time-audio-programming-101-time-waits-for-nothing

Required Methods§

Source

fn info(&self) -> SampleResourceInfo

Retrieve information about this sample resource. This information is not allowed to change for the lifetime of this sample resource.

Source

fn channel(&self, i: usize) -> Option<&[f32]>

Return an immutable slice to the entire channel at index i.

Returns None if i is out-of-bounds.

Implementors§