Skip to content

Commit

Permalink
Add _raw suffix to stream constructors
Browse files Browse the repository at this point in the history
  • Loading branch information
Ralith committed Jan 22, 2020
1 parent 5390c01 commit 78df791
Show file tree
Hide file tree
Showing 13 changed files with 41 additions and 41 deletions.
2 changes: 1 addition & 1 deletion examples/beep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ fn main() -> Result<(), anyhow::Error> {
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()?;

Expand Down
4 changes: 2 additions & 2 deletions examples/feedback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ fn main() -> Result<(), anyhow::Error> {

// Build streams.
println!("Attempting to build both streams with `{:?}`.", format);
let input_stream = input_device.build_input_stream(&format, input_data_fn, err_fn)?;
let output_stream = output_device.build_output_stream(&format, output_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_raw(&format, output_data_fn, err_fn)?;
println!("Successfully built streams.");

// Play the streams.
Expand Down
2 changes: 1 addition & 1 deletion examples/record_wav.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ fn main() -> Result<(), anyhow::Error> {
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()?;

Expand Down
4 changes: 2 additions & 2 deletions src/host/alsa/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ impl DeviceTrait for Device {
Device::default_output_format(self)
}

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

fn build_output_stream<D, E>(
fn build_output_stream_raw<D, E>(
&self,
format: &Format,
data_callback: D,
Expand Down
8 changes: 4 additions & 4 deletions src/host/asio/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ impl DeviceTrait for Device {
Device::default_output_format(self)
}

fn build_input_stream<D, E>(
fn build_input_stream_raw<D, E>(
&self,
format: &Format,
data_callback: D,
Expand All @@ -91,10 +91,10 @@ impl DeviceTrait for Device {
D: FnMut(&Data) + 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,
format: &Format,
data_callback: D,
Expand All @@ -104,7 +104,7 @@ impl DeviceTrait for Device {
D: FnMut(&mut Data) + 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)
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/host/asio/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ impl Stream {
}

impl Device {
pub fn build_input_stream<D, E>(
pub fn build_input_stream_raw<D, E>(
&self,
format: &Format,
mut data_callback: D,
Expand Down Expand Up @@ -202,7 +202,7 @@ impl Device {
}

unsupported_format_pair => unreachable!(
"`build_input_stream` should have returned with unsupported \
"`build_input_stream_raw` should have returned with unsupported \
format {:?}",
unsupported_format_pair
),
Expand All @@ -223,7 +223,7 @@ impl Device {
})
}

pub fn build_output_stream<D, E>(
pub fn build_output_stream_raw<D, E>(
&self,
format: &Format,
mut data_callback: D,
Expand Down Expand Up @@ -410,7 +410,7 @@ impl Device {
}

unsupported_format_pair => unreachable!(
"`build_output_stream` should have returned with unsupported \
"`build_output_stream_raw` should have returned with unsupported \
format {:?}",
unsupported_format_pair
),
Expand Down
12 changes: 6 additions & 6 deletions src/host/coreaudio/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ impl DeviceTrait for Device {
Device::default_output_format(self)
}

fn build_input_stream<D, E>(
fn build_input_stream_raw<D, E>(
&self,
format: &Format,
data_callback: D,
Expand All @@ -112,10 +112,10 @@ impl DeviceTrait for Device {
D: FnMut(&Data) + 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,
format: &Format,
data_callback: D,
Expand All @@ -125,7 +125,7 @@ impl DeviceTrait for Device {
D: FnMut(&mut Data) + 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)
}
}

Expand Down Expand Up @@ -467,7 +467,7 @@ fn audio_unit_from_device(device: &Device, input: bool) -> Result<AudioUnit, cor
}

impl Device {
fn build_input_stream<D, E>(
fn build_input_stream_raw<D, E>(
&self,
format: &Format,
mut data_callback: D,
Expand Down Expand Up @@ -655,7 +655,7 @@ impl Device {
}))
}

fn build_output_stream<D, E>(
fn build_output_stream_raw<D, E>(
&self,
format: &Format,
mut data_callback: D,
Expand Down
4 changes: 2 additions & 2 deletions src/host/emscripten/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ impl DeviceTrait for Device {
Device::default_output_format(self)
}

fn build_input_stream<D, E>(
fn build_input_stream_raw<D, E>(
&self,
_format: &Format,
_data_callback: D,
Expand All @@ -161,7 +161,7 @@ impl DeviceTrait for Device {
unimplemented!()
}

fn build_output_stream<D, E>(
fn build_output_stream_raw<D, E>(
&self,
format: &Format,
data_callback: D,
Expand Down
4 changes: 2 additions & 2 deletions src/host/null/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ impl DeviceTrait for Device {
unimplemented!()
}

fn build_input_stream<D, E>(
fn build_input_stream_raw<D, E>(
&self,
_format: &Format,
_data_callback: D,
Expand All @@ -75,7 +75,7 @@ impl DeviceTrait for Device {
}

/// Create an output stream.
fn build_output_stream<D, E>(
fn build_output_stream_raw<D, E>(
&self,
_format: &Format,
_data_callback: D,
Expand Down
12 changes: 6 additions & 6 deletions src/host/wasapi/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ impl DeviceTrait for Device {
Device::default_output_format(self)
}

fn build_input_stream<D, E>(
fn build_input_stream_raw<D, E>(
&self,
format: &Format,
data_callback: D,
Expand All @@ -105,15 +105,15 @@ impl DeviceTrait for Device {
D: FnMut(&Data) + 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(
stream_inner,
data_callback,
error_callback,
))
}

fn build_output_stream<D, E>(
fn build_output_stream_raw<D, E>(
&self,
format: &Format,
data_callback: D,
Expand All @@ -123,7 +123,7 @@ impl DeviceTrait for Device {
D: FnMut(&mut Data) + 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(
stream_inner,
data_callback,
Expand Down Expand Up @@ -610,7 +610,7 @@ impl Device {
}
}

pub(crate) fn build_input_stream_inner(
pub(crate) fn build_input_stream_raw_inner(
&self,
format: &Format,
) -> Result<StreamInner, BuildStreamError> {
Expand Down Expand Up @@ -754,7 +754,7 @@ impl Device {
}
}

pub(crate) fn build_output_stream_inner(
pub(crate) fn build_output_stream_raw_inner(
&self,
format: &Format,
) -> Result<StreamInner, BuildStreamError> {
Expand Down
8 changes: 4 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
//! # let host = cpal::default_host();
//! # let device = host.default_output_device().unwrap();
//! # let format = device.default_output_format().unwrap();
//! let stream = device.build_output_stream(
//! let stream = device.build_output_stream_raw(
//! &format,
//! move |data: &mut Data| {
//! // react to stream events and read or write stream data here.
Expand Down Expand Up @@ -98,7 +98,7 @@
//! SampleFormat::I16 => write_silence::<i16>(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) {
//! let data = data.as_slice_mut::<T>().unwrap();
Expand All @@ -118,7 +118,7 @@
//! # let format = device.default_output_format().unwrap();
//! # let data_fn = move |_data: &mut cpal::Data| {};
//! # 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();
//! ```
//!
Expand All @@ -132,7 +132,7 @@
//! # let format = device.default_output_format().unwrap();
//! # let data_fn = move |_data: &mut cpal::Data| {};
//! # 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();
//! ```
Expand Down
8 changes: 4 additions & 4 deletions src/platform/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ macro_rules! impl_platform_host {
}
}

fn build_input_stream<D, E>(
fn build_input_stream_raw<D, E>(
&self,
format: &crate::Format,
data_callback: D,
Expand All @@ -267,14 +267,14 @@ macro_rules! impl_platform_host {
{
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(Stream::from),
)*
}
}

fn build_output_stream<D, E>(
fn build_output_stream_raw<D, E>(
&self,
format: &crate::Format,
data_callback: D,
Expand All @@ -286,7 +286,7 @@ macro_rules! impl_platform_host {
{
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(Stream::from),
)*
Expand Down
6 changes: 3 additions & 3 deletions src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ pub trait DeviceTrait {
type SupportedInputFormats: Iterator<Item = SupportedFormat>;
/// The iterator type yielding supported output stream formats.
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;

/// The human-readable name of the device.
Expand All @@ -113,7 +113,7 @@ pub trait DeviceTrait {
fn default_output_format(&self) -> Result<Format, DefaultFormatError>;

/// Create an input stream.
fn build_input_stream<D, E>(
fn build_input_stream_raw<D, E>(
&self,
format: &Format,
data_callback: D,
Expand All @@ -124,7 +124,7 @@ pub trait DeviceTrait {
E: FnMut(StreamError) + Send + 'static;

/// Create an output stream.
fn build_output_stream<D, E>(
fn build_output_stream_raw<D, E>(
&self,
format: &Format,
data_callback: D,
Expand Down

0 comments on commit 78df791

Please sign in to comment.