diff --git a/examples/audio-queue-squarewave.rs b/examples/audio-queue-squarewave.rs index 22d237bec8..8990cb7711 100644 --- a/examples/audio-queue-squarewave.rs +++ b/examples/audio-queue-squarewave.rs @@ -36,7 +36,7 @@ fn main() -> Result<(), String> { let target_bytes = 48_000 * 4; let wave = gen_wave(target_bytes); - device.queue(&wave); + device.queue_audio(&wave)?; // Start playback device.resume(); diff --git a/src/sdl2/audio.rs b/src/sdl2/audio.rs index 07dd6d3b7e..bdbc9d8cd2 100644 --- a/src/sdl2/audio.rs +++ b/src/sdl2/audio.rs @@ -750,6 +750,10 @@ impl<'a, Channel: AudioFormatNum> AudioQueue { /// Adds data to the audio queue. #[doc(alias = "SDL_QueueAudio")] + #[deprecated( + since = "0.36.0", + note = "Users should instead use AudioQueue::queue_audio" + )] pub fn queue(&self, data: &[Channel]) -> bool { let result = unsafe { sys::SDL_QueueAudio( @@ -761,6 +765,23 @@ impl<'a, Channel: AudioFormatNum> AudioQueue { result == 0 } + /// Adds data to the audio queue. + #[doc(alias = "SDL_QueueAudio")] + pub fn queue_audio(&self, data: &[Channel]) -> Result<(), String> { + let result = unsafe { + sys::SDL_QueueAudio( + self.device_id.id(), + data.as_ptr() as *const c_void, + (data.len() * mem::size_of::()) as u32, + ) + }; + if result == 0 { + Ok(()) + } else { + Err(get_error()) + } + } + #[doc(alias = "SDL_GetQueuedAudioSize")] pub fn size(&self) -> u32 { unsafe { sys::SDL_GetQueuedAudioSize(self.device_id.id()) }