MIX_CreateMixerDevice(3)

NAME
MIX_CreateMixerDevice - Create a mixer that plays sound directly to an audio device.

SYNOPSIS
#include <SDL3_mixer/SDL_mixer.h>

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

DESCRIPTION
This is usually the function you want, vs MIX_CreateMixer().

You can choose a specific device ID to open, following SDL's usual rules, but often the correct choice is to specify SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK and let SDL figure out what device to use (and seamlessly transition you to new hardware if the default changes).

Only playback devices make sense here. Attempting to open a recording device will fail.

This will call SDL_Init(SDL_INIT_AUDIO) internally; it's safe to call SDL_Init() before this call, too, if you intend to enumerate audio devices to choose one to open here.

An audio format can be requested, and the system will try to set the hardware to those specifications, or as close as possible, but this is just a hint. SDL_mixer will handle all data conversion behind the scenes in any case, and specifying a NULL spec is a reasonable choice. The best reason to specify a format is because you know all your data is in that format and it might save some unnecessary CPU time on conversion.

The actual device format chosen is available through MIX_GetMixerFormat().

Once a mixer is created, next steps are usually to load audio (through MIX_LoadAudio() and friends), create a track (MIX_CreateTrack()), and play that audio through that track.

When done with the mixer, it can be destroyed with MIX_DestroyMixer().

FUNCTION PARAMETERS

devid
    the device to open for playback, or SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK for the default.

spec
    the audio format to request from the device. May be NULL.

RETURN VALUE
Returns a mixer that can be used to play audio, or NULL on failure; call SDL_GetError() for more information.

THREAD SAFETY
This function should only be called on the main thread.

AVAILABILITY
This function is available since SDL_mixer 3.0.0.

SEE ALSO
MIX_CreateMixer(3), MIX_DestroyMixer(3)