Merge pull request #66 from tomaka/inline

Add #[inline] attributes
This commit is contained in:
tomaka 2015-09-22 10:01:59 +02:00
commit 826ad84db4
9 changed files with 59 additions and 0 deletions

View File

@ -18,6 +18,7 @@ unsafe impl Send for EndpointsIterator {}
unsafe impl Sync for EndpointsIterator {} unsafe impl Sync for EndpointsIterator {}
impl Drop for EndpointsIterator { impl Drop for EndpointsIterator {
#[inline]
fn drop(&mut self) { fn drop(&mut self) {
unsafe { unsafe {
alsa::snd_device_name_free_hint(self.global_list as *mut _); 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<Endpoint> { pub fn get_default_endpoint() -> Option<Endpoint> {
// TODO: do in a different way? // TODO: do in a different way?
Some(Endpoint("default".to_owned())) Some(Endpoint("default".to_owned()))

View File

@ -72,14 +72,17 @@ impl Voice {
} }
} }
#[inline]
pub fn get_channels(&self) -> ::ChannelsCount { pub fn get_channels(&self) -> ::ChannelsCount {
self.num_channels self.num_channels
} }
#[inline]
pub fn get_samples_rate(&self) -> ::SamplesRate { pub fn get_samples_rate(&self) -> ::SamplesRate {
::SamplesRate(44100) ::SamplesRate(44100)
} }
#[inline]
pub fn get_samples_format(&self) -> ::SampleFormat { pub fn get_samples_format(&self) -> ::SampleFormat {
::SampleFormat::I16 ::SampleFormat::I16
} }
@ -99,11 +102,13 @@ impl Voice {
} }
} }
#[inline]
pub fn play(&mut self) { pub fn play(&mut self) {
// already playing // already playing
//unimplemented!() //unimplemented!()
} }
#[inline]
pub fn pause(&mut self) { pub fn pause(&mut self) {
unimplemented!() unimplemented!()
} }
@ -113,6 +118,7 @@ unsafe impl Send for Voice {}
unsafe impl Sync for Voice {} unsafe impl Sync for Voice {}
impl Drop for Voice { impl Drop for Voice {
#[inline]
fn drop(&mut self) { fn drop(&mut self) {
unsafe { unsafe {
alsa::snd_pcm_close(*self.channel.lock().unwrap()); alsa::snd_pcm_close(*self.channel.lock().unwrap());
@ -121,10 +127,12 @@ impl Drop for Voice {
} }
impl<'a, T> Buffer<'a, T> { impl<'a, T> Buffer<'a, T> {
#[inline]
pub fn get_buffer<'b>(&'b mut self) -> &'b mut [T] { pub fn get_buffer<'b>(&'b mut self) -> &'b mut [T] {
&mut self.buffer &mut self.buffer
} }
#[inline]
pub fn len(&self) -> usize { pub fn len(&self) -> usize {
self.buffer.len() self.buffer.len()
} }
@ -146,6 +154,7 @@ impl<'a, T> Buffer<'a, T> {
} }
} }
#[inline]
fn check_errors(err: libc::c_int) -> Result<(), String> { fn check_errors(err: libc::c_int) -> Result<(), String> {
use std::ffi; use std::ffi;

View File

@ -24,20 +24,24 @@ pub struct Buffer<'a, T: 'a> {
impl Voice { impl Voice {
#[inline]
pub fn new() -> Voice { pub fn new() -> Voice {
new_voice().unwrap() new_voice().unwrap()
} }
#[inline]
pub fn get_channels(&self) -> ::ChannelsCount { pub fn get_channels(&self) -> ::ChannelsCount {
// TODO: use AudioUnitGetProperty... // TODO: use AudioUnitGetProperty...
2 2
} }
#[inline]
pub fn get_samples_rate(&self) -> ::SamplesRate { pub fn get_samples_rate(&self) -> ::SamplesRate {
// TODO: use AudioUnitGetProperty... // TODO: use AudioUnitGetProperty...
::SamplesRate(44100) ::SamplesRate(44100)
} }
#[inline]
pub fn get_samples_format(&self) -> ::SampleFormat { pub fn get_samples_format(&self) -> ::SampleFormat {
// TODO: use AudioUnitGetProperty... // TODO: use AudioUnitGetProperty...
::SampleFormat::F32 ::SampleFormat::F32
@ -58,16 +62,19 @@ impl Voice {
} }
} }
#[inline]
pub fn play(&mut self) { pub fn play(&mut self) {
// TODO // TODO
} }
#[inline]
pub fn pause(&mut self) { pub fn pause(&mut self) {
// TODO // TODO
} }
} }
impl<'a, T> Buffer<'a, T> { impl<'a, T> Buffer<'a, T> {
#[inline]
pub fn get_buffer<'b>(&'b mut self) -> &'b mut [T] { pub fn get_buffer<'b>(&'b mut self) -> &'b mut [T] {
&mut self.samples[..] &mut self.samples[..]
} }

View File

@ -82,11 +82,13 @@ impl Iterator for EndpointsIterator {
} }
/// Return an iterator to the list of formats that are supported by the system. /// Return an iterator to the list of formats that are supported by the system.
#[inline]
pub fn get_endpoints_list() -> EndpointsIterator { pub fn get_endpoints_list() -> EndpointsIterator {
EndpointsIterator(Default::default()) EndpointsIterator(Default::default())
} }
/// Return the default endpoint, or `None` if no device is available. /// Return the default endpoint, or `None` if no device is available.
#[inline]
pub fn get_default_endpoint() -> Option<Endpoint> { pub fn get_default_endpoint() -> Option<Endpoint> {
cpal_impl::get_default_endpoint().map(Endpoint) cpal_impl::get_default_endpoint().map(Endpoint)
} }
@ -97,6 +99,7 @@ pub struct Endpoint(cpal_impl::Endpoint);
impl Endpoint { impl Endpoint {
/// Returns an iterator that produces the list of formats that are supported by the backend. /// Returns an iterator that produces the list of formats that are supported by the backend.
#[inline]
pub fn get_supported_formats_list(&self) -> Result<SupportedFormatsIterator, pub fn get_supported_formats_list(&self) -> Result<SupportedFormatsIterator,
FormatsEnumerationError> FormatsEnumerationError>
{ {
@ -183,6 +186,7 @@ pub enum UnknownTypeBuffer<'a> {
impl<'a> UnknownTypeBuffer<'a> { impl<'a> UnknownTypeBuffer<'a> {
/// Returns the length of the buffer in number of samples. /// Returns the length of the buffer in number of samples.
#[inline]
pub fn len(&self) -> usize { pub fn len(&self) -> usize {
match self { match self {
&UnknownTypeBuffer::U16(ref buf) => buf.target.as_ref().unwrap().len(), &UnknownTypeBuffer::U16(ref buf) => buf.target.as_ref().unwrap().len(),
@ -201,12 +205,14 @@ pub enum FormatsEnumerationError {
} }
impl fmt::Display for FormatsEnumerationError { impl fmt::Display for FormatsEnumerationError {
#[inline]
fn fmt(&self, fmt: &mut fmt::Formatter) -> Result<(), fmt::Error> { fn fmt(&self, fmt: &mut fmt::Formatter) -> Result<(), fmt::Error> {
write!(fmt, "{}", self.description()) write!(fmt, "{}", self.description())
} }
} }
impl Error for FormatsEnumerationError { impl Error for FormatsEnumerationError {
#[inline]
fn description(&self) -> &str { fn description(&self) -> &str {
match self { match self {
&FormatsEnumerationError::DeviceNotAvailable => { &FormatsEnumerationError::DeviceNotAvailable => {
@ -228,12 +234,14 @@ pub enum CreationError {
} }
impl fmt::Display for CreationError { impl fmt::Display for CreationError {
#[inline]
fn fmt(&self, fmt: &mut fmt::Formatter) -> Result<(), fmt::Error> { fn fmt(&self, fmt: &mut fmt::Formatter) -> Result<(), fmt::Error> {
write!(fmt, "{}", self.description()) write!(fmt, "{}", self.description())
} }
} }
impl Error for CreationError { impl Error for CreationError {
#[inline]
fn description(&self) -> &str { fn description(&self) -> &str {
match self { match self {
&CreationError::DeviceNotAvailable => { &CreationError::DeviceNotAvailable => {
@ -314,6 +322,7 @@ impl Voice {
/// ///
/// Panics if `max_samples` is 0. /// Panics if `max_samples` is 0.
/// ///
#[inline]
pub fn append_data(&mut self, max_samples: usize) -> UnknownTypeBuffer { pub fn append_data(&mut self, max_samples: usize) -> UnknownTypeBuffer {
assert!(max_samples != 0); assert!(max_samples != 0);

View File

@ -12,11 +12,13 @@ pub struct EndpointsIterator;
impl Iterator for EndpointsIterator { impl Iterator for EndpointsIterator {
type Item = Endpoint; type Item = Endpoint;
#[inline]
fn next(&mut self) -> Option<Endpoint> { fn next(&mut self) -> Option<Endpoint> {
None None
} }
} }
#[inline]
pub fn get_default_endpoint() -> Option<Endpoint> { pub fn get_default_endpoint() -> Option<Endpoint> {
None None
} }
@ -25,6 +27,7 @@ pub fn get_default_endpoint() -> Option<Endpoint> {
pub struct Endpoint; pub struct Endpoint;
impl Endpoint { impl Endpoint {
#[inline]
pub fn get_supported_formats_list(&self) pub fn get_supported_formats_list(&self)
-> Result<SupportedFormatsIterator, FormatsEnumerationError> -> Result<SupportedFormatsIterator, FormatsEnumerationError>
{ {
@ -37,6 +40,7 @@ pub struct SupportedFormatsIterator;
impl Iterator for SupportedFormatsIterator { impl Iterator for SupportedFormatsIterator {
type Item = Format; type Item = Format;
#[inline]
fn next(&mut self) -> Option<Format> { fn next(&mut self) -> Option<Format> {
None None
} }
@ -45,29 +49,36 @@ impl Iterator for SupportedFormatsIterator {
pub struct Voice; pub struct Voice;
impl Voice { impl Voice {
#[inline]
pub fn new(_: &Endpoint, _: &Format) -> Result<Voice, CreationError> { pub fn new(_: &Endpoint, _: &Format) -> Result<Voice, CreationError> {
Err(CreationError::DeviceNotAvailable) Err(CreationError::DeviceNotAvailable)
} }
#[inline]
pub fn get_channels(&self) -> ::ChannelsCount { pub fn get_channels(&self) -> ::ChannelsCount {
unreachable!() unreachable!()
} }
#[inline]
pub fn get_samples_rate(&self) -> ::SamplesRate { pub fn get_samples_rate(&self) -> ::SamplesRate {
unreachable!() unreachable!()
} }
#[inline]
pub fn get_samples_format(&self) -> ::SampleFormat { pub fn get_samples_format(&self) -> ::SampleFormat {
unreachable!() unreachable!()
} }
#[inline]
pub fn append_data<'a, T>(&'a mut self, _: usize) -> Buffer<'a, T> { pub fn append_data<'a, T>(&'a mut self, _: usize) -> Buffer<'a, T> {
unreachable!() unreachable!()
} }
#[inline]
pub fn play(&mut self) { pub fn play(&mut self) {
} }
#[inline]
pub fn pause(&mut self) { pub fn pause(&mut self) {
} }
} }
@ -77,14 +88,17 @@ pub struct Buffer<'a, T: 'a> {
} }
impl<'a, T> Buffer<'a, T> { impl<'a, T> Buffer<'a, T> {
#[inline]
pub fn get_buffer<'b>(&'b mut self) -> &'b mut [T] { pub fn get_buffer<'b>(&'b mut self) -> &'b mut [T] {
unreachable!() unreachable!()
} }
#[inline]
pub fn len(&self) -> usize { pub fn len(&self) -> usize {
0 0
} }
#[inline]
pub fn finish(self) { pub fn finish(self) {
} }
} }

View File

@ -21,12 +21,14 @@ thread_local!(static COM_INITIALIZED: ComInitialized = {
struct ComInitialized(*mut ()); struct ComInitialized(*mut ());
impl Drop for ComInitialized { impl Drop for ComInitialized {
#[inline]
fn drop(&mut self) { fn drop(&mut self) {
unsafe { ole32::CoUninitialize() }; unsafe { ole32::CoUninitialize() };
} }
} }
/// Ensures that COM is initialized in this thread. /// Ensures that COM is initialized in this thread.
#[inline]
pub fn com_initialized() { pub fn com_initialized() {
COM_INITIALIZED.with(|_| {}); COM_INITIALIZED.with(|_| {});
} }

View File

@ -37,6 +37,7 @@ unsafe impl Send for Enumerator {}
unsafe impl Sync for Enumerator {} unsafe impl Sync for Enumerator {}
impl Drop for Enumerator { impl Drop for Enumerator {
#[inline]
fn drop(&mut self) { fn drop(&mut self) {
unsafe { unsafe {
(*self.0).Release(); (*self.0).Release();
@ -55,6 +56,7 @@ unsafe impl Send for EndpointsIterator {}
unsafe impl Sync for EndpointsIterator {} unsafe impl Sync for EndpointsIterator {}
impl Drop for EndpointsIterator { impl Drop for EndpointsIterator {
#[inline]
fn drop(&mut self) { fn drop(&mut self) {
unsafe { unsafe {
(*self.collection).Release(); (*self.collection).Release();

View File

@ -22,6 +22,7 @@ mod com;
mod enumerate; mod enumerate;
mod voice; mod voice;
#[inline]
fn check_result(result: winapi::HRESULT) -> Result<(), IoError> { fn check_result(result: winapi::HRESULT) -> Result<(), IoError> {
if result < 0 { if result < 0 {
Err(IoError::from_raw_os_error(result)) Err(IoError::from_raw_os_error(result))
@ -82,6 +83,7 @@ impl Endpoint {
} }
/// Returns an uninitialized `IAudioClient`. /// Returns an uninitialized `IAudioClient`.
#[inline]
fn build_audioclient(&self) -> Result<*mut winapi::IAudioClient, IoError> { fn build_audioclient(&self) -> Result<*mut winapi::IAudioClient, IoError> {
let mut lock = try!(self.ensure_future_audio_client()); let mut lock = try!(self.ensure_future_audio_client());
let client = lock.unwrap().0; let client = lock.unwrap().0;
@ -183,6 +185,7 @@ impl Endpoint {
} }
impl PartialEq for Endpoint { impl PartialEq for Endpoint {
#[inline]
fn eq(&self, other: &Endpoint) -> bool { fn eq(&self, other: &Endpoint) -> bool {
self.device == other.device self.device == other.device
} }
@ -191,6 +194,7 @@ impl PartialEq for Endpoint {
impl Eq for Endpoint {} impl Eq for Endpoint {}
impl Clone for Endpoint { impl Clone for Endpoint {
#[inline]
fn clone(&self) -> Endpoint { fn clone(&self) -> Endpoint {
unsafe { (*self.device).AddRef(); } unsafe { (*self.device).AddRef(); }
@ -202,6 +206,7 @@ impl Clone for Endpoint {
} }
impl Drop for Endpoint { impl Drop for Endpoint {
#[inline]
fn drop(&mut self) { fn drop(&mut self) {
unsafe { (*self.device).Release(); } unsafe { (*self.device).Release(); }

View File

@ -211,14 +211,17 @@ impl Voice {
} }
} }
#[inline]
pub fn get_channels(&self) -> ::ChannelsCount { pub fn get_channels(&self) -> ::ChannelsCount {
self.num_channels as ::ChannelsCount self.num_channels as ::ChannelsCount
} }
#[inline]
pub fn get_samples_rate(&self) -> ::SamplesRate { pub fn get_samples_rate(&self) -> ::SamplesRate {
::SamplesRate(self.samples_per_second as u32) ::SamplesRate(self.samples_per_second as u32)
} }
#[inline]
pub fn get_samples_format(&self) -> ::SampleFormat { pub fn get_samples_format(&self) -> ::SampleFormat {
match self.bits_per_sample { match self.bits_per_sample {
16 => ::SampleFormat::I16, 16 => ::SampleFormat::I16,
@ -275,6 +278,7 @@ impl Voice {
} }
} }
#[inline]
pub fn play(&mut self) { pub fn play(&mut self) {
if !self.playing { if !self.playing {
unsafe { unsafe {
@ -286,6 +290,7 @@ impl Voice {
self.playing = true; self.playing = true;
} }
#[inline]
pub fn pause(&mut self) { pub fn pause(&mut self) {
if self.playing { if self.playing {
unsafe { unsafe {
@ -299,6 +304,7 @@ impl Voice {
} }
impl Drop for Voice { impl Drop for Voice {
#[inline]
fn drop(&mut self) { fn drop(&mut self) {
unsafe { unsafe {
(*self.render_client).Release(); (*self.render_client).Release();
@ -316,16 +322,19 @@ pub struct Buffer<'a, T: 'a> {
} }
impl<'a, T> Buffer<'a, T> { impl<'a, T> Buffer<'a, T> {
#[inline]
pub fn get_buffer<'b>(&'b mut self) -> &'b mut [T] { pub fn get_buffer<'b>(&'b mut self) -> &'b mut [T] {
unsafe { unsafe {
slice::from_raw_parts_mut(self.buffer_data, self.buffer_len) slice::from_raw_parts_mut(self.buffer_data, self.buffer_len)
} }
} }
#[inline]
pub fn len(&self) -> usize { pub fn len(&self) -> usize {
self.buffer_len self.buffer_len
} }
#[inline]
pub fn finish(self) { pub fn finish(self) {
// releasing buffer // releasing buffer
unsafe { unsafe {