SDL_audio.h 43 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123
  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. * \brief Audio functionality 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. * For multi-channel audio, the default SDL channel mapping is:
  39. * 2: FL FR (stereo)
  40. * 3: FL FR LFE (2.1 surround)
  41. * 4: FL FR BL BR (quad)
  42. * 5: FL FR LFE BL BR (4.1 surround)
  43. * 6: FL FR FC LFE SL SR (5.1 surround - last two can also be BL BR)
  44. * 7: FL FR FC LFE BC SL SR (6.1 surround)
  45. * 8: FL FR FC LFE BL BR SL SR (7.1 surround)
  46. */
  47. /**
  48. * \brief Audio format flags.
  49. *
  50. * These are what the 16 bits in SDL_AudioFormat currently mean...
  51. * (Unspecified bits are always zero).
  52. *
  53. * \verbatim
  54. ++-----------------------sample is signed if set
  55. ||
  56. || ++-----------sample is bigendian if set
  57. || ||
  58. || || ++---sample is float if set
  59. || || ||
  60. || || || +---sample bit size---+
  61. || || || | |
  62. 15 14 13 12 11 10 09 08 07 06 05 04 03 02 01 00
  63. \endverbatim
  64. *
  65. * There are macros in SDL 2.0 and later to query these bits.
  66. */
  67. typedef Uint16 SDL_AudioFormat;
  68. /**
  69. * \name Audio flags
  70. */
  71. /* @{ */
  72. #define SDL_AUDIO_MASK_BITSIZE (0xFF)
  73. #define SDL_AUDIO_MASK_DATATYPE (1<<8)
  74. #define SDL_AUDIO_MASK_ENDIAN (1<<12)
  75. #define SDL_AUDIO_MASK_SIGNED (1<<15)
  76. #define SDL_AUDIO_BITSIZE(x) (x & SDL_AUDIO_MASK_BITSIZE)
  77. #define SDL_AUDIO_ISFLOAT(x) (x & SDL_AUDIO_MASK_DATATYPE)
  78. #define SDL_AUDIO_ISBIGENDIAN(x) (x & SDL_AUDIO_MASK_ENDIAN)
  79. #define SDL_AUDIO_ISSIGNED(x) (x & SDL_AUDIO_MASK_SIGNED)
  80. #define SDL_AUDIO_ISINT(x) (!SDL_AUDIO_ISFLOAT(x))
  81. #define SDL_AUDIO_ISLITTLEENDIAN(x) (!SDL_AUDIO_ISBIGENDIAN(x))
  82. #define SDL_AUDIO_ISUNSIGNED(x) (!SDL_AUDIO_ISSIGNED(x))
  83. /**
  84. * \name Audio format flags
  85. *
  86. * Defaults to LSB byte order.
  87. */
  88. /* @{ */
  89. #define SDL_AUDIO_U8 0x0008 /**< Unsigned 8-bit samples */
  90. #define SDL_AUDIO_S8 0x8008 /**< Signed 8-bit samples */
  91. #define SDL_AUDIO_S16LSB 0x8010 /**< Signed 16-bit samples */
  92. #define SDL_AUDIO_S16MSB 0x9010 /**< As above, but big-endian byte order */
  93. #define SDL_AUDIO_S16 SDL_AUDIO_S16LSB
  94. /* @} */
  95. /**
  96. * \name int32 support
  97. */
  98. /* @{ */
  99. #define SDL_AUDIO_S32LSB 0x8020 /**< 32-bit integer samples */
  100. #define SDL_AUDIO_S32MSB 0x9020 /**< As above, but big-endian byte order */
  101. #define SDL_AUDIO_S32 SDL_AUDIO_S32LSB
  102. /* @} */
  103. /**
  104. * \name float32 support
  105. */
  106. /* @{ */
  107. #define SDL_AUDIO_F32LSB 0x8120 /**< 32-bit floating point samples */
  108. #define SDL_AUDIO_F32MSB 0x9120 /**< As above, but big-endian byte order */
  109. #define SDL_AUDIO_F32 SDL_AUDIO_F32LSB
  110. /* @} */
  111. /**
  112. * \name Native audio byte ordering
  113. */
  114. /* @{ */
  115. #if SDL_BYTEORDER == SDL_LIL_ENDIAN
  116. #define SDL_AUDIO_S16SYS SDL_AUDIO_S16LSB
  117. #define SDL_AUDIO_S32SYS SDL_AUDIO_S32LSB
  118. #define SDL_AUDIO_F32SYS SDL_AUDIO_F32LSB
  119. #else
  120. #define SDL_AUDIO_S16SYS SDL_AUDIO_S16MSB
  121. #define SDL_AUDIO_S32SYS SDL_AUDIO_S32MSB
  122. #define SDL_AUDIO_F32SYS SDL_AUDIO_F32MSB
  123. #endif
  124. /* @} */
  125. /* @} *//* Audio flags */
  126. typedef struct SDL_AudioSpec
  127. {
  128. SDL_AudioFormat format; /**< Audio data format */
  129. int channels; /**< Number of channels: 1 mono, 2 stereo, etc */
  130. int freq; /**< sample rate: sample frames per second */
  131. } SDL_AudioSpec;
  132. /* SDL_AudioStream is an audio conversion interface.
  133. - It can handle resampling data in chunks without generating
  134. artifacts, when it doesn't have the complete buffer available.
  135. - It can handle incoming data in any variable size.
  136. - It can handle input/output format changes on the fly.
  137. - You push data as you have it, and pull it when you need it
  138. - It can also function as a basic audio data queue even if you
  139. just have sound that needs to pass from one place to another.
  140. */
  141. struct SDL_AudioStream; /* this is opaque to the outside world. */
  142. typedef struct SDL_AudioStream SDL_AudioStream;
  143. /* Function prototypes */
  144. /**
  145. * \name Driver discovery functions
  146. *
  147. * These functions return the list of built in audio drivers, in the
  148. * order that they are normally initialized by default.
  149. */
  150. /* @{ */
  151. /**
  152. * Use this function to get the number of built-in audio drivers.
  153. *
  154. * This function returns a hardcoded number. This never returns a negative
  155. * value; if there are no drivers compiled into this build of SDL, this
  156. * function returns zero. The presence of a driver in this list does not mean
  157. * it will function, it just means SDL is capable of interacting with that
  158. * interface. For example, a build of SDL might have esound support, but if
  159. * there's no esound server available, SDL's esound driver would fail if used.
  160. *
  161. * By default, SDL tries all drivers, in its preferred order, until one is
  162. * found to be usable.
  163. *
  164. * \returns the number of built-in audio drivers.
  165. *
  166. * \since This function is available since SDL 3.0.0.
  167. *
  168. * \threadsafety It is safe to call this function from any thread.
  169. *
  170. * \sa SDL_GetAudioDriver
  171. */
  172. extern DECLSPEC int SDLCALL SDL_GetNumAudioDrivers(void);
  173. /**
  174. * Use this function to get the name of a built in audio driver.
  175. *
  176. * The list of audio drivers is given in the order that they are normally
  177. * initialized by default; the drivers that seem more reasonable to choose
  178. * first (as far as the SDL developers believe) are earlier in the list.
  179. *
  180. * The names of drivers are all simple, low-ASCII identifiers, like "alsa",
  181. * "coreaudio" or "xaudio2". These never have Unicode characters, and are not
  182. * meant to be proper names.
  183. *
  184. * \param index the index of the audio driver; the value ranges from 0 to
  185. * SDL_GetNumAudioDrivers() - 1
  186. * \returns the name of the audio driver at the requested index, or NULL if an
  187. * invalid index was specified.
  188. *
  189. * \threadsafety It is safe to call this function from any thread.
  190. *
  191. * \since This function is available since SDL 3.0.0.
  192. *
  193. * \sa SDL_GetNumAudioDrivers
  194. */
  195. extern DECLSPEC const char *SDLCALL SDL_GetAudioDriver(int index);
  196. /* @} */
  197. /**
  198. * Get the name of the current audio driver.
  199. *
  200. * The returned string points to internal static memory and thus never becomes
  201. * invalid, even if you quit the audio subsystem and initialize a new driver
  202. * (although such a case would return a different static string from another
  203. * call to this function, of course). As such, you should not modify or free
  204. * the returned string.
  205. *
  206. * \returns the name of the current audio driver or NULL if no driver has been
  207. * initialized.
  208. *
  209. * \threadsafety It is safe to call this function from any thread.
  210. *
  211. * \since This function is available since SDL 3.0.0.
  212. */
  213. extern DECLSPEC const char *SDLCALL SDL_GetCurrentAudioDriver(void);
  214. /**
  215. * SDL Audio Device instance IDs.
  216. */
  217. typedef Uint32 SDL_AudioDeviceID;
  218. /**
  219. * Get a list of currently-connected audio output devices.
  220. *
  221. * This returns of list of available devices that play sound, perhaps
  222. * to speakers or headphones ("output" devices). If you want devices
  223. * that record audio, like a microphone ("capture" devices), use
  224. * SDL_GetAudioCaptureDevices() instead.
  225. *
  226. * \param count a pointer filled in with the number of devices returned
  227. * \returns a 0 terminated array of device instance IDs which should be
  228. * freed with SDL_free(), or NULL on error; call SDL_GetError() for
  229. * more details.
  230. *
  231. * \since This function is available since SDL 3.0.0.
  232. *
  233. * \threadsafety It is safe to call this function from any thread.
  234. *
  235. * \sa SDL_OpenAudioDevice
  236. */
  237. extern DECLSPEC SDL_AudioDeviceID *SDLCALL SDL_GetAudioOutputDevices(int *count);
  238. /**
  239. * Get a list of currently-connected audio capture devices.
  240. *
  241. * This returns of list of available devices that record audio, like a
  242. * microphone ("capture" devices). If you want devices
  243. * that play sound, perhaps to speakers or headphones ("output" devices),
  244. * use SDL_GetAudioOutputDevices() instead.
  245. *
  246. * \param count a pointer filled in with the number of devices returned
  247. * \returns a 0 terminated array of device instance IDs which should be
  248. * freed with SDL_free(), or NULL on error; call SDL_GetError() for
  249. * more details.
  250. *
  251. * \since This function is available since SDL 3.0.0.
  252. *
  253. * \threadsafety It is safe to call this function from any thread.
  254. *
  255. * \sa SDL_OpenAudioDevice
  256. */
  257. extern DECLSPEC SDL_AudioDeviceID *SDLCALL SDL_GetAudioCaptureDevices(int *count);
  258. /**
  259. * Get the human-readable name of a specific audio device.
  260. *
  261. * The string returned by this function is UTF-8 encoded. The caller should
  262. * call SDL_free on the return value when done with it.
  263. *
  264. * \param devid the instance ID of the device to query.
  265. * \returns the name of the audio device, or NULL on error.
  266. *
  267. * \since This function is available since SDL 3.0.0.
  268. *
  269. * \threadsafety It is safe to call this function from any thread.
  270. *
  271. * \sa SDL_GetNumAudioDevices
  272. * \sa SDL_GetDefaultAudioInfo
  273. */
  274. extern DECLSPEC char *SDLCALL SDL_GetAudioDeviceName(SDL_AudioDeviceID devid);
  275. /**
  276. * Get the current audio format of a specific audio device.
  277. *
  278. * For an opened device, this will report the format the device is
  279. * currently using. If the device isn't yet opened, this will report
  280. * the device's preferred format (or a reasonable default if this
  281. * can't be determined).
  282. *
  283. * \param devid the instance ID of the device to query.
  284. * \param spec On return, will be filled with device details.
  285. * \returns 0 on success or a negative error code on failure; call
  286. * SDL_GetError() for more information.
  287. *
  288. * \threadsafety It is safe to call this function from any thread.
  289. *
  290. * \since This function is available since SDL 3.0.0.
  291. */
  292. extern DECLSPEC int SDLCALL SDL_GetAudioDeviceFormat(SDL_AudioDeviceID devid, SDL_AudioSpec *spec);
  293. /**
  294. * Open a specific audio device.
  295. *
  296. * Passing in a `devid` name of zero requests the most reasonable default.
  297. *
  298. * You can open both output and capture devices through this function.
  299. * Output devices will take data from bound audio streams, mix it, and
  300. * send it to the hardware. Capture devices will feed any bound audio
  301. * streams with a copy of any incoming data.
  302. *
  303. * An opened audio device starts out with no audio streams bound. To
  304. * start audio playing, bind a stream and supply audio data to it. Unlike
  305. * SDL2, there is no audio callback; you only bind audio streams and
  306. * make sure they have data flowing into them.
  307. *
  308. * You may request a specific format for the audio device, but there is
  309. * no promise the device will honor that request for several reasons. As
  310. * such, it's only meant to be a hint as to what data your app will
  311. * provide. Audio streams will accept data in whatever format you specify and
  312. * manage conversion for you as appropriate. SDL_GetAudioDeviceFormat can
  313. * tell you the preferred format for the device before opening and the
  314. * actual format the device is using after opening.
  315. *
  316. * It's legal to open the same device ID more than once; in the end, you must
  317. * close it the same number of times. This allows libraries to open a device
  318. * separate from the main app and bind its own streams without conflicting.
  319. *
  320. * This function returns the opened device ID on success, so that if you
  321. * open a device of 0, you'll have a real ID to bind streams to, but this
  322. * does not generate new instance IDs. Unlike SDL2, these IDs are assigned
  323. * to each unique device on the system, open or not, so if you request a
  324. * specific device, you'll get that same device ID back.
  325. *
  326. * Some backends might offer arbitrary devices (for example, a networked
  327. * audio protocol that can connect to an arbitrary server). For these, as
  328. * a change from SDL2, you should open a device ID of zero and use an SDL
  329. * hint to specify the target if you care, or otherwise let the backend
  330. * figure out a reasonable default. Most backends don't offer anything like
  331. * this, and often this would be an end user setting an environment
  332. * variable for their custom need, and not something an application should
  333. * specifically manage.
  334. *
  335. * \param devid the device instance id to open. 0 requests the most
  336. * reasonable default device.
  337. * \param spec the requested device configuration
  338. * \returns The device ID on success, 0 on error; call SDL_GetError() for more information.
  339. *
  340. * \since This function is available since SDL 3.0.0.
  341. *
  342. * \threadsafety It is safe to call this function from any thread.
  343. *
  344. * \sa SDL_CloseAudioDevice
  345. * \sa SDL_GetAudioDeviceFormat
  346. */
  347. extern DECLSPEC SDL_AudioDeviceID SDLCALL SDL_OpenAudioDevice(SDL_AudioDeviceID devid, const SDL_AudioSpec *spec);
  348. /**
  349. * Close a previously-opened audio device.
  350. *
  351. * The application should close open audio devices once they are no longer
  352. * needed. Audio devices can be opened multiple times; when they are closed
  353. * an equal number of times, its resources are freed, any bound streams are
  354. * unbound, and any audio will stop playing.
  355. *
  356. * This function may block briefly while pending audio data is played by the
  357. * hardware, so that applications don't drop the last buffer of data they
  358. * supplied.
  359. *
  360. * \param devid an audio device previously opened with SDL_OpenAudioDevice()
  361. *
  362. * \since This function is available since SDL 3.0.0.
  363. *
  364. * \threadsafety It is safe to call this function from any thread.
  365. *
  366. * \sa SDL_OpenAudioDevice
  367. */
  368. extern DECLSPEC void SDLCALL SDL_CloseAudioDevice(SDL_AudioDeviceID devid);
  369. /**
  370. * Bind a list of audio streams to an audio device.
  371. *
  372. * Audio data will flow through any bound streams. For an output device, data
  373. * for all bound streams will be mixed together and fed to the device. For a
  374. * capture device, a copy of recorded data will be provided to each bound
  375. * stream.
  376. *
  377. * Audio streams can only be bound to an open device. This operation is
  378. * atomic--all streams bound in the same call will start processing at the same
  379. * time, so they can stay in sync. Also: either all streams will be bound or
  380. * none of them will be.
  381. *
  382. * It is an error to bind an already-bound stream; it must be explicitly unbound
  383. * first.
  384. *
  385. * Binding a stream to a device will set its output format for output devices,
  386. * and its input format for capture devices, so they match the device's
  387. * settings. The caller is welcome to change the other end of the stream's
  388. * format at any time.
  389. *
  390. * \param devid an audio device to bind a stream to.
  391. * \param streams an array of audio streams to unbind.
  392. * \param num_streams Number streams listed in the `streams` array.
  393. * \returns 0 on success, -1 on error; call SDL_GetError() for more information.
  394. *
  395. * \since This function is available since SDL 3.0.0.
  396. *
  397. * \threadsafety It is safe to call this function from any thread.
  398. *
  399. * \sa SDL_BindAudioStreams
  400. * \sa SDL_UnbindAudioStreams
  401. * \sa SDL_UnbindAudioStream
  402. */
  403. extern DECLSPEC int SDLCALL SDL_BindAudioStreams(SDL_AudioDeviceID devid, SDL_AudioStream **streams, int num_streams);
  404. /**
  405. * Bind a single audio stream to an audio device.
  406. *
  407. * This is a convenience function, equivalent to calling
  408. * `SDL_BindAudioStreams(devid, &stream, 1)`.
  409. *
  410. * \param devid an audio device to bind a stream to.
  411. * \param stream an audio stream to bind to a device.
  412. * \returns 0 on success, -1 on error; call SDL_GetError() for more information.
  413. *
  414. * \since This function is available since SDL 3.0.0.
  415. *
  416. * \threadsafety It is safe to call this function from any thread.
  417. *
  418. * \sa SDL_BindAudioStreams
  419. * \sa SDL_UnbindAudioStreams
  420. * \sa SDL_UnbindAudioStream
  421. */
  422. extern DECLSPEC int SDLCALL SDL_BindAudioStream(SDL_AudioDeviceID devid, SDL_AudioStream *stream);
  423. /**
  424. * Unbind a list of audio streams from their audio devices.
  425. *
  426. * The streams being unbound do not all have to be on the same device.
  427. * All streams on the same device will be unbound atomically (data will stop flowing
  428. * through them all unbound streams on the same device at the same time).
  429. *
  430. * Unbinding a stream that isn't bound to a device is a legal no-op.
  431. *
  432. * \param streams an array of audio streams to unbind.
  433. * \param num_streams Number streams listed in the `streams` array.
  434. *
  435. * \since This function is available since SDL 3.0.0.
  436. *
  437. * \threadsafety It is safe to call this function from any thread.
  438. *
  439. * \sa SDL_BindAudioStreams
  440. * \sa SDL_BindAudioStream
  441. * \sa SDL_UnbindAudioStream
  442. */
  443. extern DECLSPEC void SDLCALL SDL_UnbindAudioStreams(SDL_AudioStream **streams, int num_streams);
  444. /**
  445. * Unbind a single audio stream from its audio device.
  446. *
  447. * This is a convenience function, equivalent to calling
  448. * `SDL_UnbindAudioStreams(&stream, 1)`.
  449. *
  450. * \param stream an audio stream to unbind from a device.
  451. *
  452. * \since This function is available since SDL 3.0.0.
  453. *
  454. * \threadsafety It is safe to call this function from any thread.
  455. *
  456. * \sa SDL_BindAudioStream
  457. * \sa SDL_BindAudioStreams
  458. * \sa SDL_UnbindAudioStreams
  459. */
  460. extern DECLSPEC void SDLCALL SDL_UnbindAudioStream(SDL_AudioStream *stream);
  461. /**
  462. * Create a new audio stream.
  463. *
  464. * \param src_spec The format details of the input audio
  465. * \param dst_spec The format details of the output audio
  466. * \returns 0 on success, or -1 on error.
  467. *
  468. * \threadsafety It is safe to call this function from any thread.
  469. *
  470. * \since This function is available since SDL 3.0.0.
  471. *
  472. * \sa SDL_PutAudioStreamData
  473. * \sa SDL_GetAudioStreamData
  474. * \sa SDL_GetAudioStreamAvailable
  475. * \sa SDL_FlushAudioStream
  476. * \sa SDL_ClearAudioStream
  477. * \sa SDL_ChangeAudioStreamOutput
  478. * \sa SDL_DestroyAudioStream
  479. */
  480. extern DECLSPEC SDL_AudioStream *SDLCALL SDL_CreateAudioStream(const SDL_AudioSpec *src_spec, const SDL_AudioSpec *dst_spec);
  481. /**
  482. * Query the current format of an audio stream.
  483. *
  484. * \param stream the SDL_AudioStream to query.
  485. * \param src_spec Where to store the input audio format; ignored if NULL.
  486. * \param dst_spec Where to store the output audio format; ignored if NULL.
  487. * \returns 0 on success, or -1 on error.
  488. *
  489. * \threadsafety It is safe to call this function from any thread, as it holds
  490. * a stream-specific mutex while running.
  491. *
  492. * \since This function is available since SDL 3.0.0.
  493. */
  494. extern DECLSPEC int SDLCALL SDL_GetAudioStreamFormat(SDL_AudioStream *stream,
  495. SDL_AudioSpec *src_spec,
  496. SDL_AudioSpec *dst_spec);
  497. /**
  498. * Change the input and output formats of an audio stream.
  499. *
  500. * Future calls to and SDL_GetAudioStreamAvailable and SDL_GetAudioStreamData
  501. * will reflect the new format, and future calls to SDL_PutAudioStreamData
  502. * must provide data in the new input formats.
  503. *
  504. * \param stream The stream the format is being changed
  505. * \param src_spec The new format of the audio input; if NULL, it is not changed.
  506. * \param dst_spec The new format of the audio output; if NULL, it is not changed.
  507. * \returns 0 on success, or -1 on error.
  508. *
  509. * \threadsafety It is safe to call this function from any thread, as it holds
  510. * a stream-specific mutex while running.
  511. *
  512. * \since This function is available since SDL 3.0.0.
  513. *
  514. * \sa SDL_GetAudioStreamFormat
  515. * \sa SDL_PutAudioStreamData
  516. * \sa SDL_GetAudioStreamData
  517. * \sa SDL_GetAudioStreamAvailable
  518. */
  519. extern DECLSPEC int SDLCALL SDL_SetAudioStreamFormat(SDL_AudioStream *stream,
  520. const SDL_AudioSpec *src_spec,
  521. const SDL_AudioSpec *dst_spec);
  522. /**
  523. * Add data to be converted/resampled to the stream.
  524. *
  525. * This data must match the format/channels/samplerate specified in the latest
  526. * call to SDL_SetAudioStreamFormat, or the format specified when creating the
  527. * stream if it hasn't been changed.
  528. *
  529. * Note that this call simply queues unconverted data for later. This is
  530. * different than SDL2, where data was converted during the Put call and the
  531. * Get call would just dequeue the previously-converted data.
  532. *
  533. * \param stream The stream the audio data is being added to
  534. * \param buf A pointer to the audio data to add
  535. * \param len The number of bytes to write to the stream
  536. * \returns 0 on success or a negative error code on failure; call
  537. * SDL_GetError() for more information.
  538. *
  539. * \since This function is available since SDL 3.0.0.
  540. *
  541. * \sa SDL_CreateAudioStream
  542. * \sa SDL_GetAudioStreamData
  543. * \sa SDL_GetAudioStreamAvailable
  544. * \sa SDL_FlushAudioStream
  545. * \sa SDL_ClearAudioStream
  546. * \sa SDL_DestroyAudioStream
  547. */
  548. extern DECLSPEC int SDLCALL SDL_PutAudioStreamData(SDL_AudioStream *stream, const void *buf, int len);
  549. /**
  550. * Get converted/resampled data from the stream.
  551. *
  552. * The input/output data format/channels/samplerate is specified when creating
  553. * the stream, and can be changed after creation by calling
  554. * SDL_SetAudioStreamFormat.
  555. *
  556. * Note that any conversion and resampling necessary is done during this call,
  557. * and SDL_PutAudioStreamData simply queues unconverted data for later. This
  558. * is different than SDL2, where that work was done while inputting new data
  559. * to the stream and requesting the output just copied the converted data.
  560. *
  561. * \param stream The stream the audio is being requested from
  562. * \param buf A buffer to fill with audio data
  563. * \param len The maximum number of bytes to fill
  564. * \returns the number of bytes read from the stream, or -1 on error
  565. *
  566. * \since This function is available since SDL 3.0.0.
  567. *
  568. * \sa SDL_CreateAudioStream
  569. * \sa SDL_PutAudioStreamData
  570. * \sa SDL_GetAudioStreamAvailable
  571. * \sa SDL_SetAudioStreamFormat
  572. * \sa SDL_FlushAudioStream
  573. * \sa SDL_ClearAudioStream
  574. * \sa SDL_DestroyAudioStream
  575. */
  576. extern DECLSPEC int SDLCALL SDL_GetAudioStreamData(SDL_AudioStream *stream, void *buf, int len);
  577. /**
  578. * Get the number of converted/resampled bytes available.
  579. *
  580. * The stream may be buffering data behind the scenes until it has enough to
  581. * resample correctly, so this number might be lower than what you expect, or
  582. * even be zero. Add more data or flush the stream if you need the data now.
  583. *
  584. * If the stream has so much data that it would overflow an int, the return
  585. * value is clamped to a maximum value, but no queued data is lost; if there
  586. * are gigabytes of data queued, the app might need to read some of it with
  587. * SDL_GetAudioStreamData before this function's return value is no longer
  588. * clamped.
  589. *
  590. * \param stream The audio stream to query
  591. * \returns the number of converted/resampled bytes available.
  592. *
  593. * \since This function is available since SDL 3.0.0.
  594. *
  595. * \sa SDL_CreateAudioStream
  596. * \sa SDL_PutAudioStreamData
  597. * \sa SDL_GetAudioStreamData
  598. * \sa SDL_FlushAudioStream
  599. * \sa SDL_ClearAudioStream
  600. * \sa SDL_DestroyAudioStream
  601. */
  602. extern DECLSPEC int SDLCALL SDL_GetAudioStreamAvailable(SDL_AudioStream *stream);
  603. /**
  604. * Tell the stream that you're done sending data, and anything being buffered
  605. * should be converted/resampled and made available immediately.
  606. *
  607. * It is legal to add more data to a stream after flushing, but there will be
  608. * audio gaps in the output. Generally this is intended to signal the end of
  609. * input, so the complete output becomes available.
  610. *
  611. * \param stream The audio stream to flush
  612. * \returns 0 on success or a negative error code on failure; call
  613. * SDL_GetError() for more information.
  614. *
  615. * \since This function is available since SDL 3.0.0.
  616. *
  617. * \sa SDL_CreateAudioStream
  618. * \sa SDL_PutAudioStreamData
  619. * \sa SDL_GetAudioStreamData
  620. * \sa SDL_GetAudioStreamAvailable
  621. * \sa SDL_ClearAudioStream
  622. * \sa SDL_DestroyAudioStream
  623. */
  624. extern DECLSPEC int SDLCALL SDL_FlushAudioStream(SDL_AudioStream *stream);
  625. /**
  626. * Clear any pending data in the stream without converting it
  627. *
  628. * \param stream The audio stream to clear
  629. * \returns 0 on success or a negative error code on failure; call
  630. * SDL_GetError() for more information.
  631. *
  632. * \since This function is available since SDL 3.0.0.
  633. *
  634. * \sa SDL_CreateAudioStream
  635. * \sa SDL_PutAudioStreamData
  636. * \sa SDL_GetAudioStreamData
  637. * \sa SDL_GetAudioStreamAvailable
  638. * \sa SDL_FlushAudioStream
  639. * \sa SDL_DestroyAudioStream
  640. */
  641. extern DECLSPEC int SDLCALL SDL_ClearAudioStream(SDL_AudioStream *stream);
  642. /**
  643. * Lock an audio stream for serialized access.
  644. *
  645. * Each SDL_AudioStream has an internal mutex it uses to
  646. * protect its data structures from threading conflicts. This function
  647. * allows an app to lock that mutex, which could be useful if
  648. * registering callbacks on this stream.
  649. *
  650. * One does not need to lock a stream to use in it most cases,
  651. * as the stream manages this lock internally. However, this lock
  652. * is held during callbacks, which may run from arbitrary threads
  653. * at any time, so if an app needs to protect shared data during
  654. * those callbacks, locking the stream guarantees that the
  655. * callback is not running while the lock is held.
  656. *
  657. * As this is just a wrapper over SDL_LockMutex for an internal
  658. * lock, it has all the same attributes (recursive locks are
  659. * allowed, etc).
  660. *
  661. * \param stream The audio stream to lock.
  662. * \returns 0 on success or a negative error code on failure; call
  663. * SDL_GetError() for more information.
  664. *
  665. * \since This function is available since SDL 3.0.0.
  666. *
  667. * \threadsafety It is safe to call this function from any thread.
  668. *
  669. * \sa SDL_UnlockAudioStream
  670. * \sa SDL_SetAudioStreamPutCallback
  671. * \sa SDL_SetAudioStreamGetCallback
  672. */
  673. extern DECLSPEC int SDLCALL SDL_LockAudioStream(SDL_AudioStream *stream);
  674. /**
  675. * Unlock an audio stream for serialized access.
  676. *
  677. * This unlocks an audio stream after a call to SDL_LockAudioStream.
  678. *
  679. * \param stream The audio stream to unlock.
  680. * \returns 0 on success or a negative error code on failure; call
  681. * SDL_GetError() for more information.
  682. *
  683. * \since This function is available since SDL 3.0.0.
  684. *
  685. * \threadsafety You should only call this from the same thread that
  686. * previously called SDL_LockAudioStream.
  687. *
  688. * \sa SDL_LockAudioStream
  689. * \sa SDL_SetAudioStreamPutCallback
  690. * \sa SDL_SetAudioStreamGetCallback
  691. */
  692. extern DECLSPEC int SDLCALL SDL_UnlockAudioStream(SDL_AudioStream *stream);
  693. /**
  694. * A callback that fires when data passes through an SDL_AudioStream.
  695. *
  696. * Apps can (optionally) register a callback with an audio stream that
  697. * is called when data is added with SDL_PutAudioStreamData, or requested
  698. * with SDL_GetAudioStreamData. These callbacks may run from any
  699. * thread, so if you need to protect shared data, you should use
  700. * SDL_LockAudioStream to serialize access; this lock will be held by
  701. * before your callback is called, so your callback does not need to
  702. * manage the lock explicitly.
  703. *
  704. * \param stream The SDL audio stream associated with this callback.
  705. * \param approx_request The _approximate_ amout of data, in bytes, that is requested.
  706. * This might be slightly overestimated due to buffering or
  707. * resampling, and may change from call to call anyhow.
  708. * \param userdata An opaque pointer provided by the app for their personal use.
  709. */
  710. typedef void (SDLCALL *SDL_AudioStreamRequestCallback)(SDL_AudioStream *stream, int approx_request, void *userdata);
  711. /**
  712. * Set a callback that runs when data is requested from an audio stream.
  713. *
  714. * This callback is called _before_ data is obtained from the stream,
  715. * giving the callback the chance to add more on-demand.
  716. *
  717. * The callback can (optionally) call SDL_PutAudioStreamData() to add
  718. * more audio to the stream during this call; if needed, the request
  719. * that triggered this callback will obtain the new data immediately.
  720. *
  721. * The callback's `approx_request` argument is roughly how many bytes
  722. * of _unconverted_ data (in the stream's input format) is needed by
  723. * the caller, although this may overestimate a little for safety.
  724. * This takes into account how much is already in the stream and only
  725. * asks for any extra necessary to resolve the request, which means
  726. * the callback may be asked for zero bytes, and a different amount
  727. * on each call.
  728. *
  729. * The callback is not required to supply exact amounts; it is allowed
  730. * to supply too much or too little or none at all. The caller will
  731. * get what's available, up to the amount they requested, regardless
  732. * of this callback's outcome.
  733. *
  734. * Clearing or flushing an audio stream does not call this callback.
  735. *
  736. * This function obtains the stream's lock, which means any existing
  737. * callback (get or put) in progress will finish running before setting
  738. * the new callback.
  739. *
  740. * Setting a NULL function turns off the callback.
  741. *
  742. * \param stream the audio stream to set the new callback on.
  743. * \param callback the new callback function to call when data is added to the stream.
  744. * \param userdata an opaque pointer provided to the callback for its own personal use.
  745. * \returns 0 on success, -1 on error. This only fails if `stream` is NULL.
  746. *
  747. * \since This function is available since SDL 3.0.0.
  748. *
  749. * \threadsafety It is safe to call this function from any thread.
  750. *
  751. * \sa SDL_SetAudioStreamPutCallback
  752. */
  753. extern DECLSPEC int SDLCALL SDL_SetAudioStreamGetCallback(SDL_AudioStream *stream, SDL_AudioStreamRequestCallback callback, void *userdata);
  754. /**
  755. * Set a callback that runs when data is added to an audio stream.
  756. *
  757. * This callback is called _after_ the data is added to the stream,
  758. * giving the callback the chance to obtain it immediately.
  759. *
  760. * The callback can (optionally) call SDL_GetAudioStreamData() to
  761. * obtain audio from the stream during this call.
  762. *
  763. * The callback's `approx_request` argument is how many bytes
  764. * of _converted_ data (in the stream's output format) was provided
  765. * by the caller, although this may underestimate a little for safety.
  766. * This value might be less than what is currently available in the
  767. * stream, if data was already there, and might be less than the
  768. * caller provided if the stream needs to keep a buffer to aid in
  769. * resampling. Which means the callback may be provided with zero
  770. * bytes, and a different amount on each call.
  771. *
  772. * The callback may call SDL_GetAudioStreamAvailable to see the
  773. * total amount currently available to read from the stream, instead
  774. * of the total provided by the current call.
  775. *
  776. * The callback is not required to obtain all data. It is allowed
  777. * to read less or none at all. Anything not read now simply remains
  778. * in the stream for later access.
  779. *
  780. * Clearing or flushing an audio stream does not call this callback.
  781. *
  782. * This function obtains the stream's lock, which means any existing
  783. * callback (get or put) in progress will finish running before setting
  784. * the new callback.
  785. *
  786. * Setting a NULL function turns off the callback.
  787. *
  788. * \param stream the audio stream to set the new callback on.
  789. * \param callback the new callback function to call when data is added to the stream.
  790. * \param userdata an opaque pointer provided to the callback for its own personal use.
  791. * \returns 0 on success, -1 on error. This only fails if `stream` is NULL.
  792. *
  793. * \since This function is available since SDL 3.0.0.
  794. *
  795. * \threadsafety It is safe to call this function from any thread.
  796. *
  797. * \sa SDL_SetAudioStreamGetCallback
  798. */
  799. extern DECLSPEC int SDLCALL SDL_SetAudioStreamPutCallback(SDL_AudioStream *stream, SDL_AudioStreamRequestCallback callback, void *userdata);
  800. /**
  801. * Free an audio stream
  802. *
  803. * \param stream The audio stream to free
  804. *
  805. * \since This function is available since SDL 3.0.0.
  806. *
  807. * \sa SDL_CreateAudioStream
  808. * \sa SDL_PutAudioStreamData
  809. * \sa SDL_GetAudioStreamData
  810. * \sa SDL_GetAudioStreamAvailable
  811. * \sa SDL_FlushAudioStream
  812. * \sa SDL_ClearAudioStream
  813. */
  814. extern DECLSPEC void SDLCALL SDL_DestroyAudioStream(SDL_AudioStream *stream);
  815. /**
  816. * Convenience function to create and bind an audio stream in one step.
  817. *
  818. * This manages the creation of an audio stream, and setting its format
  819. * correctly to match both the app and the audio device's needs. This is
  820. * optional, but slightly less cumbersome to set up for a common use case.
  821. *
  822. * The `spec` parameter represents the app's side of the audio stream. That
  823. * is, for recording audio, this will be the output format, and for playing
  824. * audio, this will be the input format. This function will set the other
  825. * side of the audio stream to the device's format.
  826. *
  827. * \param devid an audio device to bind a stream to. This must be an opened device, and can not be zero.
  828. * \param spec the audio stream's input format
  829. * \returns a bound audio stream on success, ready to use. NULL on error; call SDL_GetError() for more information.
  830. *
  831. * \since This function is available since SDL 3.0.0.
  832. *
  833. * \threadsafety It is safe to call this function from any thread.
  834. *
  835. * \sa SDL_BindAudioStreams
  836. * \sa SDL_UnbindAudioStreams
  837. * \sa SDL_UnbindAudioStream
  838. */
  839. extern DECLSPEC SDL_AudioStream *SDLCALL SDL_CreateAndBindAudioStream(SDL_AudioDeviceID devid, const SDL_AudioSpec *spec);
  840. /**
  841. * Load the audio data of a WAVE file into memory.
  842. *
  843. * Loading a WAVE file requires `src`, `spec`, `audio_buf` and `audio_len` to
  844. * be valid pointers. The entire data portion of the file is then loaded into
  845. * memory and decoded if necessary.
  846. *
  847. * If `freesrc` is non-zero, the data source gets automatically closed and
  848. * freed before the function returns.
  849. *
  850. * Supported formats are RIFF WAVE files with the formats PCM (8, 16, 24, and
  851. * 32 bits), IEEE Float (32 bits), Microsoft ADPCM and IMA ADPCM (4 bits), and
  852. * A-law and mu-law (8 bits). Other formats are currently unsupported and
  853. * cause an error.
  854. *
  855. * If this function succeeds, the return value is zero and the pointer to the
  856. * audio data allocated by the function is written to `audio_buf` and its
  857. * length in bytes to `audio_len`. The SDL_AudioSpec members `freq`,
  858. * `channels`, and `format` are set to the values of the audio data in the
  859. * buffer. The `samples` member is set to a sane default and all
  860. * others are set to zero.
  861. *
  862. * It's necessary to use SDL_free() to free the audio data returned in
  863. * `audio_buf` when it is no longer used.
  864. *
  865. * Because of the underspecification of the .WAV format, there are many
  866. * problematic files in the wild that cause issues with strict decoders. To
  867. * provide compatibility with these files, this decoder is lenient in regards
  868. * to the truncation of the file, the fact chunk, and the size of the RIFF
  869. * chunk. The hints `SDL_HINT_WAVE_RIFF_CHUNK_SIZE`,
  870. * `SDL_HINT_WAVE_TRUNCATION`, and `SDL_HINT_WAVE_FACT_CHUNK` can be used to
  871. * tune the behavior of the loading process.
  872. *
  873. * Any file that is invalid (due to truncation, corruption, or wrong values in
  874. * the headers), too big, or unsupported causes an error. Additionally, any
  875. * critical I/O error from the data source will terminate the loading process
  876. * with an error. The function returns NULL on error and in all cases (with
  877. * the exception of `src` being NULL), an appropriate error message will be
  878. * set.
  879. *
  880. * It is required that the data source supports seeking.
  881. *
  882. * Example:
  883. *
  884. * ```c
  885. * SDL_LoadWAV_RW(SDL_RWFromFile("sample.wav", "rb"), 1, &spec, &buf, &len);
  886. * ```
  887. *
  888. * Note that the SDL_LoadWAV function does this same thing for you, but in a
  889. * less messy way:
  890. *
  891. * ```c
  892. * SDL_LoadWAV("sample.wav", &spec, &buf, &len);
  893. * ```
  894. *
  895. * \param src The data source for the WAVE data
  896. * \param freesrc If non-zero, SDL will _always_ free the data source
  897. * \param spec A pointer to an SDL_AudioSpec that will be set to the
  898. * WAVE data's format details on successful return.
  899. * \param audio_buf A pointer filled with the audio data, allocated by the
  900. * function.
  901. * \param audio_len A pointer filled with the length of the audio data buffer
  902. * in bytes
  903. * \returns This function, if successfully called, returns 0. `audio_buf`
  904. * will be filled with a pointer to an allocated buffer
  905. * containing the audio data, and `audio_len` is filled with the
  906. * length of that audio buffer in bytes.
  907. *
  908. * This function returns -1 if the .WAV file cannot be opened, uses
  909. * an unknown data format, or is corrupt; call SDL_GetError() for
  910. * more information.
  911. *
  912. * When the application is done with the data returned in
  913. * `audio_buf`, it should call SDL_free() to dispose of it.
  914. *
  915. * \since This function is available since SDL 3.0.0.
  916. *
  917. * \sa SDL_free
  918. * \sa SDL_LoadWAV
  919. */
  920. extern DECLSPEC int SDLCALL SDL_LoadWAV_RW(SDL_RWops * src, int freesrc,
  921. SDL_AudioSpec * spec, Uint8 ** audio_buf,
  922. Uint32 * audio_len);
  923. /**
  924. * Loads a WAV from a file path.
  925. *
  926. * This is a convenience function that is effectively the same as:
  927. *
  928. * ```c
  929. * SDL_LoadWAV_RW(SDL_RWFromFile(path, "rb"), 1, spec, audio_buf, audio_len);
  930. * ```
  931. *
  932. * Note that in SDL2, this was a preprocessor macro and not a real function.
  933. *
  934. * \param path The file path of the WAV file to open.
  935. * \param spec A pointer to an SDL_AudioSpec that will be set to the
  936. * WAVE data's format details on successful return.
  937. * \param audio_buf A pointer filled with the audio data, allocated by the
  938. * function.
  939. * \param audio_len A pointer filled with the length of the audio data buffer
  940. * in bytes
  941. * \returns This function, if successfully called, returns 0. `audio_buf`
  942. * will be filled with a pointer to an allocated buffer
  943. * containing the audio data, and `audio_len` is filled with the
  944. * length of that audio buffer in bytes.
  945. *
  946. * This function returns -1 if the .WAV file cannot be opened, uses
  947. * an unknown data format, or is corrupt; call SDL_GetError() for
  948. * more information.
  949. *
  950. * When the application is done with the data returned in
  951. * `audio_buf`, it should call SDL_free() to dispose of it.
  952. *
  953. * \since This function is available since SDL 3.0.0.
  954. *
  955. * \sa SDL_free
  956. * \sa SDL_LoadWAV_RW
  957. */
  958. extern DECLSPEC int SDLCALL SDL_LoadWAV(const char *path, SDL_AudioSpec * spec,
  959. Uint8 ** audio_buf, Uint32 * audio_len);
  960. #define SDL_MIX_MAXVOLUME 128
  961. /**
  962. * Mix audio data in a specified format.
  963. *
  964. * This takes an audio buffer `src` of `len` bytes of `format` data and mixes
  965. * it into `dst`, performing addition, volume adjustment, and overflow
  966. * clipping. The buffer pointed to by `dst` must also be `len` bytes of
  967. * `format` data.
  968. *
  969. * This is provided for convenience -- you can mix your own audio data.
  970. *
  971. * Do not use this function for mixing together more than two streams of
  972. * sample data. The output from repeated application of this function may be
  973. * distorted by clipping, because there is no accumulator with greater range
  974. * than the input (not to mention this being an inefficient way of doing it).
  975. *
  976. * It is a common misconception that this function is required to write audio
  977. * data to an output stream in an audio callback. While you can do that,
  978. * SDL_MixAudioFormat() is really only needed when you're mixing a single
  979. * audio stream with a volume adjustment.
  980. *
  981. * \param dst the destination for the mixed audio
  982. * \param src the source audio buffer to be mixed
  983. * \param format the SDL_AudioFormat structure representing the desired audio
  984. * format
  985. * \param len the length of the audio buffer in bytes
  986. * \param volume ranges from 0 - 128, and should be set to SDL_MIX_MAXVOLUME
  987. * for full audio volume
  988. * \returns 0 on success or a negative error code on failure; call
  989. * SDL_GetError() for more information.
  990. *
  991. * \since This function is available since SDL 3.0.0.
  992. */
  993. extern DECLSPEC int SDLCALL SDL_MixAudioFormat(Uint8 * dst,
  994. const Uint8 * src,
  995. SDL_AudioFormat format,
  996. Uint32 len, int volume);
  997. /**
  998. * Convert some audio data of one format to another format.
  999. *
  1000. * Please note that this function is for convenience, but should not be used
  1001. * to resample audio in blocks, as it will introduce audio artifacts on the
  1002. * boundaries. You should only use this function if you are converting audio
  1003. * data in its entirety in one call. If you want to convert audio in smaller
  1004. * chunks, use an SDL_AudioStream, which is designed for this situation.
  1005. *
  1006. * Internally, this function creates and destroys an SDL_AudioStream on each
  1007. * use, so it's also less efficient than using one directly, if you need to
  1008. * convert multiple times.
  1009. *
  1010. * \param src_spec The format details of the input audio
  1011. * \param src_data The audio data to be converted
  1012. * \param src_len The len of src_data
  1013. * \param dst_spec The format details of the output audio
  1014. * \param dst_data Will be filled with a pointer to converted audio data,
  1015. * which should be freed with SDL_free(). On error, it will be
  1016. * NULL.
  1017. * \param dst_len Will be filled with the len of dst_data
  1018. * \returns 0 on success or a negative error code on failure; call
  1019. * SDL_GetError() for more information.
  1020. *
  1021. * \since This function is available since SDL 3.0.0.
  1022. *
  1023. * \sa SDL_CreateAudioStream
  1024. */
  1025. extern DECLSPEC int SDLCALL SDL_ConvertAudioSamples(const SDL_AudioSpec *src_spec,
  1026. const Uint8 *src_data,
  1027. int src_len,
  1028. const SDL_AudioSpec *dst_spec,
  1029. Uint8 **dst_data,
  1030. int *dst_len);
  1031. /**
  1032. * Get the appropriate memset value for silencing an audio format.
  1033. *
  1034. * The value returned by this function can be used as the second
  1035. * argument to memset (or SDL_memset) to set an audio buffer in
  1036. * a specific format to silence.
  1037. *
  1038. * \param format the audio data format to query.
  1039. * \returns A byte value that can be passed to memset.
  1040. *
  1041. * \threadsafety It is safe to call this function from any thread.
  1042. *
  1043. * \since This function is available since SDL 3.0.0.
  1044. */
  1045. extern DECLSPEC int SDLCALL SDL_GetSilenceValueForFormat(SDL_AudioFormat format);
  1046. /* Ends C function definitions when using C++ */
  1047. #ifdef __cplusplus
  1048. }
  1049. #endif
  1050. #include <SDL3/SDL_close_code.h>
  1051. #endif /* SDL_audio_h_ */