ezk_audio/
config.rs

1use crate::{Channels, Format, SampleRate};
2use ezk::{ConfigRange, ValueRange};
3
4#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
5pub struct RawAudioConfigRange {
6    pub sample_rate: ValueRange<SampleRate>,
7    pub channels: ValueRange<Channels>,
8    pub format: ValueRange<Format>,
9}
10
11impl ConfigRange for RawAudioConfigRange {
12    type Config = RawAudioConfig;
13
14    fn any() -> Self {
15        Self {
16            sample_rate: SampleRate::any(),
17            channels: Channels::any(),
18            format: Format::all(),
19        }
20    }
21
22    fn intersect(&self, other: &Self) -> Option<Self> {
23        Some(Self {
24            sample_rate: self.sample_rate.intersect(&other.sample_rate)?,
25            channels: self.channels.intersect(&other.channels)?,
26            format: self.format.intersect(&other.format)?,
27        })
28    }
29
30    fn contains(&self, config: &Self::Config) -> bool {
31        let Self {
32            sample_rate,
33            channels,
34            format,
35        } = self;
36
37        sample_rate.contains(&config.sample_rate)
38            && channels.contains(&config.channels)
39            && format.contains(&config.format)
40    }
41}
42
43#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
44pub struct RawAudioConfig {
45    pub sample_rate: SampleRate,
46    pub channels: Channels,
47    pub format: Format,
48}