Update supported_formats methods for all sample rates and channel combos

Closes #32.
This commit is contained in:
mitchmindtree 2018-11-08 12:54:32 +07:00
parent bc94d167ae
commit 2bc9f85970
1 changed files with 39 additions and 30 deletions

View File

@ -50,21 +50,26 @@ impl Device {
pub fn supported_input_formats( pub fn supported_input_formats(
&self, &self,
) -> Result<SupportedInputFormats, FormatsEnumerationError> { ) -> Result<SupportedInputFormats, FormatsEnumerationError> {
match self.default_input_format() { // Retrieve the default format for the total supported channels and supported sample
Ok(f) => { // format.
// Can this device support both 44100 and 48000 let mut f = match self.default_input_format() {
let supported_formats: Vec<SupportedFormat> = [44100, 48000] Err(_) => return Err(FormatsEnumerationError::DeviceNotAvailable),
.into_iter() Ok(f) => f,
.filter(|rate| self.drivers.can_sample_rate(**rate as u32)) };
.map(|rate| {
let mut format = f.clone(); // Collect a format for every combination of supported sample rate and number of channels.
format.sample_rate = SampleRate(*rate); let mut supported_formats = vec![];
SupportedFormat::from(format) for &rate in ::COMMON_SAMPLE_RATES {
}).collect(); if !self.drivers.can_sample_rate(rate.0 as u32) {
Ok(supported_formats.into_iter()) continue;
}, }
Err(_) => Err(FormatsEnumerationError::DeviceNotAvailable), for channels in 1..f.channels + 1 {
f.channels = channels;
f.sample_rate = rate;
supported_formats.push(SupportedFormat::from(f.clone()));
}
} }
Ok(supported_formats.into_iter())
} }
/// Gets the supported output formats. /// Gets the supported output formats.
@ -73,22 +78,26 @@ impl Device {
pub fn supported_output_formats( pub fn supported_output_formats(
&self, &self,
) -> Result<SupportedOutputFormats, FormatsEnumerationError> { ) -> Result<SupportedOutputFormats, FormatsEnumerationError> {
match self.default_output_format() { // Retrieve the default format for the total supported channels and supported sample
Ok(f) => { // format.
// Can this device support both 44100 and 48000 let mut f = match self.default_output_format() {
let supported_formats: Vec<SupportedFormat> = [44100, 48000] Err(_) => return Err(FormatsEnumerationError::DeviceNotAvailable),
.into_iter() Ok(f) => f,
.filter(|rate| self.drivers.can_sample_rate(**rate as u32)) };
.map(|rate| {
let mut format = f.clone(); // Collect a format for every combination of supported sample rate and number of channels.
format.sample_rate = SampleRate(*rate); let mut supported_formats = vec![];
SupportedFormat::from(format) for &rate in ::COMMON_SAMPLE_RATES {
}).collect(); if !self.drivers.can_sample_rate(rate.0 as u32) {
//Ok(vec![SupportedFormat::from(f)].into_iter()) continue;
Ok(supported_formats.into_iter()) }
}, for channels in 1..f.channels + 1 {
Err(_) => Err(FormatsEnumerationError::DeviceNotAvailable), f.channels = channels;
f.sample_rate = rate;
supported_formats.push(SupportedFormat::from(f.clone()));
}
} }
Ok(supported_formats.into_iter())
} }
/// Returns the default input format /// Returns the default input format