Add _raw suffix to stream constructors

This commit is contained in:
Benjamin Saunders 2020-01-21 21:52:18 -08:00
parent 5390c01641
commit 78df791377
13 changed files with 41 additions and 41 deletions

View File

@ -27,7 +27,7 @@ fn main() -> Result<(), anyhow::Error> {
cpal::SampleFormat::U16 => write_data::<u16>(data, channels, &mut next_value), cpal::SampleFormat::U16 => write_data::<u16>(data, channels, &mut next_value),
}; };
let stream = device.build_output_stream(&format, data_fn, err_fn)?; let stream = device.build_output_stream_raw(&format, data_fn, err_fn)?;
stream.play()?; stream.play()?;

View File

@ -82,8 +82,8 @@ fn main() -> Result<(), anyhow::Error> {
// Build streams. // Build streams.
println!("Attempting to build both streams with `{:?}`.", format); println!("Attempting to build both streams with `{:?}`.", format);
let input_stream = input_device.build_input_stream(&format, input_data_fn, err_fn)?; let input_stream = input_device.build_input_stream_raw(&format, input_data_fn, err_fn)?;
let output_stream = output_device.build_output_stream(&format, output_data_fn, err_fn)?; let output_stream = output_device.build_output_stream_raw(&format, output_data_fn, err_fn)?;
println!("Successfully built streams."); println!("Successfully built streams.");
// Play the streams. // Play the streams.

View File

@ -46,7 +46,7 @@ fn main() -> Result<(), anyhow::Error> {
cpal::SampleFormat::U16 => write_input_data::<u16, i16>(data, &writer_2), cpal::SampleFormat::U16 => write_input_data::<u16, i16>(data, &writer_2),
}; };
let stream = device.build_input_stream(&format, data_fn, err_fn)?; let stream = device.build_input_stream_raw(&format, data_fn, err_fn)?;
stream.play()?; stream.play()?;

View File

@ -80,7 +80,7 @@ impl DeviceTrait for Device {
Device::default_output_format(self) Device::default_output_format(self)
} }
fn build_input_stream<D, E>( fn build_input_stream_raw<D, E>(
&self, &self,
format: &Format, format: &Format,
data_callback: D, data_callback: D,
@ -95,7 +95,7 @@ impl DeviceTrait for Device {
Ok(stream) Ok(stream)
} }
fn build_output_stream<D, E>( fn build_output_stream_raw<D, E>(
&self, &self,
format: &Format, format: &Format,
data_callback: D, data_callback: D,

View File

@ -81,7 +81,7 @@ impl DeviceTrait for Device {
Device::default_output_format(self) Device::default_output_format(self)
} }
fn build_input_stream<D, E>( fn build_input_stream_raw<D, E>(
&self, &self,
format: &Format, format: &Format,
data_callback: D, data_callback: D,
@ -91,10 +91,10 @@ impl DeviceTrait for Device {
D: FnMut(&Data) + Send + 'static, D: FnMut(&Data) + Send + 'static,
E: FnMut(StreamError) + Send + 'static, E: FnMut(StreamError) + Send + 'static,
{ {
Device::build_input_stream(self, format, data_callback, error_callback) Device::build_input_stream_raw(self, format, data_callback, error_callback)
} }
fn build_output_stream<D, E>( fn build_output_stream_raw<D, E>(
&self, &self,
format: &Format, format: &Format,
data_callback: D, data_callback: D,
@ -104,7 +104,7 @@ impl DeviceTrait for Device {
D: FnMut(&mut Data) + Send + 'static, D: FnMut(&mut Data) + Send + 'static,
E: FnMut(StreamError) + Send + 'static, E: FnMut(StreamError) + Send + 'static,
{ {
Device::build_output_stream(self, format, data_callback, error_callback) Device::build_output_stream_raw(self, format, data_callback, error_callback)
} }
} }

View File

@ -57,7 +57,7 @@ impl Stream {
} }
impl Device { impl Device {
pub fn build_input_stream<D, E>( pub fn build_input_stream_raw<D, E>(
&self, &self,
format: &Format, format: &Format,
mut data_callback: D, mut data_callback: D,
@ -202,7 +202,7 @@ impl Device {
} }
unsupported_format_pair => unreachable!( unsupported_format_pair => unreachable!(
"`build_input_stream` should have returned with unsupported \ "`build_input_stream_raw` should have returned with unsupported \
format {:?}", format {:?}",
unsupported_format_pair unsupported_format_pair
), ),
@ -223,7 +223,7 @@ impl Device {
}) })
} }
pub fn build_output_stream<D, E>( pub fn build_output_stream_raw<D, E>(
&self, &self,
format: &Format, format: &Format,
mut data_callback: D, mut data_callback: D,
@ -410,7 +410,7 @@ impl Device {
} }
unsupported_format_pair => unreachable!( unsupported_format_pair => unreachable!(
"`build_output_stream` should have returned with unsupported \ "`build_output_stream_raw` should have returned with unsupported \
format {:?}", format {:?}",
unsupported_format_pair unsupported_format_pair
), ),

View File

@ -102,7 +102,7 @@ impl DeviceTrait for Device {
Device::default_output_format(self) Device::default_output_format(self)
} }
fn build_input_stream<D, E>( fn build_input_stream_raw<D, E>(
&self, &self,
format: &Format, format: &Format,
data_callback: D, data_callback: D,
@ -112,10 +112,10 @@ impl DeviceTrait for Device {
D: FnMut(&Data) + Send + 'static, D: FnMut(&Data) + Send + 'static,
E: FnMut(StreamError) + Send + 'static, E: FnMut(StreamError) + Send + 'static,
{ {
Device::build_input_stream(self, format, data_callback, error_callback) Device::build_input_stream_raw(self, format, data_callback, error_callback)
} }
fn build_output_stream<D, E>( fn build_output_stream_raw<D, E>(
&self, &self,
format: &Format, format: &Format,
data_callback: D, data_callback: D,
@ -125,7 +125,7 @@ impl DeviceTrait for Device {
D: FnMut(&mut Data) + Send + 'static, D: FnMut(&mut Data) + Send + 'static,
E: FnMut(StreamError) + Send + 'static, E: FnMut(StreamError) + Send + 'static,
{ {
Device::build_output_stream(self, format, data_callback, error_callback) Device::build_output_stream_raw(self, format, data_callback, error_callback)
} }
} }
@ -467,7 +467,7 @@ fn audio_unit_from_device(device: &Device, input: bool) -> Result<AudioUnit, cor
} }
impl Device { impl Device {
fn build_input_stream<D, E>( fn build_input_stream_raw<D, E>(
&self, &self,
format: &Format, format: &Format,
mut data_callback: D, mut data_callback: D,
@ -655,7 +655,7 @@ impl Device {
})) }))
} }
fn build_output_stream<D, E>( fn build_output_stream_raw<D, E>(
&self, &self,
format: &Format, format: &Format,
mut data_callback: D, mut data_callback: D,

View File

@ -148,7 +148,7 @@ impl DeviceTrait for Device {
Device::default_output_format(self) Device::default_output_format(self)
} }
fn build_input_stream<D, E>( fn build_input_stream_raw<D, E>(
&self, &self,
_format: &Format, _format: &Format,
_data_callback: D, _data_callback: D,
@ -161,7 +161,7 @@ impl DeviceTrait for Device {
unimplemented!() unimplemented!()
} }
fn build_output_stream<D, E>( fn build_output_stream_raw<D, E>(
&self, &self,
format: &Format, format: &Format,
data_callback: D, data_callback: D,

View File

@ -61,7 +61,7 @@ impl DeviceTrait for Device {
unimplemented!() unimplemented!()
} }
fn build_input_stream<D, E>( fn build_input_stream_raw<D, E>(
&self, &self,
_format: &Format, _format: &Format,
_data_callback: D, _data_callback: D,
@ -75,7 +75,7 @@ impl DeviceTrait for Device {
} }
/// Create an output stream. /// Create an output stream.
fn build_output_stream<D, E>( fn build_output_stream_raw<D, E>(
&self, &self,
_format: &Format, _format: &Format,
_data_callback: D, _data_callback: D,

View File

@ -95,7 +95,7 @@ impl DeviceTrait for Device {
Device::default_output_format(self) Device::default_output_format(self)
} }
fn build_input_stream<D, E>( fn build_input_stream_raw<D, E>(
&self, &self,
format: &Format, format: &Format,
data_callback: D, data_callback: D,
@ -105,7 +105,7 @@ impl DeviceTrait for Device {
D: FnMut(&Data) + Send + 'static, D: FnMut(&Data) + Send + 'static,
E: FnMut(StreamError) + Send + 'static, E: FnMut(StreamError) + Send + 'static,
{ {
let stream_inner = self.build_input_stream_inner(format)?; let stream_inner = self.build_input_stream_raw_inner(format)?;
Ok(Stream::new_input( Ok(Stream::new_input(
stream_inner, stream_inner,
data_callback, data_callback,
@ -113,7 +113,7 @@ impl DeviceTrait for Device {
)) ))
} }
fn build_output_stream<D, E>( fn build_output_stream_raw<D, E>(
&self, &self,
format: &Format, format: &Format,
data_callback: D, data_callback: D,
@ -123,7 +123,7 @@ impl DeviceTrait for Device {
D: FnMut(&mut Data) + Send + 'static, D: FnMut(&mut Data) + Send + 'static,
E: FnMut(StreamError) + Send + 'static, E: FnMut(StreamError) + Send + 'static,
{ {
let stream_inner = self.build_output_stream_inner(format)?; let stream_inner = self.build_output_stream_raw_inner(format)?;
Ok(Stream::new_output( Ok(Stream::new_output(
stream_inner, stream_inner,
data_callback, data_callback,
@ -610,7 +610,7 @@ impl Device {
} }
} }
pub(crate) fn build_input_stream_inner( pub(crate) fn build_input_stream_raw_inner(
&self, &self,
format: &Format, format: &Format,
) -> Result<StreamInner, BuildStreamError> { ) -> Result<StreamInner, BuildStreamError> {
@ -754,7 +754,7 @@ impl Device {
} }
} }
pub(crate) fn build_output_stream_inner( pub(crate) fn build_output_stream_raw_inner(
&self, &self,
format: &Format, format: &Format,
) -> Result<StreamInner, BuildStreamError> { ) -> Result<StreamInner, BuildStreamError> {

View File

@ -60,7 +60,7 @@
//! # let host = cpal::default_host(); //! # let host = cpal::default_host();
//! # let device = host.default_output_device().unwrap(); //! # let device = host.default_output_device().unwrap();
//! # let format = device.default_output_format().unwrap(); //! # let format = device.default_output_format().unwrap();
//! let stream = device.build_output_stream( //! let stream = device.build_output_stream_raw(
//! &format, //! &format,
//! move |data: &mut Data| { //! move |data: &mut Data| {
//! // react to stream events and read or write stream data here. //! // react to stream events and read or write stream data here.
@ -98,7 +98,7 @@
//! SampleFormat::I16 => write_silence::<i16>(data), //! SampleFormat::I16 => write_silence::<i16>(data),
//! SampleFormat::U16 => write_silence::<u16>(data), //! SampleFormat::U16 => write_silence::<u16>(data),
//! }; //! };
//! let stream = device.build_output_stream(&format, data_fn, err_fn).unwrap(); //! let stream = device.build_output_stream_raw(&format, data_fn, err_fn).unwrap();
//! //!
//! fn write_silence<T: Sample>(data: &mut Data) { //! fn write_silence<T: Sample>(data: &mut Data) {
//! let data = data.as_slice_mut::<T>().unwrap(); //! let data = data.as_slice_mut::<T>().unwrap();
@ -118,7 +118,7 @@
//! # let format = device.default_output_format().unwrap(); //! # let format = device.default_output_format().unwrap();
//! # let data_fn = move |_data: &mut cpal::Data| {}; //! # let data_fn = move |_data: &mut cpal::Data| {};
//! # let err_fn = move |_err| {}; //! # let err_fn = move |_err| {};
//! # let stream = device.build_output_stream(&format, data_fn, err_fn).unwrap(); //! # let stream = device.build_output_stream_raw(&format, data_fn, err_fn).unwrap();
//! stream.play().unwrap(); //! stream.play().unwrap();
//! ``` //! ```
//! //!
@ -132,7 +132,7 @@
//! # let format = device.default_output_format().unwrap(); //! # let format = device.default_output_format().unwrap();
//! # let data_fn = move |_data: &mut cpal::Data| {}; //! # let data_fn = move |_data: &mut cpal::Data| {};
//! # let err_fn = move |_err| {}; //! # let err_fn = move |_err| {};
//! # let stream = device.build_output_stream(&format, data_fn, err_fn).unwrap(); //! # let stream = device.build_output_stream_raw(&format, data_fn, err_fn).unwrap();
//! stream.pause().unwrap(); //! stream.pause().unwrap();
//! ``` //! ```

View File

@ -255,7 +255,7 @@ macro_rules! impl_platform_host {
} }
} }
fn build_input_stream<D, E>( fn build_input_stream_raw<D, E>(
&self, &self,
format: &crate::Format, format: &crate::Format,
data_callback: D, data_callback: D,
@ -267,14 +267,14 @@ macro_rules! impl_platform_host {
{ {
match self.0 { match self.0 {
$( $(
DeviceInner::$HostVariant(ref d) => d.build_input_stream(format, data_callback, error_callback) DeviceInner::$HostVariant(ref d) => d.build_input_stream_raw(format, data_callback, error_callback)
.map(StreamInner::$HostVariant) .map(StreamInner::$HostVariant)
.map(Stream::from), .map(Stream::from),
)* )*
} }
} }
fn build_output_stream<D, E>( fn build_output_stream_raw<D, E>(
&self, &self,
format: &crate::Format, format: &crate::Format,
data_callback: D, data_callback: D,
@ -286,7 +286,7 @@ macro_rules! impl_platform_host {
{ {
match self.0 { match self.0 {
$( $(
DeviceInner::$HostVariant(ref d) => d.build_output_stream(format, data_callback, error_callback) DeviceInner::$HostVariant(ref d) => d.build_output_stream_raw(format, data_callback, error_callback)
.map(StreamInner::$HostVariant) .map(StreamInner::$HostVariant)
.map(Stream::from), .map(Stream::from),
)* )*

View File

@ -87,7 +87,7 @@ pub trait DeviceTrait {
type SupportedInputFormats: Iterator<Item = SupportedFormat>; type SupportedInputFormats: Iterator<Item = SupportedFormat>;
/// The iterator type yielding supported output stream formats. /// The iterator type yielding supported output stream formats.
type SupportedOutputFormats: Iterator<Item = SupportedFormat>; type SupportedOutputFormats: Iterator<Item = SupportedFormat>;
/// The stream type created by `build_input_stream` and `build_output_stream`. /// The stream type created by `build_input_stream_raw` and `build_output_stream_raw`.
type Stream: StreamTrait; type Stream: StreamTrait;
/// The human-readable name of the device. /// The human-readable name of the device.
@ -113,7 +113,7 @@ pub trait DeviceTrait {
fn default_output_format(&self) -> Result<Format, DefaultFormatError>; fn default_output_format(&self) -> Result<Format, DefaultFormatError>;
/// Create an input stream. /// Create an input stream.
fn build_input_stream<D, E>( fn build_input_stream_raw<D, E>(
&self, &self,
format: &Format, format: &Format,
data_callback: D, data_callback: D,
@ -124,7 +124,7 @@ pub trait DeviceTrait {
E: FnMut(StreamError) + Send + 'static; E: FnMut(StreamError) + Send + 'static;
/// Create an output stream. /// Create an output stream.
fn build_output_stream<D, E>( fn build_output_stream_raw<D, E>(
&self, &self,
format: &Format, format: &Format,
data_callback: D, data_callback: D,