1use crate::{Channels, SampleRate, Samples};
2use std::time::Duration;
3
4#[derive(Debug, Clone)]
5pub struct RawAudioFrame {
6 pub sample_rate: SampleRate,
7 pub channels: Channels,
8 pub samples: Samples,
9}
10
11impl RawAudioFrame {
12 #[must_use]
13 pub fn duration(&self) -> Duration {
14 let samples_per_channel = u64::try_from(self.samples.len() / self.channels.channel_count())
15 .expect("samples per channel should be less than u64::MAX");
16
17 let nanos = 1_000_000_000 * samples_per_channel / u64::from(self.sample_rate.0);
18
19 Duration::from_nanos(nanos)
20 }
21}