SDL_SetAudioStreamFormat(3)

✨ SDL_SetAudioStreamFormat ✨

okay so bestie, we're in the SDL3 FUNCTIONS section of the SDL_SetAudioStreamFormat(3) manual page and honestly? this one's a bop. it's all about changing the input and output formats of an audio stream. glow-up for your audio, fr fr πŸ’…


🌸 NAME 🌸

SDL_SetAudioStreamFormat β€” change the input and output formats of an audio stream. that's it, that's the whole vibe. πŸŽ€


πŸ¦‹ SYNOPSIS πŸ¦‹

#include <SDL3/SDL_audio.h>

bool SDL_SetAudioStreamFormat(SDL_AudioStream *stream, const SDL_AudioSpec *src_spec, const SDL_AudioSpec *dst_spec);

like, look at her. she's giving main character energy and she takes three args. iconic. πŸ‘‘


πŸ’– DESCRIPTION πŸ’–

so here's the tea β˜• β€” future calls to SDL_GetAudioStreamAvailable and SDL_GetAudioStreamData will reflect the new format. and future calls to SDL_PutAudioStreamData must provide data in the new input formats. no cap.

but wait, there's more, and it's lowkey the best part: data that was previously queued in the stream will still be operated on in the format that was current when it was added. which is to say β€” and I'm literally quoting the energy here β€” you can put the end of a sound file in one format to a stream, change formats for the next sound file, and start putting that new data while the previous sound file is still queued, and everything will still play back correctly. obsessed. 🫢

now for the serious bit, bestie, pay attention:

if a stream is bound to a device, then the format of the side of the stream bound to a device cannot be changed (src_spec for recording devices, dst_spec for playback devices). attempts to make a change to this side will be ignored, but this will not report an error. the other side's format can be changed.

read that again. no error, just silence on the change. it's giving "we're not mad, we're just not doing it" 😭

and! src_spec and dst_spec may each be NULL; a NULL spec signals not to change the current format for that side of the stream. so NULL = "leave her alone, she's fine" ✨


πŸŽ€ FUNCTION PARAMETERS πŸŽ€

  • stream β€” the stream the format is being changed. the girl we're editing πŸ’œ
  • src_spec β€” the new format of the audio input; if NULL, it is not changed.
  • dst_spec β€” the new format of the audio output; if NULL, it is not changed.

🌈 RETURN VALUE 🌈

returns true on success or false on failure β€” and if it fails, call SDL_GetError() for more information. that's your group chat when something goes wrong. text her, she'll tell you πŸ’€


⭐ THREAD SAFETY ⭐

it is safe to call this function from any thread, because it holds a stream-specific mutex while running. multitasking queen. we love a function that locks her own stuff and doesn't bother anybody else πŸ”₯


πŸ’… AVAILABILITY πŸ’…

this function is available since SDL 3.2.0. so if you're on something older... bestie. update. πŸ™ˆ


πŸ‘‘ SEE ALSO πŸ‘‘


and that's the whole page, no notes πŸ“ this was served to you straight from the Simple Directmedia Layer collection, SDL 3.4.18, and yes she ate and left no crumbs. go format something gorgeous, bestie πŸ§šβœ¨πŸ’–

πŸ“¦ where this page comes from