diff --git a/src/alsa/enumerate.rs b/src/alsa/enumerate.rs index b087acb..6e590ac 100644 --- a/src/alsa/enumerate.rs +++ b/src/alsa/enumerate.rs @@ -18,6 +18,7 @@ unsafe impl Send for EndpointsIterator {} unsafe impl Sync for EndpointsIterator {} impl Drop for EndpointsIterator { + #[inline] fn drop(&mut self) { unsafe { alsa::snd_device_name_free_hint(self.global_list as *mut _); @@ -72,6 +73,7 @@ impl Iterator for EndpointsIterator { } } +#[inline] pub fn get_default_endpoint() -> Option { // TODO: do in a different way? Some(Endpoint("default".to_owned())) diff --git a/src/alsa/mod.rs b/src/alsa/mod.rs index 11bb99c..b184fe3 100644 --- a/src/alsa/mod.rs +++ b/src/alsa/mod.rs @@ -72,14 +72,17 @@ impl Voice { } } + #[inline] pub fn get_channels(&self) -> ::ChannelsCount { self.num_channels } + #[inline] pub fn get_samples_rate(&self) -> ::SamplesRate { ::SamplesRate(44100) } + #[inline] pub fn get_samples_format(&self) -> ::SampleFormat { ::SampleFormat::I16 } @@ -99,11 +102,13 @@ impl Voice { } } + #[inline] pub fn play(&mut self) { // already playing //unimplemented!() } + #[inline] pub fn pause(&mut self) { unimplemented!() } @@ -113,6 +118,7 @@ unsafe impl Send for Voice {} unsafe impl Sync for Voice {} impl Drop for Voice { + #[inline] fn drop(&mut self) { unsafe { alsa::snd_pcm_close(*self.channel.lock().unwrap()); @@ -121,10 +127,12 @@ impl Drop for Voice { } impl<'a, T> Buffer<'a, T> { + #[inline] pub fn get_buffer<'b>(&'b mut self) -> &'b mut [T] { &mut self.buffer } + #[inline] pub fn len(&self) -> usize { self.buffer.len() } @@ -146,6 +154,7 @@ impl<'a, T> Buffer<'a, T> { } } +#[inline] fn check_errors(err: libc::c_int) -> Result<(), String> { use std::ffi; diff --git a/src/coreaudio/mod.rs b/src/coreaudio/mod.rs index 131737d..bbd1ce2 100644 --- a/src/coreaudio/mod.rs +++ b/src/coreaudio/mod.rs @@ -24,20 +24,24 @@ pub struct Buffer<'a, T: 'a> { impl Voice { + #[inline] pub fn new() -> Voice { new_voice().unwrap() } + #[inline] pub fn get_channels(&self) -> ::ChannelsCount { // TODO: use AudioUnitGetProperty... 2 } + #[inline] pub fn get_samples_rate(&self) -> ::SamplesRate { // TODO: use AudioUnitGetProperty... ::SamplesRate(44100) } + #[inline] pub fn get_samples_format(&self) -> ::SampleFormat { // TODO: use AudioUnitGetProperty... ::SampleFormat::F32 @@ -58,16 +62,19 @@ impl Voice { } } + #[inline] pub fn play(&mut self) { // TODO } + #[inline] pub fn pause(&mut self) { // TODO } } impl<'a, T> Buffer<'a, T> { + #[inline] pub fn get_buffer<'b>(&'b mut self) -> &'b mut [T] { &mut self.samples[..] } diff --git a/src/lib.rs b/src/lib.rs index 7fae8d8..5d8d2d4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -82,11 +82,13 @@ impl Iterator for EndpointsIterator { } /// Return an iterator to the list of formats that are supported by the system. +#[inline] pub fn get_endpoints_list() -> EndpointsIterator { EndpointsIterator(Default::default()) } /// Return the default endpoint, or `None` if no device is available. +#[inline] pub fn get_default_endpoint() -> Option { cpal_impl::get_default_endpoint().map(Endpoint) } @@ -97,6 +99,7 @@ pub struct Endpoint(cpal_impl::Endpoint); impl Endpoint { /// Returns an iterator that produces the list of formats that are supported by the backend. + #[inline] pub fn get_supported_formats_list(&self) -> Result { @@ -183,6 +186,7 @@ pub enum UnknownTypeBuffer<'a> { impl<'a> UnknownTypeBuffer<'a> { /// Returns the length of the buffer in number of samples. + #[inline] pub fn len(&self) -> usize { match self { &UnknownTypeBuffer::U16(ref buf) => buf.target.as_ref().unwrap().len(), @@ -201,12 +205,14 @@ pub enum FormatsEnumerationError { } impl fmt::Display for FormatsEnumerationError { + #[inline] fn fmt(&self, fmt: &mut fmt::Formatter) -> Result<(), fmt::Error> { write!(fmt, "{}", self.description()) } } impl Error for FormatsEnumerationError { + #[inline] fn description(&self) -> &str { match self { &FormatsEnumerationError::DeviceNotAvailable => { @@ -228,12 +234,14 @@ pub enum CreationError { } impl fmt::Display for CreationError { + #[inline] fn fmt(&self, fmt: &mut fmt::Formatter) -> Result<(), fmt::Error> { write!(fmt, "{}", self.description()) } } impl Error for CreationError { + #[inline] fn description(&self) -> &str { match self { &CreationError::DeviceNotAvailable => { @@ -314,6 +322,7 @@ impl Voice { /// /// Panics if `max_samples` is 0. /// + #[inline] pub fn append_data(&mut self, max_samples: usize) -> UnknownTypeBuffer { assert!(max_samples != 0); diff --git a/src/null/mod.rs b/src/null/mod.rs index 6840ea2..1b0c0f3 100644 --- a/src/null/mod.rs +++ b/src/null/mod.rs @@ -12,11 +12,13 @@ pub struct EndpointsIterator; impl Iterator for EndpointsIterator { type Item = Endpoint; + #[inline] fn next(&mut self) -> Option { None } } +#[inline] pub fn get_default_endpoint() -> Option { None } @@ -25,6 +27,7 @@ pub fn get_default_endpoint() -> Option { pub struct Endpoint; impl Endpoint { + #[inline] pub fn get_supported_formats_list(&self) -> Result { @@ -37,6 +40,7 @@ pub struct SupportedFormatsIterator; impl Iterator for SupportedFormatsIterator { type Item = Format; + #[inline] fn next(&mut self) -> Option { None } @@ -45,29 +49,36 @@ impl Iterator for SupportedFormatsIterator { pub struct Voice; impl Voice { + #[inline] pub fn new(_: &Endpoint, _: &Format) -> Result { Err(CreationError::DeviceNotAvailable) } + #[inline] pub fn get_channels(&self) -> ::ChannelsCount { unreachable!() } + #[inline] pub fn get_samples_rate(&self) -> ::SamplesRate { unreachable!() } + #[inline] pub fn get_samples_format(&self) -> ::SampleFormat { unreachable!() } + #[inline] pub fn append_data<'a, T>(&'a mut self, _: usize) -> Buffer<'a, T> { unreachable!() } + #[inline] pub fn play(&mut self) { } + #[inline] pub fn pause(&mut self) { } } @@ -77,14 +88,17 @@ pub struct Buffer<'a, T: 'a> { } impl<'a, T> Buffer<'a, T> { + #[inline] pub fn get_buffer<'b>(&'b mut self) -> &'b mut [T] { unreachable!() } + #[inline] pub fn len(&self) -> usize { 0 } + #[inline] pub fn finish(self) { } } diff --git a/src/wasapi/com.rs b/src/wasapi/com.rs index 92a6f31..442cd39 100644 --- a/src/wasapi/com.rs +++ b/src/wasapi/com.rs @@ -21,12 +21,14 @@ thread_local!(static COM_INITIALIZED: ComInitialized = { struct ComInitialized(*mut ()); impl Drop for ComInitialized { + #[inline] fn drop(&mut self) { unsafe { ole32::CoUninitialize() }; } } /// Ensures that COM is initialized in this thread. +#[inline] pub fn com_initialized() { COM_INITIALIZED.with(|_| {}); } diff --git a/src/wasapi/enumerate.rs b/src/wasapi/enumerate.rs index 0c5e966..d6e6ef5 100644 --- a/src/wasapi/enumerate.rs +++ b/src/wasapi/enumerate.rs @@ -37,6 +37,7 @@ unsafe impl Send for Enumerator {} unsafe impl Sync for Enumerator {} impl Drop for Enumerator { + #[inline] fn drop(&mut self) { unsafe { (*self.0).Release(); @@ -55,6 +56,7 @@ unsafe impl Send for EndpointsIterator {} unsafe impl Sync for EndpointsIterator {} impl Drop for EndpointsIterator { + #[inline] fn drop(&mut self) { unsafe { (*self.collection).Release(); diff --git a/src/wasapi/mod.rs b/src/wasapi/mod.rs index 4d5ae68..f659d29 100644 --- a/src/wasapi/mod.rs +++ b/src/wasapi/mod.rs @@ -22,6 +22,7 @@ mod com; mod enumerate; mod voice; +#[inline] fn check_result(result: winapi::HRESULT) -> Result<(), IoError> { if result < 0 { Err(IoError::from_raw_os_error(result)) @@ -82,6 +83,7 @@ impl Endpoint { } /// Returns an uninitialized `IAudioClient`. + #[inline] fn build_audioclient(&self) -> Result<*mut winapi::IAudioClient, IoError> { let mut lock = try!(self.ensure_future_audio_client()); let client = lock.unwrap().0; @@ -183,6 +185,7 @@ impl Endpoint { } impl PartialEq for Endpoint { + #[inline] fn eq(&self, other: &Endpoint) -> bool { self.device == other.device } @@ -191,6 +194,7 @@ impl PartialEq for Endpoint { impl Eq for Endpoint {} impl Clone for Endpoint { + #[inline] fn clone(&self) -> Endpoint { unsafe { (*self.device).AddRef(); } @@ -202,6 +206,7 @@ impl Clone for Endpoint { } impl Drop for Endpoint { + #[inline] fn drop(&mut self) { unsafe { (*self.device).Release(); } diff --git a/src/wasapi/voice.rs b/src/wasapi/voice.rs index 7b9f205..f5083e6 100644 --- a/src/wasapi/voice.rs +++ b/src/wasapi/voice.rs @@ -211,14 +211,17 @@ impl Voice { } } + #[inline] pub fn get_channels(&self) -> ::ChannelsCount { self.num_channels as ::ChannelsCount } + #[inline] pub fn get_samples_rate(&self) -> ::SamplesRate { ::SamplesRate(self.samples_per_second as u32) } + #[inline] pub fn get_samples_format(&self) -> ::SampleFormat { match self.bits_per_sample { 16 => ::SampleFormat::I16, @@ -275,6 +278,7 @@ impl Voice { } } + #[inline] pub fn play(&mut self) { if !self.playing { unsafe { @@ -286,6 +290,7 @@ impl Voice { self.playing = true; } + #[inline] pub fn pause(&mut self) { if self.playing { unsafe { @@ -299,6 +304,7 @@ impl Voice { } impl Drop for Voice { + #[inline] fn drop(&mut self) { unsafe { (*self.render_client).Release(); @@ -316,16 +322,19 @@ pub struct Buffer<'a, T: 'a> { } impl<'a, T> Buffer<'a, T> { + #[inline] pub fn get_buffer<'b>(&'b mut self) -> &'b mut [T] { unsafe { slice::from_raw_parts_mut(self.buffer_data, self.buffer_len) } } + #[inline] pub fn len(&self) -> usize { self.buffer_len } + #[inline] pub fn finish(self) { // releasing buffer unsafe {