1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
use std::num::NonZeroU8;
use crate::{ChannelLayout, SampleRate, SampleType};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct System {
pub sample_rate: SampleRate,
pub channel_layout: ChannelLayout,
pub sample_type: SampleType,
}
impl System {
#[inline]
#[track_caller]
pub const fn sample_size(&self) -> NonZeroU8 {
self.channel_layout
.channels()
.checked_mul(self.sample_type.byte_depth())
.expect("Overflow trying to calculate system's sample size")
}
}
#[macro_export]
macro_rules! system {
($sample_rate:literal, $channel_layout:ident, $sample:ty) => {
::audio_time::System {
sample_rate: ::audio_time::sample_rate!($sample_rate),
channel_layout: ::audio_time::ChannelLayout::$channel_layout,
sample_type: ::audio_time::SampleType::new::<$sample>(),
}
};
}
pub const AUDIO_CD: System = system!(44_100, Stereo, i16);