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