MIX_CreateMixerDevice(3)

πŸ“¦
version 3.2.4 Β· 2 versions
, in fedora 44

πŸ’– MIX_CreateMixerDevice πŸ’–

okay bestie, come closer, we're doing the SDL_mixer3 FUNCTIONS page for MIX_CreateMixerDevice(3) and honestly? this one's a glow-up. no cap. ✨


🌸 NAME 🌸

MIX_CreateMixerDevice β€” literally creates a mixer that plays sound directly to an audio device. that's it, that's the whole vibe. πŸŽ€


✨ SYNOPSIS ✨

#include <SDL3_mixer/SDL_mixer.h>

MIX_Mixer * MIX_CreateMixerDevice(SDL_AudioDeviceID devid, const SDL_AudioSpec *spec);

look at her. two args. main character energy fr fr. πŸ‘‘


πŸ¦‹ DESCRIPTION πŸ¦‹

okay so, this is usually the function you want, versus MIX_CreateMixer(). like, if you're standing there wondering which one, it's this one. periodt.

you can choose a specific device ID to open, following SDL's usual rules πŸ’… β€” but lowkey, the correct choice most of the time is to just specify SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK and let SDL figure out what device to use. and get this β€” it'll even seamlessly transition you to new hardware if the default changes. icon behavior, honestly. 🫢

only playback devices make sense here. trying to open a recording device? it will fail. not me being dramatic, that's just the rules. πŸ’€

this will call SDL_Init(SDL_INIT_AUDIO) internally β€” no need to do it yourself first. but also, it's totally safe to call SDL_Init() before this call too, if you intend to enumerate audio devices to pick one to open here. flexible queen. ✨

you can request an audio format and the system will try to set the hardware to those specs, or as close as possible β€” but bestie, it's just a hint. πŸŽ€ SDL_mixer will handle all data conversion behind the scenes in any case, and specifying a NULL spec is a completely reasonable choice. the best reason to specify a format? because you know all your data is in that format and it might save some unnecessary CPU time on conversion. little optimization moment. πŸ’œ

the actual device format chosen is available through MIX_GetMixerFormat(). iykyk. πŸ‘€

once a mixer is created, the next steps are usually: load audio (through MIX_LoadAudio() and friends πŸ“), create a track (MIX_CreateTrack()), and play that audio through that track. the whole pipeline, slay.

when you're done with the mixer, it can be destroyed with MIX_DestroyMixer(). RIP little mixer. 🌈


πŸŽ€ FUNCTION PARAMETERS πŸŽ€

  • devid β€” the device to open for playback, or SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK for the default. (go with the default, trust.)
  • spec β€” the audio format to request from the device. may be NULL. totally valid, not a mistake, don't panic. πŸ™ˆ

⭐ RETURN VALUE ⭐

returns a mixer that can be used to play audio… or NULL on failure. 😭 if you get NULL, call SDL_GetError() for more information, bestie. it'll tell you what went wrong. πŸ”₯


πŸ’… THREAD SAFETY πŸ’…

this function should only be called on the main thread. do not try to be cute and call it from a worker thread. i said what i said. πŸ’€


🧚 AVAILABILITY 🧚

this function is available since SDL_mixer 3.0.0. so if you're on something older… babe. upgrade. πŸ¦‹


🫢 SEE ALSO 🫢


and that's the whole page, bestie, you ate it up. πŸ‘‘ this was brought to you by SDL_mixer 3.2.4, the SDL_mixer era of MIX_CreateMixerDevice(3), and honestly it's giving documentation. go make some noise. πŸ’–βœ¨πŸŽ€

πŸ“¦ where this page comes from