Skip to content

Commit 45f8e14

Browse files
Implement SDL_GetAudioDeviceSpec
1 parent 1cb06b3 commit 45f8e14

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

src/sdl2/audio.rs

+43
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,49 @@ impl AudioSubsystem {
180180
}
181181
}
182182
}
183+
184+
#[doc(alias = "SDL_GetAudioDeviceSpec")]
185+
pub fn audio_playback_device_spec(&self, index: u32) -> Result<AudioSpec, String> {
186+
let mut spec = sys::SDL_AudioSpec {
187+
freq: 0,
188+
format: 0,
189+
channels: 0,
190+
silence: 0,
191+
samples: 0,
192+
padding: 0,
193+
size: 0,
194+
callback: None,
195+
userdata: ptr::null_mut(),
196+
};
197+
198+
let result = unsafe { sys::SDL_GetAudioDeviceSpec(index as c_int, 0, &mut spec) };
199+
if result != 0 {
200+
Err(get_error())
201+
} else {
202+
Ok(AudioSpec::convert_from_ll(spec))
203+
}
204+
}
205+
#[doc(alias = "SDL_GetAudioDeviceSpec")]
206+
pub fn audio_capture_device_spec(&self, index: u32) -> Result<AudioSpec, String> {
207+
let mut spec = sys::SDL_AudioSpec {
208+
freq: 0,
209+
format: 0,
210+
channels: 0,
211+
silence: 0,
212+
samples: 0,
213+
padding: 0,
214+
size: 0,
215+
callback: None,
216+
userdata: ptr::null_mut(),
217+
};
218+
219+
let result = unsafe { sys::SDL_GetAudioDeviceSpec(index as c_int, 1, &mut spec) };
220+
if result != 0 {
221+
Err(get_error())
222+
} else {
223+
Ok(AudioSpec::convert_from_ll(spec))
224+
}
225+
}
183226
}
184227

185228
#[repr(i32)]

0 commit comments

Comments
 (0)