diff --git a/src/alsa/mod.rs b/src/alsa/mod.rs index 22b93c8..37bdc4d 100644 --- a/src/alsa/mod.rs +++ b/src/alsa/mod.rs @@ -4,7 +4,7 @@ extern crate libc; pub use self::enumerate::{Devices, default_input_device, default_output_device}; use ChannelCount; -use CreationError; +use BuildStreamError; use DefaultFormatError; use Format; use SupportedFormatsError; @@ -644,7 +644,7 @@ impl EventLoop { &self, device: &Device, format: &Format, - ) -> Result + ) -> Result { unsafe { let name = ffi::CString::new(device.0.clone()).expect("unable to clone device"); @@ -656,10 +656,10 @@ impl EventLoop { alsa::SND_PCM_STREAM_CAPTURE, alsa::SND_PCM_NONBLOCK, ) { - -16 /* determined empirically */ => return Err(CreationError::DeviceNotAvailable), - -22 => return Err(CreationError::InvalidArgument), + -16 /* determined empirically */ => return Err(BuildStreamError::DeviceNotAvailable), + -22 => return Err(BuildStreamError::InvalidArgument), e => if check_errors(e).is_err() { - return Err(CreationError::Unknown); + return Err(BuildStreamError::Unknown); } } let hw_params = HwParams::alloc(); @@ -708,7 +708,7 @@ impl EventLoop { &self, device: &Device, format: &Format, - ) -> Result + ) -> Result { unsafe { let name = ffi::CString::new(device.0.clone()).expect("unable to clone device"); @@ -720,10 +720,10 @@ impl EventLoop { alsa::SND_PCM_STREAM_PLAYBACK, alsa::SND_PCM_NONBLOCK, ) { - -16 /* determined empirically */ => return Err(CreationError::DeviceNotAvailable), - -22 => return Err(CreationError::InvalidArgument), + -16 /* determined empirically */ => return Err(BuildStreamError::DeviceNotAvailable), + -22 => return Err(BuildStreamError::InvalidArgument), e => if check_errors(e).is_err() { - return Err(CreationError::Unknown); + return Err(BuildStreamError::Unknown); } } let hw_params = HwParams::alloc(); diff --git a/src/coreaudio/mod.rs b/src/coreaudio/mod.rs index d87321e..3e8b498 100644 --- a/src/coreaudio/mod.rs +++ b/src/coreaudio/mod.rs @@ -2,7 +2,7 @@ extern crate coreaudio; extern crate core_foundation_sys; use ChannelCount; -use CreationError; +use BuildStreamError; use DefaultFormatError; use Format; use SupportedFormatsError; @@ -338,15 +338,15 @@ struct StreamInner { } // TODO need stronger error identification -impl From for CreationError { - fn from(err: coreaudio::Error) -> CreationError { +impl From for BuildStreamError { + fn from(err: coreaudio::Error) -> BuildStreamError { match err { coreaudio::Error::RenderCallbackBufferFormatDoesNotMatchAudioUnitStreamFormat | coreaudio::Error::NoKnownSubtype | coreaudio::Error::AudioUnit(coreaudio::error::AudioUnitError::FormatNotSupported) | coreaudio::Error::AudioCodec(_) | - coreaudio::Error::AudioFormat(_) => CreationError::FormatNotSupported, - _ => CreationError::DeviceNotAvailable, + coreaudio::Error::AudioFormat(_) => BuildStreamError::FormatNotSupported, + _ => BuildStreamError::DeviceNotAvailable, } } } @@ -483,7 +483,7 @@ impl EventLoop { &self, device: &Device, format: &Format, - ) -> Result + ) -> Result { // The scope and element for working with a device's input stream. let scope = Scope::Output; @@ -555,7 +555,7 @@ impl EventLoop { .iter() .position(|r| r.mMinimum as u32 == sample_rate && r.mMaximum as u32 == sample_rate); let range_index = match maybe_index { - None => return Err(CreationError::FormatNotSupported), + None => return Err(BuildStreamError::FormatNotSupported), Some(i) => i, }; @@ -700,7 +700,7 @@ impl EventLoop { &self, device: &Device, format: &Format, - ) -> Result + ) -> Result { let mut audio_unit = audio_unit_from_device(device, false)?; diff --git a/src/emscripten/mod.rs b/src/emscripten/mod.rs index 054a473..d20dfb9 100644 --- a/src/emscripten/mod.rs +++ b/src/emscripten/mod.rs @@ -8,7 +8,7 @@ use stdweb::unstable::TryInto; use stdweb::web::TypedArray; use stdweb::web::set_timeout; -use CreationError; +use BuildStreamError; use DefaultFormatError; use Format; use SupportedFormatsError; @@ -118,12 +118,12 @@ impl EventLoop { } #[inline] - pub fn build_input_stream(&self, _: &Device, _format: &Format) -> Result { + pub fn build_input_stream(&self, _: &Device, _format: &Format) -> Result { unimplemented!(); } #[inline] - pub fn build_output_stream(&self, _: &Device, _format: &Format) -> Result { + pub fn build_output_stream(&self, _: &Device, _format: &Format) -> Result { let stream = js!(return new AudioContext()).into_reference().unwrap(); let mut streams = self.streams.lock().unwrap(); diff --git a/src/lib.rs b/src/lib.rs index 003a623..4e47939 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -160,7 +160,7 @@ mod cpal_impl; #[derive(Clone, PartialEq, Eq)] pub struct Device(cpal_impl::Device); -/// Collection of voices managed together. +/// Collection of streams managed together. /// /// Created with the [`new`](struct.EventLoop.html#method.new) method. pub struct EventLoop(cpal_impl::EventLoop); @@ -306,9 +306,9 @@ pub enum DefaultFormatError { StreamTypeNotSupported, } -/// Error that can happen when creating a `Voice`. +/// Error that can happen when creating a `Stream`. #[derive(Debug, Fail)] -pub enum CreationError { +pub enum BuildStreamError { /// The device no longer exists. This can happen if the device is disconnected while the /// program is running. #[fail(display = "The requested device is no longer available. For example, it has been unplugged.")] @@ -435,7 +435,7 @@ impl EventLoop { &self, device: &Device, format: &Format, - ) -> Result + ) -> Result { self.0.build_input_stream(&device.0, format).map(StreamId) } @@ -451,7 +451,7 @@ impl EventLoop { &self, device: &Device, format: &Format, - ) -> Result + ) -> Result { self.0.build_output_stream(&device.0, format).map(StreamId) } diff --git a/src/null/mod.rs b/src/null/mod.rs index bec555f..0596b2e 100644 --- a/src/null/mod.rs +++ b/src/null/mod.rs @@ -2,7 +2,7 @@ use std::marker::PhantomData; -use CreationError; +use BuildStreamError; use DefaultFormatError; use Format; use SupportedFormatsError; @@ -25,13 +25,13 @@ impl EventLoop { } #[inline] - pub fn build_input_stream(&self, _: &Device, _: &Format) -> Result { - Err(CreationError::DeviceNotAvailable) + pub fn build_input_stream(&self, _: &Device, _: &Format) -> Result { + Err(BuildStreamError::DeviceNotAvailable) } #[inline] - pub fn build_output_stream(&self, _: &Device, _: &Format) -> Result { - Err(CreationError::DeviceNotAvailable) + pub fn build_output_stream(&self, _: &Device, _: &Format) -> Result { + Err(BuildStreamError::DeviceNotAvailable) } #[inline] diff --git a/src/wasapi/device.rs b/src/wasapi/device.rs index 49a852b..a565adc 100644 --- a/src/wasapi/device.rs +++ b/src/wasapi/device.rs @@ -187,7 +187,7 @@ pub unsafe fn is_format_supported( (_, Err(ref e)) if e.raw_os_error() == Some(AUDCLNT_E_DEVICE_INVALIDATED) => { (*audio_client).Release(); - return Err(CreationError::DeviceNotAvailable); + return Err(BuildStreamError::DeviceNotAvailable); }, (_, Err(e)) => { (*audio_client).Release(); @@ -195,7 +195,7 @@ pub unsafe fn is_format_supported( }, (winerror::S_FALSE, _) => { (*audio_client).Release(); - return Err(CreationError::FormatNotSupported); + return Err(BuildStreamError::FormatNotSupported); }, (_, Ok(())) => (), }; diff --git a/src/wasapi/stream.rs b/src/wasapi/stream.rs index 084c10a..3a140b5 100644 --- a/src/wasapi/stream.rs +++ b/src/wasapi/stream.rs @@ -20,7 +20,7 @@ use std::sync::mpsc::{channel, Sender, Receiver}; use std::sync::atomic::AtomicUsize; use std::sync::atomic::Ordering; -use CreationError; +use BuildStreamError; use Format; use SampleFormat; use StreamData; @@ -114,7 +114,7 @@ impl EventLoop { &self, device: &Device, format: &Format, - ) -> Result + ) -> Result { unsafe { // Making sure that COM is initialized. @@ -124,20 +124,20 @@ impl EventLoop { // Obtaining a `IAudioClient`. let audio_client = match device.build_audioclient() { Err(ref e) if e.raw_os_error() == Some(AUDCLNT_E_DEVICE_INVALIDATED) => - return Err(CreationError::DeviceNotAvailable), + return Err(BuildStreamError::DeviceNotAvailable), e => e.unwrap(), }; // Computing the format and initializing the device. let waveformatex = { let format_attempt = format_to_waveformatextensible(format) - .ok_or(CreationError::FormatNotSupported)?; + .ok_or(BuildStreamError::FormatNotSupported)?; let share_mode = AUDCLNT_SHAREMODE_SHARED; // Ensure the format is supported. match super::device::is_format_supported(audio_client, &format_attempt.Format) { - Ok(false) => return Err(CreationError::FormatNotSupported), - Err(_) => return Err(CreationError::DeviceNotAvailable), + Ok(false) => return Err(BuildStreamError::FormatNotSupported), + Err(_) => return Err(BuildStreamError::DeviceNotAvailable), _ => (), } @@ -154,7 +154,7 @@ impl EventLoop { Err(ref e) if e.raw_os_error() == Some(AUDCLNT_E_DEVICE_INVALIDATED) => { (*audio_client).Release(); - return Err(CreationError::DeviceNotAvailable); + return Err(BuildStreamError::DeviceNotAvailable); }, Err(e) => { (*audio_client).Release(); @@ -175,7 +175,7 @@ impl EventLoop { Err(ref e) if e.raw_os_error() == Some(AUDCLNT_E_DEVICE_INVALIDATED) => { (*audio_client).Release(); - return Err(CreationError::DeviceNotAvailable); + return Err(BuildStreamError::DeviceNotAvailable); }, Err(e) => { (*audio_client).Release(); @@ -218,7 +218,7 @@ impl EventLoop { Err(ref e) if e.raw_os_error() == Some(AUDCLNT_E_DEVICE_INVALIDATED) => { (*audio_client).Release(); - return Err(CreationError::DeviceNotAvailable); + return Err(BuildStreamError::DeviceNotAvailable); }, Err(e) => { (*audio_client).Release(); @@ -261,7 +261,7 @@ impl EventLoop { &self, device: &Device, format: &Format, - ) -> Result + ) -> Result { unsafe { // Making sure that COM is initialized. @@ -271,20 +271,20 @@ impl EventLoop { // Obtaining a `IAudioClient`. let audio_client = match device.build_audioclient() { Err(ref e) if e.raw_os_error() == Some(AUDCLNT_E_DEVICE_INVALIDATED) => - return Err(CreationError::DeviceNotAvailable), + return Err(BuildStreamError::DeviceNotAvailable), e => e.unwrap(), }; // Computing the format and initializing the device. let waveformatex = { let format_attempt = format_to_waveformatextensible(format) - .ok_or(CreationError::FormatNotSupported)?; + .ok_or(BuildStreamError::FormatNotSupported)?; let share_mode = AUDCLNT_SHAREMODE_SHARED; // Ensure the format is supported. match super::device::is_format_supported(audio_client, &format_attempt.Format) { - Ok(false) => return Err(CreationError::FormatNotSupported), - Err(_) => return Err(CreationError::DeviceNotAvailable), + Ok(false) => return Err(BuildStreamError::FormatNotSupported), + Err(_) => return Err(BuildStreamError::DeviceNotAvailable), _ => (), } @@ -299,7 +299,7 @@ impl EventLoop { Err(ref e) if e.raw_os_error() == Some(AUDCLNT_E_DEVICE_INVALIDATED) => { (*audio_client).Release(); - return Err(CreationError::DeviceNotAvailable); + return Err(BuildStreamError::DeviceNotAvailable); }, Err(e) => { (*audio_client).Release(); @@ -339,7 +339,7 @@ impl EventLoop { Err(ref e) if e.raw_os_error() == Some(AUDCLNT_E_DEVICE_INVALIDATED) => { (*audio_client).Release(); - return Err(CreationError::DeviceNotAvailable); + return Err(BuildStreamError::DeviceNotAvailable); }, Err(e) => { (*audio_client).Release(); @@ -363,7 +363,7 @@ impl EventLoop { Err(ref e) if e.raw_os_error() == Some(AUDCLNT_E_DEVICE_INVALIDATED) => { (*audio_client).Release(); - return Err(CreationError::DeviceNotAvailable); + return Err(BuildStreamError::DeviceNotAvailable); }, Err(e) => { (*audio_client).Release(); @@ -529,7 +529,7 @@ impl EventLoop { if hresult == AUDCLNT_S_BUFFER_EMPTY { continue; } debug_assert!(!buffer.is_null()); - let buffer_len = frames_available as usize + let buffer_len = frames_available as usize * stream.bytes_per_frame as usize / sample_size; // Simplify the capture callback sample format branches. @@ -568,9 +568,9 @@ impl EventLoop { &mut buffer as *mut *mut _, ); // FIXME: can return `AUDCLNT_E_DEVICE_INVALIDATED` - check_result(hresult).unwrap(); + check_result(hresult).unwrap(); debug_assert!(!buffer.is_null()); - let buffer_len = frames_available as usize + let buffer_len = frames_available as usize * stream.bytes_per_frame as usize / sample_size; // Simplify the render callback sample format branches. @@ -594,7 +594,7 @@ impl EventLoop { Err(ref e) if e.raw_os_error() == Some(AUDCLNT_E_DEVICE_INVALIDATED) => (), e => e.unwrap(), }; - }} + }} } match stream.sample_format {