SDL_PutAudioStreamData(3)

πŸ’– SDL_PutAudioStreamData β€” bestie's guide to yeeting audio into a stream πŸ’–

okay so like. you're in the SDL3 FUNCTIONS section of the manual (that's the vibe of this whole page, iykyk) and you found SDL_PutAudioStreamData(3). and honestly? iconic of you. let's get into it ✨


✨ NAME ✨

SDL_PutAudioStreamData β€” add data to the stream. that's it. that's the whole job. she's a simple girl and she slays at it πŸŽ€


🌈 SYNOPSIS 🌈

#include <SDL3/SDL_audio.h>

bool SDL_PutAudioStreamData(SDL_AudioStream *stream, const void *buf, int len);

look at her. three args. returns a bool. no cap, it's giving minimalism πŸ’…


πŸ¦‹ DESCRIPTION πŸ¦‹

okay so here's the tea, bestie. the data you're putting in has to match the format / channels / samplerate that you specified in the latest call to SDL_SetAudioStreamFormat. or β€” if you never changed it β€” whatever format was specified when you created the stream. fr fr, mismatch = chaos. πŸ’€

and now the part that lowkey blows people's minds: this call simply copies the unconverted data for later. that's it. she's not converting anything on the way in. she's just holding it. ✨

this is different from SDL2, where the data was converted during the Put call and then the Get call would just dequeue the previously-converted stuff. so if you're porting your brain over from SDL2, unlearn that. periodt. πŸ‘‘


πŸŽ€ FUNCTION PARAMETERS πŸŽ€

  • stream β€” the stream the audio data is being added to. your main character stream. 🫢
  • buf β€” a pointer to the audio data to add. just a little pointer, doing her best. πŸ’œ
  • len β€” the number of bytes to write to the stream. bytes!! not samples!! don't do the thing!! 😭

⭐ RETURN VALUE ⭐

returns true on success or false on failure πŸ₯² β€” and if it fails, you call SDL_GetError() for more information, because she will tell you what went wrong, she's not mysterious like that.


πŸ”₯ THREAD SAFETY πŸ”₯

it is 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. be mindful. vibe check your locks. πŸ”’


🌸 AVAILABILITY 🌸

this function is available since SDL 3.2.0. babygirl is relatively new. treat her with respect. πŸ‘‘


πŸ’« SEE ALSO πŸ’«

go read them. they're all connected. it's a whole friend group. 🏳️🌈


mwah πŸ’‹ that's the page!! brought to you by Simple Directmedia Layer, running on SDL 3.4.18, and yes this whole thing is SDL_PutAudioStreamData(3) β€” go put some audio in a stream, bestie, you've got this 🎧✨

πŸ“¦ where this page comes from