SDL_audio.h 44 KB

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