pub struct Sample { /* private fields */ }Expand description
A loaded audio sample — mono or stereo f32 data at a known sample rate.
Implementations§
Source§impl Sample
impl Sample
Sourcepub fn from_mono(data: Vec<f32>, sample_rate: u32) -> Self
pub fn from_mono(data: Vec<f32>, sample_rate: u32) -> Self
Create a mono sample from raw f32 data.
Sourcepub fn from_stereo(data: Vec<f32>, sample_rate: u32) -> Self
pub fn from_stereo(data: Vec<f32>, sample_rate: u32) -> Self
Create a stereo sample from interleaved f32 data.
Sourcepub fn with_slices(self, slices: Vec<usize>) -> Self
pub fn with_slices(self, slices: Vec<usize>) -> Self
Set slice points manually.
Sourcepub fn detect_onsets(&mut self, threshold: f32, min_slice_frames: usize)
pub fn detect_onsets(&mut self, threshold: f32, min_slice_frames: usize)
Auto-detect slice points via onset detection (energy-based transient detection).
threshold controls sensitivity (0.0–1.0, lower = more slices).
min_slice_frames is the minimum distance between slices.
Sourcepub fn sample_rate(&self) -> u32
pub fn sample_rate(&self) -> u32
Sample rate in Hz.
Sourcepub fn cubic_hermite(y0: f32, y1: f32, y2: f32, y3: f32, t: f32) -> f32
pub fn cubic_hermite(y0: f32, y1: f32, y2: f32, y3: f32, t: f32) -> f32
Cubic Hermite (Catmull-Rom) interpolation between four points.
y0..y3 are sample values at positions idx-1, idx, idx+1, idx+2.
t is the fractional position between y1 and y2 (0.0–1.0).
Sourcepub fn read_cubic(&self, position: f64) -> f32
pub fn read_cubic(&self, position: f64) -> f32
Read a mono value using cubic Hermite interpolation.
Uses four points around the position for smooth interpolation. For stereo, averages L+R.
Sourcepub fn read_interpolated(&self, position: f64) -> f32
pub fn read_interpolated(&self, position: f64) -> f32
Read a frame at the given position with cubic Hermite interpolation.
Returns mono sample value. For stereo, averages L+R.
Sourcepub fn read_stereo_interpolated(&self, position: f64) -> (f32, f32)
pub fn read_stereo_interpolated(&self, position: f64) -> (f32, f32)
Read a stereo frame with cubic Hermite interpolation.
Returns (left, right). For mono samples, both channels are identical.
When the simd feature is enabled on x86_64, both channels are computed
in a single SIMD pass using SSE.