#[derive(Debug, Clone, PartialEq)]
pub struct DecodedAudio {
pub samples: Vec<f32>,
pub sample_rate: u32,
pub channels: u8,
pub bit_depth: u16,
pub duration_sec: f64,
}
impl DecodedAudio {
#[cfg(test)]
#[must_use]
pub fn frame_count(&self) -> usize {
if self.channels == 0 {
0
} else {
self.samples.len() / self.channels as usize
}
}
#[cfg(test)]
#[must_use]
pub fn is_normalized(&self) -> bool {
self.samples.iter().all(|&s| (-1.0..=1.0).contains(&s))
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct MixedAudio {
pub samples: Vec<f32>,
pub original_channels: u8,
pub peak_before_mix: f32,
pub peak_after_mix: f32,
}
impl MixedAudio {
#[cfg(test)]
#[must_use]
pub fn sample_count(&self) -> usize {
self.samples.len()
}
#[cfg(test)]
#[must_use]
pub fn is_clipped(&self) -> bool {
(self.peak_after_mix - 1.0).abs() < f32::EPSILON
}
#[cfg(test)]
#[must_use]
pub fn peak_ratio(&self) -> f32 {
if self.peak_before_mix.abs() < f32::EPSILON {
1.0 } else {
self.peak_after_mix / self.peak_before_mix
}
}
}