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