SDL_SetAudioStreamGain(3)

πŸ’– SDL_SetAudioStreamGain πŸ’–

okay bestie, gather round, we're doing SDL3 audio today and honestly? it's giving volume knob energy. this one lives in the SDL3 FUNCTIONS lineup and its whole personality is changing the gain of an audio stream. that's it. that's the job. and it eats. ✨


πŸŽ€ NAME πŸŽ€

SDL_SetAudioStreamGain β€” change the gain of an audio stream. no cap, that's literally the whole thing.


🌸 SYNOPSIS 🌸

#include <SDL3/SDL_audio.h>

bool SDL_SetAudioStreamGain(SDL_AudioStream *stream, float gain);

πŸ¦‹ DESCRIPTION πŸ¦‹

so like. the gain of a stream is its volume, periodt. bigger gain = louder output, and a gain of zero means silence, like the sound went to sleep. πŸ’€

audio streams default to a gain of 1.0f, which is the "no change in output" vibe β€” you're not touching anything, you're just existing. iconic.

and here's the fun part: this gets applied during SDL_GetAudioStreamData, which means you can continuously change it to cook up all kinds of effects. fades, dips, dramatic swells... the whole main character arc. πŸ”₯


πŸ’… FUNCTION PARAMETERS πŸ’…

  • stream β€” the stream whose gain is getting changed. the glow-up target. πŸ‘‘
  • gain β€” the gain itself. 1.0f is no change, 0.0f is silence. pick your fighter.

⭐ RETURN VALUE ⭐

returns true on success or false on failure. and if it fails? call SDL_GetError() for more info, she'll tell you what went wrong. 🫢


πŸ”₯ THREAD SAFETY πŸ”₯

fr fr, you can call this from any thread and it's safe β€” it holds a stream-specific mutex the whole time it's running. so go ahead and be chaotic, it's protected. πŸ’ͺ


🌈 AVAILABILITY 🌈

this function has been available since SDL 3.2.0. she's been here, she's been serving. πŸ’œ


πŸ’€ SEE ALSO πŸ’€


⚠️ heads up bestie: 0.0f gain is full silence, not "a little quiet." don't be surprised when the vibes go completely quiet. πŸ™ˆ

okay that's the whole page!! this was brought to you by Simple Directmedia Layer (the source, the icon, the legend 🌟) running SDL 3.4.18. now go make something loud. mwah. πŸ’–βœ¨πŸŽ€

πŸ“¦ where this page comes from