diff --git a/src/sdl2/audio.rs b/src/sdl2/audio.rs index 5f622bef..73113bbe 100644 --- a/src/sdl2/audio.rs +++ b/src/sdl2/audio.rs @@ -144,6 +144,17 @@ impl AudioSubsystem { } } + #[doc(alias = "SDL_GetNumAudioDevices")] + pub fn num_audio_capture_devices(&self) -> Option { + let result = unsafe { sys::SDL_GetNumAudioDevices(1) }; + if result < 0 { + // SDL cannot retrieve a list of audio devices. This is not necessarily an error (see the SDL2 docs). + None + } else { + Some(result as u32) + } + } + #[doc(alias = "SDL_GetAudioDeviceName")] pub fn audio_playback_device_name(&self, index: u32) -> Result { unsafe { @@ -156,6 +167,19 @@ impl AudioSubsystem { } } } + + #[doc(alias = "SDL_GetAudioDeviceName")] + pub fn audio_capture_device_name(&self, index: u32) -> Result { + unsafe { + let dev_name = sys::SDL_GetAudioDeviceName(index as c_int, 1); + if dev_name.is_null() { + Err(get_error()) + } else { + let cstr = CStr::from_ptr(dev_name as *const _); + Ok(cstr.to_str().unwrap().to_owned()) + } + } + } } #[repr(i32)]