SDL_audio.h 84 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113
  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. * # CategoryAudio
  20. *
  21. * Audio functionality for the SDL library.
  22. *
  23. * All audio in SDL3 revolves around SDL_AudioStream. Whether you want to play
  24. * or record audio, convert it, stream it, buffer it, or mix it, you're going
  25. * to be passing it through an audio stream.
  26. *
  27. * Audio streams are quite flexible; they can accept any amount of data at a
  28. * time, in any supported format, and output it as needed in any other format,
  29. * even if the data format changes on either side halfway through.
  30. *
  31. * An app opens an audio device and binds any number of audio streams to it,
  32. * feeding more data to the streams as available. When the device needs more
  33. * data, it will pull it from all bound streams and mix them together for
  34. * playback.
  35. *
  36. * Audio streams can also use an app-provided callback to supply data
  37. * on-demand, which maps pretty closely to the SDL2 audio model.
  38. *
  39. * SDL also provides a simple .WAV loader in SDL_LoadWAV (and SDL_LoadWAV_IO
  40. * if you aren't reading from a file) as a basic means to load sound data into
  41. * your program.
  42. *
  43. * ## Logical audio devices
  44. *
  45. * In SDL3, opening a physical device (like a SoundBlaster 16 Pro) gives you a
  46. * logical device ID that you can bind audio streams to. In almost all cases,
  47. * logical devices can be used anywhere in the API that a physical device is
  48. * normally used. However, since each device opening generates a new logical
  49. * device, different parts of the program (say, a VoIP library, or
  50. * text-to-speech framework, or maybe some other sort of mixer on top of SDL)
  51. * can have their own device opens that do not interfere with each other; each
  52. * logical device will mix its separate audio down to a single buffer, fed to
  53. * the physical device, behind the scenes. As many logical devices as you like
  54. * can come and go; SDL will only have to open the physical device at the OS
  55. * level once, and will manage all the logical devices on top of it
  56. * internally.
  57. *
  58. * One other benefit of logical devices: if you don't open a specific physical
  59. * device, instead opting for the default, SDL can automatically migrate those
  60. * logical devices to different hardware as circumstances change: a user
  61. * plugged in headphones? The system default changed? SDL can transparently
  62. * migrate the logical devices to the correct physical device seamlessly and
  63. * keep playing; the app doesn't even have to know it happened if it doesn't
  64. * want to.
  65. *
  66. * ## Simplified audio
  67. *
  68. * As a simplified model for when a single source of audio is all that's
  69. * needed, an app can use SDL_OpenAudioDeviceStream, which is a single
  70. * function to open an audio device, create an audio stream, bind that stream
  71. * to the newly-opened device, and (optionally) provide a callback for
  72. * obtaining audio data. When using this function, the primary interface is
  73. * the SDL_AudioStream and the device handle is mostly hidden away; destroying
  74. * a stream created through this function will also close the device, stream
  75. * bindings cannot be changed, etc. One other quirk of this is that the device
  76. * is started in a _paused_ state and must be explicitly resumed; this is
  77. * partially to offer a clean migration for SDL2 apps and partially because
  78. * the app might have to do more setup before playback begins; in the
  79. * non-simplified form, nothing will play until a stream is bound to a device,
  80. * so they start _unpaused_.
  81. *
  82. * ## Channel layouts
  83. *
  84. * Audio data passing through SDL is uncompressed PCM data, interleaved. One
  85. * can provide their own decompression through an MP3, etc, decoder, but SDL
  86. * does not provide this directly. Each interleaved channel of data is meant
  87. * to be in a specific order.
  88. *
  89. * Abbreviations:
  90. *
  91. * - FRONT = single mono speaker
  92. * - FL = front left speaker
  93. * - FR = front right speaker
  94. * - FC = front center speaker
  95. * - BL = back left speaker
  96. * - BR = back right speaker
  97. * - SR = surround right speaker
  98. * - SL = surround left speaker
  99. * - BC = back center speaker
  100. * - LFE = low-frequency speaker
  101. *
  102. * These are listed in the order they are laid out in memory, so "FL, FR"
  103. * means "the front left speaker is laid out in memory first, then the front
  104. * right, then it repeats for the next audio frame".
  105. *
  106. * - 1 channel (mono) layout: FRONT
  107. * - 2 channels (stereo) layout: FL, FR
  108. * - 3 channels (2.1) layout: FL, FR, LFE
  109. * - 4 channels (quad) layout: FL, FR, BL, BR
  110. * - 5 channels (4.1) layout: FL, FR, LFE, BL, BR
  111. * - 6 channels (5.1) layout: FL, FR, FC, LFE, BL, BR (last two can also be
  112. * SL, SR)
  113. * - 7 channels (6.1) layout: FL, FR, FC, LFE, BC, SL, SR
  114. * - 8 channels (7.1) layout: FL, FR, FC, LFE, BL, BR, SL, SR
  115. *
  116. * This is the same order as DirectSound expects, but applied to all
  117. * platforms; SDL will swizzle the channels as necessary if a platform expects
  118. * something different.
  119. *
  120. * SDL_AudioStream can also be provided channel maps to change this ordering
  121. * to whatever is necessary, in other audio processing scenarios.
  122. */
  123. #ifndef SDL_audio_h_
  124. #define SDL_audio_h_
  125. #include <SDL3/SDL_stdinc.h>
  126. #include <SDL3/SDL_endian.h>
  127. #include <SDL3/SDL_error.h>
  128. #include <SDL3/SDL_mutex.h>
  129. #include <SDL3/SDL_properties.h>
  130. #include <SDL3/SDL_iostream.h>
  131. #include <SDL3/SDL_begin_code.h>
  132. /* Set up for C function definitions, even when using C++ */
  133. #ifdef __cplusplus
  134. extern "C" {
  135. #endif
  136. /* masks for different parts of SDL_AudioFormat. */
  137. #define SDL_AUDIO_MASK_BITSIZE (0xFFu)
  138. #define SDL_AUDIO_MASK_FLOAT (1u<<8)
  139. #define SDL_AUDIO_MASK_BIG_ENDIAN (1u<<12)
  140. #define SDL_AUDIO_MASK_SIGNED (1u<<15)
  141. #define SDL_DEFINE_AUDIO_FORMAT(signed, bigendian, float, size) \
  142. (((Uint16)(signed) << 15) | ((Uint16)(bigendian) << 12) | ((Uint16)(float) << 8) | ((size) & SDL_AUDIO_MASK_BITSIZE))
  143. /**
  144. * Audio format.
  145. *
  146. * \since This enum is available since SDL 3.1.3.
  147. *
  148. * \sa SDL_AUDIO_BITSIZE
  149. * \sa SDL_AUDIO_BYTESIZE
  150. * \sa SDL_AUDIO_ISINT
  151. * \sa SDL_AUDIO_ISFLOAT
  152. * \sa SDL_AUDIO_ISBIGENDIAN
  153. * \sa SDL_AUDIO_ISLITTLEENDIAN
  154. * \sa SDL_AUDIO_ISSIGNED
  155. * \sa SDL_AUDIO_ISUNSIGNED
  156. */
  157. typedef enum SDL_AudioFormat
  158. {
  159. SDL_AUDIO_UNKNOWN = 0x0000u, /**< Unspecified audio format */
  160. SDL_AUDIO_U8 = 0x0008u, /**< Unsigned 8-bit samples */
  161. /* SDL_DEFINE_AUDIO_FORMAT(0, 0, 0, 8), */
  162. SDL_AUDIO_S8 = 0x8008u, /**< Signed 8-bit samples */
  163. /* SDL_DEFINE_AUDIO_FORMAT(1, 0, 0, 8), */
  164. SDL_AUDIO_S16LE = 0x8010u, /**< Signed 16-bit samples */
  165. /* SDL_DEFINE_AUDIO_FORMAT(1, 0, 0, 16), */
  166. SDL_AUDIO_S16BE = 0x9010u, /**< As above, but big-endian byte order */
  167. /* SDL_DEFINE_AUDIO_FORMAT(1, 1, 0, 16), */
  168. SDL_AUDIO_S32LE = 0x8020u, /**< 32-bit integer samples */
  169. /* SDL_DEFINE_AUDIO_FORMAT(1, 0, 0, 32), */
  170. SDL_AUDIO_S32BE = 0x9020u, /**< As above, but big-endian byte order */
  171. /* SDL_DEFINE_AUDIO_FORMAT(1, 1, 0, 32), */
  172. SDL_AUDIO_F32LE = 0x8120u, /**< 32-bit floating point samples */
  173. /* SDL_DEFINE_AUDIO_FORMAT(1, 0, 1, 32), */
  174. SDL_AUDIO_F32BE = 0x9120u, /**< As above, but big-endian byte order */
  175. /* SDL_DEFINE_AUDIO_FORMAT(1, 1, 1, 32), */
  176. /* These represent the current system's byteorder. */
  177. #if SDL_BYTEORDER == SDL_LIL_ENDIAN
  178. SDL_AUDIO_S16 = SDL_AUDIO_S16LE,
  179. SDL_AUDIO_S32 = SDL_AUDIO_S32LE,
  180. SDL_AUDIO_F32 = SDL_AUDIO_F32LE
  181. #else
  182. SDL_AUDIO_S16 = SDL_AUDIO_S16BE,
  183. SDL_AUDIO_S32 = SDL_AUDIO_S32BE,
  184. SDL_AUDIO_F32 = SDL_AUDIO_F32BE
  185. #endif
  186. } SDL_AudioFormat;
  187. /**
  188. * Retrieve the size, in bits, from an SDL_AudioFormat.
  189. *
  190. * For example, `SDL_AUDIO_BITSIZE(SDL_AUDIO_S16)` returns 16.
  191. *
  192. * \param x an SDL_AudioFormat value.
  193. * \returns data size in bits.
  194. *
  195. * \threadsafety It is safe to call this macro from any thread.
  196. *
  197. * \since This macro is available since SDL 3.1.3.
  198. */
  199. #define SDL_AUDIO_BITSIZE(x) ((x) & SDL_AUDIO_MASK_BITSIZE)
  200. /**
  201. * Retrieve the size, in bytes, from an SDL_AudioFormat.
  202. *
  203. * For example, `SDL_AUDIO_BYTESIZE(SDL_AUDIO_S16)` returns 2.
  204. *
  205. * \param x an SDL_AudioFormat value.
  206. * \returns data size in bytes.
  207. *
  208. * \threadsafety It is safe to call this macro from any thread.
  209. *
  210. * \since This macro is available since SDL 3.1.3.
  211. */
  212. #define SDL_AUDIO_BYTESIZE(x) (SDL_AUDIO_BITSIZE(x) / 8)
  213. /**
  214. * Determine if an SDL_AudioFormat represents floating point data.
  215. *
  216. * For example, `SDL_AUDIO_ISFLOAT(SDL_AUDIO_S16)` returns 0.
  217. *
  218. * \param x an SDL_AudioFormat value.
  219. * \returns non-zero if format is floating point, zero otherwise.
  220. *
  221. * \threadsafety It is safe to call this macro from any thread.
  222. *
  223. * \since This macro is available since SDL 3.1.3.
  224. */
  225. #define SDL_AUDIO_ISFLOAT(x) ((x) & SDL_AUDIO_MASK_FLOAT)
  226. /**
  227. * Determine if an SDL_AudioFormat represents bigendian data.
  228. *
  229. * For example, `SDL_AUDIO_ISBIGENDIAN(SDL_AUDIO_S16LE)` returns 0.
  230. *
  231. * \param x an SDL_AudioFormat value.
  232. * \returns non-zero if format is bigendian, zero otherwise.
  233. *
  234. * \threadsafety It is safe to call this macro from any thread.
  235. *
  236. * \since This macro is available since SDL 3.1.3.
  237. */
  238. #define SDL_AUDIO_ISBIGENDIAN(x) ((x) & SDL_AUDIO_MASK_BIG_ENDIAN)
  239. /**
  240. * Determine if an SDL_AudioFormat represents littleendian data.
  241. *
  242. * For example, `SDL_AUDIO_ISLITTLEENDIAN(SDL_AUDIO_S16BE)` returns 0.
  243. *
  244. * \param x an SDL_AudioFormat value.
  245. * \returns non-zero if format is littleendian, zero otherwise.
  246. *
  247. * \threadsafety It is safe to call this macro from any thread.
  248. *
  249. * \since This macro is available since SDL 3.1.3.
  250. */
  251. #define SDL_AUDIO_ISLITTLEENDIAN(x) (!SDL_AUDIO_ISBIGENDIAN(x))
  252. /**
  253. * Determine if an SDL_AudioFormat represents signed data.
  254. *
  255. * For example, `SDL_AUDIO_ISSIGNED(SDL_AUDIO_U8)` returns 0.
  256. *
  257. * \param x an SDL_AudioFormat value.
  258. * \returns non-zero if format is signed, zero otherwise.
  259. *
  260. * \threadsafety It is safe to call this macro from any thread.
  261. *
  262. * \since This macro is available since SDL 3.1.3.
  263. */
  264. #define SDL_AUDIO_ISSIGNED(x) ((x) & SDL_AUDIO_MASK_SIGNED)
  265. /**
  266. * Determine if an SDL_AudioFormat represents integer data.
  267. *
  268. * For example, `SDL_AUDIO_ISINT(SDL_AUDIO_F32)` returns 0.
  269. *
  270. * \param x an SDL_AudioFormat value.
  271. * \returns non-zero if format is integer, zero otherwise.
  272. *
  273. * \threadsafety It is safe to call this macro from any thread.
  274. *
  275. * \since This macro is available since SDL 3.1.3.
  276. */
  277. #define SDL_AUDIO_ISINT(x) (!SDL_AUDIO_ISFLOAT(x))
  278. /**
  279. * Determine if an SDL_AudioFormat represents unsigned data.
  280. *
  281. * For example, `SDL_AUDIO_ISUNSIGNED(SDL_AUDIO_S16)` returns 0.
  282. *
  283. * \param x an SDL_AudioFormat value.
  284. * \returns non-zero if format is unsigned, zero otherwise.
  285. *
  286. * \threadsafety It is safe to call this macro from any thread.
  287. *
  288. * \since This macro is available since SDL 3.1.3.
  289. */
  290. #define SDL_AUDIO_ISUNSIGNED(x) (!SDL_AUDIO_ISSIGNED(x))
  291. /**
  292. * SDL Audio Device instance IDs.
  293. *
  294. * Zero is used to signify an invalid/null device.
  295. *
  296. * \since This datatype is available since SDL 3.1.3.
  297. */
  298. typedef Uint32 SDL_AudioDeviceID;
  299. /**
  300. * A value used to request a default playback audio device.
  301. *
  302. * Several functions that require an SDL_AudioDeviceID will accept this value
  303. * to signify the app just wants the system to choose a default device instead
  304. * of the app providing a specific one.
  305. *
  306. * \since This macro is available since SDL 3.1.3.
  307. */
  308. #define SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK ((SDL_AudioDeviceID) 0xFFFFFFFFu)
  309. /**
  310. * A value used to request a default recording audio device.
  311. *
  312. * Several functions that require an SDL_AudioDeviceID will accept this value
  313. * to signify the app just wants the system to choose a default device instead
  314. * of the app providing a specific one.
  315. *
  316. * \since This macro is available since SDL 3.1.3.
  317. */
  318. #define SDL_AUDIO_DEVICE_DEFAULT_RECORDING ((SDL_AudioDeviceID) 0xFFFFFFFEu)
  319. /**
  320. * Format specifier for audio data.
  321. *
  322. * \since This struct is available since SDL 3.1.3.
  323. *
  324. * \sa SDL_AudioFormat
  325. */
  326. typedef struct SDL_AudioSpec
  327. {
  328. SDL_AudioFormat format; /**< Audio data format */
  329. int channels; /**< Number of channels: 1 mono, 2 stereo, etc */
  330. int freq; /**< sample rate: sample frames per second */
  331. } SDL_AudioSpec;
  332. /**
  333. * Calculate the size of each audio frame (in bytes) from an SDL_AudioSpec.
  334. *
  335. * This reports on the size of an audio sample frame: stereo Sint16 data (2
  336. * channels of 2 bytes each) would be 4 bytes per frame, for example.
  337. *
  338. * \param x an SDL_AudioSpec to query.
  339. * \returns the number of bytes used per sample frame.
  340. *
  341. * \threadsafety It is safe to call this macro from any thread.
  342. *
  343. * \since This macro is available since SDL 3.1.3.
  344. */
  345. #define SDL_AUDIO_FRAMESIZE(x) (SDL_AUDIO_BYTESIZE((x).format) * (x).channels)
  346. /**
  347. * The opaque handle that represents an audio stream.
  348. *
  349. * SDL_AudioStream is an audio conversion interface.
  350. *
  351. * - It can handle resampling data in chunks without generating artifacts,
  352. * when it doesn't have the complete buffer available.
  353. * - It can handle incoming data in any variable size.
  354. * - It can handle input/output format changes on the fly.
  355. * - It can remap audio channels between inputs and outputs.
  356. * - You push data as you have it, and pull it when you need it
  357. * - It can also function as a basic audio data queue even if you just have
  358. * sound that needs to pass from one place to another.
  359. * - You can hook callbacks up to them when more data is added or requested,
  360. * to manage data on-the-fly.
  361. *
  362. * Audio streams are the core of the SDL3 audio interface. You create one or
  363. * more of them, bind them to an opened audio device, and feed data to them
  364. * (or for recording, consume data from them).
  365. *
  366. * \since This struct is available since SDL 3.1.3.
  367. *
  368. * \sa SDL_CreateAudioStream
  369. */
  370. typedef struct SDL_AudioStream SDL_AudioStream;
  371. /* Function prototypes */
  372. /**
  373. * \name Driver discovery functions
  374. *
  375. * These functions return the list of built in audio drivers, in the
  376. * order that they are normally initialized by default.
  377. */
  378. /* @{ */
  379. /**
  380. * Use this function to get the number of built-in audio drivers.
  381. *
  382. * This function returns a hardcoded number. This never returns a negative
  383. * value; if there are no drivers compiled into this build of SDL, this
  384. * function returns zero. The presence of a driver in this list does not mean
  385. * it will function, it just means SDL is capable of interacting with that
  386. * interface. For example, a build of SDL might have esound support, but if
  387. * there's no esound server available, SDL's esound driver would fail if used.
  388. *
  389. * By default, SDL tries all drivers, in its preferred order, until one is
  390. * found to be usable.
  391. *
  392. * \returns the number of built-in audio drivers.
  393. *
  394. * \threadsafety It is safe to call this function from any thread.
  395. *
  396. * \since This function is available since SDL 3.1.3.
  397. *
  398. * \sa SDL_GetAudioDriver
  399. */
  400. extern SDL_DECLSPEC int SDLCALL SDL_GetNumAudioDrivers(void);
  401. /**
  402. * Use this function to get the name of a built in audio driver.
  403. *
  404. * The list of audio drivers is given in the order that they are normally
  405. * initialized by default; the drivers that seem more reasonable to choose
  406. * first (as far as the SDL developers believe) are earlier in the list.
  407. *
  408. * The names of drivers are all simple, low-ASCII identifiers, like "alsa",
  409. * "coreaudio" or "wasapi". These never have Unicode characters, and are not
  410. * meant to be proper names.
  411. *
  412. * \param index the index of the audio driver; the value ranges from 0 to
  413. * SDL_GetNumAudioDrivers() - 1.
  414. * \returns the name of the audio driver at the requested index, or NULL if an
  415. * invalid index was specified.
  416. *
  417. * \threadsafety It is safe to call this function from any thread.
  418. *
  419. * \since This function is available since SDL 3.1.3.
  420. *
  421. * \sa SDL_GetNumAudioDrivers
  422. */
  423. extern SDL_DECLSPEC const char * SDLCALL SDL_GetAudioDriver(int index);
  424. /* @} */
  425. /**
  426. * Get the name of the current audio driver.
  427. *
  428. * The names of drivers are all simple, low-ASCII identifiers, like "alsa",
  429. * "coreaudio" or "wasapi". These never have Unicode characters, and are not
  430. * meant to be proper names.
  431. *
  432. * \returns the name of the current audio driver or NULL if no driver has been
  433. * initialized.
  434. *
  435. * \threadsafety It is safe to call this function from any thread.
  436. *
  437. * \since This function is available since SDL 3.1.3.
  438. */
  439. extern SDL_DECLSPEC const char * SDLCALL SDL_GetCurrentAudioDriver(void);
  440. /**
  441. * Get a list of currently-connected audio playback devices.
  442. *
  443. * This returns of list of available devices that play sound, perhaps to
  444. * speakers or headphones ("playback" devices). If you want devices that
  445. * record audio, like a microphone ("recording" devices), use
  446. * SDL_GetAudioRecordingDevices() instead.
  447. *
  448. * This only returns a list of physical devices; it will not have any device
  449. * IDs returned by SDL_OpenAudioDevice().
  450. *
  451. * If this function returns NULL, to signify an error, `*count` will be set to
  452. * zero.
  453. *
  454. * \param count a pointer filled in with the number of devices returned, may
  455. * be NULL.
  456. * \returns a 0 terminated array of device instance IDs or NULL on error; call
  457. * SDL_GetError() for more information. This should be freed with
  458. * SDL_free() when it is no longer needed.
  459. *
  460. * \threadsafety It is safe to call this function from any thread.
  461. *
  462. * \since This function is available since SDL 3.1.3.
  463. *
  464. * \sa SDL_OpenAudioDevice
  465. * \sa SDL_GetAudioRecordingDevices
  466. */
  467. extern SDL_DECLSPEC SDL_AudioDeviceID * SDLCALL SDL_GetAudioPlaybackDevices(int *count);
  468. /**
  469. * Get a list of currently-connected audio recording devices.
  470. *
  471. * This returns of list of available devices that record audio, like a
  472. * microphone ("recording" devices). If you want devices that play sound,
  473. * perhaps to speakers or headphones ("playback" devices), use
  474. * SDL_GetAudioPlaybackDevices() instead.
  475. *
  476. * This only returns a list of physical devices; it will not have any device
  477. * IDs returned by SDL_OpenAudioDevice().
  478. *
  479. * If this function returns NULL, to signify an error, `*count` will be set to
  480. * zero.
  481. *
  482. * \param count a pointer filled in with the number of devices returned, may
  483. * be NULL.
  484. * \returns a 0 terminated array of device instance IDs, or NULL on failure;
  485. * call SDL_GetError() for more information. This should be freed
  486. * with SDL_free() when it is no longer needed.
  487. *
  488. * \threadsafety It is safe to call this function from any thread.
  489. *
  490. * \since This function is available since SDL 3.1.3.
  491. *
  492. * \sa SDL_OpenAudioDevice
  493. * \sa SDL_GetAudioPlaybackDevices
  494. */
  495. extern SDL_DECLSPEC SDL_AudioDeviceID * SDLCALL SDL_GetAudioRecordingDevices(int *count);
  496. /**
  497. * Get the human-readable name of a specific audio device.
  498. *
  499. * \param devid the instance ID of the device to query.
  500. * \returns the name of the audio device, or NULL on failure; call
  501. * SDL_GetError() for more information.
  502. *
  503. * \threadsafety It is safe to call this function from any thread.
  504. *
  505. * \since This function is available since SDL 3.1.3.
  506. *
  507. * \sa SDL_GetAudioPlaybackDevices
  508. * \sa SDL_GetAudioRecordingDevices
  509. */
  510. extern SDL_DECLSPEC const char * SDLCALL SDL_GetAudioDeviceName(SDL_AudioDeviceID devid);
  511. /**
  512. * Get the current audio format of a specific audio device.
  513. *
  514. * For an opened device, this will report the format the device is currently
  515. * using. If the device isn't yet opened, this will report the device's
  516. * preferred format (or a reasonable default if this can't be determined).
  517. *
  518. * You may also specify SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK or
  519. * SDL_AUDIO_DEVICE_DEFAULT_RECORDING here, which is useful for getting a
  520. * reasonable recommendation before opening the system-recommended default
  521. * device.
  522. *
  523. * You can also use this to request the current device buffer size. This is
  524. * specified in sample frames and represents the amount of data SDL will feed
  525. * to the physical hardware in each chunk. This can be converted to
  526. * milliseconds of audio with the following equation:
  527. *
  528. * `ms = (int) ((((Sint64) frames) * 1000) / spec.freq);`
  529. *
  530. * Buffer size is only important if you need low-level control over the audio
  531. * playback timing. Most apps do not need this.
  532. *
  533. * \param devid the instance ID of the device to query.
  534. * \param spec on return, will be filled with device details.
  535. * \param sample_frames pointer to store device buffer size, in sample frames.
  536. * Can be NULL.
  537. * \returns true on success or false on failure; call SDL_GetError() for more
  538. * information.
  539. *
  540. * \threadsafety It is safe to call this function from any thread.
  541. *
  542. * \since This function is available since SDL 3.1.3.
  543. */
  544. extern SDL_DECLSPEC bool SDLCALL SDL_GetAudioDeviceFormat(SDL_AudioDeviceID devid, SDL_AudioSpec *spec, int *sample_frames);
  545. /**
  546. * Get the current channel map of an audio device.
  547. *
  548. * Channel maps are optional; most things do not need them, instead passing
  549. * data in the [order that SDL expects](CategoryAudio#channel-layouts).
  550. *
  551. * Audio devices usually have no remapping applied. This is represented by
  552. * returning NULL, and does not signify an error.
  553. *
  554. * \param devid the instance ID of the device to query.
  555. * \param count On output, set to number of channels in the map. Can be NULL.
  556. * \returns an array of the current channel mapping, with as many elements as
  557. * the current output spec's channels, or NULL if default. This
  558. * should be freed with SDL_free() when it is no longer needed.
  559. *
  560. * \threadsafety It is safe to call this function from any thread.
  561. *
  562. * \since This function is available since SDL 3.1.3.
  563. *
  564. * \sa SDL_SetAudioStreamInputChannelMap
  565. */
  566. extern SDL_DECLSPEC int * SDLCALL SDL_GetAudioDeviceChannelMap(SDL_AudioDeviceID devid, int *count);
  567. /**
  568. * Open a specific audio device.
  569. *
  570. * You can open both playback and recording devices through this function.
  571. * Playback devices will take data from bound audio streams, mix it, and send
  572. * it to the hardware. Recording devices will feed any bound audio streams
  573. * with a copy of any incoming data.
  574. *
  575. * An opened audio device starts out with no audio streams bound. To start
  576. * audio playing, bind a stream and supply audio data to it. Unlike SDL2,
  577. * there is no audio callback; you only bind audio streams and make sure they
  578. * have data flowing into them (however, you can simulate SDL2's semantics
  579. * fairly closely by using SDL_OpenAudioDeviceStream instead of this
  580. * function).
  581. *
  582. * If you don't care about opening a specific device, pass a `devid` of either
  583. * `SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK` or
  584. * `SDL_AUDIO_DEVICE_DEFAULT_RECORDING`. In this case, SDL will try to pick
  585. * the most reasonable default, and may also switch between physical devices
  586. * seamlessly later, if the most reasonable default changes during the
  587. * lifetime of this opened device (user changed the default in the OS's system
  588. * preferences, the default got unplugged so the system jumped to a new
  589. * default, the user plugged in headphones on a mobile device, etc). Unless
  590. * you have a good reason to choose a specific device, this is probably what
  591. * you want.
  592. *
  593. * You may request a specific format for the audio device, but there is no
  594. * promise the device will honor that request for several reasons. As such,
  595. * it's only meant to be a hint as to what data your app will provide. Audio
  596. * streams will accept data in whatever format you specify and manage
  597. * conversion for you as appropriate. SDL_GetAudioDeviceFormat can tell you
  598. * the preferred format for the device before opening and the actual format
  599. * the device is using after opening.
  600. *
  601. * It's legal to open the same device ID more than once; each successful open
  602. * will generate a new logical SDL_AudioDeviceID that is managed separately
  603. * from others on the same physical device. This allows libraries to open a
  604. * device separately from the main app and bind its own streams without
  605. * conflicting.
  606. *
  607. * It is also legal to open a device ID returned by a previous call to this
  608. * function; doing so just creates another logical device on the same physical
  609. * device. This may be useful for making logical groupings of audio streams.
  610. *
  611. * This function returns the opened device ID on success. This is a new,
  612. * unique SDL_AudioDeviceID that represents a logical device.
  613. *
  614. * Some backends might offer arbitrary devices (for example, a networked audio
  615. * protocol that can connect to an arbitrary server). For these, as a change
  616. * from SDL2, you should open a default device ID and use an SDL hint to
  617. * specify the target if you care, or otherwise let the backend figure out a
  618. * reasonable default. Most backends don't offer anything like this, and often
  619. * this would be an end user setting an environment variable for their custom
  620. * need, and not something an application should specifically manage.
  621. *
  622. * When done with an audio device, possibly at the end of the app's life, one
  623. * should call SDL_CloseAudioDevice() on the returned device id.
  624. *
  625. * \param devid the device instance id to open, or
  626. * SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK or
  627. * SDL_AUDIO_DEVICE_DEFAULT_RECORDING for the most reasonable
  628. * default device.
  629. * \param spec the requested device configuration. Can be NULL to use
  630. * reasonable defaults.
  631. * \returns the device ID on success or 0 on failure; call SDL_GetError() for
  632. * more information.
  633. *
  634. * \threadsafety It is safe to call this function from any thread.
  635. *
  636. * \since This function is available since SDL 3.1.3.
  637. *
  638. * \sa SDL_CloseAudioDevice
  639. * \sa SDL_GetAudioDeviceFormat
  640. */
  641. extern SDL_DECLSPEC SDL_AudioDeviceID SDLCALL SDL_OpenAudioDevice(SDL_AudioDeviceID devid, const SDL_AudioSpec *spec);
  642. /**
  643. * Determine if an audio device is physical (instead of logical).
  644. *
  645. * An SDL_AudioDeviceID that represents physical hardware is a physical
  646. * device; there is one for each piece of hardware that SDL can see. Logical
  647. * devices are created by calling SDL_OpenAudioDevice or
  648. * SDL_OpenAudioDeviceStream, and while each is associated with a physical
  649. * device, there can be any number of logical devices on one physical device.
  650. *
  651. * For the most part, logical and physical IDs are interchangeable--if you try
  652. * to open a logical device, SDL understands to assign that effort to the
  653. * underlying physical device, etc. However, it might be useful to know if an
  654. * arbitrary device ID is physical or logical. This function reports which.
  655. *
  656. * This function may return either true or false for invalid device IDs.
  657. *
  658. * \param devid the device ID to query.
  659. * \returns true if devid is a physical device, false if it is logical.
  660. *
  661. * \threadsafety It is safe to call this function from any thread.
  662. *
  663. * \since This function is available since SDL 3.2.0.
  664. */
  665. extern SDL_DECLSPEC bool SDLCALL SDL_IsAudioDevicePhysical(SDL_AudioDeviceID devid);
  666. /**
  667. * Determine if an audio device is a playback device (instead of recording).
  668. *
  669. * This function may return either true or false for invalid device IDs.
  670. *
  671. * \param devid the device ID to query.
  672. * \returns true if devid is a playback device, false if it is recording.
  673. *
  674. * \threadsafety It is safe to call this function from any thread.
  675. *
  676. * \since This function is available since SDL 3.2.0.
  677. */
  678. extern SDL_DECLSPEC bool SDLCALL SDL_IsAudioDevicePlayback(SDL_AudioDeviceID devid);
  679. /**
  680. * Use this function to pause audio playback on a specified device.
  681. *
  682. * This function pauses audio processing for a given device. Any bound audio
  683. * streams will not progress, and no audio will be generated. Pausing one
  684. * device does not prevent other unpaused devices from running.
  685. *
  686. * Unlike in SDL2, audio devices start in an _unpaused_ state, since an app
  687. * has to bind a stream before any audio will flow. Pausing a paused device is
  688. * a legal no-op.
  689. *
  690. * Pausing a device can be useful to halt all audio without unbinding all the
  691. * audio streams. This might be useful while a game is paused, or a level is
  692. * loading, etc.
  693. *
  694. * Physical devices can not be paused or unpaused, only logical devices
  695. * created through SDL_OpenAudioDevice() can be.
  696. *
  697. * \param dev a device opened by SDL_OpenAudioDevice().
  698. * \returns true on success or false on failure; call SDL_GetError() for more
  699. * information.
  700. *
  701. * \threadsafety It is safe to call this function from any thread.
  702. *
  703. * \since This function is available since SDL 3.1.3.
  704. *
  705. * \sa SDL_ResumeAudioDevice
  706. * \sa SDL_AudioDevicePaused
  707. */
  708. extern SDL_DECLSPEC bool SDLCALL SDL_PauseAudioDevice(SDL_AudioDeviceID dev);
  709. /**
  710. * Use this function to unpause audio playback on a specified device.
  711. *
  712. * This function unpauses audio processing for a given device that has
  713. * previously been paused with SDL_PauseAudioDevice(). Once unpaused, any
  714. * bound audio streams will begin to progress again, and audio can be
  715. * generated.
  716. *
  717. * Unlike in SDL2, audio devices start in an _unpaused_ state, since an app
  718. * has to bind a stream before any audio will flow. Unpausing an unpaused
  719. * device is a legal no-op.
  720. *
  721. * Physical devices can not be paused or unpaused, only logical devices
  722. * created through SDL_OpenAudioDevice() can be.
  723. *
  724. * \param dev a device opened by SDL_OpenAudioDevice().
  725. * \returns true on success or false on failure; call SDL_GetError() for more
  726. * information.
  727. *
  728. * \threadsafety It is safe to call this function from any thread.
  729. *
  730. * \since This function is available since SDL 3.1.3.
  731. *
  732. * \sa SDL_AudioDevicePaused
  733. * \sa SDL_PauseAudioDevice
  734. */
  735. extern SDL_DECLSPEC bool SDLCALL SDL_ResumeAudioDevice(SDL_AudioDeviceID dev);
  736. /**
  737. * Use this function to query if an audio device is paused.
  738. *
  739. * Unlike in SDL2, audio devices start in an _unpaused_ state, since an app
  740. * has to bind a stream before any audio will flow.
  741. *
  742. * Physical devices can not be paused or unpaused, only logical devices
  743. * created through SDL_OpenAudioDevice() can be. Physical and invalid device
  744. * IDs will report themselves as unpaused here.
  745. *
  746. * \param dev a device opened by SDL_OpenAudioDevice().
  747. * \returns true if device is valid and paused, false otherwise.
  748. *
  749. * \threadsafety It is safe to call this function from any thread.
  750. *
  751. * \since This function is available since SDL 3.1.3.
  752. *
  753. * \sa SDL_PauseAudioDevice
  754. * \sa SDL_ResumeAudioDevice
  755. */
  756. extern SDL_DECLSPEC bool SDLCALL SDL_AudioDevicePaused(SDL_AudioDeviceID dev);
  757. /**
  758. * Get the gain of an audio device.
  759. *
  760. * The gain of a device is its volume; a larger gain means a louder output,
  761. * with a gain of zero being silence.
  762. *
  763. * Audio devices default to a gain of 1.0f (no change in output).
  764. *
  765. * Physical devices may not have their gain changed, only logical devices, and
  766. * this function will always return -1.0f when used on physical devices.
  767. *
  768. * \param devid the audio device to query.
  769. * \returns the gain of the device or -1.0f on failure; call SDL_GetError()
  770. * for more information.
  771. *
  772. * \threadsafety It is safe to call this function from any thread.
  773. *
  774. * \since This function is available since SDL 3.1.3.
  775. *
  776. * \sa SDL_SetAudioDeviceGain
  777. */
  778. extern SDL_DECLSPEC float SDLCALL SDL_GetAudioDeviceGain(SDL_AudioDeviceID devid);
  779. /**
  780. * Change the gain of an audio device.
  781. *
  782. * The gain of a device is its volume; a larger gain means a louder output,
  783. * with a gain of zero being silence.
  784. *
  785. * Audio devices default to a gain of 1.0f (no change in output).
  786. *
  787. * Physical devices may not have their gain changed, only logical devices, and
  788. * this function will always return false when used on physical devices. While
  789. * it might seem attractive to adjust several logical devices at once in this
  790. * way, it would allow an app or library to interfere with another portion of
  791. * the program's otherwise-isolated devices.
  792. *
  793. * This is applied, along with any per-audiostream gain, during playback to
  794. * the hardware, and can be continuously changed to create various effects. On
  795. * recording devices, this will adjust the gain before passing the data into
  796. * an audiostream; that recording audiostream can then adjust its gain further
  797. * when outputting the data elsewhere, if it likes, but that second gain is
  798. * not applied until the data leaves the audiostream again.
  799. *
  800. * \param devid the audio device on which to change gain.
  801. * \param gain the gain. 1.0f is no change, 0.0f is silence.
  802. * \returns true on success or false on failure; call SDL_GetError() for more
  803. * information.
  804. *
  805. * \threadsafety It is safe to call this function from any thread, as it holds
  806. * a stream-specific mutex while running.
  807. *
  808. * \since This function is available since SDL 3.1.3.
  809. *
  810. * \sa SDL_GetAudioDeviceGain
  811. */
  812. extern SDL_DECLSPEC bool SDLCALL SDL_SetAudioDeviceGain(SDL_AudioDeviceID devid, float gain);
  813. /**
  814. * Close a previously-opened audio device.
  815. *
  816. * The application should close open audio devices once they are no longer
  817. * needed.
  818. *
  819. * This function may block briefly while pending audio data is played by the
  820. * hardware, so that applications don't drop the last buffer of data they
  821. * supplied if terminating immediately afterwards.
  822. *
  823. * \param devid an audio device id previously returned by
  824. * SDL_OpenAudioDevice().
  825. *
  826. * \threadsafety It is safe to call this function from any thread.
  827. *
  828. * \since This function is available since SDL 3.1.3.
  829. *
  830. * \sa SDL_OpenAudioDevice
  831. */
  832. extern SDL_DECLSPEC void SDLCALL SDL_CloseAudioDevice(SDL_AudioDeviceID devid);
  833. /**
  834. * Bind a list of audio streams to an audio device.
  835. *
  836. * Audio data will flow through any bound streams. For a playback device, data
  837. * for all bound streams will be mixed together and fed to the device. For a
  838. * recording device, a copy of recorded data will be provided to each bound
  839. * stream.
  840. *
  841. * Audio streams can only be bound to an open device. This operation is
  842. * atomic--all streams bound in the same call will start processing at the
  843. * same time, so they can stay in sync. Also: either all streams will be bound
  844. * or none of them will be.
  845. *
  846. * It is an error to bind an already-bound stream; it must be explicitly
  847. * unbound first.
  848. *
  849. * Binding a stream to a device will set its output format for playback
  850. * devices, and its input format for recording devices, so they match the
  851. * device's settings. The caller is welcome to change the other end of the
  852. * stream's format at any time.
  853. *
  854. * \param devid an audio device to bind a stream to.
  855. * \param streams an array of audio streams to bind.
  856. * \param num_streams number streams listed in the `streams` array.
  857. * \returns true on success or false on failure; call SDL_GetError() for more
  858. * information.
  859. *
  860. * \threadsafety It is safe to call this function from any thread.
  861. *
  862. * \since This function is available since SDL 3.1.3.
  863. *
  864. * \sa SDL_BindAudioStreams
  865. * \sa SDL_UnbindAudioStream
  866. * \sa SDL_GetAudioStreamDevice
  867. */
  868. extern SDL_DECLSPEC bool SDLCALL SDL_BindAudioStreams(SDL_AudioDeviceID devid, SDL_AudioStream **streams, int num_streams);
  869. /**
  870. * Bind a single audio stream to an audio device.
  871. *
  872. * This is a convenience function, equivalent to calling
  873. * `SDL_BindAudioStreams(devid, &stream, 1)`.
  874. *
  875. * \param devid an audio device to bind a stream to.
  876. * \param stream an audio stream to bind to a device.
  877. * \returns true on success or false on failure; call SDL_GetError() for more
  878. * information.
  879. *
  880. * \threadsafety It is safe to call this function from any thread.
  881. *
  882. * \since This function is available since SDL 3.1.3.
  883. *
  884. * \sa SDL_BindAudioStreams
  885. * \sa SDL_UnbindAudioStream
  886. * \sa SDL_GetAudioStreamDevice
  887. */
  888. extern SDL_DECLSPEC bool SDLCALL SDL_BindAudioStream(SDL_AudioDeviceID devid, SDL_AudioStream *stream);
  889. /**
  890. * Unbind a list of audio streams from their audio devices.
  891. *
  892. * The streams being unbound do not all have to be on the same device. All
  893. * streams on the same device will be unbound atomically (data will stop
  894. * flowing through all unbound streams on the same device at the same time).
  895. *
  896. * Unbinding a stream that isn't bound to a device is a legal no-op.
  897. *
  898. * \param streams an array of audio streams to unbind.
  899. * \param num_streams number streams listed in the `streams` array.
  900. *
  901. * \threadsafety It is safe to call this function from any thread.
  902. *
  903. * \since This function is available since SDL 3.1.3.
  904. *
  905. * \sa SDL_BindAudioStreams
  906. */
  907. extern SDL_DECLSPEC void SDLCALL SDL_UnbindAudioStreams(SDL_AudioStream **streams, int num_streams);
  908. /**
  909. * Unbind a single audio stream from its audio device.
  910. *
  911. * This is a convenience function, equivalent to calling
  912. * `SDL_UnbindAudioStreams(&stream, 1)`.
  913. *
  914. * \param stream an audio stream to unbind from a device.
  915. *
  916. * \threadsafety It is safe to call this function from any thread.
  917. *
  918. * \since This function is available since SDL 3.1.3.
  919. *
  920. * \sa SDL_BindAudioStream
  921. */
  922. extern SDL_DECLSPEC void SDLCALL SDL_UnbindAudioStream(SDL_AudioStream *stream);
  923. /**
  924. * Query an audio stream for its currently-bound device.
  925. *
  926. * This reports the audio device that an audio stream is currently bound to.
  927. *
  928. * If not bound, or invalid, this returns zero, which is not a valid device
  929. * ID.
  930. *
  931. * \param stream the audio stream to query.
  932. * \returns the bound audio device, or 0 if not bound or invalid.
  933. *
  934. * \threadsafety It is safe to call this function from any thread.
  935. *
  936. * \since This function is available since SDL 3.1.3.
  937. *
  938. * \sa SDL_BindAudioStream
  939. * \sa SDL_BindAudioStreams
  940. */
  941. extern SDL_DECLSPEC SDL_AudioDeviceID SDLCALL SDL_GetAudioStreamDevice(SDL_AudioStream *stream);
  942. /**
  943. * Create a new audio stream.
  944. *
  945. * \param src_spec the format details of the input audio.
  946. * \param dst_spec the format details of the output audio.
  947. * \returns a new audio stream on success or NULL on failure; call
  948. * SDL_GetError() for more information.
  949. *
  950. * \threadsafety It is safe to call this function from any thread.
  951. *
  952. * \since This function is available since SDL 3.1.3.
  953. *
  954. * \sa SDL_PutAudioStreamData
  955. * \sa SDL_GetAudioStreamData
  956. * \sa SDL_GetAudioStreamAvailable
  957. * \sa SDL_FlushAudioStream
  958. * \sa SDL_ClearAudioStream
  959. * \sa SDL_SetAudioStreamFormat
  960. * \sa SDL_DestroyAudioStream
  961. */
  962. extern SDL_DECLSPEC SDL_AudioStream * SDLCALL SDL_CreateAudioStream(const SDL_AudioSpec *src_spec, const SDL_AudioSpec *dst_spec);
  963. /**
  964. * Get the properties associated with an audio stream.
  965. *
  966. * \param stream the SDL_AudioStream to query.
  967. * \returns a valid property ID on success or 0 on failure; call
  968. * SDL_GetError() for more information.
  969. *
  970. * \threadsafety It is safe to call this function from any thread.
  971. *
  972. * \since This function is available since SDL 3.1.3.
  973. */
  974. extern SDL_DECLSPEC SDL_PropertiesID SDLCALL SDL_GetAudioStreamProperties(SDL_AudioStream *stream);
  975. /**
  976. * Query the current format of an audio stream.
  977. *
  978. * \param stream the SDL_AudioStream to query.
  979. * \param src_spec where to store the input audio format; ignored if NULL.
  980. * \param dst_spec where to store the output audio format; ignored if NULL.
  981. * \returns true on success or false on failure; call SDL_GetError() for more
  982. * information.
  983. *
  984. * \threadsafety It is safe to call this function from any thread, as it holds
  985. * a stream-specific mutex while running.
  986. *
  987. * \since This function is available since SDL 3.1.3.
  988. *
  989. * \sa SDL_SetAudioStreamFormat
  990. */
  991. extern SDL_DECLSPEC bool SDLCALL SDL_GetAudioStreamFormat(SDL_AudioStream *stream, SDL_AudioSpec *src_spec, SDL_AudioSpec *dst_spec);
  992. /**
  993. * Change the input and output formats of an audio stream.
  994. *
  995. * Future calls to and SDL_GetAudioStreamAvailable and SDL_GetAudioStreamData
  996. * will reflect the new format, and future calls to SDL_PutAudioStreamData
  997. * must provide data in the new input formats.
  998. *
  999. * Data that was previously queued in the stream will still be operated on in
  1000. * the format that was current when it was added, which is to say you can put
  1001. * the end of a sound file in one format to a stream, change formats for the
  1002. * next sound file, and start putting that new data while the previous sound
  1003. * file is still queued, and everything will still play back correctly.
  1004. *
  1005. * \param stream the stream the format is being changed.
  1006. * \param src_spec the new format of the audio input; if NULL, it is not
  1007. * changed.
  1008. * \param dst_spec the new format of the audio output; if NULL, it is not
  1009. * changed.
  1010. * \returns true on success or false on failure; call SDL_GetError() for more
  1011. * information.
  1012. *
  1013. * \threadsafety It is safe to call this function from any thread, as it holds
  1014. * a stream-specific mutex while running.
  1015. *
  1016. * \since This function is available since SDL 3.1.3.
  1017. *
  1018. * \sa SDL_GetAudioStreamFormat
  1019. * \sa SDL_SetAudioStreamFrequencyRatio
  1020. */
  1021. extern SDL_DECLSPEC bool SDLCALL SDL_SetAudioStreamFormat(SDL_AudioStream *stream, const SDL_AudioSpec *src_spec, const SDL_AudioSpec *dst_spec);
  1022. /**
  1023. * Get the frequency ratio of an audio stream.
  1024. *
  1025. * \param stream the SDL_AudioStream to query.
  1026. * \returns the frequency ratio of the stream or 0.0 on failure; call
  1027. * SDL_GetError() for more information.
  1028. *
  1029. * \threadsafety It is safe to call this function from any thread, as it holds
  1030. * a stream-specific mutex while running.
  1031. *
  1032. * \since This function is available since SDL 3.1.3.
  1033. *
  1034. * \sa SDL_SetAudioStreamFrequencyRatio
  1035. */
  1036. extern SDL_DECLSPEC float SDLCALL SDL_GetAudioStreamFrequencyRatio(SDL_AudioStream *stream);
  1037. /**
  1038. * Change the frequency ratio of an audio stream.
  1039. *
  1040. * The frequency ratio is used to adjust the rate at which input data is
  1041. * consumed. Changing this effectively modifies the speed and pitch of the
  1042. * audio. A value greater than 1.0 will play the audio faster, and at a higher
  1043. * pitch. A value less than 1.0 will play the audio slower, and at a lower
  1044. * pitch.
  1045. *
  1046. * This is applied during SDL_GetAudioStreamData, and can be continuously
  1047. * changed to create various effects.
  1048. *
  1049. * \param stream the stream the frequency ratio is being changed.
  1050. * \param ratio the frequency ratio. 1.0 is normal speed. Must be between 0.01
  1051. * and 100.
  1052. * \returns true on success or false on failure; call SDL_GetError() for more
  1053. * information.
  1054. *
  1055. * \threadsafety It is safe to call this function from any thread, as it holds
  1056. * a stream-specific mutex while running.
  1057. *
  1058. * \since This function is available since SDL 3.1.3.
  1059. *
  1060. * \sa SDL_GetAudioStreamFrequencyRatio
  1061. * \sa SDL_SetAudioStreamFormat
  1062. */
  1063. extern SDL_DECLSPEC bool SDLCALL SDL_SetAudioStreamFrequencyRatio(SDL_AudioStream *stream, float ratio);
  1064. /**
  1065. * Get the gain of an audio stream.
  1066. *
  1067. * The gain of a stream is its volume; a larger gain means a louder output,
  1068. * with a gain of zero being silence.
  1069. *
  1070. * Audio streams default to a gain of 1.0f (no change in output).
  1071. *
  1072. * \param stream the SDL_AudioStream to query.
  1073. * \returns the gain of the stream or -1.0f on failure; call SDL_GetError()
  1074. * for more information.
  1075. *
  1076. * \threadsafety It is safe to call this function from any thread, as it holds
  1077. * a stream-specific mutex while running.
  1078. *
  1079. * \since This function is available since SDL 3.1.3.
  1080. *
  1081. * \sa SDL_SetAudioStreamGain
  1082. */
  1083. extern SDL_DECLSPEC float SDLCALL SDL_GetAudioStreamGain(SDL_AudioStream *stream);
  1084. /**
  1085. * Change the gain of an audio stream.
  1086. *
  1087. * The gain of a stream is its volume; a larger gain means a louder output,
  1088. * with a gain of zero being silence.
  1089. *
  1090. * Audio streams default to a gain of 1.0f (no change in output).
  1091. *
  1092. * This is applied during SDL_GetAudioStreamData, and can be continuously
  1093. * changed to create various effects.
  1094. *
  1095. * \param stream the stream on which the gain is being changed.
  1096. * \param gain the gain. 1.0f is no change, 0.0f is silence.
  1097. * \returns true on success or false on failure; call SDL_GetError() for more
  1098. * information.
  1099. *
  1100. * \threadsafety It is safe to call this function from any thread, as it holds
  1101. * a stream-specific mutex while running.
  1102. *
  1103. * \since This function is available since SDL 3.1.3.
  1104. *
  1105. * \sa SDL_GetAudioStreamGain
  1106. */
  1107. extern SDL_DECLSPEC bool SDLCALL SDL_SetAudioStreamGain(SDL_AudioStream *stream, float gain);
  1108. /**
  1109. * Get the current input channel map of an audio stream.
  1110. *
  1111. * Channel maps are optional; most things do not need them, instead passing
  1112. * data in the [order that SDL expects](CategoryAudio#channel-layouts).
  1113. *
  1114. * Audio streams default to no remapping applied. This is represented by
  1115. * returning NULL, and does not signify an error.
  1116. *
  1117. * \param stream the SDL_AudioStream to query.
  1118. * \param count On output, set to number of channels in the map. Can be NULL.
  1119. * \returns an array of the current channel mapping, with as many elements as
  1120. * the current output spec's channels, or NULL if default. This
  1121. * should be freed with SDL_free() when it is no longer needed.
  1122. *
  1123. * \threadsafety It is safe to call this function from any thread, as it holds
  1124. * a stream-specific mutex while running.
  1125. *
  1126. * \since This function is available since SDL 3.1.3.
  1127. *
  1128. * \sa SDL_SetAudioStreamInputChannelMap
  1129. */
  1130. extern SDL_DECLSPEC int * SDLCALL SDL_GetAudioStreamInputChannelMap(SDL_AudioStream *stream, int *count);
  1131. /**
  1132. * Get the current output channel map of an audio stream.
  1133. *
  1134. * Channel maps are optional; most things do not need them, instead passing
  1135. * data in the [order that SDL expects](CategoryAudio#channel-layouts).
  1136. *
  1137. * Audio streams default to no remapping applied. This is represented by
  1138. * returning NULL, and does not signify an error.
  1139. *
  1140. * \param stream the SDL_AudioStream to query.
  1141. * \param count On output, set to number of channels in the map. Can be NULL.
  1142. * \returns an array of the current channel mapping, with as many elements as
  1143. * the current output spec's channels, or NULL if default. This
  1144. * should be freed with SDL_free() when it is no longer needed.
  1145. *
  1146. * \threadsafety It is safe to call this function from any thread, as it holds
  1147. * a stream-specific mutex while running.
  1148. *
  1149. * \since This function is available since SDL 3.1.3.
  1150. *
  1151. * \sa SDL_SetAudioStreamInputChannelMap
  1152. */
  1153. extern SDL_DECLSPEC int * SDLCALL SDL_GetAudioStreamOutputChannelMap(SDL_AudioStream *stream, int *count);
  1154. /**
  1155. * Set the current input channel map of an audio stream.
  1156. *
  1157. * Channel maps are optional; most things do not need them, instead passing
  1158. * data in the [order that SDL expects](CategoryAudio#channel-layouts).
  1159. *
  1160. * The input channel map reorders data that is added to a stream via
  1161. * SDL_PutAudioStreamData. Future calls to SDL_PutAudioStreamData must provide
  1162. * data in the new channel order.
  1163. *
  1164. * Each item in the array represents an input channel, and its value is the
  1165. * channel that it should be remapped to. To reverse a stereo signal's left
  1166. * and right values, you'd have an array of `{ 1, 0 }`. It is legal to remap
  1167. * multiple channels to the same thing, so `{ 1, 1 }` would duplicate the
  1168. * right channel to both channels of a stereo signal. An element in the
  1169. * channel map set to -1 instead of a valid channel will mute that channel,
  1170. * setting it to a silence value.
  1171. *
  1172. * You cannot change the number of channels through a channel map, just
  1173. * reorder/mute them.
  1174. *
  1175. * Data that was previously queued in the stream will still be operated on in
  1176. * the order that was current when it was added, which is to say you can put
  1177. * the end of a sound file in one order to a stream, change orders for the
  1178. * next sound file, and start putting that new data while the previous sound
  1179. * file is still queued, and everything will still play back correctly.
  1180. *
  1181. * Audio streams default to no remapping applied. Passing a NULL channel map
  1182. * is legal, and turns off remapping.
  1183. *
  1184. * SDL will copy the channel map; the caller does not have to save this array
  1185. * after this call.
  1186. *
  1187. * If `count` is not equal to the current number of channels in the audio
  1188. * stream's format, this will fail. This is a safety measure to make sure a
  1189. * race condition hasn't changed the format while this call is setting the
  1190. * channel map.
  1191. *
  1192. * \param stream the SDL_AudioStream to change.
  1193. * \param chmap the new channel map, NULL to reset to default.
  1194. * \param count The number of channels in the map.
  1195. * \returns true on success or false on failure; call SDL_GetError() for more
  1196. * information.
  1197. *
  1198. * \threadsafety It is safe to call this function from any thread, as it holds
  1199. * a stream-specific mutex while running. Don't change the
  1200. * stream's format to have a different number of channels from a
  1201. * a different thread at the same time, though!
  1202. *
  1203. * \since This function is available since SDL 3.1.3.
  1204. *
  1205. * \sa SDL_SetAudioStreamInputChannelMap
  1206. */
  1207. extern SDL_DECLSPEC bool SDLCALL SDL_SetAudioStreamInputChannelMap(SDL_AudioStream *stream, const int *chmap, int count);
  1208. /**
  1209. * Set the current output channel map of an audio stream.
  1210. *
  1211. * Channel maps are optional; most things do not need them, instead passing
  1212. * data in the [order that SDL expects](CategoryAudio#channel-layouts).
  1213. *
  1214. * The output channel map reorders data that leaving a stream via
  1215. * SDL_GetAudioStreamData.
  1216. *
  1217. * Each item in the array represents an input channel, and its value is the
  1218. * channel that it should be remapped to. To reverse a stereo signal's left
  1219. * and right values, you'd have an array of `{ 1, 0 }`. It is legal to remap
  1220. * multiple channels to the same thing, so `{ 1, 1 }` would duplicate the
  1221. * right channel to both channels of a stereo signal. An element in the
  1222. * channel map set to -1 instead of a valid channel will mute that channel,
  1223. * setting it to a silence value.
  1224. *
  1225. * You cannot change the number of channels through a channel map, just
  1226. * reorder/mute them.
  1227. *
  1228. * The output channel map can be changed at any time, as output remapping is
  1229. * applied during SDL_GetAudioStreamData.
  1230. *
  1231. * Audio streams default to no remapping applied. Passing a NULL channel map
  1232. * is legal, and turns off remapping.
  1233. *
  1234. * SDL will copy the channel map; the caller does not have to save this array
  1235. * after this call.
  1236. *
  1237. * If `count` is not equal to the current number of channels in the audio
  1238. * stream's format, this will fail. This is a safety measure to make sure a
  1239. * race condition hasn't changed the format while this call is setting the
  1240. * channel map.
  1241. *
  1242. * \param stream the SDL_AudioStream to change.
  1243. * \param chmap the new channel map, NULL to reset to default.
  1244. * \param count The number of channels in the map.
  1245. * \returns true on success or false on failure; call SDL_GetError() for more
  1246. * information.
  1247. *
  1248. * \threadsafety It is safe to call this function from any thread, as it holds
  1249. * a stream-specific mutex while running. Don't change the
  1250. * stream's format to have a different number of channels from a
  1251. * a different thread at the same time, though!
  1252. *
  1253. * \since This function is available since SDL 3.1.3.
  1254. *
  1255. * \sa SDL_SetAudioStreamInputChannelMap
  1256. */
  1257. extern SDL_DECLSPEC bool SDLCALL SDL_SetAudioStreamOutputChannelMap(SDL_AudioStream *stream, const int *chmap, int count);
  1258. /**
  1259. * Add data to the stream.
  1260. *
  1261. * This data must match the format/channels/samplerate specified in the latest
  1262. * call to SDL_SetAudioStreamFormat, or the format specified when creating the
  1263. * stream if it hasn't been changed.
  1264. *
  1265. * Note that this call simply copies the unconverted data for later. This is
  1266. * different than SDL2, where data was converted during the Put call and the
  1267. * Get call would just dequeue the previously-converted data.
  1268. *
  1269. * \param stream the stream the audio data is being added to.
  1270. * \param buf a pointer to the audio data to add.
  1271. * \param len the number of bytes to write to the stream.
  1272. * \returns true on success or false on failure; call SDL_GetError() for more
  1273. * information.
  1274. *
  1275. * \threadsafety It is safe to call this function from any thread, but if the
  1276. * stream has a callback set, the caller might need to manage
  1277. * extra locking.
  1278. *
  1279. * \since This function is available since SDL 3.1.3.
  1280. *
  1281. * \sa SDL_ClearAudioStream
  1282. * \sa SDL_FlushAudioStream
  1283. * \sa SDL_GetAudioStreamData
  1284. * \sa SDL_GetAudioStreamQueued
  1285. */
  1286. extern SDL_DECLSPEC bool SDLCALL SDL_PutAudioStreamData(SDL_AudioStream *stream, const void *buf, int len);
  1287. /**
  1288. * Get converted/resampled data from the stream.
  1289. *
  1290. * The input/output data format/channels/samplerate is specified when creating
  1291. * the stream, and can be changed after creation by calling
  1292. * SDL_SetAudioStreamFormat.
  1293. *
  1294. * Note that any conversion and resampling necessary is done during this call,
  1295. * and SDL_PutAudioStreamData simply queues unconverted data for later. This
  1296. * is different than SDL2, where that work was done while inputting new data
  1297. * to the stream and requesting the output just copied the converted data.
  1298. *
  1299. * \param stream the stream the audio is being requested from.
  1300. * \param buf a buffer to fill with audio data.
  1301. * \param len the maximum number of bytes to fill.
  1302. * \returns the number of bytes read from the stream or -1 on failure; call
  1303. * SDL_GetError() for more information.
  1304. *
  1305. * \threadsafety It is safe to call this function from any thread, but if the
  1306. * stream has a callback set, the caller might need to manage
  1307. * extra locking.
  1308. *
  1309. * \since This function is available since SDL 3.1.3.
  1310. *
  1311. * \sa SDL_ClearAudioStream
  1312. * \sa SDL_GetAudioStreamAvailable
  1313. * \sa SDL_PutAudioStreamData
  1314. */
  1315. extern SDL_DECLSPEC int SDLCALL SDL_GetAudioStreamData(SDL_AudioStream *stream, void *buf, int len);
  1316. /**
  1317. * Get the number of converted/resampled bytes available.
  1318. *
  1319. * The stream may be buffering data behind the scenes until it has enough to
  1320. * resample correctly, so this number might be lower than what you expect, or
  1321. * even be zero. Add more data or flush the stream if you need the data now.
  1322. *
  1323. * If the stream has so much data that it would overflow an int, the return
  1324. * value is clamped to a maximum value, but no queued data is lost; if there
  1325. * are gigabytes of data queued, the app might need to read some of it with
  1326. * SDL_GetAudioStreamData before this function's return value is no longer
  1327. * clamped.
  1328. *
  1329. * \param stream the audio stream to query.
  1330. * \returns the number of converted/resampled bytes available or -1 on
  1331. * failure; call SDL_GetError() for more information.
  1332. *
  1333. * \threadsafety It is safe to call this function from any thread.
  1334. *
  1335. * \since This function is available since SDL 3.1.3.
  1336. *
  1337. * \sa SDL_GetAudioStreamData
  1338. * \sa SDL_PutAudioStreamData
  1339. */
  1340. extern SDL_DECLSPEC int SDLCALL SDL_GetAudioStreamAvailable(SDL_AudioStream *stream);
  1341. /**
  1342. * Get the number of bytes currently queued.
  1343. *
  1344. * This is the number of bytes put into a stream as input, not the number that
  1345. * can be retrieved as output. Because of several details, it's not possible
  1346. * to calculate one number directly from the other. If you need to know how
  1347. * much usable data can be retrieved right now, you should use
  1348. * SDL_GetAudioStreamAvailable() and not this function.
  1349. *
  1350. * Note that audio streams can change their input format at any time, even if
  1351. * there is still data queued in a different format, so the returned byte
  1352. * count will not necessarily match the number of _sample frames_ available.
  1353. * Users of this API should be aware of format changes they make when feeding
  1354. * a stream and plan accordingly.
  1355. *
  1356. * Queued data is not converted until it is consumed by
  1357. * SDL_GetAudioStreamData, so this value should be representative of the exact
  1358. * data that was put into the stream.
  1359. *
  1360. * If the stream has so much data that it would overflow an int, the return
  1361. * value is clamped to a maximum value, but no queued data is lost; if there
  1362. * are gigabytes of data queued, the app might need to read some of it with
  1363. * SDL_GetAudioStreamData before this function's return value is no longer
  1364. * clamped.
  1365. *
  1366. * \param stream the audio stream to query.
  1367. * \returns the number of bytes queued or -1 on failure; call SDL_GetError()
  1368. * for more information.
  1369. *
  1370. * \threadsafety It is safe to call this function from any thread.
  1371. *
  1372. * \since This function is available since SDL 3.1.3.
  1373. *
  1374. * \sa SDL_PutAudioStreamData
  1375. * \sa SDL_ClearAudioStream
  1376. */
  1377. extern SDL_DECLSPEC int SDLCALL SDL_GetAudioStreamQueued(SDL_AudioStream *stream);
  1378. /**
  1379. * Tell the stream that you're done sending data, and anything being buffered
  1380. * should be converted/resampled and made available immediately.
  1381. *
  1382. * It is legal to add more data to a stream after flushing, but there may be
  1383. * audio gaps in the output. Generally this is intended to signal the end of
  1384. * input, so the complete output becomes available.
  1385. *
  1386. * \param stream the audio stream to flush.
  1387. * \returns true on success or false on failure; call SDL_GetError() for more
  1388. * information.
  1389. *
  1390. * \threadsafety It is safe to call this function from any thread.
  1391. *
  1392. * \since This function is available since SDL 3.1.3.
  1393. *
  1394. * \sa SDL_PutAudioStreamData
  1395. */
  1396. extern SDL_DECLSPEC bool SDLCALL SDL_FlushAudioStream(SDL_AudioStream *stream);
  1397. /**
  1398. * Clear any pending data in the stream.
  1399. *
  1400. * This drops any queued data, so there will be nothing to read from the
  1401. * stream until more is added.
  1402. *
  1403. * \param stream the audio stream to clear.
  1404. * \returns true on success or false on failure; call SDL_GetError() for more
  1405. * information.
  1406. *
  1407. * \threadsafety It is safe to call this function from any thread.
  1408. *
  1409. * \since This function is available since SDL 3.1.3.
  1410. *
  1411. * \sa SDL_GetAudioStreamAvailable
  1412. * \sa SDL_GetAudioStreamData
  1413. * \sa SDL_GetAudioStreamQueued
  1414. * \sa SDL_PutAudioStreamData
  1415. */
  1416. extern SDL_DECLSPEC bool SDLCALL SDL_ClearAudioStream(SDL_AudioStream *stream);
  1417. /**
  1418. * Use this function to pause audio playback on the audio device associated
  1419. * with an audio stream.
  1420. *
  1421. * This function pauses audio processing for a given device. Any bound audio
  1422. * streams will not progress, and no audio will be generated. Pausing one
  1423. * device does not prevent other unpaused devices from running.
  1424. *
  1425. * Pausing a device can be useful to halt all audio without unbinding all the
  1426. * audio streams. This might be useful while a game is paused, or a level is
  1427. * loading, etc.
  1428. *
  1429. * \param stream the audio stream associated with the audio device to pause.
  1430. * \returns true on success or false on failure; call SDL_GetError() for more
  1431. * information.
  1432. *
  1433. * \threadsafety It is safe to call this function from any thread.
  1434. *
  1435. * \since This function is available since SDL 3.1.3.
  1436. *
  1437. * \sa SDL_ResumeAudioStreamDevice
  1438. */
  1439. extern SDL_DECLSPEC bool SDLCALL SDL_PauseAudioStreamDevice(SDL_AudioStream *stream);
  1440. /**
  1441. * Use this function to unpause audio playback on the audio device associated
  1442. * with an audio stream.
  1443. *
  1444. * This function unpauses audio processing for a given device that has
  1445. * previously been paused. Once unpaused, any bound audio streams will begin
  1446. * to progress again, and audio can be generated.
  1447. *
  1448. * \param stream the audio stream associated with the audio device to resume.
  1449. * \returns true on success or false on failure; call SDL_GetError() for more
  1450. * information.
  1451. *
  1452. * \threadsafety It is safe to call this function from any thread.
  1453. *
  1454. * \since This function is available since SDL 3.1.3.
  1455. *
  1456. * \sa SDL_PauseAudioStreamDevice
  1457. */
  1458. extern SDL_DECLSPEC bool SDLCALL SDL_ResumeAudioStreamDevice(SDL_AudioStream *stream);
  1459. /**
  1460. * Lock an audio stream for serialized access.
  1461. *
  1462. * Each SDL_AudioStream has an internal mutex it uses to protect its data
  1463. * structures from threading conflicts. This function allows an app to lock
  1464. * that mutex, which could be useful if registering callbacks on this stream.
  1465. *
  1466. * One does not need to lock a stream to use in it most cases, as the stream
  1467. * manages this lock internally. However, this lock is held during callbacks,
  1468. * which may run from arbitrary threads at any time, so if an app needs to
  1469. * protect shared data during those callbacks, locking the stream guarantees
  1470. * that the callback is not running while the lock is held.
  1471. *
  1472. * As this is just a wrapper over SDL_LockMutex for an internal lock; it has
  1473. * all the same attributes (recursive locks are allowed, etc).
  1474. *
  1475. * \param stream the audio stream to lock.
  1476. * \returns true on success or false on failure; call SDL_GetError() for more
  1477. * information.
  1478. *
  1479. * \threadsafety It is safe to call this function from any thread.
  1480. *
  1481. * \since This function is available since SDL 3.1.3.
  1482. *
  1483. * \sa SDL_UnlockAudioStream
  1484. */
  1485. extern SDL_DECLSPEC bool SDLCALL SDL_LockAudioStream(SDL_AudioStream *stream);
  1486. /**
  1487. * Unlock an audio stream for serialized access.
  1488. *
  1489. * This unlocks an audio stream after a call to SDL_LockAudioStream.
  1490. *
  1491. * \param stream the audio stream to unlock.
  1492. * \returns true on success or false on failure; call SDL_GetError() for more
  1493. * information.
  1494. *
  1495. * \threadsafety You should only call this from the same thread that
  1496. * previously called SDL_LockAudioStream.
  1497. *
  1498. * \since This function is available since SDL 3.1.3.
  1499. *
  1500. * \sa SDL_LockAudioStream
  1501. */
  1502. extern SDL_DECLSPEC bool SDLCALL SDL_UnlockAudioStream(SDL_AudioStream *stream);
  1503. /**
  1504. * A callback that fires when data passes through an SDL_AudioStream.
  1505. *
  1506. * Apps can (optionally) register a callback with an audio stream that is
  1507. * called when data is added with SDL_PutAudioStreamData, or requested with
  1508. * SDL_GetAudioStreamData.
  1509. *
  1510. * Two values are offered here: one is the amount of additional data needed to
  1511. * satisfy the immediate request (which might be zero if the stream already
  1512. * has enough data queued) and the other is the total amount being requested.
  1513. * In a Get call triggering a Put callback, these values can be different. In
  1514. * a Put call triggering a Get callback, these values are always the same.
  1515. *
  1516. * Byte counts might be slightly overestimated due to buffering or resampling,
  1517. * and may change from call to call.
  1518. *
  1519. * This callback is not required to do anything. Generally this is useful for
  1520. * adding/reading data on demand, and the app will often put/get data as
  1521. * appropriate, but the system goes on with the data currently available to it
  1522. * if this callback does nothing.
  1523. *
  1524. * \param stream the SDL audio stream associated with this callback.
  1525. * \param additional_amount the amount of data, in bytes, that is needed right
  1526. * now.
  1527. * \param total_amount the total amount of data requested, in bytes, that is
  1528. * requested or available.
  1529. * \param userdata an opaque pointer provided by the app for their personal
  1530. * use.
  1531. *
  1532. * \threadsafety This callbacks may run from any thread, so if you need to
  1533. * protect shared data, you should use SDL_LockAudioStream to
  1534. * serialize access; this lock will be held before your callback
  1535. * is called, so your callback does not need to manage the lock
  1536. * explicitly.
  1537. *
  1538. * \since This datatype is available since SDL 3.1.3.
  1539. *
  1540. * \sa SDL_SetAudioStreamGetCallback
  1541. * \sa SDL_SetAudioStreamPutCallback
  1542. */
  1543. typedef void (SDLCALL *SDL_AudioStreamCallback)(void *userdata, SDL_AudioStream *stream, int additional_amount, int total_amount);
  1544. /**
  1545. * Set a callback that runs when data is requested from an audio stream.
  1546. *
  1547. * This callback is called _before_ data is obtained from the stream, giving
  1548. * the callback the chance to add more on-demand.
  1549. *
  1550. * The callback can (optionally) call SDL_PutAudioStreamData() to add more
  1551. * audio to the stream during this call; if needed, the request that triggered
  1552. * this callback will obtain the new data immediately.
  1553. *
  1554. * The callback's `approx_request` argument is roughly how many bytes of
  1555. * _unconverted_ data (in the stream's input format) is needed by the caller,
  1556. * although this may overestimate a little for safety. This takes into account
  1557. * how much is already in the stream and only asks for any extra necessary to
  1558. * resolve the request, which means the callback may be asked for zero bytes,
  1559. * and a different amount on each call.
  1560. *
  1561. * The callback is not required to supply exact amounts; it is allowed to
  1562. * supply too much or too little or none at all. The caller will get what's
  1563. * available, up to the amount they requested, regardless of this callback's
  1564. * outcome.
  1565. *
  1566. * Clearing or flushing an audio stream does not call this callback.
  1567. *
  1568. * This function obtains the stream's lock, which means any existing callback
  1569. * (get or put) in progress will finish running before setting the new
  1570. * callback.
  1571. *
  1572. * Setting a NULL function turns off the callback.
  1573. *
  1574. * \param stream the audio stream to set the new callback on.
  1575. * \param callback the new callback function to call when data is requested
  1576. * from the stream.
  1577. * \param userdata an opaque pointer provided to the callback for its own
  1578. * personal use.
  1579. * \returns true on success or false on failure; call SDL_GetError() for more
  1580. * information. This only fails if `stream` is NULL.
  1581. *
  1582. * \threadsafety It is safe to call this function from any thread.
  1583. *
  1584. * \since This function is available since SDL 3.1.3.
  1585. *
  1586. * \sa SDL_SetAudioStreamPutCallback
  1587. */
  1588. extern SDL_DECLSPEC bool SDLCALL SDL_SetAudioStreamGetCallback(SDL_AudioStream *stream, SDL_AudioStreamCallback callback, void *userdata);
  1589. /**
  1590. * Set a callback that runs when data is added to an audio stream.
  1591. *
  1592. * This callback is called _after_ the data is added to the stream, giving the
  1593. * callback the chance to obtain it immediately.
  1594. *
  1595. * The callback can (optionally) call SDL_GetAudioStreamData() to obtain audio
  1596. * from the stream during this call.
  1597. *
  1598. * The callback's `approx_request` argument is how many bytes of _converted_
  1599. * data (in the stream's output format) was provided by the caller, although
  1600. * this may underestimate a little for safety. This value might be less than
  1601. * what is currently available in the stream, if data was already there, and
  1602. * might be less than the caller provided if the stream needs to keep a buffer
  1603. * to aid in resampling. Which means the callback may be provided with zero
  1604. * bytes, and a different amount on each call.
  1605. *
  1606. * The callback may call SDL_GetAudioStreamAvailable to see the total amount
  1607. * currently available to read from the stream, instead of the total provided
  1608. * by the current call.
  1609. *
  1610. * The callback is not required to obtain all data. It is allowed to read less
  1611. * or none at all. Anything not read now simply remains in the stream for
  1612. * later access.
  1613. *
  1614. * Clearing or flushing an audio stream does not call this callback.
  1615. *
  1616. * This function obtains the stream's lock, which means any existing callback
  1617. * (get or put) in progress will finish running before setting the new
  1618. * callback.
  1619. *
  1620. * Setting a NULL function turns off the callback.
  1621. *
  1622. * \param stream the audio stream to set the new callback on.
  1623. * \param callback the new callback function to call when data is added to the
  1624. * stream.
  1625. * \param userdata an opaque pointer provided to the callback for its own
  1626. * personal use.
  1627. * \returns true on success or false on failure; call SDL_GetError() for more
  1628. * information. This only fails if `stream` is NULL.
  1629. *
  1630. * \threadsafety It is safe to call this function from any thread.
  1631. *
  1632. * \since This function is available since SDL 3.1.3.
  1633. *
  1634. * \sa SDL_SetAudioStreamGetCallback
  1635. */
  1636. extern SDL_DECLSPEC bool SDLCALL SDL_SetAudioStreamPutCallback(SDL_AudioStream *stream, SDL_AudioStreamCallback callback, void *userdata);
  1637. /**
  1638. * Free an audio stream.
  1639. *
  1640. * This will release all allocated data, including any audio that is still
  1641. * queued. You do not need to manually clear the stream first.
  1642. *
  1643. * If this stream was bound to an audio device, it is unbound during this
  1644. * call. If this stream was created with SDL_OpenAudioDeviceStream, the audio
  1645. * device that was opened alongside this stream's creation will be closed,
  1646. * too.
  1647. *
  1648. * \param stream the audio stream to destroy.
  1649. *
  1650. * \threadsafety It is safe to call this function from any thread.
  1651. *
  1652. * \since This function is available since SDL 3.1.3.
  1653. *
  1654. * \sa SDL_CreateAudioStream
  1655. */
  1656. extern SDL_DECLSPEC void SDLCALL SDL_DestroyAudioStream(SDL_AudioStream *stream);
  1657. /**
  1658. * Convenience function for straightforward audio init for the common case.
  1659. *
  1660. * If all your app intends to do is provide a single source of PCM audio, this
  1661. * function allows you to do all your audio setup in a single call.
  1662. *
  1663. * This is also intended to be a clean means to migrate apps from SDL2.
  1664. *
  1665. * This function will open an audio device, create a stream and bind it.
  1666. * Unlike other methods of setup, the audio device will be closed when this
  1667. * stream is destroyed, so the app can treat the returned SDL_AudioStream as
  1668. * the only object needed to manage audio playback.
  1669. *
  1670. * Also unlike other functions, the audio device begins paused. This is to map
  1671. * more closely to SDL2-style behavior, since there is no extra step here to
  1672. * bind a stream to begin audio flowing. The audio device should be resumed
  1673. * with `SDL_ResumeAudioStreamDevice(stream);`
  1674. *
  1675. * This function works with both playback and recording devices.
  1676. *
  1677. * The `spec` parameter represents the app's side of the audio stream. That
  1678. * is, for recording audio, this will be the output format, and for playing
  1679. * audio, this will be the input format. If spec is NULL, the system will
  1680. * choose the format, and the app can use SDL_GetAudioStreamFormat() to obtain
  1681. * this information later.
  1682. *
  1683. * If you don't care about opening a specific audio device, you can (and
  1684. * probably _should_), use SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK for playback and
  1685. * SDL_AUDIO_DEVICE_DEFAULT_RECORDING for recording.
  1686. *
  1687. * One can optionally provide a callback function; if NULL, the app is
  1688. * expected to queue audio data for playback (or unqueue audio data if
  1689. * capturing). Otherwise, the callback will begin to fire once the device is
  1690. * unpaused.
  1691. *
  1692. * Destroying the returned stream with SDL_DestroyAudioStream will also close
  1693. * the audio device associated with this stream.
  1694. *
  1695. * \param devid an audio device to open, or SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK
  1696. * or SDL_AUDIO_DEVICE_DEFAULT_RECORDING.
  1697. * \param spec the audio stream's data format. Can be NULL.
  1698. * \param callback a callback where the app will provide new data for
  1699. * playback, or receive new data for recording. Can be NULL,
  1700. * in which case the app will need to call
  1701. * SDL_PutAudioStreamData or SDL_GetAudioStreamData as
  1702. * necessary.
  1703. * \param userdata app-controlled pointer passed to callback. Can be NULL.
  1704. * Ignored if callback is NULL.
  1705. * \returns an audio stream on success, ready to use, or NULL on failure; call
  1706. * SDL_GetError() for more information. When done with this stream,
  1707. * call SDL_DestroyAudioStream to free resources and close the
  1708. * device.
  1709. *
  1710. * \threadsafety It is safe to call this function from any thread.
  1711. *
  1712. * \since This function is available since SDL 3.1.3.
  1713. *
  1714. * \sa SDL_GetAudioStreamDevice
  1715. * \sa SDL_ResumeAudioStreamDevice
  1716. */
  1717. extern SDL_DECLSPEC SDL_AudioStream * SDLCALL SDL_OpenAudioDeviceStream(SDL_AudioDeviceID devid, const SDL_AudioSpec *spec, SDL_AudioStreamCallback callback, void *userdata);
  1718. /**
  1719. * A callback that fires when data is about to be fed to an audio device.
  1720. *
  1721. * This is useful for accessing the final mix, perhaps for writing a
  1722. * visualizer or applying a final effect to the audio data before playback.
  1723. *
  1724. * This callback should run as quickly as possible and not block for any
  1725. * significant time, as this callback delays submission of data to the audio
  1726. * device, which can cause audio playback problems.
  1727. *
  1728. * The postmix callback _must_ be able to handle any audio data format
  1729. * specified in `spec`, which can change between callbacks if the audio device
  1730. * changed. However, this only covers frequency and channel count; data is
  1731. * always provided here in SDL_AUDIO_F32 format.
  1732. *
  1733. * The postmix callback runs _after_ logical device gain and audiostream gain
  1734. * have been applied, which is to say you can make the output data louder at
  1735. * this point than the gain settings would suggest.
  1736. *
  1737. * \param userdata a pointer provided by the app through
  1738. * SDL_SetAudioPostmixCallback, for its own use.
  1739. * \param spec the current format of audio that is to be submitted to the
  1740. * audio device.
  1741. * \param buffer the buffer of audio samples to be submitted. The callback can
  1742. * inspect and/or modify this data.
  1743. * \param buflen the size of `buffer` in bytes.
  1744. *
  1745. * \threadsafety This will run from a background thread owned by SDL. The
  1746. * application is responsible for locking resources the callback
  1747. * touches that need to be protected.
  1748. *
  1749. * \since This datatype is available since SDL 3.1.3.
  1750. *
  1751. * \sa SDL_SetAudioPostmixCallback
  1752. */
  1753. typedef void (SDLCALL *SDL_AudioPostmixCallback)(void *userdata, const SDL_AudioSpec *spec, float *buffer, int buflen);
  1754. /**
  1755. * Set a callback that fires when data is about to be fed to an audio device.
  1756. *
  1757. * This is useful for accessing the final mix, perhaps for writing a
  1758. * visualizer or applying a final effect to the audio data before playback.
  1759. *
  1760. * The buffer is the final mix of all bound audio streams on an opened device;
  1761. * this callback will fire regularly for any device that is both opened and
  1762. * unpaused. If there is no new data to mix, either because no streams are
  1763. * bound to the device or all the streams are empty, this callback will still
  1764. * fire with the entire buffer set to silence.
  1765. *
  1766. * This callback is allowed to make changes to the data; the contents of the
  1767. * buffer after this call is what is ultimately passed along to the hardware.
  1768. *
  1769. * The callback is always provided the data in float format (values from -1.0f
  1770. * to 1.0f), but the number of channels or sample rate may be different than
  1771. * the format the app requested when opening the device; SDL might have had to
  1772. * manage a conversion behind the scenes, or the playback might have jumped to
  1773. * new physical hardware when a system default changed, etc. These details may
  1774. * change between calls. Accordingly, the size of the buffer might change
  1775. * between calls as well.
  1776. *
  1777. * This callback can run at any time, and from any thread; if you need to
  1778. * serialize access to your app's data, you should provide and use a mutex or
  1779. * other synchronization device.
  1780. *
  1781. * All of this to say: there are specific needs this callback can fulfill, but
  1782. * it is not the simplest interface. Apps should generally provide audio in
  1783. * their preferred format through an SDL_AudioStream and let SDL handle the
  1784. * difference.
  1785. *
  1786. * This function is extremely time-sensitive; the callback should do the least
  1787. * amount of work possible and return as quickly as it can. The longer the
  1788. * callback runs, the higher the risk of audio dropouts or other problems.
  1789. *
  1790. * This function will block until the audio device is in between iterations,
  1791. * so any existing callback that might be running will finish before this
  1792. * function sets the new callback and returns.
  1793. *
  1794. * Setting a NULL callback function disables any previously-set callback.
  1795. *
  1796. * \param devid the ID of an opened audio device.
  1797. * \param callback a callback function to be called. Can be NULL.
  1798. * \param userdata app-controlled pointer passed to callback. Can be NULL.
  1799. * \returns true on success or false on failure; call SDL_GetError() for more
  1800. * information.
  1801. *
  1802. * \threadsafety It is safe to call this function from any thread.
  1803. *
  1804. * \since This function is available since SDL 3.1.3.
  1805. */
  1806. extern SDL_DECLSPEC bool SDLCALL SDL_SetAudioPostmixCallback(SDL_AudioDeviceID devid, SDL_AudioPostmixCallback callback, void *userdata);
  1807. /**
  1808. * Load the audio data of a WAVE file into memory.
  1809. *
  1810. * Loading a WAVE file requires `src`, `spec`, `audio_buf` and `audio_len` to
  1811. * be valid pointers. The entire data portion of the file is then loaded into
  1812. * memory and decoded if necessary.
  1813. *
  1814. * Supported formats are RIFF WAVE files with the formats PCM (8, 16, 24, and
  1815. * 32 bits), IEEE Float (32 bits), Microsoft ADPCM and IMA ADPCM (4 bits), and
  1816. * A-law and mu-law (8 bits). Other formats are currently unsupported and
  1817. * cause an error.
  1818. *
  1819. * If this function succeeds, the return value is zero and the pointer to the
  1820. * audio data allocated by the function is written to `audio_buf` and its
  1821. * length in bytes to `audio_len`. The SDL_AudioSpec members `freq`,
  1822. * `channels`, and `format` are set to the values of the audio data in the
  1823. * buffer.
  1824. *
  1825. * It's necessary to use SDL_free() to free the audio data returned in
  1826. * `audio_buf` when it is no longer used.
  1827. *
  1828. * Because of the underspecification of the .WAV format, there are many
  1829. * problematic files in the wild that cause issues with strict decoders. To
  1830. * provide compatibility with these files, this decoder is lenient in regards
  1831. * to the truncation of the file, the fact chunk, and the size of the RIFF
  1832. * chunk. The hints `SDL_HINT_WAVE_RIFF_CHUNK_SIZE`,
  1833. * `SDL_HINT_WAVE_TRUNCATION`, and `SDL_HINT_WAVE_FACT_CHUNK` can be used to
  1834. * tune the behavior of the loading process.
  1835. *
  1836. * Any file that is invalid (due to truncation, corruption, or wrong values in
  1837. * the headers), too big, or unsupported causes an error. Additionally, any
  1838. * critical I/O error from the data source will terminate the loading process
  1839. * with an error. The function returns NULL on error and in all cases (with
  1840. * the exception of `src` being NULL), an appropriate error message will be
  1841. * set.
  1842. *
  1843. * It is required that the data source supports seeking.
  1844. *
  1845. * Example:
  1846. *
  1847. * ```c
  1848. * SDL_LoadWAV_IO(SDL_IOFromFile("sample.wav", "rb"), true, &spec, &buf, &len);
  1849. * ```
  1850. *
  1851. * Note that the SDL_LoadWAV function does this same thing for you, but in a
  1852. * less messy way:
  1853. *
  1854. * ```c
  1855. * SDL_LoadWAV("sample.wav", &spec, &buf, &len);
  1856. * ```
  1857. *
  1858. * \param src the data source for the WAVE data.
  1859. * \param closeio if true, calls SDL_CloseIO() on `src` before returning, even
  1860. * in the case of an error.
  1861. * \param spec a pointer to an SDL_AudioSpec that will be set to the WAVE
  1862. * data's format details on successful return.
  1863. * \param audio_buf a pointer filled with the audio data, allocated by the
  1864. * function.
  1865. * \param audio_len a pointer filled with the length of the audio data buffer
  1866. * in bytes.
  1867. * \returns true on success. `audio_buf` will be filled with a pointer to an
  1868. * allocated buffer containing the audio data, and `audio_len` is
  1869. * filled with the length of that audio buffer in bytes.
  1870. *
  1871. * This function returns false if the .WAV file cannot be opened,
  1872. * uses an unknown data format, or is corrupt; call SDL_GetError()
  1873. * for more information.
  1874. *
  1875. * When the application is done with the data returned in
  1876. * `audio_buf`, it should call SDL_free() to dispose of it.
  1877. *
  1878. * \threadsafety It is safe to call this function from any thread.
  1879. *
  1880. * \since This function is available since SDL 3.1.3.
  1881. *
  1882. * \sa SDL_free
  1883. * \sa SDL_LoadWAV
  1884. */
  1885. extern SDL_DECLSPEC bool SDLCALL SDL_LoadWAV_IO(SDL_IOStream *src, bool closeio, SDL_AudioSpec *spec, Uint8 **audio_buf, Uint32 *audio_len);
  1886. /**
  1887. * Loads a WAV from a file path.
  1888. *
  1889. * This is a convenience function that is effectively the same as:
  1890. *
  1891. * ```c
  1892. * SDL_LoadWAV_IO(SDL_IOFromFile(path, "rb"), true, spec, audio_buf, audio_len);
  1893. * ```
  1894. *
  1895. * \param path the file path of the WAV file to open.
  1896. * \param spec a pointer to an SDL_AudioSpec that will be set to the WAVE
  1897. * data's format details on successful return.
  1898. * \param audio_buf a pointer filled with the audio data, allocated by the
  1899. * function.
  1900. * \param audio_len a pointer filled with the length of the audio data buffer
  1901. * in bytes.
  1902. * \returns true on success. `audio_buf` will be filled with a pointer to an
  1903. * allocated buffer containing the audio data, and `audio_len` is
  1904. * filled with the length of that audio buffer in bytes.
  1905. *
  1906. * This function returns false if the .WAV file cannot be opened,
  1907. * uses an unknown data format, or is corrupt; call SDL_GetError()
  1908. * for more information.
  1909. *
  1910. * When the application is done with the data returned in
  1911. * `audio_buf`, it should call SDL_free() to dispose of it.
  1912. *
  1913. * \threadsafety It is safe to call this function from any thread.
  1914. *
  1915. * \since This function is available since SDL 3.1.3.
  1916. *
  1917. * \sa SDL_free
  1918. * \sa SDL_LoadWAV_IO
  1919. */
  1920. extern SDL_DECLSPEC bool SDLCALL SDL_LoadWAV(const char *path, SDL_AudioSpec *spec, Uint8 **audio_buf, Uint32 *audio_len);
  1921. /**
  1922. * Mix audio data in a specified format.
  1923. *
  1924. * This takes an audio buffer `src` of `len` bytes of `format` data and mixes
  1925. * it into `dst`, performing addition, volume adjustment, and overflow
  1926. * clipping. The buffer pointed to by `dst` must also be `len` bytes of
  1927. * `format` data.
  1928. *
  1929. * This is provided for convenience -- you can mix your own audio data.
  1930. *
  1931. * Do not use this function for mixing together more than two streams of
  1932. * sample data. The output from repeated application of this function may be
  1933. * distorted by clipping, because there is no accumulator with greater range
  1934. * than the input (not to mention this being an inefficient way of doing it).
  1935. *
  1936. * It is a common misconception that this function is required to write audio
  1937. * data to an output stream in an audio callback. While you can do that,
  1938. * SDL_MixAudio() is really only needed when you're mixing a single audio
  1939. * stream with a volume adjustment.
  1940. *
  1941. * \param dst the destination for the mixed audio.
  1942. * \param src the source audio buffer to be mixed.
  1943. * \param format the SDL_AudioFormat structure representing the desired audio
  1944. * format.
  1945. * \param len the length of the audio buffer in bytes.
  1946. * \param volume ranges from 0.0 - 1.0, and should be set to 1.0 for full
  1947. * audio volume.
  1948. * \returns true on success or false on failure; call SDL_GetError() for more
  1949. * information.
  1950. *
  1951. * \threadsafety It is safe to call this function from any thread.
  1952. *
  1953. * \since This function is available since SDL 3.1.3.
  1954. */
  1955. extern SDL_DECLSPEC bool SDLCALL SDL_MixAudio(Uint8 *dst, const Uint8 *src, SDL_AudioFormat format, Uint32 len, float volume);
  1956. /**
  1957. * Convert some audio data of one format to another format.
  1958. *
  1959. * Please note that this function is for convenience, but should not be used
  1960. * to resample audio in blocks, as it will introduce audio artifacts on the
  1961. * boundaries. You should only use this function if you are converting audio
  1962. * data in its entirety in one call. If you want to convert audio in smaller
  1963. * chunks, use an SDL_AudioStream, which is designed for this situation.
  1964. *
  1965. * Internally, this function creates and destroys an SDL_AudioStream on each
  1966. * use, so it's also less efficient than using one directly, if you need to
  1967. * convert multiple times.
  1968. *
  1969. * \param src_spec the format details of the input audio.
  1970. * \param src_data the audio data to be converted.
  1971. * \param src_len the len of src_data.
  1972. * \param dst_spec the format details of the output audio.
  1973. * \param dst_data will be filled with a pointer to converted audio data,
  1974. * which should be freed with SDL_free(). On error, it will be
  1975. * NULL.
  1976. * \param dst_len will be filled with the len of dst_data.
  1977. * \returns true on success or false on failure; call SDL_GetError() for more
  1978. * information.
  1979. *
  1980. * \threadsafety It is safe to call this function from any thread.
  1981. *
  1982. * \since This function is available since SDL 3.1.3.
  1983. */
  1984. extern SDL_DECLSPEC bool SDLCALL SDL_ConvertAudioSamples(const SDL_AudioSpec *src_spec, const Uint8 *src_data, int src_len, const SDL_AudioSpec *dst_spec, Uint8 **dst_data, int *dst_len);
  1985. /**
  1986. * Get the human readable name of an audio format.
  1987. *
  1988. * \param format the audio format to query.
  1989. * \returns the human readable name of the specified audio format or
  1990. * "SDL_AUDIO_UNKNOWN" if the format isn't recognized.
  1991. *
  1992. * \threadsafety It is safe to call this function from any thread.
  1993. *
  1994. * \since This function is available since SDL 3.1.3.
  1995. */
  1996. extern SDL_DECLSPEC const char * SDLCALL SDL_GetAudioFormatName(SDL_AudioFormat format);
  1997. /**
  1998. * Get the appropriate memset value for silencing an audio format.
  1999. *
  2000. * The value returned by this function can be used as the second argument to
  2001. * memset (or SDL_memset) to set an audio buffer in a specific format to
  2002. * silence.
  2003. *
  2004. * \param format the audio data format to query.
  2005. * \returns a byte value that can be passed to memset.
  2006. *
  2007. * \threadsafety It is safe to call this function from any thread.
  2008. *
  2009. * \since This function is available since SDL 3.1.3.
  2010. */
  2011. extern SDL_DECLSPEC int SDLCALL SDL_GetSilenceValueForFormat(SDL_AudioFormat format);
  2012. /* Ends C function definitions when using C++ */
  2013. #ifdef __cplusplus
  2014. }
  2015. #endif
  2016. #include <SDL3/SDL_close_code.h>
  2017. #endif /* SDL_audio_h_ */