SDL_GetAudioStreamData(3)

✨ SDL_GetAudioStreamData ✨

okay bestie, gather round, because this is a page from the SDL3 FUNCTIONS manual and it's literally the one that hands you your audio πŸ’–


πŸ’… NAME

SDL_GetAudioStreamData β€” grab the converted/resampled data out of the stream 🎧✨


🌸 SYNOPSIS

#include <SDL3/SDL_audio.h>

int SDL_GetAudioStreamData(SDL_AudioStream *stream, void *buf, int len);

πŸ¦‹ DESCRIPTION

So here's the tea: the input/output data format, channels and samplerate? Those get set the moment you create the stream, and if you wanna change your mind later you can just call SDL_SetAudioStreamFormat. slay, flexible πŸ’…

ngl the important part is when the work happens: any conversion and resampling that needs doing gets done during this very call. Meanwhile SDL_PutAudioStreamData just queues up unconverted data for later, no thoughts, head empty 🫢. This is different than SDL2, where the conversion/resampling work happened while you were inputting new data, and requesting output just copied the already-converted data. so yeah, that's the glow-up ✨


πŸŽ€ FUNCTION PARAMETERS

  • stream β€” the stream you're requesting audio from, your main character 🎀
  • buf β€” a buffer to fill with audio data, hand it over and it gets fed πŸ“
  • len β€” the maximum number of bytes to fill. it's a cap, not a promise, bestie πŸ’€

πŸ‘‘ RETURN VALUE

Returns the number of bytes read from the stream, or -1 on failure 😭. If it flops, call SDL_GetError() for more info β€” she'll tell you what went wrong, fr fr.


πŸ”₯ THREAD SAFETY

It's safe to call this function from any thread 🧚 β€” but if the stream has a callback set, the caller might need to manage extra locking. so like, keep an eye on that, iykyk πŸ”’


⭐ AVAILABILITY

This function is available since SDL 3.2.0. old enough to be iconic, new enough to be cute πŸ’œ


🌈 SEE ALSO


Simple Directmedia Layer said it, SDL 3.4.18 stamped it, and that's the whole vibe check β€” SDL_GetAudioStreamData(3), periodt πŸ’–πŸ¦‹βœ¨

πŸ“¦ where this page comes from