SDL_SETAUDIOSTREAMPUTCALLBACK(3)
β¨ SDL_SetAudioStreamPutCallback(3) β¨
okay bestie, welcome to the SDL3 FUNCTIONS corner of the manual π this one's all about the put callback β the lil function that fires the second somebody drops data into your audio stream. buckle up, it's giving audio nerd but make it cute π
π¦ NAME π¦
SDL_SetAudioStreamPutCallback β set a callback that runs when data is added to an audio stream.
πΈ SYNOPSIS πΈ
#include <SDL3/SDL_audio.h>
bool SDL_SetAudioStreamPutCallback(SDL_AudioStream *stream, SDL_AudioStreamCallback callback, void *userdata);
π DESCRIPTION π
So here's the tea, bestie: this callback gets called _after_ the data is added to the stream. After, not before. Which means your callback gets the chance to grab that data immediately β like, right off the counter, still warm π₯
Your callback can (optionally!) call SDL_GetAudioStreamData() to snag audio from the stream during this very call. Optional though, no pressure, she's not obligated β¨
Now the callback's additional_amount argument β this is how many bytes of _converted_ data (in the stream's output format, iykyk) was provided by the caller. Lowkey it might underestimate a little bit, but that's on purpose, for safety π«Ά
And here's the messy part that you need to know: that value might be less than what's currently available in the stream, if data was already chillin' there from before. And it might be less than what the caller provided if the stream needs to keep a buffer to aid in resampling. Which meansβ¦ yeah, the callback may be handed zero bytes, and a different amount on each call. Not a bug, just the vibe check failing sometimes π
If you want the real numbers, the callback may call SDL_GetAudioStreamAvailable to see the total amount currently available to read from the stream β instead of just the total provided by the current call. That's your actual main character move π
Oh and β the callback is not required to obtain all the data. She can read less, or none at all. Whatever. Anything not read right now simply remains in the stream for later access. No data is wasted, periodt π
heads up: clearing or flushing an audio stream does NOT call this callback. so don't be waiting on it, bestie π
One more thing: this function obtains the stream's lock. Which means any existing callback (get or put) that's in progress will finish running before the new callback gets set. So no chaotic overlapping, it's very orderly, very demure πΈ
And if you set a NULL function? That turns off the callback. bye bestie π
π FUNCTION PARAMETERS π
streamβ the audio stream to set the new callback on. the canvas, the moment, the whole point π¨callbackβ the new callback function to call when data is added to the stream. your lil star of the show βuserdataβ an opaque pointer provided to the callback for its own personal use. it's giving private diary, only the callback reads it π
β RETURN VALUE β
Returns true on success or false on failure β and if it fails, call SDL_GetError() for more info, she'll tell you everything π
Fun fact: this only fails if stream is NULL. That's it. That's the only way to fumble this one, no cap.
π THREAD SAFETY π
It is safe to call this function from any thread. go off, multithreaded queen πβ¨
π AVAILABILITY π
This function is available since SDL 3.2.0. brand new, freshly dropped, iconic behavior π
π«Ά SEE ALSO π«Ά
SDL_SetAudioStreamGetCallback(3)β her sister, the get side of the story π¦
and that's the whole page bestie!! π this manual page came to you courtesy of Simple Directmedia Layer, straight outta SDL 3.4.18, and yeah it's literally titled SDL_SetAudioStreamPutCallback(3) because of course it is π mwah, go set some callbacks, slay β¨πΈ
π¦ 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