Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return Result from AudioQueue::queue instead of bool #1189

Merged
merged 1 commit into from
Dec 31, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/audio-queue-squarewave.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
21 changes: 21 additions & 0 deletions src/sdl2/audio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -750,6 +750,10 @@ impl<'a, Channel: AudioFormatNum> AudioQueue<Channel> {

/// Adds data to the audio queue.
#[doc(alias = "SDL_QueueAudio")]
#[deprecated(
since = "0.36.0",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what the next version is. If 0.35.2 is better, please let me know.

note = "Users should instead use AudioQueue::queue_audio"
)]
pub fn queue(&self, data: &[Channel]) -> bool {
let result = unsafe {
sys::SDL_QueueAudio(
Expand All @@ -761,6 +765,23 @@ impl<'a, Channel: AudioFormatNum> AudioQueue<Channel> {
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::<Channel>()) 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()) }
Expand Down