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 {}
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<Endpoint> {
// TODO: do in a different way?
Some(Endpoint("default".to_owned()))

View File

@ -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;

View File

@ -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[..]
}

View File

@ -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<Endpoint> {
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<SupportedFormatsIterator,
FormatsEnumerationError>
{
@ -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);

View File

@ -12,11 +12,13 @@ pub struct EndpointsIterator;
impl Iterator for EndpointsIterator {
type Item = Endpoint;
#[inline]
fn next(&mut self) -> Option<Endpoint> {
None
}
}
#[inline]
pub fn get_default_endpoint() -> Option<Endpoint> {
None
}
@ -25,6 +27,7 @@ pub fn get_default_endpoint() -> Option<Endpoint> {
pub struct Endpoint;
impl Endpoint {
#[inline]
pub fn get_supported_formats_list(&self)
-> Result<SupportedFormatsIterator, FormatsEnumerationError>
{
@ -37,6 +40,7 @@ pub struct SupportedFormatsIterator;
impl Iterator for SupportedFormatsIterator {
type Item = Format;
#[inline]
fn next(&mut self) -> Option<Format> {
None
}
@ -45,29 +49,36 @@ impl Iterator for SupportedFormatsIterator {
pub struct Voice;
impl Voice {
#[inline]
pub fn new(_: &Endpoint, _: &Format) -> Result<Voice, CreationError> {
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) {
}
}

View File

@ -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(|_| {});
}

View File

@ -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();

View File

@ -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(); }

View File

@ -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 {