SDL_SetAudioDeviceGain(3)

πŸ’– SDL_SetAudioDeviceGain πŸ’–

okay bestie, welcome to the SDL3 FUNCTIONS section of the SDL_SetAudioDeviceGain(3) manual, and yes we are about to talk about volume. gain. whatever you wanna call it. let's go ✨


🌸 NAME 🌸

SDL_SetAudioDeviceGain β€” change the gain of an audio device. that's it, that's the whole job, and she does it flawlessly πŸ’…


πŸŽ€ SYNOPSIS πŸŽ€

#include <SDL3/SDL_audio.h>

bool SDL_SetAudioDeviceGain(SDL_AudioDeviceID devid, float gain);

like. look at her. two args. one bool. iconic.


πŸ¦‹ DESCRIPTION πŸ¦‹

okay so first things first: the gain of a device is its volume. a bigger gain means a louder output, and a gain of zero means... silence. nothing. the void. 🀫

audio devices default to a gain of 1.0f, which is the "no change in output" setting. so if you don't touch it, nothing moves. periodt.

⚠️ now here's the tea, and it's important tea: physical devices may not have their gain changed β€” only logical devices. and this function will always return false when you use it on a physical device. no cap.

and yeah, it might seem super attractive to just reach over and adjust several logical devices all at once this way, but no ma'am β€” that would let an app or a library mess with another part of the program's otherwise-isolated devices. rude. we don't do that. πŸ™ˆ

here's how it actually flows, bestie:

  • during playback: this gain gets applied to the hardware, along with any per-audiostream gain, and you can change it continuously to create all kinds of fun effects. go off ✨
  • on recording devices: this adjusts the gain before the data gets passed into an audiostream. that recording audiostream can then adjust its gain further when it outputs the data somewhere else, if it feels like it β€” but heads up, that second gain is not applied until the data leaves the audiostream again.

⭐ FUNCTION PARAMETERS ⭐

  • devid β€” the audio device on which to change gain. πŸ‘‘
  • gain β€” the gain. 1.0f is no change, 0.0f is silence. simple as that, fr fr.

πŸ’œ RETURN VALUE πŸ’œ

returns true on success, or false on failure. and if it fails, please call SDL_GetError() for more information β€” she will tell you what went wrong, she's very upfront like that. 🫢


πŸ”₯ THREAD SAFETY πŸ”₯

it is safe to call this function from any thread, because it holds a stream-specific mutex while running. multitask, babe. it's giving responsible. πŸ’…


🌈 AVAILABILITY 🌈

this function has been available since SDL 3.2.0. so if you're on something older, bestie, it's not you, it's the version. 😭


πŸ’€ SEE ALSO πŸ’€


and that's the whole page!! brought to you by the fine folks at Simple Directmedia Layer, running SDL 3.4.18. mwah, go make something loud πŸ’–βœ¨πŸŽ€

πŸ“¦ where this page comes from