37 lines
873 B
Rust
37 lines
873 B
Rust
use std::sync::Arc;
|
|
|
|
/// shared interleaved-stereo pcm bundle paired with the track's sample rate and dsp frame size.
|
|
#[derive(Debug, Clone)]
|
|
pub struct TrackData {
|
|
pub pcm: Arc<[f32]>,
|
|
pub sample_rate: u32,
|
|
pub frame_size: usize,
|
|
}
|
|
|
|
impl TrackData {
|
|
/// builds a zero-length placeholder at 48 kHz with a 4096-sample frame.
|
|
pub fn empty() -> Self {
|
|
Self {
|
|
pcm: Arc::from(Vec::<f32>::new()),
|
|
sample_rate: 48_000,
|
|
frame_size: 4096,
|
|
}
|
|
}
|
|
|
|
/// counts stereo frames (pcm length divided by two channels).
|
|
pub fn total_samples(&self) -> usize {
|
|
self.pcm.len() / 2
|
|
}
|
|
|
|
/// reports whether the pcm slice holds any samples.
|
|
pub fn is_valid(&self) -> bool {
|
|
!self.pcm.is_empty()
|
|
}
|
|
}
|
|
|
|
impl Default for TrackData {
|
|
fn default() -> Self {
|
|
Self::empty()
|
|
}
|
|
}
|