SDL_audio.h 63 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2024 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. /**
  19. * \file SDL_audio.h
  20. *
  21. * Audio functionality for the SDL library.
  22. */
  23. #ifndef SDL_audio_h_
  24. #define SDL_audio_h_
  25. #include <SDL3/SDL_stdinc.h>
  26. #include <SDL3/SDL_endian.h>
  27. #include <SDL3/SDL_error.h>
  28. #include <SDL3/SDL_mutex.h>
  29. #include <SDL3/SDL_properties.h>
  30. #include <SDL3/SDL_iostream.h>
  31. #include <SDL3/SDL_thread.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. * Audio format flags.
  49. *
  50. * These are what the 16 bits in SDL_AudioFormat currently mean...
  51. * (Unspecified bits are always zero).
  52. *
  53. * ```
  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. * ```
  64. *
  65. * There are macros to query these bits.
  66. *
  67. * \since This datatype is available since SDL 3.0.0.
  68. *
  69. * \sa SDL_AUDIO_BITSIZE
  70. * \sa SDL_AUDIO_BYTESIZE
  71. * \sa SDL_AUDIO_ISINT
  72. * \sa SDL_AUDIO_ISFLOAT
  73. * \sa SDL_AUDIO_ISBIGENDIAN
  74. * \sa SDL_AUDIO_ISLITTLEENDIAN
  75. * \sa SDL_AUDIO_ISSIGNED
  76. * \sa SDL_AUDIO_ISUNSIGNED
  77. */
  78. typedef Uint16 SDL_AudioFormat;
  79. #define SDL_AUDIO_U8 0x0008 /**< Unsigned 8-bit samples */
  80. #define SDL_AUDIO_S8 0x8008 /**< Signed 8-bit samples */
  81. #define SDL_AUDIO_S16LE 0x8010 /**< Signed 16-bit samples */
  82. #define SDL_AUDIO_S16BE 0x9010 /**< As above, but big-endian byte order */
  83. #define SDL_AUDIO_S32LE 0x8020 /**< 32-bit integer samples */
  84. #define SDL_AUDIO_S32BE 0x9020 /**< As above, but big-endian byte order */
  85. #define SDL_AUDIO_F32LE 0x8120 /**< 32-bit floating point samples */
  86. #define SDL_AUDIO_F32BE 0x9120 /**< As above, but big-endian byte order */
  87. #if SDL_BYTEORDER == SDL_LIL_ENDIAN
  88. #define SDL_AUDIO_S16 SDL_AUDIO_S16LE
  89. #define SDL_AUDIO_S32 SDL_AUDIO_S32LE
  90. #define SDL_AUDIO_F32 SDL_AUDIO_F32LE
  91. #else
  92. #define SDL_AUDIO_S16 SDL_AUDIO_S16BE
  93. #define SDL_AUDIO_S32 SDL_AUDIO_S32BE
  94. #define SDL_AUDIO_F32 SDL_AUDIO_F32BE
  95. #endif
  96. /* masks for different parts of SDL_AudioFormat. */
  97. #define SDL_AUDIO_MASK_BITSIZE (0xFF)
  98. #define SDL_AUDIO_MASK_FLOAT (1<<8)
  99. #define SDL_AUDIO_MASK_BIG_ENDIAN (1<<12)
  100. #define SDL_AUDIO_MASK_SIGNED (1<<15)
  101. /**
  102. * Retrieve the size, in bits, from an SDL_AudioFormat.
  103. *
  104. * For example, `SDL_AUDIO_BITSIZE(SDL_AUDIO_S16)` returns 16.
  105. *
  106. * \param x an SDL_AudioFormat value
  107. * \returns data size in bits
  108. *
  109. * \threadsafety It is safe to call this macro from any thread.
  110. *
  111. * \since This macro is available since SDL 3.0.0.
  112. */
  113. #define SDL_AUDIO_BITSIZE(x) ((x) & SDL_AUDIO_MASK_BITSIZE)
  114. /**
  115. * Retrieve the size, in bytes, from an SDL_AudioFormat.
  116. *
  117. * For example, `SDL_AUDIO_BYTESIZE(SDL_AUDIO_S16)` returns 2.
  118. *
  119. * \param x an SDL_AudioFormat value
  120. * \returns data size in bytes
  121. *
  122. * \threadsafety It is safe to call this macro from any thread.
  123. *
  124. * \since This macro is available since SDL 3.0.0.
  125. */
  126. #define SDL_AUDIO_BYTESIZE(x) (SDL_AUDIO_BITSIZE(x) / 8)
  127. /**
  128. * Determine if an SDL_AudioFormat represents floating point data.
  129. *
  130. * For example, `SDL_AUDIO_ISFLOAT(SDL_AUDIO_S16)` returns 0.
  131. *
  132. * \param x an SDL_AudioFormat value
  133. * \returns non-zero if format is floating point, zero otherwise.
  134. *
  135. * \threadsafety It is safe to call this macro from any thread.
  136. *
  137. * \since This macro is available since SDL 3.0.0.
  138. */
  139. #define SDL_AUDIO_ISFLOAT(x) ((x) & SDL_AUDIO_MASK_FLOAT)
  140. /**
  141. * Determine if an SDL_AudioFormat represents bigendian data.
  142. *
  143. * For example, `SDL_AUDIO_ISBIGENDIAN(SDL_AUDIO_S16LE)` returns 0.
  144. *
  145. * \param x an SDL_AudioFormat value
  146. * \returns non-zero if format is bigendian, zero otherwise.
  147. *
  148. * \threadsafety It is safe to call this macro from any thread.
  149. *
  150. * \since This macro is available since SDL 3.0.0.
  151. */
  152. #define SDL_AUDIO_ISBIGENDIAN(x) ((x) & SDL_AUDIO_MASK_BIG_ENDIAN)
  153. /**
  154. * Determine if an SDL_AudioFormat represents littleendian data.
  155. *
  156. * For example, `SDL_AUDIO_ISLITTLEENDIAN(SDL_AUDIO_S16BE)` returns 0.
  157. *
  158. * \param x an SDL_AudioFormat value
  159. * \returns non-zero if format is littleendian, zero otherwise.
  160. *
  161. * \threadsafety It is safe to call this macro from any thread.
  162. *
  163. * \since This macro is available since SDL 3.0.0.
  164. */
  165. #define SDL_AUDIO_ISLITTLEENDIAN(x) (!SDL_AUDIO_ISBIGENDIAN(x))
  166. /**
  167. * Determine if an SDL_AudioFormat represents signed data.
  168. *
  169. * For example, `SDL_AUDIO_ISSIGNED(SDL_AUDIO_U8)` returns 0.
  170. *
  171. * \param x an SDL_AudioFormat value
  172. * \returns non-zero if format is signed, zero otherwise.
  173. *
  174. * \threadsafety It is safe to call this macro from any thread.
  175. *
  176. * \since This macro is available since SDL 3.0.0.
  177. */
  178. #define SDL_AUDIO_ISSIGNED(x) ((x) & SDL_AUDIO_MASK_SIGNED)
  179. /**
  180. * Determine if an SDL_AudioFormat represents integer data.
  181. *
  182. * For example, `SDL_AUDIO_ISINT(SDL_AUDIO_F32)` returns 0.
  183. *
  184. * \param x an SDL_AudioFormat value
  185. * \returns non-zero if format is integer, zero otherwise.
  186. *
  187. * \threadsafety It is safe to call this macro from any thread.
  188. *
  189. * \since This macro is available since SDL 3.0.0.
  190. */
  191. #define SDL_AUDIO_ISINT(x) (!SDL_AUDIO_ISFLOAT(x))
  192. /**
  193. * Determine if an SDL_AudioFormat represents unsigned data.
  194. *
  195. * For example, `SDL_AUDIO_ISUNSIGNED(SDL_AUDIO_S16)` returns 0.
  196. *
  197. * \param x an SDL_AudioFormat value
  198. * \returns non-zero if format is unsigned, zero otherwise.
  199. *
  200. * \threadsafety It is safe to call this macro from any thread.
  201. *
  202. * \since This macro is available since SDL 3.0.0.
  203. */
  204. #define SDL_AUDIO_ISUNSIGNED(x) (!SDL_AUDIO_ISSIGNED(x))
  205. /**
  206. * SDL Audio Device instance IDs.
  207. *
  208. * Zero is used to signify an invalid/null device.
  209. *
  210. * \since This datatype is available since SDL 3.0.0.
  211. */
  212. typedef Uint32 SDL_AudioDeviceID;
  213. /**
  214. * A value used to request a default output audio device.
  215. *
  216. * Several functions that require an SDL_AudioDeviceID will accept this value
  217. * to signify the app just wants the system to choose a default device instead
  218. * of the app providing a specific one.
  219. *
  220. * \since This macro is available since SDL 3.0.0.
  221. */
  222. #define SDL_AUDIO_DEVICE_DEFAULT_OUTPUT ((SDL_AudioDeviceID) 0xFFFFFFFF)
  223. /**
  224. * A value used to request a default capture audio device.
  225. *
  226. * Several functions that require an SDL_AudioDeviceID will accept this value
  227. * to signify the app just wants the system to choose a default device instead
  228. * of the app providing a specific one.
  229. *
  230. * \since This macro is available since SDL 3.0.0.
  231. */
  232. #define SDL_AUDIO_DEVICE_DEFAULT_CAPTURE ((SDL_AudioDeviceID) 0xFFFFFFFE)
  233. /**
  234. * Format specifier for audio data.
  235. *
  236. * \since This struct is available since SDL 3.0.0.
  237. *
  238. * \sa SDL_AudioFormat
  239. */
  240. typedef struct SDL_AudioSpec
  241. {
  242. SDL_AudioFormat format; /**< Audio data format */
  243. int channels; /**< Number of channels: 1 mono, 2 stereo, etc */
  244. int freq; /**< sample rate: sample frames per second */
  245. } SDL_AudioSpec;
  246. /**
  247. * Calculate the size of each audio frame (in bytes) from an SDL_AudioSpec.
  248. *
  249. * This reports on the size of an audio sample frame: stereo Sint16 data (2
  250. * channels of 2 bytes each) would be 4 bytes per frame, for example.
  251. *
  252. * \param x an SDL_AudioSpec to query.
  253. * \returns the number of bytes used per sample frame.
  254. *
  255. * \threadsafety It is safe to call this macro from any thread.
  256. *
  257. * \since This macro is available since SDL 3.0.0.
  258. */
  259. #define SDL_AUDIO_FRAMESIZE(x) (SDL_AUDIO_BYTESIZE((x).format) * (x).channels)
  260. /**
  261. * The opaque handle that represents an audio stream.
  262. *
  263. * SDL_AudioStream is an audio conversion interface.
  264. *
  265. * - It can handle resampling data in chunks without generating artifacts,
  266. * when it doesn't have the complete buffer available.
  267. * - It can handle incoming data in any variable size.
  268. * - It can handle input/output format changes on the fly.
  269. * - You push data as you have it, and pull it when you need it
  270. * - It can also function as a basic audio data queue even if you just have
  271. * sound that needs to pass from one place to another.
  272. * - You can hook callbacks up to them when more data is added or requested,
  273. * to manage data on-the-fly.
  274. *
  275. * Audio streams are the core of the SDL3 audio interface. You create one or
  276. * more of them, bind them to an opened audio device, and feed data to them
  277. * (or for recording, consume data from them).
  278. *
  279. * \since This struct is available since SDL 3.0.0.
  280. *
  281. * \sa SDL_CreateAudioStream
  282. */
  283. struct SDL_AudioStream; /**< this is opaque to the outside world. */
  284. typedef struct SDL_AudioStream SDL_AudioStream;
  285. /* Function prototypes */
  286. /**
  287. * \name Driver discovery functions
  288. *
  289. * These functions return the list of built in audio drivers, in the
  290. * order that they are normally initialized by default.
  291. */
  292. /* @{ */
  293. /**
  294. * Use this function to get the number of built-in audio drivers.
  295. *
  296. * This function returns a hardcoded number. This never returns a negative
  297. * value; if there are no drivers compiled into this build of SDL, this
  298. * function returns zero. The presence of a driver in this list does not mean
  299. * it will function, it just means SDL is capable of interacting with that
  300. * interface. For example, a build of SDL might have esound support, but if
  301. * there's no esound server available, SDL's esound driver would fail if used.
  302. *
  303. * By default, SDL tries all drivers, in its preferred order, until one is
  304. * found to be usable.
  305. *
  306. * \returns the number of built-in audio drivers.
  307. *
  308. * \threadsafety It is safe to call this function from any thread.
  309. *
  310. * \since This function is available since SDL 3.0.0.
  311. *
  312. * \sa SDL_GetAudioDriver
  313. */
  314. extern DECLSPEC int SDLCALL SDL_GetNumAudioDrivers(void);
  315. /**
  316. * Use this function to get the name of a built in audio driver.
  317. *
  318. * The list of audio drivers is given in the order that they are normally
  319. * initialized by default; the drivers that seem more reasonable to choose
  320. * first (as far as the SDL developers believe) are earlier in the list.
  321. *
  322. * The names of drivers are all simple, low-ASCII identifiers, like "alsa",
  323. * "coreaudio" or "xaudio2". These never have Unicode characters, and are not
  324. * meant to be proper names.
  325. *
  326. * \param index the index of the audio driver; the value ranges from 0 to
  327. * SDL_GetNumAudioDrivers() - 1
  328. * \returns the name of the audio driver at the requested index, or NULL if an
  329. * invalid index was specified.
  330. *
  331. * \threadsafety It is safe to call this function from any thread.
  332. *
  333. * \since This function is available since SDL 3.0.0.
  334. *
  335. * \sa SDL_GetNumAudioDrivers
  336. */
  337. extern DECLSPEC const char *SDLCALL SDL_GetAudioDriver(int index);
  338. /* @} */
  339. /**
  340. * Get the name of the current audio driver.
  341. *
  342. * The returned string points to internal static memory and thus never becomes
  343. * invalid, even if you quit the audio subsystem and initialize a new driver
  344. * (although such a case would return a different static string from another
  345. * call to this function, of course). As such, you should not modify or free
  346. * the returned string.
  347. *
  348. * \returns the name of the current audio driver or NULL if no driver has been
  349. * initialized.
  350. *
  351. * \threadsafety It is safe to call this function from any thread.
  352. *
  353. * \since This function is available since SDL 3.0.0.
  354. */
  355. extern DECLSPEC const char *SDLCALL SDL_GetCurrentAudioDriver(void);
  356. /**
  357. * Get a list of currently-connected audio output devices.
  358. *
  359. * This returns of list of available devices that play sound, perhaps to
  360. * speakers or headphones ("output" devices). If you want devices that record
  361. * audio, like a microphone ("capture" devices), use
  362. * SDL_GetAudioCaptureDevices() instead.
  363. *
  364. * This only returns a list of physical devices; it will not have any device
  365. * IDs returned by SDL_OpenAudioDevice().
  366. *
  367. * \param count a pointer filled in with the number of devices returned
  368. * \returns a 0 terminated array of device instance IDs which should be freed
  369. * with SDL_free(), or NULL on error; call SDL_GetError() for more
  370. * details.
  371. *
  372. * \threadsafety It is safe to call this function from any thread.
  373. *
  374. * \since This function is available since SDL 3.0.0.
  375. *
  376. * \sa SDL_OpenAudioDevice
  377. * \sa SDL_GetAudioCaptureDevices
  378. */
  379. extern DECLSPEC SDL_AudioDeviceID *SDLCALL SDL_GetAudioOutputDevices(int *count);
  380. /**
  381. * Get a list of currently-connected audio capture devices.
  382. *
  383. * This returns of list of available devices that record audio, like a
  384. * microphone ("capture" devices). If you want devices that play sound,
  385. * perhaps to speakers or headphones ("output" devices), use
  386. * SDL_GetAudioOutputDevices() instead.
  387. *
  388. * This only returns a list of physical devices; it will not have any device
  389. * IDs returned by SDL_OpenAudioDevice().
  390. *
  391. * \param count a pointer filled in with the number of devices returned
  392. * \returns a 0 terminated array of device instance IDs which should be freed
  393. * with SDL_free(), or NULL on error; call SDL_GetError() for more
  394. * details.
  395. *
  396. * \threadsafety It is safe to call this function from any thread.
  397. *
  398. * \since This function is available since SDL 3.0.0.
  399. *
  400. * \sa SDL_OpenAudioDevice
  401. * \sa SDL_GetAudioOutputDevices
  402. */
  403. extern DECLSPEC SDL_AudioDeviceID *SDLCALL SDL_GetAudioCaptureDevices(int *count);
  404. /**
  405. * Get the human-readable name of a specific audio device.
  406. *
  407. * The string returned by this function is UTF-8 encoded. The caller should
  408. * call SDL_free on the return value when done with it.
  409. *
  410. * \param devid the instance ID of the device to query.
  411. * \returns the name of the audio device, or NULL on error.
  412. *
  413. * \threadsafety It is safe to call this function from any thread.
  414. *
  415. * \since This function is available since SDL 3.0.0.
  416. *
  417. * \sa SDL_GetAudioOutputDevices
  418. * \sa SDL_GetAudioCaptureDevices
  419. * \sa SDL_GetDefaultAudioInfo
  420. */
  421. extern DECLSPEC char *SDLCALL SDL_GetAudioDeviceName(SDL_AudioDeviceID devid);
  422. /**
  423. * Get the current audio format of a specific audio device.
  424. *
  425. * For an opened device, this will report the format the device is currently
  426. * using. If the device isn't yet opened, this will report the device's
  427. * preferred format (or a reasonable default if this can't be determined).
  428. *
  429. * You may also specify SDL_AUDIO_DEVICE_DEFAULT_OUTPUT or
  430. * SDL_AUDIO_DEVICE_DEFAULT_CAPTURE here, which is useful for getting a
  431. * reasonable recommendation before opening the system-recommended default
  432. * device.
  433. *
  434. * You can also use this to request the current device buffer size. This is
  435. * specified in sample frames and represents the amount of data SDL will feed
  436. * to the physical hardware in each chunk. This can be converted to
  437. * milliseconds of audio with the following equation:
  438. *
  439. * `ms = (int) ((((Sint64) frames) * 1000) / spec.freq);`
  440. *
  441. * Buffer size is only important if you need low-level control over the audio
  442. * playback timing. Most apps do not need this.
  443. *
  444. * \param devid the instance ID of the device to query.
  445. * \param spec On return, will be filled with device details.
  446. * \param sample_frames Pointer to store device buffer size, in sample frames.
  447. * Can be NULL.
  448. * \returns 0 on success or a negative error code on failure; call
  449. * SDL_GetError() for more information.
  450. *
  451. * \threadsafety It is safe to call this function from any thread.
  452. *
  453. * \since This function is available since SDL 3.0.0.
  454. */
  455. extern DECLSPEC int SDLCALL SDL_GetAudioDeviceFormat(SDL_AudioDeviceID devid, SDL_AudioSpec *spec, int *sample_frames);
  456. /**
  457. * Open a specific audio device.
  458. *
  459. * You can open both output and capture devices through this function. Output
  460. * devices will take data from bound audio streams, mix it, and send it to the
  461. * hardware. Capture devices will feed any bound audio streams with a copy of
  462. * any incoming data.
  463. *
  464. * An opened audio device starts out with no audio streams bound. To start
  465. * audio playing, bind a stream and supply audio data to it. Unlike SDL2,
  466. * there is no audio callback; you only bind audio streams and make sure they
  467. * have data flowing into them (however, you can simulate SDL2's semantics
  468. * fairly closely by using SDL_OpenAudioDeviceStream instead of this
  469. * function).
  470. *
  471. * If you don't care about opening a specific device, pass a `devid` of either
  472. * `SDL_AUDIO_DEVICE_DEFAULT_OUTPUT` or `SDL_AUDIO_DEVICE_DEFAULT_CAPTURE`. In
  473. * this case, SDL will try to pick the most reasonable default, and may also
  474. * switch between physical devices seamlessly later, if the most reasonable
  475. * default changes during the lifetime of this opened device (user changed the
  476. * default in the OS's system preferences, the default got unplugged so the
  477. * system jumped to a new default, the user plugged in headphones on a mobile
  478. * device, etc). Unless you have a good reason to choose a specific device,
  479. * this is probably what you want.
  480. *
  481. * You may request a specific format for the audio device, but there is no
  482. * promise the device will honor that request for several reasons. As such,
  483. * it's only meant to be a hint as to what data your app will provide. Audio
  484. * streams will accept data in whatever format you specify and manage
  485. * conversion for you as appropriate. SDL_GetAudioDeviceFormat can tell you
  486. * the preferred format for the device before opening and the actual format
  487. * the device is using after opening.
  488. *
  489. * It's legal to open the same device ID more than once; each successful open
  490. * will generate a new logical SDL_AudioDeviceID that is managed separately
  491. * from others on the same physical device. This allows libraries to open a
  492. * device separately from the main app and bind its own streams without
  493. * conflicting.
  494. *
  495. * It is also legal to open a device ID returned by a previous call to this
  496. * function; doing so just creates another logical device on the same physical
  497. * device. This may be useful for making logical groupings of audio streams.
  498. *
  499. * This function returns the opened device ID on success. This is a new,
  500. * unique SDL_AudioDeviceID that represents a logical device.
  501. *
  502. * Some backends might offer arbitrary devices (for example, a networked audio
  503. * protocol that can connect to an arbitrary server). For these, as a change
  504. * from SDL2, you should open a default device ID and use an SDL hint to
  505. * specify the target if you care, or otherwise let the backend figure out a
  506. * reasonable default. Most backends don't offer anything like this, and often
  507. * this would be an end user setting an environment variable for their custom
  508. * need, and not something an application should specifically manage.
  509. *
  510. * When done with an audio device, possibly at the end of the app's life, one
  511. * should call SDL_CloseAudioDevice() on the returned device id.
  512. *
  513. * \param devid the device instance id to open, or
  514. * SDL_AUDIO_DEVICE_DEFAULT_OUTPUT or
  515. * SDL_AUDIO_DEVICE_DEFAULT_CAPTURE for the most reasonable
  516. * default device.
  517. * \param spec the requested device configuration. Can be NULL to use
  518. * reasonable defaults.
  519. * \returns The device ID on success, 0 on error; call SDL_GetError() for more
  520. * information.
  521. *
  522. * \threadsafety It is safe to call this function from any thread.
  523. *
  524. * \since This function is available since SDL 3.0.0.
  525. *
  526. * \sa SDL_CloseAudioDevice
  527. * \sa SDL_GetAudioDeviceFormat
  528. */
  529. extern DECLSPEC SDL_AudioDeviceID SDLCALL SDL_OpenAudioDevice(SDL_AudioDeviceID devid, const SDL_AudioSpec *spec);
  530. /**
  531. * Use this function to pause audio playback on a specified device.
  532. *
  533. * This function pauses audio processing for a given device. Any bound audio
  534. * streams will not progress, and no audio will be generated. Pausing one
  535. * device does not prevent other unpaused devices from running.
  536. *
  537. * Unlike in SDL2, audio devices start in an _unpaused_ state, since an app
  538. * has to bind a stream before any audio will flow. Pausing a paused device is
  539. * a legal no-op.
  540. *
  541. * Pausing a device can be useful to halt all audio without unbinding all the
  542. * audio streams. This might be useful while a game is paused, or a level is
  543. * loading, etc.
  544. *
  545. * Physical devices can not be paused or unpaused, only logical devices
  546. * created through SDL_OpenAudioDevice() can be.
  547. *
  548. * \param dev a device opened by SDL_OpenAudioDevice()
  549. * \returns 0 on success or a negative error code on failure; call
  550. * SDL_GetError() for more information.
  551. *
  552. * \threadsafety It is safe to call this function from any thread.
  553. *
  554. * \since This function is available since SDL 3.0.0.
  555. *
  556. * \sa SDL_ResumeAudioDevice
  557. * \sa SDL_AudioDevicePaused
  558. */
  559. extern DECLSPEC int SDLCALL SDL_PauseAudioDevice(SDL_AudioDeviceID dev);
  560. /**
  561. * Use this function to unpause audio playback on a specified device.
  562. *
  563. * This function unpauses audio processing for a given device that has
  564. * previously been paused with SDL_PauseAudioDevice(). Once unpaused, any
  565. * bound audio streams will begin to progress again, and audio can be
  566. * generated.
  567. *
  568. * Unlike in SDL2, audio devices start in an _unpaused_ state, since an app
  569. * has to bind a stream before any audio will flow. Unpausing an unpaused
  570. * device is a legal no-op.
  571. *
  572. * Physical devices can not be paused or unpaused, only logical devices
  573. * created through SDL_OpenAudioDevice() can be.
  574. *
  575. * \param dev a device opened by SDL_OpenAudioDevice()
  576. * \returns 0 on success or a negative error code on failure; call
  577. * SDL_GetError() for more information.
  578. *
  579. * \threadsafety It is safe to call this function from any thread.
  580. *
  581. * \since This function is available since SDL 3.0.0.
  582. *
  583. * \sa SDL_AudioDevicePaused
  584. * \sa SDL_PauseAudioDevice
  585. */
  586. extern DECLSPEC int SDLCALL SDL_ResumeAudioDevice(SDL_AudioDeviceID dev);
  587. /**
  588. * Use this function to query if an audio device is paused.
  589. *
  590. * Unlike in SDL2, audio devices start in an _unpaused_ state, since an app
  591. * has to bind a stream before any audio will flow.
  592. *
  593. * Physical devices can not be paused or unpaused, only logical devices
  594. * created through SDL_OpenAudioDevice() can be. Physical and invalid device
  595. * IDs will report themselves as unpaused here.
  596. *
  597. * \param dev a device opened by SDL_OpenAudioDevice()
  598. * \returns SDL_TRUE if device is valid and paused, SDL_FALSE otherwise.
  599. *
  600. * \threadsafety It is safe to call this function from any thread.
  601. *
  602. * \since This function is available since SDL 3.0.0.
  603. *
  604. * \sa SDL_PauseAudioDevice
  605. * \sa SDL_ResumeAudioDevice
  606. */
  607. extern DECLSPEC SDL_bool SDLCALL SDL_AudioDevicePaused(SDL_AudioDeviceID dev);
  608. /**
  609. * Close a previously-opened audio device.
  610. *
  611. * The application should close open audio devices once they are no longer
  612. * needed.
  613. *
  614. * This function may block briefly while pending audio data is played by the
  615. * hardware, so that applications don't drop the last buffer of data they
  616. * supplied if terminating immediately afterwards.
  617. *
  618. * \param devid an audio device id previously returned by
  619. * SDL_OpenAudioDevice()
  620. *
  621. * \threadsafety It is safe to call this function from any thread.
  622. *
  623. * \since This function is available since SDL 3.0.0.
  624. *
  625. * \sa SDL_OpenAudioDevice
  626. */
  627. extern DECLSPEC void SDLCALL SDL_CloseAudioDevice(SDL_AudioDeviceID devid);
  628. /**
  629. * Bind a list of audio streams to an audio device.
  630. *
  631. * Audio data will flow through any bound streams. For an output device, data
  632. * for all bound streams will be mixed together and fed to the device. For a
  633. * capture device, a copy of recorded data will be provided to each bound
  634. * stream.
  635. *
  636. * Audio streams can only be bound to an open device. This operation is
  637. * atomic--all streams bound in the same call will start processing at the
  638. * same time, so they can stay in sync. Also: either all streams will be bound
  639. * or none of them will be.
  640. *
  641. * It is an error to bind an already-bound stream; it must be explicitly
  642. * unbound first.
  643. *
  644. * Binding a stream to a device will set its output format for output devices,
  645. * and its input format for capture devices, so they match the device's
  646. * settings. The caller is welcome to change the other end of the stream's
  647. * format at any time.
  648. *
  649. * \param devid an audio device to bind a stream to.
  650. * \param streams an array of audio streams to unbind.
  651. * \param num_streams Number streams listed in the `streams` array.
  652. * \returns 0 on success, -1 on error; call SDL_GetError() for more
  653. * information.
  654. *
  655. * \threadsafety It is safe to call this function from any thread.
  656. *
  657. * \since This function is available since SDL 3.0.0.
  658. *
  659. * \sa SDL_BindAudioStreams
  660. * \sa SDL_UnbindAudioStream
  661. * \sa SDL_GetAudioStreamDevice
  662. */
  663. extern DECLSPEC int SDLCALL SDL_BindAudioStreams(SDL_AudioDeviceID devid, SDL_AudioStream **streams, int num_streams);
  664. /**
  665. * Bind a single audio stream to an audio device.
  666. *
  667. * This is a convenience function, equivalent to calling
  668. * `SDL_BindAudioStreams(devid, &stream, 1)`.
  669. *
  670. * \param devid an audio device to bind a stream to.
  671. * \param stream an audio stream to bind to a device.
  672. * \returns 0 on success, -1 on error; call SDL_GetError() for more
  673. * information.
  674. *
  675. * \threadsafety It is safe to call this function from any thread.
  676. *
  677. * \since This function is available since SDL 3.0.0.
  678. *
  679. * \sa SDL_BindAudioStreams
  680. * \sa SDL_UnbindAudioStream
  681. * \sa SDL_GetAudioStreamDevice
  682. */
  683. extern DECLSPEC int SDLCALL SDL_BindAudioStream(SDL_AudioDeviceID devid, SDL_AudioStream *stream);
  684. /**
  685. * Unbind a list of audio streams from their audio devices.
  686. *
  687. * The streams being unbound do not all have to be on the same device. All
  688. * streams on the same device will be unbound atomically (data will stop
  689. * flowing through all unbound streams on the same device at the same time).
  690. *
  691. * Unbinding a stream that isn't bound to a device is a legal no-op.
  692. *
  693. * \param streams an array of audio streams to unbind.
  694. * \param num_streams Number streams listed in the `streams` array.
  695. *
  696. * \threadsafety It is safe to call this function from any thread.
  697. *
  698. * \since This function is available since SDL 3.0.0.
  699. *
  700. * \sa SDL_BindAudioStreams
  701. */
  702. extern DECLSPEC void SDLCALL SDL_UnbindAudioStreams(SDL_AudioStream **streams, int num_streams);
  703. /**
  704. * Unbind a single audio stream from its audio device.
  705. *
  706. * This is a convenience function, equivalent to calling
  707. * `SDL_UnbindAudioStreams(&stream, 1)`.
  708. *
  709. * \param stream an audio stream to unbind from a device.
  710. *
  711. * \threadsafety It is safe to call this function from any thread.
  712. *
  713. * \since This function is available since SDL 3.0.0.
  714. *
  715. * \sa SDL_BindAudioStream
  716. */
  717. extern DECLSPEC void SDLCALL SDL_UnbindAudioStream(SDL_AudioStream *stream);
  718. /**
  719. * Query an audio stream for its currently-bound device.
  720. *
  721. * This reports the audio device that an audio stream is currently bound to.
  722. *
  723. * If not bound, or invalid, this returns zero, which is not a valid device
  724. * ID.
  725. *
  726. * \param stream the audio stream to query.
  727. * \returns The bound audio device, or 0 if not bound or invalid.
  728. *
  729. * \threadsafety It is safe to call this function from any thread.
  730. *
  731. * \since This function is available since SDL 3.0.0.
  732. *
  733. * \sa SDL_BindAudioStream
  734. * \sa SDL_BindAudioStreams
  735. */
  736. extern DECLSPEC SDL_AudioDeviceID SDLCALL SDL_GetAudioStreamDevice(SDL_AudioStream *stream);
  737. /**
  738. * Create a new audio stream.
  739. *
  740. * \param src_spec The format details of the input audio
  741. * \param dst_spec The format details of the output audio
  742. * \returns a new audio stream on success, or NULL on failure.
  743. *
  744. * \threadsafety It is safe to call this function from any thread.
  745. *
  746. * \since This function is available since SDL 3.0.0.
  747. *
  748. * \sa SDL_PutAudioStreamData
  749. * \sa SDL_GetAudioStreamData
  750. * \sa SDL_GetAudioStreamAvailable
  751. * \sa SDL_FlushAudioStream
  752. * \sa SDL_ClearAudioStream
  753. * \sa SDL_ChangeAudioStreamOutput
  754. * \sa SDL_DestroyAudioStream
  755. */
  756. extern DECLSPEC SDL_AudioStream *SDLCALL SDL_CreateAudioStream(const SDL_AudioSpec *src_spec, const SDL_AudioSpec *dst_spec);
  757. /**
  758. * Get the properties associated with an audio stream.
  759. *
  760. * \param stream the SDL_AudioStream to query
  761. * \returns a valid property ID on success or 0 on failure; call
  762. * SDL_GetError() for more information.
  763. *
  764. * \since This function is available since SDL 3.0.0.
  765. *
  766. * \sa SDL_GetProperty
  767. * \sa SDL_SetProperty
  768. */
  769. extern DECLSPEC SDL_PropertiesID SDLCALL SDL_GetAudioStreamProperties(SDL_AudioStream *stream);
  770. /**
  771. * Query the current format of an audio stream.
  772. *
  773. * \param stream the SDL_AudioStream to query.
  774. * \param src_spec Where to store the input audio format; ignored if NULL.
  775. * \param dst_spec Where to store the output audio format; ignored if NULL.
  776. * \returns 0 on success, or -1 on error.
  777. *
  778. * \threadsafety It is safe to call this function from any thread, as it holds
  779. * a stream-specific mutex while running.
  780. *
  781. * \since This function is available since SDL 3.0.0.
  782. */
  783. extern DECLSPEC int SDLCALL SDL_GetAudioStreamFormat(SDL_AudioStream *stream,
  784. SDL_AudioSpec *src_spec,
  785. SDL_AudioSpec *dst_spec);
  786. /**
  787. * Change the input and output formats of an audio stream.
  788. *
  789. * Future calls to and SDL_GetAudioStreamAvailable and SDL_GetAudioStreamData
  790. * will reflect the new format, and future calls to SDL_PutAudioStreamData
  791. * must provide data in the new input formats.
  792. *
  793. * Data that was previously queued in the stream will still be operated on in
  794. * the format that was current when it was added, which is to say you can put
  795. * the end of a sound file in one format to a stream, change formats for the
  796. * next sound file, and start putting that new data while the previous sound
  797. * file is still queued, and everything will still play back correctly.
  798. *
  799. * \param stream The stream the format is being changed
  800. * \param src_spec The new format of the audio input; if NULL, it is not
  801. * changed.
  802. * \param dst_spec The new format of the audio output; if NULL, it is not
  803. * changed.
  804. * \returns 0 on success, or -1 on error.
  805. *
  806. * \threadsafety It is safe to call this function from any thread, as it holds
  807. * a stream-specific mutex while running.
  808. *
  809. * \since This function is available since SDL 3.0.0.
  810. *
  811. * \sa SDL_GetAudioStreamFormat
  812. * \sa SDL_SetAudioStreamFrequencyRatio
  813. */
  814. extern DECLSPEC int SDLCALL SDL_SetAudioStreamFormat(SDL_AudioStream *stream,
  815. const SDL_AudioSpec *src_spec,
  816. const SDL_AudioSpec *dst_spec);
  817. /**
  818. * Get the frequency ratio of an audio stream.
  819. *
  820. * \param stream the SDL_AudioStream to query.
  821. * \returns the frequency ratio of the stream, or 0.0 on error
  822. *
  823. * \threadsafety It is safe to call this function from any thread, as it holds
  824. * a stream-specific mutex while running.
  825. *
  826. * \since This function is available since SDL 3.0.0.
  827. *
  828. * \sa SDL_SetAudioStreamFrequencyRatio
  829. */
  830. extern DECLSPEC float SDLCALL SDL_GetAudioStreamFrequencyRatio(SDL_AudioStream *stream);
  831. /**
  832. * Change the frequency ratio of an audio stream.
  833. *
  834. * The frequency ratio is used to adjust the rate at which input data is
  835. * consumed. Changing this effectively modifies the speed and pitch of the
  836. * audio. A value greater than 1.0 will play the audio faster, and at a higher
  837. * pitch. A value less than 1.0 will play the audio slower, and at a lower
  838. * pitch.
  839. *
  840. * This is applied during SDL_GetAudioStreamData, and can be continuously
  841. * changed to create various effects.
  842. *
  843. * \param stream The stream the frequency ratio is being changed
  844. * \param ratio The frequency ratio. 1.0 is normal speed. Must be between 0.01
  845. * and 100.
  846. * \returns 0 on success, or -1 on error.
  847. *
  848. * \threadsafety It is safe to call this function from any thread, as it holds
  849. * a stream-specific mutex while running.
  850. *
  851. * \since This function is available since SDL 3.0.0.
  852. *
  853. * \sa SDL_GetAudioStreamFrequencyRatio
  854. * \sa SDL_SetAudioStreamFormat
  855. */
  856. extern DECLSPEC int SDLCALL SDL_SetAudioStreamFrequencyRatio(SDL_AudioStream *stream, float ratio);
  857. /**
  858. * Add data to the stream.
  859. *
  860. * This data must match the format/channels/samplerate specified in the latest
  861. * call to SDL_SetAudioStreamFormat, or the format specified when creating the
  862. * stream if it hasn't been changed.
  863. *
  864. * Note that this call simply copies the unconverted data for later. This is
  865. * different than SDL2, where data was converted during the Put call and the
  866. * Get call would just dequeue the previously-converted data.
  867. *
  868. * \param stream The stream the audio data is being added to
  869. * \param buf A pointer to the audio data to add
  870. * \param len The number of bytes to write to the stream
  871. * \returns 0 on success or a negative error code on failure; call
  872. * SDL_GetError() for more information.
  873. *
  874. * \threadsafety It is safe to call this function from any thread, but if the
  875. * stream has a callback set, the caller might need to manage
  876. * extra locking.
  877. *
  878. * \since This function is available since SDL 3.0.0.
  879. *
  880. * \sa SDL_ClearAudioStream
  881. * \sa SDL_FlushAudioStream
  882. * \sa SDL_GetAudioStreamData
  883. * \sa SDL_GetAudioStreamQueued
  884. */
  885. extern DECLSPEC int SDLCALL SDL_PutAudioStreamData(SDL_AudioStream *stream, const void *buf, int len);
  886. /**
  887. * Get converted/resampled data from the stream.
  888. *
  889. * The input/output data format/channels/samplerate is specified when creating
  890. * the stream, and can be changed after creation by calling
  891. * SDL_SetAudioStreamFormat.
  892. *
  893. * Note that any conversion and resampling necessary is done during this call,
  894. * and SDL_PutAudioStreamData simply queues unconverted data for later. This
  895. * is different than SDL2, where that work was done while inputting new data
  896. * to the stream and requesting the output just copied the converted data.
  897. *
  898. * \param stream The stream the audio is being requested from
  899. * \param buf A buffer to fill with audio data
  900. * \param len The maximum number of bytes to fill
  901. * \returns the number of bytes read from the stream, or -1 on error
  902. *
  903. * \threadsafety It is safe to call this function from any thread, but if the
  904. * stream has a callback set, the caller might need to manage
  905. * extra locking.
  906. *
  907. * \since This function is available since SDL 3.0.0.
  908. *
  909. * \sa SDL_ClearAudioStream
  910. * \sa SDL_GetAudioStreamAvailable
  911. * \sa SDL_PutAudioStreamData
  912. */
  913. extern DECLSPEC int SDLCALL SDL_GetAudioStreamData(SDL_AudioStream *stream, void *buf, int len);
  914. /**
  915. * Get the number of converted/resampled bytes available.
  916. *
  917. * The stream may be buffering data behind the scenes until it has enough to
  918. * resample correctly, so this number might be lower than what you expect, or
  919. * even be zero. Add more data or flush the stream if you need the data now.
  920. *
  921. * If the stream has so much data that it would overflow an int, the return
  922. * value is clamped to a maximum value, but no queued data is lost; if there
  923. * are gigabytes of data queued, the app might need to read some of it with
  924. * SDL_GetAudioStreamData before this function's return value is no longer
  925. * clamped.
  926. *
  927. * \param stream The audio stream to query
  928. * \returns the number of converted/resampled bytes available.
  929. *
  930. * \threadsafety It is safe to call this function from any thread.
  931. *
  932. * \since This function is available since SDL 3.0.0.
  933. *
  934. * \sa SDL_GetAudioStreamData
  935. * \sa SDL_PutAudioStreamData
  936. */
  937. extern DECLSPEC int SDLCALL SDL_GetAudioStreamAvailable(SDL_AudioStream *stream);
  938. /**
  939. * Get the number of bytes currently queued.
  940. *
  941. * Note that audio streams can change their input format at any time, even if
  942. * there is still data queued in a different format, so the returned byte
  943. * count will not necessarily match the number of _sample frames_ available.
  944. * Users of this API should be aware of format changes they make when feeding
  945. * a stream and plan accordingly.
  946. *
  947. * Queued data is not converted until it is consumed by
  948. * SDL_GetAudioStreamData, so this value should be representative of the exact
  949. * data that was put into the stream.
  950. *
  951. * If the stream has so much data that it would overflow an int, the return
  952. * value is clamped to a maximum value, but no queued data is lost; if there
  953. * are gigabytes of data queued, the app might need to read some of it with
  954. * SDL_GetAudioStreamData before this function's return value is no longer
  955. * clamped.
  956. *
  957. * \param stream The audio stream to query
  958. * \returns the number of bytes queued.
  959. *
  960. * \threadsafety It is safe to call this function from any thread.
  961. *
  962. * \since This function is available since SDL 3.0.0.
  963. *
  964. * \sa SDL_PutAudioStreamData
  965. * \sa SDL_ClearAudioStream
  966. */
  967. extern DECLSPEC int SDLCALL SDL_GetAudioStreamQueued(SDL_AudioStream *stream);
  968. /**
  969. * Tell the stream that you're done sending data, and anything being buffered
  970. * should be converted/resampled and made available immediately.
  971. *
  972. * It is legal to add more data to a stream after flushing, but there may be
  973. * audio gaps in the output. Generally this is intended to signal the end of
  974. * input, so the complete output becomes available.
  975. *
  976. * \param stream The audio stream to flush
  977. * \returns 0 on success or a negative error code on failure; call
  978. * SDL_GetError() for more information.
  979. *
  980. * \threadsafety It is safe to call this function from any thread.
  981. *
  982. * \since This function is available since SDL 3.0.0.
  983. *
  984. * \sa SDL_PutAudioStreamData
  985. */
  986. extern DECLSPEC int SDLCALL SDL_FlushAudioStream(SDL_AudioStream *stream);
  987. /**
  988. * Clear any pending data in the stream.
  989. *
  990. * This drops any queued data, so there will be nothing to read from the
  991. * stream until more is added.
  992. *
  993. * \param stream The audio stream to clear
  994. * \returns 0 on success or a negative error code on failure; call
  995. * SDL_GetError() for more information.
  996. *
  997. * \threadsafety It is safe to call this function from any thread.
  998. *
  999. * \since This function is available since SDL 3.0.0.
  1000. *
  1001. * \sa SDL_GetAudioStreamAvailable
  1002. * \sa SDL_GetAudioStreamData
  1003. * \sa SDL_GetAudioStreamQueued
  1004. * \sa SDL_PutAudioStreamData
  1005. */
  1006. extern DECLSPEC int SDLCALL SDL_ClearAudioStream(SDL_AudioStream *stream);
  1007. /**
  1008. * Lock an audio stream for serialized access.
  1009. *
  1010. * Each SDL_AudioStream has an internal mutex it uses to protect its data
  1011. * structures from threading conflicts. This function allows an app to lock
  1012. * that mutex, which could be useful if registering callbacks on this stream.
  1013. *
  1014. * One does not need to lock a stream to use in it most cases, as the stream
  1015. * manages this lock internally. However, this lock is held during callbacks,
  1016. * which may run from arbitrary threads at any time, so if an app needs to
  1017. * protect shared data during those callbacks, locking the stream guarantees
  1018. * that the callback is not running while the lock is held.
  1019. *
  1020. * As this is just a wrapper over SDL_LockMutex for an internal lock; it has
  1021. * all the same attributes (recursive locks are allowed, etc).
  1022. *
  1023. * \param stream The audio stream to lock.
  1024. * \returns 0 on success or a negative error code on failure; call
  1025. * SDL_GetError() for more information.
  1026. *
  1027. * \threadsafety It is safe to call this function from any thread.
  1028. *
  1029. * \since This function is available since SDL 3.0.0.
  1030. *
  1031. * \sa SDL_UnlockAudioStream
  1032. */
  1033. extern DECLSPEC int SDLCALL SDL_LockAudioStream(SDL_AudioStream *stream);
  1034. /**
  1035. * Unlock an audio stream for serialized access.
  1036. *
  1037. * This unlocks an audio stream after a call to SDL_LockAudioStream.
  1038. *
  1039. * \param stream The audio stream to unlock.
  1040. * \returns 0 on success or a negative error code on failure; call
  1041. * SDL_GetError() for more information.
  1042. *
  1043. * \threadsafety You should only call this from the same thread that
  1044. * previously called SDL_LockAudioStream.
  1045. *
  1046. * \since This function is available since SDL 3.0.0.
  1047. *
  1048. * \sa SDL_LockAudioStream
  1049. */
  1050. extern DECLSPEC int SDLCALL SDL_UnlockAudioStream(SDL_AudioStream *stream);
  1051. /**
  1052. * A callback that fires when data passes through an SDL_AudioStream.
  1053. *
  1054. * Apps can (optionally) register a callback with an audio stream that is
  1055. * called when data is added with SDL_PutAudioStreamData, or requested with
  1056. * SDL_GetAudioStreamData.
  1057. *
  1058. * Two values are offered here: one is the amount of additional data needed to
  1059. * satisfy the immediate request (which might be zero if the stream already
  1060. * has enough data queued) and the other is the total amount being requested.
  1061. * In a Get call triggering a Put callback, these values can be different. In
  1062. * a Put call triggering a Get callback, these values are always the same.
  1063. *
  1064. * Byte counts might be slightly overestimated due to buffering or resampling,
  1065. * and may change from call to call.
  1066. *
  1067. * This callback is not required to do anything. Generally this is useful for
  1068. * adding/reading data on demand, and the app will often put/get data as
  1069. * appropriate, but the system goes on with the data currently available to it
  1070. * if this callback does nothing.
  1071. *
  1072. * \param stream The SDL audio stream associated with this callback.
  1073. * \param additional_amount The amount of data, in bytes, that is needed right
  1074. * now.
  1075. * \param total_amount The total amount of data requested, in bytes, that is
  1076. * requested or available.
  1077. * \param userdata An opaque pointer provided by the app for their personal
  1078. * use.
  1079. *
  1080. * \threadsafety This callbacks may run from any thread, so if you need to
  1081. * protect shared data, you should use SDL_LockAudioStream to
  1082. * serialize access; this lock will be held before your callback
  1083. * is called, so your callback does not need to manage the lock
  1084. * explicitly.
  1085. *
  1086. * \since This datatype is available since SDL 3.0.0.
  1087. *
  1088. * \sa SDL_SetAudioStreamGetCallback
  1089. * \sa SDL_SetAudioStreamPutCallback
  1090. */
  1091. typedef void (SDLCALL *SDL_AudioStreamCallback)(void *userdata, SDL_AudioStream *stream, int additional_amount, int total_amount);
  1092. /**
  1093. * Set a callback that runs when data is requested from an audio stream.
  1094. *
  1095. * This callback is called _before_ data is obtained from the stream, giving
  1096. * the callback the chance to add more on-demand.
  1097. *
  1098. * The callback can (optionally) call SDL_PutAudioStreamData() to add more
  1099. * audio to the stream during this call; if needed, the request that triggered
  1100. * this callback will obtain the new data immediately.
  1101. *
  1102. * The callback's `approx_request` argument is roughly how many bytes of
  1103. * _unconverted_ data (in the stream's input format) is needed by the caller,
  1104. * although this may overestimate a little for safety. This takes into account
  1105. * how much is already in the stream and only asks for any extra necessary to
  1106. * resolve the request, which means the callback may be asked for zero bytes,
  1107. * and a different amount on each call.
  1108. *
  1109. * The callback is not required to supply exact amounts; it is allowed to
  1110. * supply too much or too little or none at all. The caller will get what's
  1111. * available, up to the amount they requested, regardless of this callback's
  1112. * outcome.
  1113. *
  1114. * Clearing or flushing an audio stream does not call this callback.
  1115. *
  1116. * This function obtains the stream's lock, which means any existing callback
  1117. * (get or put) in progress will finish running before setting the new
  1118. * callback.
  1119. *
  1120. * Setting a NULL function turns off the callback.
  1121. *
  1122. * \param stream the audio stream to set the new callback on.
  1123. * \param callback the new callback function to call when data is added to the
  1124. * stream.
  1125. * \param userdata an opaque pointer provided to the callback for its own
  1126. * personal use.
  1127. * \returns 0 on success, -1 on error. This only fails if `stream` is NULL.
  1128. *
  1129. * \threadsafety It is safe to call this function from any thread.
  1130. *
  1131. * \since This function is available since SDL 3.0.0.
  1132. *
  1133. * \sa SDL_SetAudioStreamPutCallback
  1134. */
  1135. extern DECLSPEC int SDLCALL SDL_SetAudioStreamGetCallback(SDL_AudioStream *stream, SDL_AudioStreamCallback callback, void *userdata);
  1136. /**
  1137. * Set a callback that runs when data is added to an audio stream.
  1138. *
  1139. * This callback is called _after_ the data is added to the stream, giving the
  1140. * callback the chance to obtain it immediately.
  1141. *
  1142. * The callback can (optionally) call SDL_GetAudioStreamData() to obtain audio
  1143. * from the stream during this call.
  1144. *
  1145. * The callback's `approx_request` argument is how many bytes of _converted_
  1146. * data (in the stream's output format) was provided by the caller, although
  1147. * this may underestimate a little for safety. This value might be less than
  1148. * what is currently available in the stream, if data was already there, and
  1149. * might be less than the caller provided if the stream needs to keep a buffer
  1150. * to aid in resampling. Which means the callback may be provided with zero
  1151. * bytes, and a different amount on each call.
  1152. *
  1153. * The callback may call SDL_GetAudioStreamAvailable to see the total amount
  1154. * currently available to read from the stream, instead of the total provided
  1155. * by the current call.
  1156. *
  1157. * The callback is not required to obtain all data. It is allowed to read less
  1158. * or none at all. Anything not read now simply remains in the stream for
  1159. * later access.
  1160. *
  1161. * Clearing or flushing an audio stream does not call this callback.
  1162. *
  1163. * This function obtains the stream's lock, which means any existing callback
  1164. * (get or put) in progress will finish running before setting the new
  1165. * callback.
  1166. *
  1167. * Setting a NULL function turns off the callback.
  1168. *
  1169. * \param stream the audio stream to set the new callback on.
  1170. * \param callback the new callback function to call when data is added to the
  1171. * stream.
  1172. * \param userdata an opaque pointer provided to the callback for its own
  1173. * personal use.
  1174. * \returns 0 on success, -1 on error. This only fails if `stream` is NULL.
  1175. *
  1176. * \threadsafety It is safe to call this function from any thread.
  1177. *
  1178. * \since This function is available since SDL 3.0.0.
  1179. *
  1180. * \sa SDL_SetAudioStreamGetCallback
  1181. */
  1182. extern DECLSPEC int SDLCALL SDL_SetAudioStreamPutCallback(SDL_AudioStream *stream, SDL_AudioStreamCallback callback, void *userdata);
  1183. /**
  1184. * Free an audio stream.
  1185. *
  1186. * This will release all allocated data, including any audio that is still
  1187. * queued. You do not need to manually clear the stream first.
  1188. *
  1189. * If this stream was bound to an audio device, it is unbound during this
  1190. * call. If this stream was created with SDL_OpenAudioDeviceStream, the audio
  1191. * device that was opened alongside this stream's creation will be closed,
  1192. * too.
  1193. *
  1194. * \param stream The audio stream to destroy.
  1195. *
  1196. * \threadsafety It is safe to call this function from any thread.
  1197. *
  1198. * \since This function is available since SDL 3.0.0.
  1199. *
  1200. * \sa SDL_CreateAudioStream
  1201. */
  1202. extern DECLSPEC void SDLCALL SDL_DestroyAudioStream(SDL_AudioStream *stream);
  1203. /**
  1204. * Convenience function for straightforward audio init for the common case.
  1205. *
  1206. * If all your app intends to do is provide a single source of PCM audio, this
  1207. * function allows you to do all your audio setup in a single call.
  1208. *
  1209. * This is also intended to be a clean means to migrate apps from SDL2.
  1210. *
  1211. * This function will open an audio device, create a stream and bind it.
  1212. * Unlike other methods of setup, the audio device will be closed when this
  1213. * stream is destroyed, so the app can treat the returned SDL_AudioStream as
  1214. * the only object needed to manage audio playback.
  1215. *
  1216. * Also unlike other functions, the audio device begins paused. This is to map
  1217. * more closely to SDL2-style behavior, since there is no extra step here to
  1218. * bind a stream to begin audio flowing. The audio device should be resumed
  1219. * with `SDL_ResumeAudioDevice(SDL_GetAudioStreamDevice(stream));`
  1220. *
  1221. * This function works with both playback and capture devices.
  1222. *
  1223. * The `spec` parameter represents the app's side of the audio stream. That
  1224. * is, for recording audio, this will be the output format, and for playing
  1225. * audio, this will be the input format.
  1226. *
  1227. * If you don't care about opening a specific audio device, you can (and
  1228. * probably _should_), use SDL_AUDIO_DEVICE_DEFAULT_OUTPUT for playback and
  1229. * SDL_AUDIO_DEVICE_DEFAULT_CAPTURE for recording.
  1230. *
  1231. * One can optionally provide a callback function; if NULL, the app is
  1232. * expected to queue audio data for playback (or unqueue audio data if
  1233. * capturing). Otherwise, the callback will begin to fire once the device is
  1234. * unpaused.
  1235. *
  1236. * \param devid an audio device to open, or SDL_AUDIO_DEVICE_DEFAULT_OUTPUT or
  1237. * SDL_AUDIO_DEVICE_DEFAULT_CAPTURE.
  1238. * \param spec the audio stream's data format. Required.
  1239. * \param callback A callback where the app will provide new data for
  1240. * playback, or receive new data for capture. Can be NULL, in
  1241. * which case the app will need to call SDL_PutAudioStreamData
  1242. * or SDL_GetAudioStreamData as necessary.
  1243. * \param userdata App-controlled pointer passed to callback. Can be NULL.
  1244. * Ignored if callback is NULL.
  1245. * \returns an audio stream on success, ready to use. NULL on error; call
  1246. * SDL_GetError() for more information. When done with this stream,
  1247. * call SDL_DestroyAudioStream to free resources and close the
  1248. * device.
  1249. *
  1250. * \threadsafety It is safe to call this function from any thread.
  1251. *
  1252. * \since This function is available since SDL 3.0.0.
  1253. *
  1254. * \sa SDL_GetAudioStreamDevice
  1255. * \sa SDL_ResumeAudioDevice
  1256. */
  1257. extern DECLSPEC SDL_AudioStream *SDLCALL SDL_OpenAudioDeviceStream(SDL_AudioDeviceID devid, const SDL_AudioSpec *spec, SDL_AudioStreamCallback callback, void *userdata);
  1258. /**
  1259. * A callback that fires when data is about to be fed to an audio device.
  1260. *
  1261. * This is useful for accessing the final mix, perhaps for writing a
  1262. * visualizer or applying a final effect to the audio data before playback.
  1263. *
  1264. * This callback should run as quickly as possible and not block for any
  1265. * significant time, as this callback delays submission of data to the audio
  1266. * device, which can cause audio playback problems.
  1267. *
  1268. * The postmix callback _must_ be able to handle any audio data format
  1269. * specified in `spec`, which can change between callbacks if the audio device
  1270. * changed. However, this only covers frequency and channel count; data is
  1271. * always provided here in SDL_AUDIO_F32 format.
  1272. *
  1273. * \param userdata a pointer provided by the app through
  1274. * SDL_SetAudioDevicePostmixCallback, for its own use.
  1275. * \param spec the current format of audio that is to be submitted to the
  1276. * audio device.
  1277. * \param buffer the buffer of audio samples to be submitted. The callback can
  1278. * inspect and/or modify this data.
  1279. * \param buflen the size of `buffer` in bytes.
  1280. *
  1281. * \threadsafety This will run from a background thread owned by SDL. The
  1282. * application is responsible for locking resources the callback
  1283. * touches that need to be protected.
  1284. *
  1285. * \since This datatype is available since SDL 3.0.0.
  1286. *
  1287. * \sa SDL_SetAudioDevicePostmixCallback
  1288. */
  1289. typedef void (SDLCALL *SDL_AudioPostmixCallback)(void *userdata, const SDL_AudioSpec *spec, float *buffer, int buflen);
  1290. /**
  1291. * Set a callback that fires when data is about to be fed to an audio device.
  1292. *
  1293. * This is useful for accessing the final mix, perhaps for writing a
  1294. * visualizer or applying a final effect to the audio data before playback.
  1295. *
  1296. * The buffer is the final mix of all bound audio streams on an opened device;
  1297. * this callback will fire regularly for any device that is both opened and
  1298. * unpaused. If there is no new data to mix, either because no streams are
  1299. * bound to the device or all the streams are empty, this callback will still
  1300. * fire with the entire buffer set to silence.
  1301. *
  1302. * This callback is allowed to make changes to the data; the contents of the
  1303. * buffer after this call is what is ultimately passed along to the hardware.
  1304. *
  1305. * The callback is always provided the data in float format (values from -1.0f
  1306. * to 1.0f), but the number of channels or sample rate may be different than
  1307. * the format the app requested when opening the device; SDL might have had to
  1308. * manage a conversion behind the scenes, or the playback might have jumped to
  1309. * new physical hardware when a system default changed, etc. These details may
  1310. * change between calls. Accordingly, the size of the buffer might change
  1311. * between calls as well.
  1312. *
  1313. * This callback can run at any time, and from any thread; if you need to
  1314. * serialize access to your app's data, you should provide and use a mutex or
  1315. * other synchronization device.
  1316. *
  1317. * All of this to say: there are specific needs this callback can fulfill, but
  1318. * it is not the simplest interface. Apps should generally provide audio in
  1319. * their preferred format through an SDL_AudioStream and let SDL handle the
  1320. * difference.
  1321. *
  1322. * This function is extremely time-sensitive; the callback should do the least
  1323. * amount of work possible and return as quickly as it can. The longer the
  1324. * callback runs, the higher the risk of audio dropouts or other problems.
  1325. *
  1326. * This function will block until the audio device is in between iterations,
  1327. * so any existing callback that might be running will finish before this
  1328. * function sets the new callback and returns.
  1329. *
  1330. * Setting a NULL callback function disables any previously-set callback.
  1331. *
  1332. * \param devid The ID of an opened audio device.
  1333. * \param callback A callback function to be called. Can be NULL.
  1334. * \param userdata App-controlled pointer passed to callback. Can be NULL.
  1335. * \returns zero on success, -1 on error; call SDL_GetError() for more
  1336. * information.
  1337. *
  1338. * \threadsafety It is safe to call this function from any thread.
  1339. *
  1340. * \since This function is available since SDL 3.0.0.
  1341. */
  1342. extern DECLSPEC int SDLCALL SDL_SetAudioPostmixCallback(SDL_AudioDeviceID devid, SDL_AudioPostmixCallback callback, void *userdata);
  1343. /**
  1344. * Load the audio data of a WAVE file into memory.
  1345. *
  1346. * Loading a WAVE file requires `src`, `spec`, `audio_buf` and `audio_len` to
  1347. * be valid pointers. The entire data portion of the file is then loaded into
  1348. * memory and decoded if necessary.
  1349. *
  1350. * Supported formats are RIFF WAVE files with the formats PCM (8, 16, 24, and
  1351. * 32 bits), IEEE Float (32 bits), Microsoft ADPCM and IMA ADPCM (4 bits), and
  1352. * A-law and mu-law (8 bits). Other formats are currently unsupported and
  1353. * cause an error.
  1354. *
  1355. * If this function succeeds, the return value is zero and the pointer to the
  1356. * audio data allocated by the function is written to `audio_buf` and its
  1357. * length in bytes to `audio_len`. The SDL_AudioSpec members `freq`,
  1358. * `channels`, and `format` are set to the values of the audio data in the
  1359. * buffer.
  1360. *
  1361. * It's necessary to use SDL_free() to free the audio data returned in
  1362. * `audio_buf` when it is no longer used.
  1363. *
  1364. * Because of the underspecification of the .WAV format, there are many
  1365. * problematic files in the wild that cause issues with strict decoders. To
  1366. * provide compatibility with these files, this decoder is lenient in regards
  1367. * to the truncation of the file, the fact chunk, and the size of the RIFF
  1368. * chunk. The hints `SDL_HINT_WAVE_RIFF_CHUNK_SIZE`,
  1369. * `SDL_HINT_WAVE_TRUNCATION`, and `SDL_HINT_WAVE_FACT_CHUNK` can be used to
  1370. * tune the behavior of the loading process.
  1371. *
  1372. * Any file that is invalid (due to truncation, corruption, or wrong values in
  1373. * the headers), too big, or unsupported causes an error. Additionally, any
  1374. * critical I/O error from the data source will terminate the loading process
  1375. * with an error. The function returns NULL on error and in all cases (with
  1376. * the exception of `src` being NULL), an appropriate error message will be
  1377. * set.
  1378. *
  1379. * It is required that the data source supports seeking.
  1380. *
  1381. * Example:
  1382. *
  1383. * ```c
  1384. * SDL_LoadWAV_IO(SDL_IOFromFile("sample.wav", "rb"), 1, &spec, &buf, &len);
  1385. * ```
  1386. *
  1387. * Note that the SDL_LoadWAV function does this same thing for you, but in a
  1388. * less messy way:
  1389. *
  1390. * ```c
  1391. * SDL_LoadWAV("sample.wav", &spec, &buf, &len);
  1392. * ```
  1393. *
  1394. * \param src The data source for the WAVE data
  1395. * \param closeio If SDL_TRUE, calls SDL_CloseIO() on `src` before returning,
  1396. * even in the case of an error
  1397. * \param spec A pointer to an SDL_AudioSpec that will be set to the WAVE
  1398. * data's format details on successful return
  1399. * \param audio_buf A pointer filled with the audio data, allocated by the
  1400. * function
  1401. * \param audio_len A pointer filled with the length of the audio data buffer
  1402. * in bytes
  1403. * \returns 0 on success. `audio_buf` will be filled with a pointer to an
  1404. * allocated buffer containing the audio data, and `audio_len` is
  1405. * filled with the length of that audio buffer in bytes.
  1406. *
  1407. * This function returns -1 if the .WAV file cannot be opened, uses
  1408. * an unknown data format, or is corrupt; call SDL_GetError() for
  1409. * more information.
  1410. *
  1411. * When the application is done with the data returned in
  1412. * `audio_buf`, it should call SDL_free() to dispose of it.
  1413. *
  1414. * \threadsafety It is safe to call this function from any thread.
  1415. *
  1416. * \since This function is available since SDL 3.0.0.
  1417. *
  1418. * \sa SDL_free
  1419. * \sa SDL_LoadWAV
  1420. */
  1421. extern DECLSPEC int SDLCALL SDL_LoadWAV_IO(SDL_IOStream * src, SDL_bool closeio,
  1422. SDL_AudioSpec * spec, Uint8 ** audio_buf,
  1423. Uint32 * audio_len);
  1424. /**
  1425. * Loads a WAV from a file path.
  1426. *
  1427. * This is a convenience function that is effectively the same as:
  1428. *
  1429. * ```c
  1430. * SDL_LoadWAV_IO(SDL_IOFromFile(path, "rb"), 1, spec, audio_buf, audio_len);
  1431. * ```
  1432. *
  1433. * \param path The file path of the WAV file to open.
  1434. * \param spec A pointer to an SDL_AudioSpec that will be set to the WAVE
  1435. * data's format details on successful return.
  1436. * \param audio_buf A pointer filled with the audio data, allocated by the
  1437. * function.
  1438. * \param audio_len A pointer filled with the length of the audio data buffer
  1439. * in bytes
  1440. * \returns 0 on success. `audio_buf` will be filled with a pointer to an
  1441. * allocated buffer containing the audio data, and `audio_len` is
  1442. * filled with the length of that audio buffer in bytes.
  1443. *
  1444. * This function returns -1 if the .WAV file cannot be opened, uses
  1445. * an unknown data format, or is corrupt; call SDL_GetError() for
  1446. * more information.
  1447. *
  1448. * When the application is done with the data returned in
  1449. * `audio_buf`, it should call SDL_free() to dispose of it.
  1450. *
  1451. * \threadsafety It is safe to call this function from any thread.
  1452. *
  1453. * \since This function is available since SDL 3.0.0.
  1454. *
  1455. * \sa SDL_free
  1456. * \sa SDL_LoadWAV_IO
  1457. */
  1458. extern DECLSPEC int SDLCALL SDL_LoadWAV(const char *path, SDL_AudioSpec * spec,
  1459. Uint8 ** audio_buf, Uint32 * audio_len);
  1460. #define SDL_MIX_MAXVOLUME 128
  1461. /**
  1462. * Mix audio data in a specified format.
  1463. *
  1464. * This takes an audio buffer `src` of `len` bytes of `format` data and mixes
  1465. * it into `dst`, performing addition, volume adjustment, and overflow
  1466. * clipping. The buffer pointed to by `dst` must also be `len` bytes of
  1467. * `format` data.
  1468. *
  1469. * This is provided for convenience -- you can mix your own audio data.
  1470. *
  1471. * Do not use this function for mixing together more than two streams of
  1472. * sample data. The output from repeated application of this function may be
  1473. * distorted by clipping, because there is no accumulator with greater range
  1474. * than the input (not to mention this being an inefficient way of doing it).
  1475. *
  1476. * It is a common misconception that this function is required to write audio
  1477. * data to an output stream in an audio callback. While you can do that,
  1478. * SDL_MixAudioFormat() is really only needed when you're mixing a single
  1479. * audio stream with a volume adjustment.
  1480. *
  1481. * \param dst the destination for the mixed audio
  1482. * \param src the source audio buffer to be mixed
  1483. * \param format the SDL_AudioFormat structure representing the desired audio
  1484. * format
  1485. * \param len the length of the audio buffer in bytes
  1486. * \param volume ranges from 0 - 128, and should be set to SDL_MIX_MAXVOLUME
  1487. * for full audio volume
  1488. * \returns 0 on success or a negative error code on failure; call
  1489. * SDL_GetError() for more information.
  1490. *
  1491. * \threadsafety It is safe to call this function from any thread.
  1492. *
  1493. * \since This function is available since SDL 3.0.0.
  1494. */
  1495. extern DECLSPEC int SDLCALL SDL_MixAudioFormat(Uint8 * dst,
  1496. const Uint8 * src,
  1497. SDL_AudioFormat format,
  1498. Uint32 len, int volume);
  1499. /**
  1500. * Convert some audio data of one format to another format.
  1501. *
  1502. * Please note that this function is for convenience, but should not be used
  1503. * to resample audio in blocks, as it will introduce audio artifacts on the
  1504. * boundaries. You should only use this function if you are converting audio
  1505. * data in its entirety in one call. If you want to convert audio in smaller
  1506. * chunks, use an SDL_AudioStream, which is designed for this situation.
  1507. *
  1508. * Internally, this function creates and destroys an SDL_AudioStream on each
  1509. * use, so it's also less efficient than using one directly, if you need to
  1510. * convert multiple times.
  1511. *
  1512. * \param src_spec The format details of the input audio
  1513. * \param src_data The audio data to be converted
  1514. * \param src_len The len of src_data
  1515. * \param dst_spec The format details of the output audio
  1516. * \param dst_data Will be filled with a pointer to converted audio data,
  1517. * which should be freed with SDL_free(). On error, it will be
  1518. * NULL.
  1519. * \param dst_len Will be filled with the len of dst_data
  1520. * \returns 0 on success or a negative error code on failure; call
  1521. * SDL_GetError() for more information.
  1522. *
  1523. * \threadsafety It is safe to call this function from any thread.
  1524. *
  1525. * \since This function is available since SDL 3.0.0.
  1526. */
  1527. extern DECLSPEC int SDLCALL SDL_ConvertAudioSamples(const SDL_AudioSpec *src_spec,
  1528. const Uint8 *src_data,
  1529. int src_len,
  1530. const SDL_AudioSpec *dst_spec,
  1531. Uint8 **dst_data,
  1532. int *dst_len);
  1533. /**
  1534. * Get the appropriate memset value for silencing an audio format.
  1535. *
  1536. * The value returned by this function can be used as the second argument to
  1537. * memset (or SDL_memset) to set an audio buffer in a specific format to
  1538. * silence.
  1539. *
  1540. * \param format the audio data format to query.
  1541. * \returns A byte value that can be passed to memset.
  1542. *
  1543. * \threadsafety It is safe to call this function from any thread.
  1544. *
  1545. * \since This function is available since SDL 3.0.0.
  1546. */
  1547. extern DECLSPEC int SDLCALL SDL_GetSilenceValueForFormat(SDL_AudioFormat format);
  1548. /* Ends C function definitions when using C++ */
  1549. #ifdef __cplusplus
  1550. }
  1551. #endif
  1552. #include <SDL3/SDL_close_code.h>
  1553. #endif /* SDL_audio_h_ */