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