@@ -253,7 +253,46 @@ typedef struct SDL_AudioCVT
253253 * order that they are normally initialized by default.
254254 */
255255/* @{ */
256+
257+ /**
258+ * Use this function to get the number of built-in audio drivers.
259+ *
260+ * This function returns a hardcoded number. This never returns a negative
261+ * value; if there are no drivers compiled into this build of SDL, this
262+ * function returns zero. The presence of a driver in this list does not mean
263+ * it will function, it just means SDL is capable of interacting with that
264+ * interface. For example, a build of SDL might have esound support, but if
265+ * there's no esound server available, SDL's esound driver would fail if used.
266+ *
267+ * By default, SDL tries all drivers, in its preferred order, until one is
268+ * found to be usable.
269+ *
270+ * \returns the number of built-in audio drivers.
271+ *
272+ * \since This function is available since SDL 2.0.0.
273+ *
274+ * \sa SDL_GetAudioDriver
275+ */
256276extern DECLSPEC int SDLCALL SDL_GetNumAudioDrivers (void );
277+
278+ /**
279+ * Use this function to get the name of a built in audio driver.
280+ *
281+ * The list of audio drivers is given in the order that they are normally
282+ * initialized by default; the drivers that seem more reasonable to choose
283+ * first (as far as the SDL developers believe) are earlier in the list.
284+ *
285+ * The names of drivers are all simple, low-ASCII identifiers, like "alsa",
286+ * "coreaudio" or "xaudio2". These never have Unicode characters, and are not
287+ * meant to be proper names.
288+ *
289+ * \param index the index of the audio driver; the value ranges from 0 to
290+ * SDL_GetNumAudioDrivers() - 1
291+ * \returns the name of the audio driver at the requested index, or NULL if an
292+ * invalid index was specified.
293+ *
294+ * \sa SDL_GetNumAudioDrivers
295+ */
257296extern DECLSPEC const char * SDLCALL SDL_GetAudioDriver (int index );
258297/* @} */
259298
@@ -265,7 +304,32 @@ extern DECLSPEC const char *SDLCALL SDL_GetAudioDriver(int index);
265304 * use. You should normally use SDL_Init() or SDL_InitSubSystem().
266305 */
267306/* @{ */
307+
308+ /**
309+ * Use this function to initialize a particular audio driver.
310+ *
311+ * This function is used internally, and should not be used unless you have a
312+ * specific need to designate the audio driver you want to use. You should
313+ * normally use SDL_Init() or SDL_InitSubSystem().
314+ *
315+ * \param driver_name the name of the desired audio driver
316+ * \returns 0 on success or a negative error code on failure; call
317+ * SDL_GetError() for more information.
318+ *
319+ * \sa SDL_AudioQuit
320+ */
268321extern DECLSPEC int SDLCALL SDL_AudioInit (const char * driver_name );
322+
323+ /**
324+ * Use this function to shut down audio if you initialized it with
325+ * SDL_AudioInit().
326+ *
327+ * This function is used internally, and should not be used unless you have a
328+ * specific need to specify the audio driver you want to use. You should
329+ * normally use SDL_Quit() or SDL_QuitSubSystem().
330+ *
331+ * \sa SDL_AudioInit
332+ */
269333extern DECLSPEC void SDLCALL SDL_AudioQuit (void );
270334/* @} */
271335
@@ -296,7 +360,7 @@ extern DECLSPEC const char *SDLCALL SDL_GetCurrentAudioDriver(void);
296360 *
297361 * This function is roughly equivalent to:
298362 *
299- * ```c++
363+ * ```c
300364 * SDL_OpenAudioDevice(NULL, 0, desired, obtained, SDL_AUDIO_ALLOW_ANY_CHANGE);
301365 * ```
302366 *
@@ -370,7 +434,7 @@ typedef Uint32 SDL_AudioDeviceID;
370434 * should not be called for each iteration of a loop, but rather once at the
371435 * start of a loop:
372436 *
373- * ```c++
437+ * ```c
374438 * // Don't do this:
375439 * for (int i = 0; i < SDL_GetNumAudioDevices(0); i++)
376440 *
@@ -577,7 +641,34 @@ typedef enum
577641 SDL_AUDIO_PLAYING ,
578642 SDL_AUDIO_PAUSED
579643} SDL_AudioStatus ;
644+
645+ /**
646+ * This function is a legacy means of querying the audio device.
647+ *
648+ * New programs might want to use SDL_GetAudioDeviceStatus() instead. This
649+ * function is equivalent to calling...
650+ *
651+ * ```c
652+ * SDL_GetAudioDeviceStatus(1);
653+ * ```
654+ *
655+ * ...and is only useful if you used the legacy SDL_OpenAudio() function.
656+ *
657+ * \returns the SDL_AudioStatus of the audio device opened by SDL_OpenAudio().
658+ *
659+ * \sa SDL_GetAudioDeviceStatus
660+ */
580661extern DECLSPEC SDL_AudioStatus SDLCALL SDL_GetAudioStatus (void );
662+
663+ /**
664+ * Use this function to get the current audio state of an audio device.
665+ *
666+ * \param dev the ID of an audio device previously opened with
667+ * SDL_OpenAudioDevice()
668+ * \returns the SDL_AudioStatus of the specified audio device.
669+ *
670+ * \sa SDL_PauseAudioDevice
671+ */
581672extern DECLSPEC SDL_AudioStatus SDLCALL SDL_GetAudioDeviceStatus (SDL_AudioDeviceID dev );
582673/* @} */ /* Audio State */
583674
@@ -591,7 +682,52 @@ extern DECLSPEC SDL_AudioStatus SDLCALL SDL_GetAudioDeviceStatus(SDL_AudioDevice
591682 * Silence will be written to the audio device during the pause.
592683 */
593684/* @{ */
685+
686+ /**
687+ * This function is a legacy means of pausing the audio device.
688+ *
689+ * New programs might want to use SDL_PauseAudioDevice() instead. This
690+ * function is equivalent to calling...
691+ *
692+ * ```c
693+ * SDL_PauseAudioDevice(1, pause_on);
694+ * ```
695+ *
696+ * ...and is only useful if you used the legacy SDL_OpenAudio() function.
697+ *
698+ * \param pause_on non-zero to pause, 0 to unpause
699+ *
700+ * \sa SDL_GetAudioStatus
701+ * \sa SDL_PauseAudioDevice
702+ */
594703extern DECLSPEC void SDLCALL SDL_PauseAudio (int pause_on );
704+
705+ /**
706+ * Use this function to pause and unpause audio playback on a specified
707+ * device.
708+ *
709+ * This function pauses and unpauses the audio callback processing for a given
710+ * device. Newly-opened audio devices start in the paused state, so you must
711+ * call this function with **pause_on**=0 after opening the specified audio
712+ * device to start playing sound. This allows you to safely initialize data
713+ * for your callback function after opening the audio device. Silence will be
714+ * written to the audio device while paused, and the audio callback is
715+ * guaranteed to not be called. Pausing one device does not prevent other
716+ * unpaused devices from running their callbacks.
717+ *
718+ * Pausing state does not stack; even if you pause a device several times, a
719+ * single unpause will start the device playing again, and vice versa. This is
720+ * different from how SDL_LockAudioDevice() works.
721+ *
722+ * If you just need to protect a few variables from race conditions vs your
723+ * callback, you shouldn't pause the audio device, as it will lead to dropouts
724+ * in the audio playback. Instead, you should use SDL_LockAudioDevice().
725+ *
726+ * \param dev a device opened by SDL_OpenAudioDevice()
727+ * \param pause_on non-zero to pause, 0 to unpause
728+ *
729+ * \sa SDL_LockAudioDevice
730+ */
595731extern DECLSPEC void SDLCALL SDL_PauseAudioDevice (SDL_AudioDeviceID dev ,
596732 int pause_on );
597733/* @} */ /* Pause audio functions */
@@ -640,14 +776,14 @@ extern DECLSPEC void SDLCALL SDL_PauseAudioDevice(SDL_AudioDeviceID dev,
640776 *
641777 * Example:
642778 *
643- * ```c++
779+ * ```c
644780 * SDL_LoadWAV_RW(SDL_RWFromFile("sample.wav", "rb"), 1, &spec, &buf, &len);
645781 * ```
646782 *
647783 * Note that the SDL_LoadWAV macro does this same thing for you, but in a less
648784 * messy way:
649785 *
650- * ```c++
786+ * ```c
651787 * SDL_LoadWAV("sample.wav", &spec, &buf, &len);
652788 * ```
653789 *
@@ -907,17 +1043,18 @@ extern DECLSPEC void SDLCALL SDL_AudioStreamClear(SDL_AudioStream *stream);
9071043extern DECLSPEC void SDLCALL SDL_FreeAudioStream (SDL_AudioStream * stream );
9081044
9091045#define SDL_MIX_MAXVOLUME 128
1046+
9101047/**
9111048 * This function is a legacy means of mixing audio.
9121049 *
913- * This function is equivalent to calling
1050+ * This function is equivalent to calling...
9141051 *
915- * ```c++
1052+ * ```c
9161053 * SDL_MixAudioFormat(dst, src, format, len, volume);
9171054 * ```
9181055 *
919- * where `format` is the obtained format of the audio device from the legacy
920- * SDL_OpenAudio() function.
1056+ * ... where `format` is the obtained format of the audio device from the
1057+ * legacy SDL_OpenAudio() function.
9211058 *
9221059 * \param dst the destination for the mixed audio
9231060 * \param src the source audio buffer to be mixed
@@ -1137,22 +1274,102 @@ extern DECLSPEC void SDLCALL SDL_ClearQueuedAudio(SDL_AudioDeviceID dev);
11371274 * function or you will cause deadlock.
11381275 */
11391276/* @{ */
1277+
1278+ /**
1279+ * This function is a legacy means of locking the audio device.
1280+ *
1281+ * New programs might want to use SDL_LockAudioDevice() instead. This function
1282+ * is equivalent to calling...
1283+ *
1284+ * ```c
1285+ * SDL_LockAudioDevice(1);
1286+ * ```
1287+ *
1288+ * ...and is only useful if you used the legacy SDL_OpenAudio() function.
1289+ *
1290+ * \sa SDL_LockAudioDevice
1291+ * \sa SDL_UnlockAudio
1292+ * \sa SDL_UnlockAudioDevice
1293+ */
11401294extern DECLSPEC void SDLCALL SDL_LockAudio (void );
1295+
1296+ /**
1297+ * Use this function to lock out the audio callback function for a specified
1298+ * device.
1299+ *
1300+ * The lock manipulated by these functions protects the audio callback
1301+ * function specified in SDL_OpenAudioDevice(). During a
1302+ * SDL_LockAudioDevice()/SDL_UnlockAudioDevice() pair, you can be guaranteed
1303+ * that the callback function for that device is not running, even if the
1304+ * device is not paused. While a device is locked, any other unpaused,
1305+ * unlocked devices may still run their callbacks.
1306+ *
1307+ * Calling this function from inside your audio callback is unnecessary. SDL
1308+ * obtains this lock before calling your function, and releases it when the
1309+ * function returns.
1310+ *
1311+ * You should not hold the lock longer than absolutely necessary. If you hold
1312+ * it too long, you'll experience dropouts in your audio playback. Ideally,
1313+ * your application locks the device, sets a few variables and unlocks again.
1314+ * Do not do heavy work while holding the lock for a device.
1315+ *
1316+ * It is safe to lock the audio device multiple times, as long as you unlock
1317+ * it an equivalent number of times. The callback will not run until the
1318+ * device has been unlocked completely in this way. If your application fails
1319+ * to unlock the device appropriately, your callback will never run, you might
1320+ * hear repeating bursts of audio, and SDL_CloseAudioDevice() will probably
1321+ * deadlock.
1322+ *
1323+ * Internally, the audio device lock is a mutex; if you lock from two threads
1324+ * at once, not only will you block the audio callback, you'll block the other
1325+ * thread.
1326+ *
1327+ * \param dev the ID of the device to be locked
1328+ *
1329+ * \sa SDL_UnlockAudioDevice
1330+ */
11411331extern DECLSPEC void SDLCALL SDL_LockAudioDevice (SDL_AudioDeviceID dev );
1332+
1333+ /**
1334+ * This function is a legacy means of unlocking the audio device.
1335+ *
1336+ * New programs might want to use SDL_UnlockAudioDevice() instead. This
1337+ * function is equivalent to calling...
1338+ *
1339+ * ```c
1340+ * SDL_UnlockAudioDevice(1);
1341+ * ```
1342+ *
1343+ * ...and is only useful if you used the legacy SDL_OpenAudio() function.
1344+ *
1345+ * \sa SDL_LockAudio
1346+ * \sa SDL_UnlockAudioDevice
1347+ */
11421348extern DECLSPEC void SDLCALL SDL_UnlockAudio (void );
1349+
1350+ /**
1351+ * Use this function to unlock the audio callback function for a specified
1352+ * device.
1353+ *
1354+ * This function should be paired with a previous SDL_LockAudioDevice() call.
1355+ *
1356+ * \param dev the ID of the device to be unlocked
1357+ *
1358+ * \sa SDL_LockAudioDevice
1359+ */
11431360extern DECLSPEC void SDLCALL SDL_UnlockAudioDevice (SDL_AudioDeviceID dev );
11441361/* @} */ /* Audio lock functions */
11451362
11461363/**
11471364 * This function is a legacy means of closing the audio device.
11481365 *
1149- * This function is equivalent to calling
1366+ * This function is equivalent to calling...
11501367 *
1151- * ```c++
1368+ * ```c
11521369 * SDL_CloseAudioDevice(1);
11531370 * ```
11541371 *
1155- * and is only useful if you used the legacy SDL_OpenAudio() function.
1372+ * ... and is only useful if you used the legacy SDL_OpenAudio() function.
11561373 *
11571374 * \sa SDL_OpenAudio
11581375 */
0 commit comments