SDL_audio.h 46 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
  4. This software is provided 'as-is', without any express or implied
  5. warranty. In no event will the authors be held liable for any damages
  6. arising from the use of this software.
  7. Permission is granted to anyone to use this software for any purpose,
  8. including commercial applications, and to alter it and redistribute it
  9. freely, subject to the following restrictions:
  10. 1. The origin of this software must not be misrepresented; you must not
  11. claim that you wrote the original software. If you use this software
  12. in a product, an acknowledgment in the product documentation would be
  13. appreciated but is not required.
  14. 2. Altered source versions must be plainly marked as such, and must not be
  15. misrepresented as being the original software.
  16. 3. This notice may not be removed or altered from any source distribution.
  17. */
  18. /* !!! FIXME: several functions in here need Doxygen comments. */
  19. /**
  20. * \file SDL_audio.h
  21. *
  22. * Access to the raw audio mixing buffer for the SDL library.
  23. */
  24. #ifndef SDL_audio_h_
  25. #define SDL_audio_h_
  26. #include <SDL3/SDL_stdinc.h>
  27. #include <SDL3/SDL_error.h>
  28. #include <SDL3/SDL_endian.h>
  29. #include <SDL3/SDL_mutex.h>
  30. #include <SDL3/SDL_thread.h>
  31. #include <SDL3/SDL_rwops.h>
  32. #include <SDL3/SDL_begin_code.h>
  33. /* Set up for C function definitions, even when using C++ */
  34. #ifdef __cplusplus
  35. extern "C" {
  36. #endif
  37. /**
  38. * \brief Audio format flags.
  39. *
  40. * These are what the 16 bits in SDL_AudioFormat currently mean...
  41. * (Unspecified bits are always zero).
  42. *
  43. * \verbatim
  44. ++-----------------------sample is signed if set
  45. ||
  46. || ++-----------sample is bigendian if set
  47. || ||
  48. || || ++---sample is float if set
  49. || || ||
  50. || || || +---sample bit size---+
  51. || || || | |
  52. 15 14 13 12 11 10 09 08 07 06 05 04 03 02 01 00
  53. \endverbatim
  54. *
  55. * There are macros in SDL 2.0 and later to query these bits.
  56. */
  57. typedef Uint16 SDL_AudioFormat;
  58. /**
  59. * \name Audio flags
  60. */
  61. /* @{ */
  62. #define SDL_AUDIO_MASK_BITSIZE (0xFF)
  63. #define SDL_AUDIO_MASK_DATATYPE (1<<8)
  64. #define SDL_AUDIO_MASK_ENDIAN (1<<12)
  65. #define SDL_AUDIO_MASK_SIGNED (1<<15)
  66. #define SDL_AUDIO_BITSIZE(x) (x & SDL_AUDIO_MASK_BITSIZE)
  67. #define SDL_AUDIO_ISFLOAT(x) (x & SDL_AUDIO_MASK_DATATYPE)
  68. #define SDL_AUDIO_ISBIGENDIAN(x) (x & SDL_AUDIO_MASK_ENDIAN)
  69. #define SDL_AUDIO_ISSIGNED(x) (x & SDL_AUDIO_MASK_SIGNED)
  70. #define SDL_AUDIO_ISINT(x) (!SDL_AUDIO_ISFLOAT(x))
  71. #define SDL_AUDIO_ISLITTLEENDIAN(x) (!SDL_AUDIO_ISBIGENDIAN(x))
  72. #define SDL_AUDIO_ISUNSIGNED(x) (!SDL_AUDIO_ISSIGNED(x))
  73. /**
  74. * \name Audio format flags
  75. *
  76. * Defaults to LSB byte order.
  77. */
  78. /* @{ */
  79. #define AUDIO_U8 0x0008 /**< Unsigned 8-bit samples */
  80. #define AUDIO_S8 0x8008 /**< Signed 8-bit samples */
  81. #define AUDIO_U16LSB 0x0010 /**< Unsigned 16-bit samples */
  82. #define AUDIO_S16LSB 0x8010 /**< Signed 16-bit samples */
  83. #define AUDIO_U16MSB 0x1010 /**< As above, but big-endian byte order */
  84. #define AUDIO_S16MSB 0x9010 /**< As above, but big-endian byte order */
  85. #define AUDIO_U16 AUDIO_U16LSB
  86. #define AUDIO_S16 AUDIO_S16LSB
  87. /* @} */
  88. /**
  89. * \name int32 support
  90. */
  91. /* @{ */
  92. #define AUDIO_S32LSB 0x8020 /**< 32-bit integer samples */
  93. #define AUDIO_S32MSB 0x9020 /**< As above, but big-endian byte order */
  94. #define AUDIO_S32 AUDIO_S32LSB
  95. /* @} */
  96. /**
  97. * \name float32 support
  98. */
  99. /* @{ */
  100. #define AUDIO_F32LSB 0x8120 /**< 32-bit floating point samples */
  101. #define AUDIO_F32MSB 0x9120 /**< As above, but big-endian byte order */
  102. #define AUDIO_F32 AUDIO_F32LSB
  103. /* @} */
  104. /**
  105. * \name Native audio byte ordering
  106. */
  107. /* @{ */
  108. #if SDL_BYTEORDER == SDL_LIL_ENDIAN
  109. #define AUDIO_U16SYS AUDIO_U16LSB
  110. #define AUDIO_S16SYS AUDIO_S16LSB
  111. #define AUDIO_S32SYS AUDIO_S32LSB
  112. #define AUDIO_F32SYS AUDIO_F32LSB
  113. #else
  114. #define AUDIO_U16SYS AUDIO_U16MSB
  115. #define AUDIO_S16SYS AUDIO_S16MSB
  116. #define AUDIO_S32SYS AUDIO_S32MSB
  117. #define AUDIO_F32SYS AUDIO_F32MSB
  118. #endif
  119. /* @} */
  120. /**
  121. * \name Allow change flags
  122. *
  123. * Which audio format changes are allowed when opening a device.
  124. */
  125. /* @{ */
  126. #define SDL_AUDIO_ALLOW_FREQUENCY_CHANGE 0x00000001
  127. #define SDL_AUDIO_ALLOW_FORMAT_CHANGE 0x00000002
  128. #define SDL_AUDIO_ALLOW_CHANNELS_CHANGE 0x00000004
  129. #define SDL_AUDIO_ALLOW_SAMPLES_CHANGE 0x00000008
  130. #define SDL_AUDIO_ALLOW_ANY_CHANGE (SDL_AUDIO_ALLOW_FREQUENCY_CHANGE|SDL_AUDIO_ALLOW_FORMAT_CHANGE|SDL_AUDIO_ALLOW_CHANNELS_CHANGE|SDL_AUDIO_ALLOW_SAMPLES_CHANGE)
  131. /* @} */
  132. /* @} *//* Audio flags */
  133. /**
  134. * This function is called when the audio device needs more data.
  135. *
  136. * \param userdata An application-specific parameter saved in
  137. * the SDL_AudioSpec structure
  138. * \param stream A pointer to the audio data buffer.
  139. * \param len The length of that buffer in bytes.
  140. *
  141. * Once the callback returns, the buffer will no longer be valid.
  142. * Stereo samples are stored in a LRLRLR ordering.
  143. *
  144. * You can choose to avoid callbacks and use SDL_QueueAudio() instead, if
  145. * you like. Just open your audio device with a NULL callback.
  146. */
  147. typedef void (SDLCALL * SDL_AudioCallback) (void *userdata, Uint8 * stream,
  148. int len);
  149. /**
  150. * The calculated values in this structure are calculated by SDL_OpenAudioDevice().
  151. *
  152. * For multi-channel audio, the default SDL channel mapping is:
  153. * 2: FL FR (stereo)
  154. * 3: FL FR LFE (2.1 surround)
  155. * 4: FL FR BL BR (quad)
  156. * 5: FL FR LFE BL BR (4.1 surround)
  157. * 6: FL FR FC LFE SL SR (5.1 surround - last two can also be BL BR)
  158. * 7: FL FR FC LFE BC SL SR (6.1 surround)
  159. * 8: FL FR FC LFE BL BR SL SR (7.1 surround)
  160. */
  161. typedef struct SDL_AudioSpec
  162. {
  163. int freq; /**< DSP frequency -- samples per second */
  164. SDL_AudioFormat format; /**< Audio data format */
  165. Uint8 channels; /**< Number of channels: 1 mono, 2 stereo */
  166. Uint8 silence; /**< Audio buffer silence value (calculated) */
  167. Uint16 samples; /**< Audio buffer size in sample FRAMES (total samples divided by channel count) */
  168. Uint16 padding; /**< Necessary for some compile environments */
  169. Uint32 size; /**< Audio buffer size in bytes (calculated) */
  170. SDL_AudioCallback callback; /**< Callback that feeds the audio device (NULL to use SDL_QueueAudio()). */
  171. void *userdata; /**< Userdata passed to callback (ignored for NULL callbacks). */
  172. } SDL_AudioSpec;
  173. /* Function prototypes */
  174. /**
  175. * \name Driver discovery functions
  176. *
  177. * These functions return the list of built in audio drivers, in the
  178. * order that they are normally initialized by default.
  179. */
  180. /* @{ */
  181. /**
  182. * Use this function to get the number of built-in audio drivers.
  183. *
  184. * This function returns a hardcoded number. This never returns a negative
  185. * value; if there are no drivers compiled into this build of SDL, this
  186. * function returns zero. The presence of a driver in this list does not mean
  187. * it will function, it just means SDL is capable of interacting with that
  188. * interface. For example, a build of SDL might have esound support, but if
  189. * there's no esound server available, SDL's esound driver would fail if used.
  190. *
  191. * By default, SDL tries all drivers, in its preferred order, until one is
  192. * found to be usable.
  193. *
  194. * \returns the number of built-in audio drivers.
  195. *
  196. * \since This function is available since SDL 3.0.0.
  197. *
  198. * \sa SDL_GetAudioDriver
  199. */
  200. extern DECLSPEC int SDLCALL SDL_GetNumAudioDrivers(void);
  201. /**
  202. * Use this function to get the name of a built in audio driver.
  203. *
  204. * The list of audio drivers is given in the order that they are normally
  205. * initialized by default; the drivers that seem more reasonable to choose
  206. * first (as far as the SDL developers believe) are earlier in the list.
  207. *
  208. * The names of drivers are all simple, low-ASCII identifiers, like "alsa",
  209. * "coreaudio" or "xaudio2". These never have Unicode characters, and are not
  210. * meant to be proper names.
  211. *
  212. * \param index the index of the audio driver; the value ranges from 0 to
  213. * SDL_GetNumAudioDrivers() - 1
  214. * \returns the name of the audio driver at the requested index, or NULL if an
  215. * invalid index was specified.
  216. *
  217. * \since This function is available since SDL 3.0.0.
  218. *
  219. * \sa SDL_GetNumAudioDrivers
  220. */
  221. extern DECLSPEC const char *SDLCALL SDL_GetAudioDriver(int index);
  222. /* @} */
  223. /**
  224. * Get the name of the current audio driver.
  225. *
  226. * The returned string points to internal static memory and thus never becomes
  227. * invalid, even if you quit the audio subsystem and initialize a new driver
  228. * (although such a case would return a different static string from another
  229. * call to this function, of course). As such, you should not modify or free
  230. * the returned string.
  231. *
  232. * \returns the name of the current audio driver or NULL if no driver has been
  233. * initialized.
  234. *
  235. * \since This function is available since SDL 3.0.0.
  236. */
  237. extern DECLSPEC const char *SDLCALL SDL_GetCurrentAudioDriver(void);
  238. /**
  239. * SDL Audio Device IDs.
  240. */
  241. typedef Uint32 SDL_AudioDeviceID;
  242. /**
  243. * Get the number of built-in audio devices.
  244. *
  245. * This function is only valid after successfully initializing the audio
  246. * subsystem.
  247. *
  248. * Note that audio capture support is not implemented as of SDL 2.0.4, so the
  249. * `iscapture` parameter is for future expansion and should always be zero for
  250. * now.
  251. *
  252. * This function will return -1 if an explicit list of devices can't be
  253. * determined. Returning -1 is not an error. For example, if SDL is set up to
  254. * talk to a remote audio server, it can't list every one available on the
  255. * Internet, but it will still allow a specific host to be specified in
  256. * SDL_OpenAudioDevice().
  257. *
  258. * In many common cases, when this function returns a value <= 0, it can still
  259. * successfully open the default device (NULL for first argument of
  260. * SDL_OpenAudioDevice()).
  261. *
  262. * This function may trigger a complete redetect of available hardware. It
  263. * should not be called for each iteration of a loop, but rather once at the
  264. * start of a loop:
  265. *
  266. * ```c
  267. * // Don't do this:
  268. * for (int i = 0; i < SDL_GetNumAudioDevices(0); i++)
  269. *
  270. * // do this instead:
  271. * const int count = SDL_GetNumAudioDevices(0);
  272. * for (int i = 0; i < count; ++i) { do_something_here(); }
  273. * ```
  274. *
  275. * \param iscapture zero to request playback devices, non-zero to request
  276. * recording devices
  277. * \returns the number of available devices exposed by the current driver or
  278. * -1 if an explicit list of devices can't be determined. A return
  279. * value of -1 does not necessarily mean an error condition.
  280. *
  281. * \since This function is available since SDL 3.0.0.
  282. *
  283. * \sa SDL_GetAudioDeviceName
  284. * \sa SDL_OpenAudioDevice
  285. */
  286. extern DECLSPEC int SDLCALL SDL_GetNumAudioDevices(int iscapture);
  287. /**
  288. * Get the human-readable name of a specific audio device.
  289. *
  290. * This function is only valid after successfully initializing the audio
  291. * subsystem. The values returned by this function reflect the latest call to
  292. * SDL_GetNumAudioDevices(); re-call that function to redetect available
  293. * hardware.
  294. *
  295. * The string returned by this function is UTF-8 encoded, read-only, and
  296. * managed internally. You are not to free it. If you need to keep the string
  297. * for any length of time, you should make your own copy of it, as it will be
  298. * invalid next time any of several other SDL functions are called.
  299. *
  300. * \param index the index of the audio device; valid values range from 0 to
  301. * SDL_GetNumAudioDevices() - 1
  302. * \param iscapture non-zero to query the list of recording devices, zero to
  303. * query the list of output devices.
  304. * \returns the name of the audio device at the requested index, or NULL on
  305. * error.
  306. *
  307. * \since This function is available since SDL 3.0.0.
  308. *
  309. * \sa SDL_GetNumAudioDevices
  310. * \sa SDL_GetDefaultAudioInfo
  311. */
  312. extern DECLSPEC const char *SDLCALL SDL_GetAudioDeviceName(int index,
  313. int iscapture);
  314. /**
  315. * Get the preferred audio format of a specific audio device.
  316. *
  317. * This function is only valid after a successfully initializing the audio
  318. * subsystem. The values returned by this function reflect the latest call to
  319. * SDL_GetNumAudioDevices(); re-call that function to redetect available
  320. * hardware.
  321. *
  322. * `spec` will be filled with the sample rate, sample format, and channel
  323. * count.
  324. *
  325. * \param index the index of the audio device; valid values range from 0 to
  326. * SDL_GetNumAudioDevices() - 1
  327. * \param iscapture non-zero to query the list of recording devices, zero to
  328. * query the list of output devices.
  329. * \param spec The SDL_AudioSpec to be initialized by this function.
  330. * \returns 0 on success, nonzero on error
  331. *
  332. * \since This function is available since SDL 3.0.0.
  333. *
  334. * \sa SDL_GetNumAudioDevices
  335. * \sa SDL_GetDefaultAudioInfo
  336. */
  337. extern DECLSPEC int SDLCALL SDL_GetAudioDeviceSpec(int index,
  338. int iscapture,
  339. SDL_AudioSpec *spec);
  340. /**
  341. * Get the name and preferred format of the default audio device.
  342. *
  343. * Some (but not all!) platforms have an isolated mechanism to get information
  344. * about the "default" device. This can actually be a completely different
  345. * device that's not in the list you get from SDL_GetAudioDeviceSpec(). It can
  346. * even be a network address! (This is discussed in SDL_OpenAudioDevice().)
  347. *
  348. * As a result, this call is not guaranteed to be performant, as it can query
  349. * the sound server directly every time, unlike the other query functions. You
  350. * should call this function sparingly!
  351. *
  352. * `spec` will be filled with the sample rate, sample format, and channel
  353. * count, if a default device exists on the system. If `name` is provided,
  354. * will be filled with either a dynamically-allocated UTF-8 string or NULL.
  355. *
  356. * \param name A pointer to be filled with the name of the default device (can
  357. * be NULL). Please call SDL_free() when you are done with this
  358. * pointer!
  359. * \param spec The SDL_AudioSpec to be initialized by this function.
  360. * \param iscapture non-zero to query the default recording device, zero to
  361. * query the default output device.
  362. * \returns 0 on success, nonzero on error
  363. *
  364. * \since This function is available since SDL 3.0.0.
  365. *
  366. * \sa SDL_GetAudioDeviceName
  367. * \sa SDL_GetAudioDeviceSpec
  368. * \sa SDL_OpenAudioDevice
  369. */
  370. extern DECLSPEC int SDLCALL SDL_GetDefaultAudioInfo(char **name,
  371. SDL_AudioSpec *spec,
  372. int iscapture);
  373. /**
  374. * Open a specific audio device.
  375. *
  376. * Passing in a `device` name of NULL requests the most reasonable default.
  377. * The `device` name is a UTF-8 string reported by SDL_GetAudioDeviceName(),
  378. * but some drivers allow arbitrary and driver-specific strings, such as a
  379. * hostname/IP address for a remote audio server, or a filename in the
  380. * diskaudio driver.
  381. *
  382. * An opened audio device starts out paused, and should be enabled for playing
  383. * by calling SDL_PlayAudioDevice(devid) when you are ready for your audio
  384. * callback function to be called. Since the audio driver may modify the
  385. * requested size of the audio buffer, you should allocate any local mixing
  386. * buffers after you open the audio device.
  387. *
  388. * The audio callback runs in a separate thread in most cases; you can prevent
  389. * race conditions between your callback and other threads without fully
  390. * pausing playback with SDL_LockAudioDevice(). For more information about the
  391. * callback, see SDL_AudioSpec.
  392. *
  393. * Managing the audio spec via 'desired' and 'obtained':
  394. *
  395. * When filling in the desired audio spec structure:
  396. *
  397. * - `desired->freq` should be the frequency in sample-frames-per-second (Hz).
  398. * - `desired->format` should be the audio format (`AUDIO_S16SYS`, etc).
  399. * - `desired->samples` is the desired size of the audio buffer, in _sample
  400. * frames_ (with stereo output, two samples--left and right--would make a
  401. * single sample frame). This number should be a power of two, and may be
  402. * adjusted by the audio driver to a value more suitable for the hardware.
  403. * Good values seem to range between 512 and 8096 inclusive, depending on
  404. * the application and CPU speed. Smaller values reduce latency, but can
  405. * lead to underflow if the application is doing heavy processing and cannot
  406. * fill the audio buffer in time. Note that the number of sample frames is
  407. * directly related to time by the following formula: `ms =
  408. * (sampleframes*1000)/freq`
  409. * - `desired->size` is the size in _bytes_ of the audio buffer, and is
  410. * calculated by SDL_OpenAudioDevice(). You don't initialize this.
  411. * - `desired->silence` is the value used to set the buffer to silence, and is
  412. * calculated by SDL_OpenAudioDevice(). You don't initialize this.
  413. * - `desired->callback` should be set to a function that will be called when
  414. * the audio device is ready for more data. It is passed a pointer to the
  415. * audio buffer, and the length in bytes of the audio buffer. This function
  416. * usually runs in a separate thread, and so you should protect data
  417. * structures that it accesses by calling SDL_LockAudioDevice() and
  418. * SDL_UnlockAudioDevice() in your code. Alternately, you may pass a NULL
  419. * pointer here, and call SDL_QueueAudio() with some frequency, to queue
  420. * more audio samples to be played (or for capture devices, call
  421. * SDL_DequeueAudio() with some frequency, to obtain audio samples).
  422. * - `desired->userdata` is passed as the first parameter to your callback
  423. * function. If you passed a NULL callback, this value is ignored.
  424. *
  425. * `allowed_changes` can have the following flags OR'd together:
  426. *
  427. * - `SDL_AUDIO_ALLOW_FREQUENCY_CHANGE`
  428. * - `SDL_AUDIO_ALLOW_FORMAT_CHANGE`
  429. * - `SDL_AUDIO_ALLOW_CHANNELS_CHANGE`
  430. * - `SDL_AUDIO_ALLOW_SAMPLES_CHANGE`
  431. * - `SDL_AUDIO_ALLOW_ANY_CHANGE`
  432. *
  433. * These flags specify how SDL should behave when a device cannot offer a
  434. * specific feature. If the application requests a feature that the hardware
  435. * doesn't offer, SDL will always try to get the closest equivalent.
  436. *
  437. * For example, if you ask for float32 audio format, but the sound card only
  438. * supports int16, SDL will set the hardware to int16. If you had set
  439. * SDL_AUDIO_ALLOW_FORMAT_CHANGE, SDL will change the format in the `obtained`
  440. * structure. If that flag was *not* set, SDL will prepare to convert your
  441. * callback's float32 audio to int16 before feeding it to the hardware and
  442. * will keep the originally requested format in the `obtained` structure.
  443. *
  444. * The resulting audio specs, varying depending on hardware and on what
  445. * changes were allowed, will then be written back to `obtained`.
  446. *
  447. * If your application can only handle one specific data format, pass a zero
  448. * for `allowed_changes` and let SDL transparently handle any differences.
  449. *
  450. * \param device a UTF-8 string reported by SDL_GetAudioDeviceName() or a
  451. * driver-specific name as appropriate. NULL requests the most
  452. * reasonable default device.
  453. * \param iscapture non-zero to specify a device should be opened for
  454. * recording, not playback
  455. * \param desired an SDL_AudioSpec structure representing the desired output
  456. * format
  457. * \param obtained an SDL_AudioSpec structure filled in with the actual output
  458. * format
  459. * \param allowed_changes 0, or one or more flags OR'd together
  460. * \returns a valid device ID that is > 0 on success or 0 on failure; call
  461. * SDL_GetError() for more information.
  462. *
  463. * For compatibility with SDL 1.2, this will never return 1, since
  464. * SDL reserves that ID for the legacy SDL_OpenAudio() function.
  465. *
  466. * \since This function is available since SDL 3.0.0.
  467. *
  468. * \sa SDL_CloseAudioDevice
  469. * \sa SDL_GetAudioDeviceName
  470. * \sa SDL_LockAudioDevice
  471. * \sa SDL_PlayAudioDevice
  472. * \sa SDL_PauseAudioDevice
  473. * \sa SDL_UnlockAudioDevice
  474. */
  475. extern DECLSPEC SDL_AudioDeviceID SDLCALL SDL_OpenAudioDevice(
  476. const char *device,
  477. int iscapture,
  478. const SDL_AudioSpec *desired,
  479. SDL_AudioSpec *obtained,
  480. int allowed_changes);
  481. /**
  482. * \name Audio state
  483. *
  484. * Get the current audio state.
  485. */
  486. /* @{ */
  487. typedef enum
  488. {
  489. SDL_AUDIO_STOPPED = 0,
  490. SDL_AUDIO_PLAYING,
  491. SDL_AUDIO_PAUSED
  492. } SDL_AudioStatus;
  493. /**
  494. * Use this function to get the current audio state of an audio device.
  495. *
  496. * \param dev the ID of an audio device previously opened with
  497. * SDL_OpenAudioDevice()
  498. * \returns the SDL_AudioStatus of the specified audio device.
  499. *
  500. * \since This function is available since SDL 3.0.0.
  501. *
  502. * \sa SDL_PlayAudioDevice
  503. * \sa SDL_PauseAudioDevice
  504. */
  505. extern DECLSPEC SDL_AudioStatus SDLCALL SDL_GetAudioDeviceStatus(SDL_AudioDeviceID dev);
  506. /* @} *//* Audio State */
  507. /**
  508. * Use this function to play audio on a specified device.
  509. *
  510. * Newly-opened audio devices start in the paused state, so you must call this
  511. * function after opening the specified audio device to start playing sound.
  512. * This allows you to safely initialize data for your callback function after
  513. * opening the audio device. Silence will be written to the audio device while
  514. * paused, and the audio callback is guaranteed to not be called. Pausing one
  515. * device does not prevent other unpaused devices from running their
  516. * callbacks.
  517. *
  518. * \param dev a device opened by SDL_OpenAudioDevice()
  519. *
  520. * \since This function is available since SDL 3.0.0.
  521. *
  522. * \sa SDL_LockAudioDevice
  523. * \sa SDL_PauseAudioDevice
  524. */
  525. extern DECLSPEC void SDLCALL SDL_PlayAudioDevice(SDL_AudioDeviceID dev);
  526. /**
  527. * Use this function to pause audio playback on a specified device.
  528. *
  529. * This function pauses the audio callback processing for a given device.
  530. * Silence will be written to the audio device while paused, and the audio
  531. * callback is guaranteed to not be called. Pausing one device does not
  532. * prevent other unpaused devices from running their callbacks.
  533. *
  534. * If you just need to protect a few variables from race conditions vs your
  535. * callback, you shouldn't pause the audio device, as it will lead to dropouts
  536. * in the audio playback. Instead, you should use SDL_LockAudioDevice().
  537. *
  538. * \param dev a device opened by SDL_OpenAudioDevice()
  539. *
  540. * \since This function is available since SDL 3.0.0.
  541. *
  542. * \sa SDL_LockAudioDevice
  543. * \sa SDL_PlayAudioDevice
  544. */
  545. extern DECLSPEC void SDLCALL SDL_PauseAudioDevice(SDL_AudioDeviceID dev);
  546. /**
  547. * Load the audio data of a WAVE file into memory.
  548. *
  549. * Loading a WAVE file requires `src`, `spec`, `audio_buf` and `audio_len` to
  550. * be valid pointers. The entire data portion of the file is then loaded into
  551. * memory and decoded if necessary.
  552. *
  553. * If `freesrc` is non-zero, the data source gets automatically closed and
  554. * freed before the function returns.
  555. *
  556. * Supported formats are RIFF WAVE files with the formats PCM (8, 16, 24, and
  557. * 32 bits), IEEE Float (32 bits), Microsoft ADPCM and IMA ADPCM (4 bits), and
  558. * A-law and mu-law (8 bits). Other formats are currently unsupported and
  559. * cause an error.
  560. *
  561. * If this function succeeds, the pointer returned by it is equal to `spec`
  562. * and the pointer to the audio data allocated by the function is written to
  563. * `audio_buf` and its length in bytes to `audio_len`. The SDL_AudioSpec
  564. * members `freq`, `channels`, and `format` are set to the values of the audio
  565. * data in the buffer. The `samples` member is set to a sane default and all
  566. * others are set to zero.
  567. *
  568. * It's necessary to use SDL_free() to free the audio data returned in
  569. * `audio_buf` when it is no longer used.
  570. *
  571. * Because of the underspecification of the .WAV format, there are many
  572. * problematic files in the wild that cause issues with strict decoders. To
  573. * provide compatibility with these files, this decoder is lenient in regards
  574. * to the truncation of the file, the fact chunk, and the size of the RIFF
  575. * chunk. The hints `SDL_HINT_WAVE_RIFF_CHUNK_SIZE`,
  576. * `SDL_HINT_WAVE_TRUNCATION`, and `SDL_HINT_WAVE_FACT_CHUNK` can be used to
  577. * tune the behavior of the loading process.
  578. *
  579. * Any file that is invalid (due to truncation, corruption, or wrong values in
  580. * the headers), too big, or unsupported causes an error. Additionally, any
  581. * critical I/O error from the data source will terminate the loading process
  582. * with an error. The function returns NULL on error and in all cases (with
  583. * the exception of `src` being NULL), an appropriate error message will be
  584. * set.
  585. *
  586. * It is required that the data source supports seeking.
  587. *
  588. * Example:
  589. *
  590. * ```c
  591. * SDL_LoadWAV_RW(SDL_RWFromFile("sample.wav", "rb"), 1, &spec, &buf, &len);
  592. * ```
  593. *
  594. * Note that the SDL_LoadWAV macro does this same thing for you, but in a less
  595. * messy way:
  596. *
  597. * ```c
  598. * SDL_LoadWAV("sample.wav", &spec, &buf, &len);
  599. * ```
  600. *
  601. * \param src The data source for the WAVE data
  602. * \param freesrc If non-zero, SDL will _always_ free the data source
  603. * \param spec An SDL_AudioSpec that will be filled in with the wave file's
  604. * format details
  605. * \param audio_buf A pointer filled with the audio data, allocated by the
  606. * function.
  607. * \param audio_len A pointer filled with the length of the audio data buffer
  608. * in bytes
  609. * \returns This function, if successfully called, returns `spec`, which will
  610. * be filled with the audio data format of the wave source data.
  611. * `audio_buf` will be filled with a pointer to an allocated buffer
  612. * containing the audio data, and `audio_len` is filled with the
  613. * length of that audio buffer in bytes.
  614. *
  615. * This function returns NULL if the .WAV file cannot be opened, uses
  616. * an unknown data format, or is corrupt; call SDL_GetError() for
  617. * more information.
  618. *
  619. * When the application is done with the data returned in
  620. * `audio_buf`, it should call SDL_free() to dispose of it.
  621. *
  622. * \since This function is available since SDL 3.0.0.
  623. *
  624. * \sa SDL_free
  625. * \sa SDL_LoadWAV
  626. */
  627. extern DECLSPEC SDL_AudioSpec *SDLCALL SDL_LoadWAV_RW(SDL_RWops * src,
  628. int freesrc,
  629. SDL_AudioSpec * spec,
  630. Uint8 ** audio_buf,
  631. Uint32 * audio_len);
  632. /**
  633. * Loads a WAV from a file.
  634. * Compatibility convenience function.
  635. */
  636. #define SDL_LoadWAV(file, spec, audio_buf, audio_len) \
  637. SDL_LoadWAV_RW(SDL_RWFromFile(file, "rb"),1, spec,audio_buf,audio_len)
  638. /* SDL_AudioStream is a new audio conversion interface.
  639. The benefits vs SDL_AudioCVT:
  640. - it can handle resampling data in chunks without generating
  641. artifacts, when it doesn't have the complete buffer available.
  642. - it can handle incoming data in any variable size.
  643. - You push data as you have it, and pull it when you need it
  644. */
  645. /* this is opaque to the outside world. */
  646. struct SDL_AudioStream;
  647. typedef struct SDL_AudioStream SDL_AudioStream;
  648. /**
  649. * Create a new audio stream.
  650. *
  651. * \param src_format The format of the source audio
  652. * \param src_channels The number of channels of the source audio
  653. * \param src_rate The sampling rate of the source audio
  654. * \param dst_format The format of the desired audio output
  655. * \param dst_channels The number of channels of the desired audio output
  656. * \param dst_rate The sampling rate of the desired audio output
  657. * \returns 0 on success, or -1 on error.
  658. *
  659. * \since This function is available since SDL 3.0.0.
  660. *
  661. * \sa SDL_PutAudioStreamData
  662. * \sa SDL_GetAudioStreamData
  663. * \sa SDL_GetAudioStreamAvailable
  664. * \sa SDL_FlushAudioStream
  665. * \sa SDL_ClearAudioStream
  666. * \sa SDL_DestroyAudioStream
  667. */
  668. extern DECLSPEC SDL_AudioStream *SDLCALL SDL_CreateAudioStream(SDL_AudioFormat src_format,
  669. Uint8 src_channels,
  670. int src_rate,
  671. SDL_AudioFormat dst_format,
  672. Uint8 dst_channels,
  673. int dst_rate);
  674. /**
  675. * Add data to be converted/resampled to the stream.
  676. *
  677. * \param stream The stream the audio data is being added to
  678. * \param buf A pointer to the audio data to add
  679. * \param len The number of bytes to write to the stream
  680. * \returns 0 on success, or -1 on error.
  681. *
  682. * \since This function is available since SDL 3.0.0.
  683. *
  684. * \sa SDL_CreateAudioStream
  685. * \sa SDL_GetAudioStreamData
  686. * \sa SDL_GetAudioStreamAvailable
  687. * \sa SDL_FlushAudioStream
  688. * \sa SDL_ClearAudioStream
  689. * \sa SDL_DestroyAudioStream
  690. */
  691. extern DECLSPEC int SDLCALL SDL_PutAudioStreamData(SDL_AudioStream *stream, const void *buf, int len);
  692. /**
  693. * Get converted/resampled data from the stream
  694. *
  695. * \param stream The stream the audio is being requested from
  696. * \param buf A buffer to fill with audio data
  697. * \param len The maximum number of bytes to fill
  698. * \returns the number of bytes read from the stream, or -1 on error
  699. *
  700. * \since This function is available since SDL 3.0.0.
  701. *
  702. * \sa SDL_CreateAudioStream
  703. * \sa SDL_PutAudioStreamData
  704. * \sa SDL_GetAudioStreamAvailable
  705. * \sa SDL_FlushAudioStream
  706. * \sa SDL_ClearAudioStream
  707. * \sa SDL_DestroyAudioStream
  708. */
  709. extern DECLSPEC int SDLCALL SDL_GetAudioStreamData(SDL_AudioStream *stream, void *buf, int len);
  710. /**
  711. * Get the number of converted/resampled bytes available.
  712. *
  713. * The stream may be buffering data behind the scenes until it has enough to
  714. * resample correctly, so this number might be lower than what you expect, or
  715. * even be zero. Add more data or flush the stream if you need the data now.
  716. *
  717. * \since This function is available since SDL 3.0.0.
  718. *
  719. * \sa SDL_CreateAudioStream
  720. * \sa SDL_PutAudioStreamData
  721. * \sa SDL_GetAudioStreamData
  722. * \sa SDL_FlushAudioStream
  723. * \sa SDL_ClearAudioStream
  724. * \sa SDL_DestroyAudioStream
  725. */
  726. extern DECLSPEC int SDLCALL SDL_GetAudioStreamAvailable(SDL_AudioStream *stream);
  727. /**
  728. * Tell the stream that you're done sending data, and anything being buffered
  729. * should be converted/resampled and made available immediately.
  730. *
  731. * It is legal to add more data to a stream after flushing, but there will be
  732. * audio gaps in the output. Generally this is intended to signal the end of
  733. * input, so the complete output becomes available.
  734. *
  735. * \since This function is available since SDL 3.0.0.
  736. *
  737. * \sa SDL_CreateAudioStream
  738. * \sa SDL_PutAudioStreamData
  739. * \sa SDL_GetAudioStreamData
  740. * \sa SDL_GetAudioStreamAvailable
  741. * \sa SDL_ClearAudioStream
  742. * \sa SDL_DestroyAudioStream
  743. */
  744. extern DECLSPEC int SDLCALL SDL_FlushAudioStream(SDL_AudioStream *stream);
  745. /**
  746. * Clear any pending data in the stream without converting it
  747. *
  748. * \since This function is available since SDL 3.0.0.
  749. *
  750. * \sa SDL_CreateAudioStream
  751. * \sa SDL_PutAudioStreamData
  752. * \sa SDL_GetAudioStreamData
  753. * \sa SDL_GetAudioStreamAvailable
  754. * \sa SDL_FlushAudioStream
  755. * \sa SDL_DestroyAudioStream
  756. */
  757. extern DECLSPEC void SDLCALL SDL_ClearAudioStream(SDL_AudioStream *stream);
  758. /**
  759. * Free an audio stream
  760. *
  761. * \since This function is available since SDL 3.0.0.
  762. *
  763. * \sa SDL_CreateAudioStream
  764. * \sa SDL_PutAudioStreamData
  765. * \sa SDL_GetAudioStreamData
  766. * \sa SDL_GetAudioStreamAvailable
  767. * \sa SDL_FlushAudioStream
  768. * \sa SDL_ClearAudioStream
  769. */
  770. extern DECLSPEC void SDLCALL SDL_DestroyAudioStream(SDL_AudioStream *stream);
  771. #define SDL_MIX_MAXVOLUME 128
  772. /**
  773. * Mix audio data in a specified format.
  774. *
  775. * This takes an audio buffer `src` of `len` bytes of `format` data and mixes
  776. * it into `dst`, performing addition, volume adjustment, and overflow
  777. * clipping. The buffer pointed to by `dst` must also be `len` bytes of
  778. * `format` data.
  779. *
  780. * This is provided for convenience -- you can mix your own audio data.
  781. *
  782. * Do not use this function for mixing together more than two streams of
  783. * sample data. The output from repeated application of this function may be
  784. * distorted by clipping, because there is no accumulator with greater range
  785. * than the input (not to mention this being an inefficient way of doing it).
  786. *
  787. * It is a common misconception that this function is required to write audio
  788. * data to an output stream in an audio callback. While you can do that,
  789. * SDL_MixAudioFormat() is really only needed when you're mixing a single
  790. * audio stream with a volume adjustment.
  791. *
  792. * \param dst the destination for the mixed audio
  793. * \param src the source audio buffer to be mixed
  794. * \param format the SDL_AudioFormat structure representing the desired audio
  795. * format
  796. * \param len the length of the audio buffer in bytes
  797. * \param volume ranges from 0 - 128, and should be set to SDL_MIX_MAXVOLUME
  798. * for full audio volume
  799. *
  800. * \since This function is available since SDL 3.0.0.
  801. */
  802. extern DECLSPEC void SDLCALL SDL_MixAudioFormat(Uint8 * dst,
  803. const Uint8 * src,
  804. SDL_AudioFormat format,
  805. Uint32 len, int volume);
  806. /**
  807. * Queue more audio on non-callback devices.
  808. *
  809. * If you are looking to retrieve queued audio from a non-callback capture
  810. * device, you want SDL_DequeueAudio() instead. SDL_QueueAudio() will return
  811. * -1 to signify an error if you use it with capture devices.
  812. *
  813. * SDL offers two ways to feed audio to the device: you can either supply a
  814. * callback that SDL triggers with some frequency to obtain more audio (pull
  815. * method), or you can supply no callback, and then SDL will expect you to
  816. * supply data at regular intervals (push method) with this function.
  817. *
  818. * There are no limits on the amount of data you can queue, short of
  819. * exhaustion of address space. Queued data will drain to the device as
  820. * necessary without further intervention from you. If the device needs audio
  821. * but there is not enough queued, it will play silence to make up the
  822. * difference. This means you will have skips in your audio playback if you
  823. * aren't routinely queueing sufficient data.
  824. *
  825. * This function copies the supplied data, so you are safe to free it when the
  826. * function returns. This function is thread-safe, but queueing to the same
  827. * device from two threads at once does not promise which buffer will be
  828. * queued first.
  829. *
  830. * You may not queue audio on a device that is using an application-supplied
  831. * callback; doing so returns an error. You have to use the audio callback or
  832. * queue audio with this function, but not both.
  833. *
  834. * You should not call SDL_LockAudio() on the device before queueing; SDL
  835. * handles locking internally for this function.
  836. *
  837. * Note that SDL does not support planar audio. You will need to resample from
  838. * planar audio formats into a non-planar one (see SDL_AudioFormat) before
  839. * queuing audio.
  840. *
  841. * \param dev the device ID to which we will queue audio
  842. * \param data the data to queue to the device for later playback
  843. * \param len the number of bytes (not samples!) to which `data` points
  844. * \returns 0 on success or a negative error code on failure; call
  845. * SDL_GetError() for more information.
  846. *
  847. * \since This function is available since SDL 3.0.0.
  848. *
  849. * \sa SDL_ClearQueuedAudio
  850. * \sa SDL_GetQueuedAudioSize
  851. */
  852. extern DECLSPEC int SDLCALL SDL_QueueAudio(SDL_AudioDeviceID dev, const void *data, Uint32 len);
  853. /**
  854. * Dequeue more audio on non-callback devices.
  855. *
  856. * If you are looking to queue audio for output on a non-callback playback
  857. * device, you want SDL_QueueAudio() instead. SDL_DequeueAudio() will always
  858. * return 0 if you use it with playback devices.
  859. *
  860. * SDL offers two ways to retrieve audio from a capture device: you can either
  861. * supply a callback that SDL triggers with some frequency as the device
  862. * records more audio data, (push method), or you can supply no callback, and
  863. * then SDL will expect you to retrieve data at regular intervals (pull
  864. * method) with this function.
  865. *
  866. * There are no limits on the amount of data you can queue, short of
  867. * exhaustion of address space. Data from the device will keep queuing as
  868. * necessary without further intervention from you. This means you will
  869. * eventually run out of memory if you aren't routinely dequeueing data.
  870. *
  871. * Capture devices will not queue data when paused; if you are expecting to
  872. * not need captured audio for some length of time, use SDL_PauseAudioDevice()
  873. * to stop the capture device from queueing more data. This can be useful
  874. * during, say, level loading times. When unpaused, capture devices will start
  875. * queueing data from that point, having flushed any capturable data available
  876. * while paused.
  877. *
  878. * This function is thread-safe, but dequeueing from the same device from two
  879. * threads at once does not promise which thread will dequeue data first.
  880. *
  881. * You may not dequeue audio from a device that is using an
  882. * application-supplied callback; doing so returns an error. You have to use
  883. * the audio callback, or dequeue audio with this function, but not both.
  884. *
  885. * You should not call SDL_LockAudio() on the device before dequeueing; SDL
  886. * handles locking internally for this function.
  887. *
  888. * \param dev the device ID from which we will dequeue audio
  889. * \param data a pointer into where audio data should be copied
  890. * \param len the number of bytes (not samples!) to which (data) points
  891. * \returns the number of bytes dequeued, which could be less than requested;
  892. * call SDL_GetError() for more information.
  893. *
  894. * \since This function is available since SDL 3.0.0.
  895. *
  896. * \sa SDL_ClearQueuedAudio
  897. * \sa SDL_GetQueuedAudioSize
  898. */
  899. extern DECLSPEC Uint32 SDLCALL SDL_DequeueAudio(SDL_AudioDeviceID dev, void *data, Uint32 len);
  900. /**
  901. * Get the number of bytes of still-queued audio.
  902. *
  903. * For playback devices: this is the number of bytes that have been queued for
  904. * playback with SDL_QueueAudio(), but have not yet been sent to the hardware.
  905. *
  906. * Once we've sent it to the hardware, this function can not decide the exact
  907. * byte boundary of what has been played. It's possible that we just gave the
  908. * hardware several kilobytes right before you called this function, but it
  909. * hasn't played any of it yet, or maybe half of it, etc.
  910. *
  911. * For capture devices, this is the number of bytes that have been captured by
  912. * the device and are waiting for you to dequeue. This number may grow at any
  913. * time, so this only informs of the lower-bound of available data.
  914. *
  915. * You may not queue or dequeue audio on a device that is using an
  916. * application-supplied callback; calling this function on such a device
  917. * always returns 0. You have to use the audio callback or queue audio, but
  918. * not both.
  919. *
  920. * You should not call SDL_LockAudio() on the device before querying; SDL
  921. * handles locking internally for this function.
  922. *
  923. * \param dev the device ID of which we will query queued audio size
  924. * \returns the number of bytes (not samples!) of queued audio.
  925. *
  926. * \since This function is available since SDL 3.0.0.
  927. *
  928. * \sa SDL_ClearQueuedAudio
  929. * \sa SDL_QueueAudio
  930. * \sa SDL_DequeueAudio
  931. */
  932. extern DECLSPEC Uint32 SDLCALL SDL_GetQueuedAudioSize(SDL_AudioDeviceID dev);
  933. /**
  934. * Drop any queued audio data waiting to be sent to the hardware.
  935. *
  936. * Immediately after this call, SDL_GetQueuedAudioSize() will return 0. For
  937. * output devices, the hardware will start playing silence if more audio isn't
  938. * queued. For capture devices, the hardware will start filling the empty
  939. * queue with new data if the capture device isn't paused.
  940. *
  941. * This will not prevent playback of queued audio that's already been sent to
  942. * the hardware, as we can not undo that, so expect there to be some fraction
  943. * of a second of audio that might still be heard. This can be useful if you
  944. * want to, say, drop any pending music or any unprocessed microphone input
  945. * during a level change in your game.
  946. *
  947. * You may not queue or dequeue audio on a device that is using an
  948. * application-supplied callback; calling this function on such a device
  949. * always returns 0. You have to use the audio callback or queue audio, but
  950. * not both.
  951. *
  952. * You should not call SDL_LockAudio() on the device before clearing the
  953. * queue; SDL handles locking internally for this function.
  954. *
  955. * This function always succeeds and thus returns void.
  956. *
  957. * \param dev the device ID of which to clear the audio queue
  958. *
  959. * \since This function is available since SDL 3.0.0.
  960. *
  961. * \sa SDL_GetQueuedAudioSize
  962. * \sa SDL_QueueAudio
  963. * \sa SDL_DequeueAudio
  964. */
  965. extern DECLSPEC void SDLCALL SDL_ClearQueuedAudio(SDL_AudioDeviceID dev);
  966. /**
  967. * \name Audio lock functions
  968. *
  969. * The lock manipulated by these functions protects the callback function.
  970. * During a SDL_LockAudio()/SDL_UnlockAudio() pair, you can be guaranteed that
  971. * the callback function is not running. Do not call these from the callback
  972. * function or you will cause deadlock.
  973. */
  974. /* @{ */
  975. /**
  976. * Use this function to lock out the audio callback function for a specified
  977. * device.
  978. *
  979. * The lock manipulated by these functions protects the audio callback
  980. * function specified in SDL_OpenAudioDevice(). During a
  981. * SDL_LockAudioDevice()/SDL_UnlockAudioDevice() pair, you can be guaranteed
  982. * that the callback function for that device is not running, even if the
  983. * device is not paused. While a device is locked, any other unpaused,
  984. * unlocked devices may still run their callbacks.
  985. *
  986. * Calling this function from inside your audio callback is unnecessary. SDL
  987. * obtains this lock before calling your function, and releases it when the
  988. * function returns.
  989. *
  990. * You should not hold the lock longer than absolutely necessary. If you hold
  991. * it too long, you'll experience dropouts in your audio playback. Ideally,
  992. * your application locks the device, sets a few variables and unlocks again.
  993. * Do not do heavy work while holding the lock for a device.
  994. *
  995. * It is safe to lock the audio device multiple times, as long as you unlock
  996. * it an equivalent number of times. The callback will not run until the
  997. * device has been unlocked completely in this way. If your application fails
  998. * to unlock the device appropriately, your callback will never run, you might
  999. * hear repeating bursts of audio, and SDL_CloseAudioDevice() will probably
  1000. * deadlock.
  1001. *
  1002. * Internally, the audio device lock is a mutex; if you lock from two threads
  1003. * at once, not only will you block the audio callback, you'll block the other
  1004. * thread.
  1005. *
  1006. * \param dev the ID of the device to be locked
  1007. *
  1008. * \since This function is available since SDL 3.0.0.
  1009. *
  1010. * \sa SDL_UnlockAudioDevice
  1011. */
  1012. extern DECLSPEC void SDLCALL SDL_LockAudioDevice(SDL_AudioDeviceID dev);
  1013. /**
  1014. * Use this function to unlock the audio callback function for a specified
  1015. * device.
  1016. *
  1017. * This function should be paired with a previous SDL_LockAudioDevice() call.
  1018. *
  1019. * \param dev the ID of the device to be unlocked
  1020. *
  1021. * \since This function is available since SDL 3.0.0.
  1022. *
  1023. * \sa SDL_LockAudioDevice
  1024. */
  1025. extern DECLSPEC void SDLCALL SDL_UnlockAudioDevice(SDL_AudioDeviceID dev);
  1026. /* @} *//* Audio lock functions */
  1027. /**
  1028. * Use this function to shut down audio processing and close the audio device.
  1029. *
  1030. * The application should close open audio devices once they are no longer
  1031. * needed. Calling this function will wait until the device's audio callback
  1032. * is not running, release the audio hardware and then clean up internal
  1033. * state. No further audio will play from this device once this function
  1034. * returns.
  1035. *
  1036. * This function may block briefly while pending audio data is played by the
  1037. * hardware, so that applications don't drop the last buffer of data they
  1038. * supplied.
  1039. *
  1040. * The device ID is invalid as soon as the device is closed, and is eligible
  1041. * for reuse in a new SDL_OpenAudioDevice() call immediately.
  1042. *
  1043. * \param dev an audio device previously opened with SDL_OpenAudioDevice()
  1044. *
  1045. * \since This function is available since SDL 3.0.0.
  1046. *
  1047. * \sa SDL_OpenAudioDevice
  1048. */
  1049. extern DECLSPEC void SDLCALL SDL_CloseAudioDevice(SDL_AudioDeviceID dev);
  1050. /**
  1051. * Convert some audio data of one format to another format.
  1052. *
  1053. * \param src_format The format of the source audio
  1054. * \param src_channels The number of channels of the source audio
  1055. * \param src_rate The sampling rate of the source audio
  1056. * \param src_len The len of src_data
  1057. * \param src_data The audio data to be converted
  1058. * \param dst_format The format of the desired audio output
  1059. * \param dst_channels The number of channels of the desired audio output
  1060. * \param dst_rate The sampling rate of the desired audio output
  1061. * \param dst_len Will be filled with the len of dst_data
  1062. * \param dst_data Will be filled with a pointer to converted audio data,
  1063. * which should be freed with SDL_free().
  1064. * \returns 0 on success or a negative error code on failure. On error,
  1065. * *dst_data will be NULL and so not allocated.
  1066. *
  1067. * \since This function is available since SDL 3.0.0.
  1068. *
  1069. * \sa SDL_CreateAudioStream
  1070. */
  1071. extern DECLSPEC int SDLCALL SDL_ConvertAudioSamples(SDL_AudioFormat src_format,
  1072. Uint8 src_channels,
  1073. int src_rate,
  1074. int src_len,
  1075. Uint8 *src_data,
  1076. SDL_AudioFormat dst_format,
  1077. Uint8 dst_channels,
  1078. int dst_rate,
  1079. int *dst_len,
  1080. Uint8 **dst_data);
  1081. /* Ends C function definitions when using C++ */
  1082. #ifdef __cplusplus
  1083. }
  1084. #endif
  1085. #include <SDL3/SDL_close_code.h>
  1086. #endif /* SDL_audio_h_ */