Skip to content

SDL_GetAudioStreamQueued Wrapper for Audio Stream and Audio Stream with Callback #167

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

Merged
merged 2 commits into from
Apr 29, 2025
Merged
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
15 changes: 15 additions & 0 deletions src/sdl3/audio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1197,6 +1197,17 @@ impl AudioStream {
}
}

/// Gets the number of bytes queued.
#[doc(alias = "SDL_GetAudioStreamQueued")]
pub fn queued_bytes(&self) -> Result<i32, Error> {
let queue = unsafe { sys::audio::SDL_GetAudioStreamQueued(self.stream) };
if queue == -1 {
Err(get_error())
} else {
Ok(queue)
}
}

/// Converts a slice of bytes to a f32 sample based on AudioFormat.
/// Returns a Result containing the converted f32 or an error message.
fn read_bytes_to_f32(&self, chunk: &[u8]) -> Result<f32, Error> {
Expand Down Expand Up @@ -1392,6 +1403,10 @@ impl<CB> AudioStreamWithCallback<CB> {
self.base_stream.resume()
}

pub fn queued_bytes(&self) -> Result<i32, Error> {
self.base_stream.queued_bytes()
}

pub fn lock(&mut self) -> Option<AudioStreamLockGuard<CB>> {
let raw_stream = self.base_stream.stream;
let result = unsafe { sys::audio::SDL_LockAudioStream(raw_stream) };
Expand Down