SDL_AudioS...eteCallback(3type)
π SDL_AudioS...eteCallback β a datatype from the SDL3 DATATYPES crew π
okay bestie, sit down, hydrate, and let me tell you about the single most underrated little callback in the whole audio section. it's giving "I'll tell you the exact moment your buffer is free" energy and honestly? iconic.
β¨ NAME β¨
SDL_AudioStreamDataCompleteCallback β a callback that fires when the data you handed over with SDL_PutAudioStreamDataNoCopy() is finally, officially, completely done. π
πΈ SYNOPSIS πΈ
#include <SDL3/SDL_audio.h>
typedef void (SDLCALL *SDL_AudioStreamDataCompleteCallback)(void *userdata, const void *buf, int buflen);
look at her. gorgeous. no notes. π¦
π«Ά DESCRIPTION π«Ά
so here's the situation, bestie. when you use SDL_PutAudioStreamDataNoCopy() to feed data into an SDL_AudioStream, you're basically saying "hey, use this buffer, I'm not making you a copy, we're being efficient." which slays, truly. but β and this is the important part β it is NOT safe to dispose of that data until the stream has completely consumed it. no cap.
and the annoying part? often times it's difficult to know exactly when this has happened. like, the stream just... has your pointer... and you're sitting there like π "is it done? can I free it? hello?"
this callback is the answer. it fires once when the stream no longer needs the buffer, which lets the app easily free or reuse it. that's it. that's the whole vibe. closure, literally. πβ¨
π FUNCTION PARAMETERS π
userdataβ an opaque pointer that you the app provided, for your own personal use. no questions asked, no interpretation made. it's yours. πbufβ the pointer that was provided toSDL_PutAudioStreamDataNoCopy(). yes, that exact one. πbuflenβ the size of buffer, in bytes, that was provided toSDL_PutAudioStreamDataNoCopy(). π«
π§ THREAD SAFETY π§
okay this part matters so listen up. this callback may run from any thread. so if you need to protect shared data, you should use SDL_LockAudioStream to serialize access.
but here's the cute part: this lock will be held before your callback is called, so your callback does not need to manage the lock explicitly. she already did that for you. main character behavior, honestly. π
β AVAILABILITY β
this datatype has been available since SDL 3.4.0. so if you're on 3.4.0 or later, you're good. π
π SEE ALSO π
go read those too bestie, they're all in the same friend group. π«Ά
π tiny reminder before you go: the whole reason this callback exists is that SDL_PutAudioStreamDataNoCopy() means no copy, which means you keep ownership of that memory, which means freeing it too early is a you problem that this callback is here to prevent. free it when she tells you to. periodt.
okay that's the whole page, you ate it, I'm obsessed with you, bye bestie ππΈπ¦ β brought to you by Simple Directmedia Layer, running SDL 3.4.18 (that's the source + version babe, that's the date vibe, that's the footer energy), mwah π β¨
π¦ where this page comes from
- fedora 43: SDL3-devel 3.4.18-1.fc43 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- fedora 43: SDL3-devel 3.4.18-1.fc43 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- fedora 44: SDL3-devel 3.4.18-1.fc44 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- fedora 44: SDL3-devel 3.4.18-1.fc44 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms