From b40180b612d7c1de15cfaf897bb6f0b8fb3ade05 Mon Sep 17 00:00:00 2001 From: Dan Spencer Date: Wed, 7 Jan 2015 11:29:00 -0700 Subject: [PATCH] Remove AudioCVT for now. --- src/sdl2/audio.rs | 74 +++++------------------------------------------ 1 file changed, 8 insertions(+), 66 deletions(-) diff --git a/src/sdl2/audio.rs b/src/sdl2/audio.rs index 3a033bd2..8ba37d63 100644 --- a/src/sdl2/audio.rs +++ b/src/sdl2/audio.rs @@ -1,11 +1,15 @@ //! Audio Functions use std::ptr; +<<<<<<< HEAD use std::mem; use std::ffi::{c_str_to_bytes, CString}; +======= +use std::c_str::{CString, ToCStr}; +use std::c_vec::CVec; +>>>>>>> Remove AudioCVT for now. use std::borrow::ToOwned; use std::num::FromPrimitive; -use libc; -use libc::{c_int, size_t, c_void}; +use libc::{c_int, c_void}; use libc::{uint8_t}; use std::ops::{Deref, DerefMut}; @@ -215,9 +219,9 @@ impl, CB: AudioCallback> AudioSpecDesired { samples: 0, padding: 0, size: 0, - callback: Some(audio_callback_marshall:: + callback: Some(audio_callback_marshall:: as extern "C" fn - (arg1: *const c_void, + (arg1: *const c_void, arg2: *const uint8_t, arg3: c_int)), userdata: transmute(userdata) @@ -394,65 +398,3 @@ impl<'a, CB> Drop for AudioDeviceLockGuard<'a, CB> { unsafe { ll::SDL_UnlockAudioDevice(self.device.device_id.id()) } } } - -#[derive(PartialEq)] #[allow(raw_pointer_derive)] -pub struct AudioCVT { - raw: *mut ll::SDL_AudioCVT, - owned: bool, -} - -impl_raw_accessors!(AudioCVT, *mut ll::SDL_AudioCVT); -impl_owned_accessors!(AudioCVT, owned); - -impl Drop for AudioCVT { - fn drop(&mut self) { - if self.owned { - unsafe { libc::free(self.raw as *mut c_void) } - } - } -} - -impl AudioCVT { - pub fn new(src_format: ll::SDL_AudioFormat, src_channels: u8, src_rate: int, - dst_format: ll::SDL_AudioFormat, dst_channels: u8, dst_rate: int) -> SdlResult { - unsafe { - let c_cvt_p = libc::malloc(mem::size_of::() as size_t) as *mut ll::SDL_AudioCVT; - let ret = ll::SDL_BuildAudioCVT(c_cvt_p, - src_format, src_channels, src_rate as c_int, - dst_format, dst_channels, dst_rate as c_int); - if ret == 1 || ret == 0 { - Ok(AudioCVT { raw: c_cvt_p, owned: true }) - } else { - Err(get_error()) - } - } - } - - pub fn convert(&self, src: CVec) -> SdlResult> { - //! Convert audio data to a desired audio format. - - unsafe { - if (*self.raw).needed != 1 { - return Err("no convertion needed!".to_owned()) - } - // set len - (*self.raw).len = src.len() as c_int; - // alloc buf - let size = (*self.raw).len * (*self.raw).len_mult; - (*self.raw).buf = libc::malloc(size as size_t) as *mut u8; - // set buf - ptr::copy_memory::((*self.raw).buf, src.as_slice().as_ptr(), src.len()); - // convert - let ret = ll::SDL_ConvertAudio(self.raw); - // return - let p = ptr::Unique((*self.raw).buf as *mut c_void); // send to move || - if ret == 0 { - Ok( CVec::new_with_dtor(p.0 as *mut u8, (*self.raw).len_cvt as uint, - move || { libc::free(p.0) }) - ) - } else { - Err(get_error()) - } - } - } -}