Add SupportedFormat (#168)
This commit is contained in:
parent
393206bde9
commit
87949d859b
9 changed files with 75 additions and 30 deletions
40
src/lib.rs
40
src/lib.rs
|
|
@ -11,7 +11,8 @@ let endpoint = cpal::default_endpoint().unwrap();
|
|||
// a `Result` to handle this situation
|
||||
|
||||
// getting a format for the PCM
|
||||
let format = endpoint.supported_formats().unwrap().next().unwrap();
|
||||
let supported_formats_range = endpoint.supported_formats().unwrap().next().unwrap();
|
||||
let format = supported_formats_range.with_max_samples_rate();
|
||||
|
||||
let event_loop = cpal::EventLoop::new();
|
||||
|
||||
|
|
@ -188,10 +189,10 @@ pub struct Format {
|
|||
pub struct SupportedFormatsIterator(cpal_impl::SupportedFormatsIterator);
|
||||
|
||||
impl Iterator for SupportedFormatsIterator {
|
||||
type Item = Format;
|
||||
type Item = SupportedFormat;
|
||||
|
||||
#[inline]
|
||||
fn next(&mut self) -> Option<Format> {
|
||||
fn next(&mut self) -> Option<SupportedFormat> {
|
||||
self.0.next()
|
||||
}
|
||||
|
||||
|
|
@ -201,6 +202,39 @@ impl Iterator for SupportedFormatsIterator {
|
|||
}
|
||||
}
|
||||
|
||||
/// Describes a format.
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct SupportedFormat {
|
||||
pub channels: Vec<ChannelPosition>,
|
||||
pub min_samples_rate: SamplesRate,
|
||||
pub max_samples_rate: SamplesRate,
|
||||
pub data_type: SampleFormat,
|
||||
}
|
||||
|
||||
impl SupportedFormat {
|
||||
/// Builds a corresponding `Format` corresponding to the maximum samples rate.
|
||||
#[inline]
|
||||
pub fn with_max_samples_rate(self) -> Format {
|
||||
Format {
|
||||
channels: self.channels,
|
||||
samples_rate: self.max_samples_rate,
|
||||
data_type: self.data_type,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Format> for SupportedFormat {
|
||||
#[inline]
|
||||
fn from(format: Format) -> SupportedFormat {
|
||||
SupportedFormat {
|
||||
channels: format.channels,
|
||||
min_samples_rate: format.samples_rate,
|
||||
max_samples_rate: format.samples_rate,
|
||||
data_type: format.data_type,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct EventLoop(cpal_impl::EventLoop);
|
||||
|
||||
impl EventLoop {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue