fn open<'a, F, D>(a: &AudioSubsystem, device: D, spec: &AudioSpecDesired, get_callback: F, capture: bool) -> Result<AudioDevice <CB>, String>
    where
        F: FnOnce(AudioSpec) -> CB,
        D: Into<Option<&'a str>>,
    {

        let mut userdata: Box<Option<CB>> = Box::new(None);
        let desired = AudioSpecDesired::convert_to_ll(spec.freq, spec.channels, spec.samples, &mut *userdata);

        let mut obtained = unsafe { mem::uninitialized::<sys::SDL_AudioSpec>() };
        unsafe {
            let device = match device.into() {
                Some(device) => Some(CString::new(device).unwrap()),
                None => None
            };
            let device_ptr = device.map_or(ptr::null(), |s| s.as_ptr());

            let iscapture_flag = if capture { 1 } else { 0 };
            let device_id = sys::SDL_OpenAudioDevice(
                device_ptr as *const c_char, iscapture_flag, &desired,
                &mut obtained, 0
            );
            match device_id {
                0 => {
                    Err(get_error())
                },
                id => {
                    let device_id = AudioDeviceID::PlaybackDevice(id);
                    let spec = AudioSpec::convert_from_ll(obtained);

                    *userdata = Some(get_callback(spec));

                    Ok(AudioDevice {
                        subsystem: a.clone(),
                        device_id: device_id,
                        userdata: userdata,
                        spec: spec,
                    })
                }
            }
        }
    }
/// Opens a new audio device for playback or capture (given the desired parameters and callback).
Opens a new audio device for playback or capture (given the desired parameters and callback).
Opens a new audio device for playback or capture ( given the desired parameters and callback ) .
fn open<'a, F, D>(a: &AudioSubsystem, device: D, spec: &AudioSpecDesired, get_callback: F, capture: bool) -> Result<AudioDevice <CB>, String>
    where
        F: FnOnce(AudioSpec) -> CB,
        D: Into<Option<&'a str>>,
    {
        let mut userdata: Box<Option<CB>> = Box::new(None);
        let desired = AudioSpecDesired::convert_to_ll(spec.freq, spec.channels, spec.samples, &mut *userdata);
        let mut obtained = unsafe { mem::uninitialized::<sys::SDL_AudioSpec>() };
        unsafe {
            let device = match device.into() {
                Some(device) => Some(CString::new(device).unwrap()),
                None => None
            };
            let device_ptr = device.map_or(ptr::null(), |s| s.as_ptr());
            let iscapture_flag = if capture { 1 } else { 0 };
            let device_id = sys::SDL_OpenAudioDevice(
                device_ptr as *const c_char, iscapture_flag, &desired,
                &mut obtained, 0
            );
            match device_id {
                0 => {
                    Err(get_error())
                },
                id => {
                    let device_id = AudioDeviceID::PlaybackDevice(id);
                    let spec = AudioSpec::convert_from_ll(obtained);
                    *userdata = Some(get_callback(spec));
                    Ok(AudioDevice {
                        subsystem: a.clone(),
                        device_id: device_id,
                        userdata: userdata,
                        spec: spec,
                    })
                }
            }
        }
    }
fn open < ' a , F , D > ( a : & AudioSubsystem , device : D , spec : & AudioSpecDesired , get_callback : F , capture : bool ) -> Result < AudioDevice < CB > , String > where F : FnOnce ( AudioSpec ) -> CB , D : Into < Option < & ' a str > > , { let mut userdata : Box < Option < CB > > = Box :: new ( None ) ; let desired = AudioSpecDesired :: convert_to_ll ( spec . freq , spec . channels , spec . samples , & mut * userdata ) ; let mut obtained = unsafe { mem :: uninitialized :: < sys :: SDL_AudioSpec > ( ) } ; unsafe { let device = match device . into ( ) { Some ( device ) => Some ( CString :: new ( device ) . unwrap ( ) ) , None => None } ; let device_ptr = device . map_or ( ptr :: null ( ) , | s | s . as_ptr ( ) ) ; let iscapture_flag = if capture { 1 } else { 0 } ; let device_id = sys :: SDL_OpenAudioDevice ( device_ptr as * const c_char , iscapture_flag , & desired , & mut obtained , 0 ) ; match device_id { 0 => { Err ( get_error ( ) ) } , id => { let device_id = AudioDeviceID :: PlaybackDevice ( id ) ; let spec = AudioSpec :: convert_from_ll ( obtained ) ; * userdata = Some ( get_callback ( spec ) ) ; Ok ( AudioDevice { subsystem : a . clone ( ) , device_id : device_id , userdata : userdata , spec : spec , } ) } } } }
Opens a new audio device for playback or capture (given the desired parameters and callback).
Opens a new audio device for playback or capture ( given the desired parameters and callback ) .
a
&AudioSubsystem
device
D
spec
&AudioSpecDesired
get_callback
F
capture
bool
a
&AudioSubsystem
device
D
spec
&AudioSpecDesired
get_callback
F
capture
bool