.\" This manpage content is licensed under Creative Commons
.\"  Attribution 4.0 International (CC BY 4.0)
.\"   https://creativecommons.org/licenses/by/4.0/
.\" This manpage was generated from SDL_mixer's wiki page for Mix_OpenAudio:
.\"   https://wiki.libsdl.org/SDL_mixer/Mix_OpenAudio
.\" Generated with SDL/build-scripts/wikiheaders.pl
.\"  revision 3~git20250302~78a2035+ds-1
.\" Please report issues in this manpage's content at:
.\"   https://github.com/libsdl-org/sdlwiki/issues/new
.\" Please report issues in the generation of this manpage from the wiki at:
.\"   https://github.com/libsdl-org/SDL/issues/new?title=Misgenerated%20manpage%20for%20Mix_OpenAudio
.\" SDL_mixer can be found at https://libsdl.org/projects/SDL_mixer
.de URL
\$2 \(laURL: \$1 \(ra\$3
..
.if \n[.g] .mso www.tmac
.TH Mix_OpenAudio 3 "SDL_mixer 3.0.0" "SDL_mixer" "SDL_mixer3 FUNCTIONS"
.SH NAME
Mix_OpenAudio \- Open an audio device for playback\[char46]
.SH HEADER FILE
Defined in SDL3_mixer/SDL_mixer\[char46]h

.SH SYNOPSIS
.nf
.B #include \(dqSDL3_mixer/SDL_mixer.h\(dq
.PP
.BI "bool Mix_OpenAudio(SDL_AudioDeviceID devid, const SDL_AudioSpec *spec);
.fi
.SH DESCRIPTION
An audio device is what generates sound, so the app must open one to make
noise\[char46]

This function will check if SDL's audio system is initialized, and if not,
it will initialize it by calling
.BR SDL_Init(SDL_INIT_AUDIO)
on your behalf\[char46]
You are free to (and encouraged to!) initialize it yourself before calling
this function, as this gives your program more control over the process\[char46]

If you aren't particularly concerned with the specifics of the audio
device, and your data isn't in a specific format, you can pass a NULL for
the
.BR spec
parameter and SDL_mixer will choose a reasonable default\[char46]
SDL_mixer will convert audio data you feed it to the hardware's format
behind the scenes\[char46]

That being said, if you have control of your audio data and you know its
format ahead of time, you may save CPU time by opening the audio device in
that exact format so SDL_mixer does not have to spend time converting
anything behind the scenes, and can just pass the data straight through to
the hardware\[char46]

The other reason to care about specific formats: if you plan to touch the
mix buffer directly (with 
.BR Mix_SetPostMix
, a registered
effect, or 
.BR Mix_HookMusic
), you might have code that
expects it to be in a specific format, and you should specify that here\[char46]

This function allows you to select specific audio hardware on the system
with the
.BR devid
parameter\[char46] If you specify 0, SDL_mixer will choose the
best default it can on your behalf (which, in many cases, is exactly what
you want anyhow)\[char46] This is equivalent to specifying
.BR SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK
, but is less wordy\[char46] SDL_mixer does not
offer a mechanism to determine device IDs to open, but you can use
SDL_GetAudioOutputDevices() to get a list of available devices\[char46] If you do
this, be sure to call
.BR SDL_Init(SDL_INIT_AUDIO)
first to initialize SDL's
audio system!

If this function reports success, you are ready to start making noise! Load
some audio data and start playing!

When done with an audio device, probably at the end of the program, the app
should close the audio with 
.BR Mix_CloseAudio
()\[char46]

.SH FUNCTION PARAMETERS
.TP
.I devid
the device name to open, or 0 for a reasonable default\[char46]
.TP
.I spec
the audio format you'd like SDL_mixer to work in\[char46]
.SH RETURN VALUE
Returns true on success or false on failure; call SDL_GetError() for
more information\[char46]

.SH AVAILABILITY
This function is available since SDL_mixer 3\[char46]0\[char46]0\[char46]

.SH SEE ALSO
.BR \(bu (3),
.BR Mix_CloseAudio (3),
.BR \(bu (3),
.BR Mix_QuerySpec (3)