diff --git a/src/lib.rs b/src/lib.rs index e97b2ac..abea8ea 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -191,13 +191,13 @@ pub struct StreamConfig { /// `Device::supported_input/output_configs` method. #[derive(Debug, Clone, PartialEq, Eq)] pub struct SupportedStreamConfigRange { - pub channels: ChannelCount, + pub(crate) channels: ChannelCount, /// Minimum value for the samples rate of the supported formats. - pub min_sample_rate: SampleRate, + pub(crate) min_sample_rate: SampleRate, /// Maximum value for the samples rate of the supported formats. - pub max_sample_rate: SampleRate, + pub(crate) max_sample_rate: SampleRate, /// Type of data expected by the device. - pub sample_format: SampleFormat, + pub(crate) sample_format: SampleFormat, } /// Describes a single supported stream configuration, retrieved via either a @@ -335,6 +335,35 @@ impl Data { } impl SupportedStreamConfigRange { + pub fn channels(&self) -> ChannelCount { + self.channels + } + + pub fn min_sample_rate(&self) -> SampleRate { + self.min_sample_rate + } + + pub fn max_sample_rate(&self) -> SampleRate { + self.max_sample_rate + } + + pub fn sample_format(&self) -> SampleFormat { + self.sample_format + } + + /// Retrieve a `SupportedStreamConfig` with the given sample rate. + /// + /// **panic!**s if the given `sample_rate` is outside the range specified within this + /// `SupportedStreamConfigRange` instance. + pub fn with_sample_rate(self, sample_rate: SampleRate) -> SupportedStreamConfig { + assert!(sample_rate <= self.min_sample_rate && sample_rate <= self.max_sample_rate); + SupportedStreamConfig { + channels: self.channels, + sample_format: self.sample_format, + sample_rate, + } + } + /// Turns this `SupportedStreamConfigRange` into a `SupportedStreamConfig` corresponding to the maximum samples rate. #[inline] pub fn with_max_sample_rate(self) -> SupportedStreamConfig {