SDL Library

Dependents:   H261_decoder

Committer:
miruga27
Date:
Thu Sep 22 00:03:09 2016 +0000
Revision:
0:7fb6877b5d7c
SDL

Who changed what in which revision?

UserRevisionLine numberNew contents of line
miruga27 0:7fb6877b5d7c 1 /*
miruga27 0:7fb6877b5d7c 2 Simple DirectMedia Layer
miruga27 0:7fb6877b5d7c 3 Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
miruga27 0:7fb6877b5d7c 4
miruga27 0:7fb6877b5d7c 5 This software is provided 'as-is', without any express or implied
miruga27 0:7fb6877b5d7c 6 warranty. In no event will the authors be held liable for any damages
miruga27 0:7fb6877b5d7c 7 arising from the use of this software.
miruga27 0:7fb6877b5d7c 8
miruga27 0:7fb6877b5d7c 9 Permission is granted to anyone to use this software for any purpose,
miruga27 0:7fb6877b5d7c 10 including commercial applications, and to alter it and redistribute it
miruga27 0:7fb6877b5d7c 11 freely, subject to the following restrictions:
miruga27 0:7fb6877b5d7c 12
miruga27 0:7fb6877b5d7c 13 1. The origin of this software must not be misrepresented; you must not
miruga27 0:7fb6877b5d7c 14 claim that you wrote the original software. If you use this software
miruga27 0:7fb6877b5d7c 15 in a product, an acknowledgment in the product documentation would be
miruga27 0:7fb6877b5d7c 16 appreciated but is not required.
miruga27 0:7fb6877b5d7c 17 2. Altered source versions must be plainly marked as such, and must not be
miruga27 0:7fb6877b5d7c 18 misrepresented as being the original software.
miruga27 0:7fb6877b5d7c 19 3. This notice may not be removed or altered from any source distribution.
miruga27 0:7fb6877b5d7c 20 */
miruga27 0:7fb6877b5d7c 21
miruga27 0:7fb6877b5d7c 22 /**
miruga27 0:7fb6877b5d7c 23 * \file SDL_audio.h
miruga27 0:7fb6877b5d7c 24 *
miruga27 0:7fb6877b5d7c 25 * Access to the raw audio mixing buffer for the SDL library.
miruga27 0:7fb6877b5d7c 26 */
miruga27 0:7fb6877b5d7c 27
miruga27 0:7fb6877b5d7c 28 #ifndef _SDL_audio_h
miruga27 0:7fb6877b5d7c 29 #define _SDL_audio_h
miruga27 0:7fb6877b5d7c 30
miruga27 0:7fb6877b5d7c 31 #include "SDL_stdinc.h"
miruga27 0:7fb6877b5d7c 32 #include "SDL_error.h"
miruga27 0:7fb6877b5d7c 33 #include "SDL_endian.h"
miruga27 0:7fb6877b5d7c 34 #include "SDL_mutex.h"
miruga27 0:7fb6877b5d7c 35 #include "SDL_thread.h"
miruga27 0:7fb6877b5d7c 36 #include "SDL_rwops.h"
miruga27 0:7fb6877b5d7c 37
miruga27 0:7fb6877b5d7c 38 #include "begin_code.h"
miruga27 0:7fb6877b5d7c 39 /* Set up for C function definitions, even when using C++ */
miruga27 0:7fb6877b5d7c 40 #ifdef __cplusplus
miruga27 0:7fb6877b5d7c 41 extern "C" {
miruga27 0:7fb6877b5d7c 42 #endif
miruga27 0:7fb6877b5d7c 43
miruga27 0:7fb6877b5d7c 44 /**
miruga27 0:7fb6877b5d7c 45 * \brief Audio format flags.
miruga27 0:7fb6877b5d7c 46 *
miruga27 0:7fb6877b5d7c 47 * These are what the 16 bits in SDL_AudioFormat currently mean...
miruga27 0:7fb6877b5d7c 48 * (Unspecified bits are always zero).
miruga27 0:7fb6877b5d7c 49 *
miruga27 0:7fb6877b5d7c 50 * \verbatim
miruga27 0:7fb6877b5d7c 51 ++-----------------------sample is signed if set
miruga27 0:7fb6877b5d7c 52 ||
miruga27 0:7fb6877b5d7c 53 || ++-----------sample is bigendian if set
miruga27 0:7fb6877b5d7c 54 || ||
miruga27 0:7fb6877b5d7c 55 || || ++---sample is float if set
miruga27 0:7fb6877b5d7c 56 || || ||
miruga27 0:7fb6877b5d7c 57 || || || +---sample bit size---+
miruga27 0:7fb6877b5d7c 58 || || || | |
miruga27 0:7fb6877b5d7c 59 15 14 13 12 11 10 09 08 07 06 05 04 03 02 01 00
miruga27 0:7fb6877b5d7c 60 \endverbatim
miruga27 0:7fb6877b5d7c 61 *
miruga27 0:7fb6877b5d7c 62 * There are macros in SDL 2.0 and later to query these bits.
miruga27 0:7fb6877b5d7c 63 */
miruga27 0:7fb6877b5d7c 64 typedef Uint16 SDL_AudioFormat;
miruga27 0:7fb6877b5d7c 65
miruga27 0:7fb6877b5d7c 66 /**
miruga27 0:7fb6877b5d7c 67 * \name Audio flags
miruga27 0:7fb6877b5d7c 68 */
miruga27 0:7fb6877b5d7c 69 /* @{ */
miruga27 0:7fb6877b5d7c 70
miruga27 0:7fb6877b5d7c 71 #define SDL_AUDIO_MASK_BITSIZE (0xFF)
miruga27 0:7fb6877b5d7c 72 #define SDL_AUDIO_MASK_DATATYPE (1<<8)
miruga27 0:7fb6877b5d7c 73 #define SDL_AUDIO_MASK_ENDIAN (1<<12)
miruga27 0:7fb6877b5d7c 74 #define SDL_AUDIO_MASK_SIGNED (1<<15)
miruga27 0:7fb6877b5d7c 75 #define SDL_AUDIO_BITSIZE(x) (x & SDL_AUDIO_MASK_BITSIZE)
miruga27 0:7fb6877b5d7c 76 #define SDL_AUDIO_ISFLOAT(x) (x & SDL_AUDIO_MASK_DATATYPE)
miruga27 0:7fb6877b5d7c 77 #define SDL_AUDIO_ISBIGENDIAN(x) (x & SDL_AUDIO_MASK_ENDIAN)
miruga27 0:7fb6877b5d7c 78 #define SDL_AUDIO_ISSIGNED(x) (x & SDL_AUDIO_MASK_SIGNED)
miruga27 0:7fb6877b5d7c 79 #define SDL_AUDIO_ISINT(x) (!SDL_AUDIO_ISFLOAT(x))
miruga27 0:7fb6877b5d7c 80 #define SDL_AUDIO_ISLITTLEENDIAN(x) (!SDL_AUDIO_ISBIGENDIAN(x))
miruga27 0:7fb6877b5d7c 81 #define SDL_AUDIO_ISUNSIGNED(x) (!SDL_AUDIO_ISSIGNED(x))
miruga27 0:7fb6877b5d7c 82
miruga27 0:7fb6877b5d7c 83 /**
miruga27 0:7fb6877b5d7c 84 * \name Audio format flags
miruga27 0:7fb6877b5d7c 85 *
miruga27 0:7fb6877b5d7c 86 * Defaults to LSB byte order.
miruga27 0:7fb6877b5d7c 87 */
miruga27 0:7fb6877b5d7c 88 /* @{ */
miruga27 0:7fb6877b5d7c 89 #define AUDIO_U8 0x0008 /**< Unsigned 8-bit samples */
miruga27 0:7fb6877b5d7c 90 #define AUDIO_S8 0x8008 /**< Signed 8-bit samples */
miruga27 0:7fb6877b5d7c 91 #define AUDIO_U16LSB 0x0010 /**< Unsigned 16-bit samples */
miruga27 0:7fb6877b5d7c 92 #define AUDIO_S16LSB 0x8010 /**< Signed 16-bit samples */
miruga27 0:7fb6877b5d7c 93 #define AUDIO_U16MSB 0x1010 /**< As above, but big-endian byte order */
miruga27 0:7fb6877b5d7c 94 #define AUDIO_S16MSB 0x9010 /**< As above, but big-endian byte order */
miruga27 0:7fb6877b5d7c 95 #define AUDIO_U16 AUDIO_U16LSB
miruga27 0:7fb6877b5d7c 96 #define AUDIO_S16 AUDIO_S16LSB
miruga27 0:7fb6877b5d7c 97 /* @} */
miruga27 0:7fb6877b5d7c 98
miruga27 0:7fb6877b5d7c 99 /**
miruga27 0:7fb6877b5d7c 100 * \name int32 support
miruga27 0:7fb6877b5d7c 101 */
miruga27 0:7fb6877b5d7c 102 /* @{ */
miruga27 0:7fb6877b5d7c 103 #define AUDIO_S32LSB 0x8020 /**< 32-bit integer samples */
miruga27 0:7fb6877b5d7c 104 #define AUDIO_S32MSB 0x9020 /**< As above, but big-endian byte order */
miruga27 0:7fb6877b5d7c 105 #define AUDIO_S32 AUDIO_S32LSB
miruga27 0:7fb6877b5d7c 106 /* @} */
miruga27 0:7fb6877b5d7c 107
miruga27 0:7fb6877b5d7c 108 /**
miruga27 0:7fb6877b5d7c 109 * \name float32 support
miruga27 0:7fb6877b5d7c 110 */
miruga27 0:7fb6877b5d7c 111 /* @{ */
miruga27 0:7fb6877b5d7c 112 #define AUDIO_F32LSB 0x8120 /**< 32-bit floating point samples */
miruga27 0:7fb6877b5d7c 113 #define AUDIO_F32MSB 0x9120 /**< As above, but big-endian byte order */
miruga27 0:7fb6877b5d7c 114 #define AUDIO_F32 AUDIO_F32LSB
miruga27 0:7fb6877b5d7c 115 /* @} */
miruga27 0:7fb6877b5d7c 116
miruga27 0:7fb6877b5d7c 117 /**
miruga27 0:7fb6877b5d7c 118 * \name Native audio byte ordering
miruga27 0:7fb6877b5d7c 119 */
miruga27 0:7fb6877b5d7c 120 /* @{ */
miruga27 0:7fb6877b5d7c 121 #if SDL_BYTEORDER == SDL_LIL_ENDIAN
miruga27 0:7fb6877b5d7c 122 #define AUDIO_U16SYS AUDIO_U16LSB
miruga27 0:7fb6877b5d7c 123 #define AUDIO_S16SYS AUDIO_S16LSB
miruga27 0:7fb6877b5d7c 124 #define AUDIO_S32SYS AUDIO_S32LSB
miruga27 0:7fb6877b5d7c 125 #define AUDIO_F32SYS AUDIO_F32LSB
miruga27 0:7fb6877b5d7c 126 #else
miruga27 0:7fb6877b5d7c 127 #define AUDIO_U16SYS AUDIO_U16MSB
miruga27 0:7fb6877b5d7c 128 #define AUDIO_S16SYS AUDIO_S16MSB
miruga27 0:7fb6877b5d7c 129 #define AUDIO_S32SYS AUDIO_S32MSB
miruga27 0:7fb6877b5d7c 130 #define AUDIO_F32SYS AUDIO_F32MSB
miruga27 0:7fb6877b5d7c 131 #endif
miruga27 0:7fb6877b5d7c 132 /* @} */
miruga27 0:7fb6877b5d7c 133
miruga27 0:7fb6877b5d7c 134 /**
miruga27 0:7fb6877b5d7c 135 * \name Allow change flags
miruga27 0:7fb6877b5d7c 136 *
miruga27 0:7fb6877b5d7c 137 * Which audio format changes are allowed when opening a device.
miruga27 0:7fb6877b5d7c 138 */
miruga27 0:7fb6877b5d7c 139 /* @{ */
miruga27 0:7fb6877b5d7c 140 #define SDL_AUDIO_ALLOW_FREQUENCY_CHANGE 0x00000001
miruga27 0:7fb6877b5d7c 141 #define SDL_AUDIO_ALLOW_FORMAT_CHANGE 0x00000002
miruga27 0:7fb6877b5d7c 142 #define SDL_AUDIO_ALLOW_CHANNELS_CHANGE 0x00000004
miruga27 0:7fb6877b5d7c 143 #define SDL_AUDIO_ALLOW_ANY_CHANGE (SDL_AUDIO_ALLOW_FREQUENCY_CHANGE|SDL_AUDIO_ALLOW_FORMAT_CHANGE|SDL_AUDIO_ALLOW_CHANNELS_CHANGE)
miruga27 0:7fb6877b5d7c 144 /* @} */
miruga27 0:7fb6877b5d7c 145
miruga27 0:7fb6877b5d7c 146 /* @} *//* Audio flags */
miruga27 0:7fb6877b5d7c 147
miruga27 0:7fb6877b5d7c 148 /**
miruga27 0:7fb6877b5d7c 149 * This function is called when the audio device needs more data.
miruga27 0:7fb6877b5d7c 150 *
miruga27 0:7fb6877b5d7c 151 * \param userdata An application-specific parameter saved in
miruga27 0:7fb6877b5d7c 152 * the SDL_AudioSpec structure
miruga27 0:7fb6877b5d7c 153 * \param stream A pointer to the audio data buffer.
miruga27 0:7fb6877b5d7c 154 * \param len The length of that buffer in bytes.
miruga27 0:7fb6877b5d7c 155 *
miruga27 0:7fb6877b5d7c 156 * Once the callback returns, the buffer will no longer be valid.
miruga27 0:7fb6877b5d7c 157 * Stereo samples are stored in a LRLRLR ordering.
miruga27 0:7fb6877b5d7c 158 */
miruga27 0:7fb6877b5d7c 159 typedef void (SDLCALL * SDL_AudioCallback) (void *userdata, Uint8 * stream,
miruga27 0:7fb6877b5d7c 160 int len);
miruga27 0:7fb6877b5d7c 161
miruga27 0:7fb6877b5d7c 162 /**
miruga27 0:7fb6877b5d7c 163 * The calculated values in this structure are calculated by SDL_OpenAudio().
miruga27 0:7fb6877b5d7c 164 */
miruga27 0:7fb6877b5d7c 165 typedef struct SDL_AudioSpec
miruga27 0:7fb6877b5d7c 166 {
miruga27 0:7fb6877b5d7c 167 int freq; /**< DSP frequency -- samples per second */
miruga27 0:7fb6877b5d7c 168 SDL_AudioFormat format; /**< Audio data format */
miruga27 0:7fb6877b5d7c 169 Uint8 channels; /**< Number of channels: 1 mono, 2 stereo */
miruga27 0:7fb6877b5d7c 170 Uint8 silence; /**< Audio buffer silence value (calculated) */
miruga27 0:7fb6877b5d7c 171 Uint16 samples; /**< Audio buffer size in samples (power of 2) */
miruga27 0:7fb6877b5d7c 172 Uint16 padding; /**< Necessary for some compile environments */
miruga27 0:7fb6877b5d7c 173 Uint32 size; /**< Audio buffer size in bytes (calculated) */
miruga27 0:7fb6877b5d7c 174 SDL_AudioCallback callback;
miruga27 0:7fb6877b5d7c 175 void *userdata;
miruga27 0:7fb6877b5d7c 176 } SDL_AudioSpec;
miruga27 0:7fb6877b5d7c 177
miruga27 0:7fb6877b5d7c 178
miruga27 0:7fb6877b5d7c 179 struct SDL_AudioCVT;
miruga27 0:7fb6877b5d7c 180 typedef void (SDLCALL * SDL_AudioFilter) (struct SDL_AudioCVT * cvt,
miruga27 0:7fb6877b5d7c 181 SDL_AudioFormat format);
miruga27 0:7fb6877b5d7c 182
miruga27 0:7fb6877b5d7c 183 /**
miruga27 0:7fb6877b5d7c 184 * A structure to hold a set of audio conversion filters and buffers.
miruga27 0:7fb6877b5d7c 185 */
miruga27 0:7fb6877b5d7c 186 #ifdef __GNUC__
miruga27 0:7fb6877b5d7c 187 /* This structure is 84 bytes on 32-bit architectures, make sure GCC doesn't
miruga27 0:7fb6877b5d7c 188 pad it out to 88 bytes to guarantee ABI compatibility between compilers.
miruga27 0:7fb6877b5d7c 189 vvv
miruga27 0:7fb6877b5d7c 190 The next time we rev the ABI, make sure to size the ints and add padding.
miruga27 0:7fb6877b5d7c 191 */
miruga27 0:7fb6877b5d7c 192 #define SDL_AUDIOCVT_PACKED __attribute__((packed))
miruga27 0:7fb6877b5d7c 193 #else
miruga27 0:7fb6877b5d7c 194 #define SDL_AUDIOCVT_PACKED
miruga27 0:7fb6877b5d7c 195 #endif
miruga27 0:7fb6877b5d7c 196 /* */
miruga27 0:7fb6877b5d7c 197 typedef struct SDL_AudioCVT
miruga27 0:7fb6877b5d7c 198 {
miruga27 0:7fb6877b5d7c 199 int needed; /**< Set to 1 if conversion possible */
miruga27 0:7fb6877b5d7c 200 SDL_AudioFormat src_format; /**< Source audio format */
miruga27 0:7fb6877b5d7c 201 SDL_AudioFormat dst_format; /**< Target audio format */
miruga27 0:7fb6877b5d7c 202 double rate_incr; /**< Rate conversion increment */
miruga27 0:7fb6877b5d7c 203 Uint8 *buf; /**< Buffer to hold entire audio data */
miruga27 0:7fb6877b5d7c 204 int len; /**< Length of original audio buffer */
miruga27 0:7fb6877b5d7c 205 int len_cvt; /**< Length of converted audio buffer */
miruga27 0:7fb6877b5d7c 206 int len_mult; /**< buffer must be len*len_mult big */
miruga27 0:7fb6877b5d7c 207 double len_ratio; /**< Given len, final size is len*len_ratio */
miruga27 0:7fb6877b5d7c 208 SDL_AudioFilter filters[10]; /**< Filter list */
miruga27 0:7fb6877b5d7c 209 int filter_index; /**< Current audio conversion function */
miruga27 0:7fb6877b5d7c 210 } SDL_AUDIOCVT_PACKED SDL_AudioCVT;
miruga27 0:7fb6877b5d7c 211
miruga27 0:7fb6877b5d7c 212
miruga27 0:7fb6877b5d7c 213 /* Function prototypes */
miruga27 0:7fb6877b5d7c 214
miruga27 0:7fb6877b5d7c 215 /**
miruga27 0:7fb6877b5d7c 216 * \name Driver discovery functions
miruga27 0:7fb6877b5d7c 217 *
miruga27 0:7fb6877b5d7c 218 * These functions return the list of built in audio drivers, in the
miruga27 0:7fb6877b5d7c 219 * order that they are normally initialized by default.
miruga27 0:7fb6877b5d7c 220 */
miruga27 0:7fb6877b5d7c 221 /* @{ */
miruga27 0:7fb6877b5d7c 222 extern DECLSPEC int SDLCALL SDL_GetNumAudioDrivers(void);
miruga27 0:7fb6877b5d7c 223 extern DECLSPEC const char *SDLCALL SDL_GetAudioDriver(int index);
miruga27 0:7fb6877b5d7c 224 /* @} */
miruga27 0:7fb6877b5d7c 225
miruga27 0:7fb6877b5d7c 226 /**
miruga27 0:7fb6877b5d7c 227 * \name Initialization and cleanup
miruga27 0:7fb6877b5d7c 228 *
miruga27 0:7fb6877b5d7c 229 * \internal These functions are used internally, and should not be used unless
miruga27 0:7fb6877b5d7c 230 * you have a specific need to specify the audio driver you want to
miruga27 0:7fb6877b5d7c 231 * use. You should normally use SDL_Init() or SDL_InitSubSystem().
miruga27 0:7fb6877b5d7c 232 */
miruga27 0:7fb6877b5d7c 233 /* @{ */
miruga27 0:7fb6877b5d7c 234 extern DECLSPEC int SDLCALL SDL_AudioInit(const char *driver_name);
miruga27 0:7fb6877b5d7c 235 extern DECLSPEC void SDLCALL SDL_AudioQuit(void);
miruga27 0:7fb6877b5d7c 236 /* @} */
miruga27 0:7fb6877b5d7c 237
miruga27 0:7fb6877b5d7c 238 /**
miruga27 0:7fb6877b5d7c 239 * This function returns the name of the current audio driver, or NULL
miruga27 0:7fb6877b5d7c 240 * if no driver has been initialized.
miruga27 0:7fb6877b5d7c 241 */
miruga27 0:7fb6877b5d7c 242 extern DECLSPEC const char *SDLCALL SDL_GetCurrentAudioDriver(void);
miruga27 0:7fb6877b5d7c 243
miruga27 0:7fb6877b5d7c 244 /**
miruga27 0:7fb6877b5d7c 245 * This function opens the audio device with the desired parameters, and
miruga27 0:7fb6877b5d7c 246 * returns 0 if successful, placing the actual hardware parameters in the
miruga27 0:7fb6877b5d7c 247 * structure pointed to by \c obtained. If \c obtained is NULL, the audio
miruga27 0:7fb6877b5d7c 248 * data passed to the callback function will be guaranteed to be in the
miruga27 0:7fb6877b5d7c 249 * requested format, and will be automatically converted to the hardware
miruga27 0:7fb6877b5d7c 250 * audio format if necessary. This function returns -1 if it failed
miruga27 0:7fb6877b5d7c 251 * to open the audio device, or couldn't set up the audio thread.
miruga27 0:7fb6877b5d7c 252 *
miruga27 0:7fb6877b5d7c 253 * When filling in the desired audio spec structure,
miruga27 0:7fb6877b5d7c 254 * - \c desired->freq should be the desired audio frequency in samples-per-
miruga27 0:7fb6877b5d7c 255 * second.
miruga27 0:7fb6877b5d7c 256 * - \c desired->format should be the desired audio format.
miruga27 0:7fb6877b5d7c 257 * - \c desired->samples is the desired size of the audio buffer, in
miruga27 0:7fb6877b5d7c 258 * samples. This number should be a power of two, and may be adjusted by
miruga27 0:7fb6877b5d7c 259 * the audio driver to a value more suitable for the hardware. Good values
miruga27 0:7fb6877b5d7c 260 * seem to range between 512 and 8096 inclusive, depending on the
miruga27 0:7fb6877b5d7c 261 * application and CPU speed. Smaller values yield faster response time,
miruga27 0:7fb6877b5d7c 262 * but can lead to underflow if the application is doing heavy processing
miruga27 0:7fb6877b5d7c 263 * and cannot fill the audio buffer in time. A stereo sample consists of
miruga27 0:7fb6877b5d7c 264 * both right and left channels in LR ordering.
miruga27 0:7fb6877b5d7c 265 * Note that the number of samples is directly related to time by the
miruga27 0:7fb6877b5d7c 266 * following formula: \code ms = (samples*1000)/freq \endcode
miruga27 0:7fb6877b5d7c 267 * - \c desired->size is the size in bytes of the audio buffer, and is
miruga27 0:7fb6877b5d7c 268 * calculated by SDL_OpenAudio().
miruga27 0:7fb6877b5d7c 269 * - \c desired->silence is the value used to set the buffer to silence,
miruga27 0:7fb6877b5d7c 270 * and is calculated by SDL_OpenAudio().
miruga27 0:7fb6877b5d7c 271 * - \c desired->callback should be set to a function that will be called
miruga27 0:7fb6877b5d7c 272 * when the audio device is ready for more data. It is passed a pointer
miruga27 0:7fb6877b5d7c 273 * to the audio buffer, and the length in bytes of the audio buffer.
miruga27 0:7fb6877b5d7c 274 * This function usually runs in a separate thread, and so you should
miruga27 0:7fb6877b5d7c 275 * protect data structures that it accesses by calling SDL_LockAudio()
miruga27 0:7fb6877b5d7c 276 * and SDL_UnlockAudio() in your code.
miruga27 0:7fb6877b5d7c 277 * - \c desired->userdata is passed as the first parameter to your callback
miruga27 0:7fb6877b5d7c 278 * function.
miruga27 0:7fb6877b5d7c 279 *
miruga27 0:7fb6877b5d7c 280 * The audio device starts out playing silence when it's opened, and should
miruga27 0:7fb6877b5d7c 281 * be enabled for playing by calling \c SDL_PauseAudio(0) when you are ready
miruga27 0:7fb6877b5d7c 282 * for your audio callback function to be called. Since the audio driver
miruga27 0:7fb6877b5d7c 283 * may modify the requested size of the audio buffer, you should allocate
miruga27 0:7fb6877b5d7c 284 * any local mixing buffers after you open the audio device.
miruga27 0:7fb6877b5d7c 285 */
miruga27 0:7fb6877b5d7c 286 extern DECLSPEC int SDLCALL SDL_OpenAudio(SDL_AudioSpec * desired,
miruga27 0:7fb6877b5d7c 287 SDL_AudioSpec * obtained);
miruga27 0:7fb6877b5d7c 288
miruga27 0:7fb6877b5d7c 289 /**
miruga27 0:7fb6877b5d7c 290 * SDL Audio Device IDs.
miruga27 0:7fb6877b5d7c 291 *
miruga27 0:7fb6877b5d7c 292 * A successful call to SDL_OpenAudio() is always device id 1, and legacy
miruga27 0:7fb6877b5d7c 293 * SDL audio APIs assume you want this device ID. SDL_OpenAudioDevice() calls
miruga27 0:7fb6877b5d7c 294 * always returns devices >= 2 on success. The legacy calls are good both
miruga27 0:7fb6877b5d7c 295 * for backwards compatibility and when you don't care about multiple,
miruga27 0:7fb6877b5d7c 296 * specific, or capture devices.
miruga27 0:7fb6877b5d7c 297 */
miruga27 0:7fb6877b5d7c 298 typedef Uint32 SDL_AudioDeviceID;
miruga27 0:7fb6877b5d7c 299
miruga27 0:7fb6877b5d7c 300 /**
miruga27 0:7fb6877b5d7c 301 * Get the number of available devices exposed by the current driver.
miruga27 0:7fb6877b5d7c 302 * Only valid after a successfully initializing the audio subsystem.
miruga27 0:7fb6877b5d7c 303 * Returns -1 if an explicit list of devices can't be determined; this is
miruga27 0:7fb6877b5d7c 304 * not an error. For example, if SDL is set up to talk to a remote audio
miruga27 0:7fb6877b5d7c 305 * server, it can't list every one available on the Internet, but it will
miruga27 0:7fb6877b5d7c 306 * still allow a specific host to be specified to SDL_OpenAudioDevice().
miruga27 0:7fb6877b5d7c 307 *
miruga27 0:7fb6877b5d7c 308 * In many common cases, when this function returns a value <= 0, it can still
miruga27 0:7fb6877b5d7c 309 * successfully open the default device (NULL for first argument of
miruga27 0:7fb6877b5d7c 310 * SDL_OpenAudioDevice()).
miruga27 0:7fb6877b5d7c 311 */
miruga27 0:7fb6877b5d7c 312 extern DECLSPEC int SDLCALL SDL_GetNumAudioDevices(int iscapture);
miruga27 0:7fb6877b5d7c 313
miruga27 0:7fb6877b5d7c 314 /**
miruga27 0:7fb6877b5d7c 315 * Get the human-readable name of a specific audio device.
miruga27 0:7fb6877b5d7c 316 * Must be a value between 0 and (number of audio devices-1).
miruga27 0:7fb6877b5d7c 317 * Only valid after a successfully initializing the audio subsystem.
miruga27 0:7fb6877b5d7c 318 * The values returned by this function reflect the latest call to
miruga27 0:7fb6877b5d7c 319 * SDL_GetNumAudioDevices(); recall that function to redetect available
miruga27 0:7fb6877b5d7c 320 * hardware.
miruga27 0:7fb6877b5d7c 321 *
miruga27 0:7fb6877b5d7c 322 * The string returned by this function is UTF-8 encoded, read-only, and
miruga27 0:7fb6877b5d7c 323 * managed internally. You are not to free it. If you need to keep the
miruga27 0:7fb6877b5d7c 324 * string for any length of time, you should make your own copy of it, as it
miruga27 0:7fb6877b5d7c 325 * will be invalid next time any of several other SDL functions is called.
miruga27 0:7fb6877b5d7c 326 */
miruga27 0:7fb6877b5d7c 327 extern DECLSPEC const char *SDLCALL SDL_GetAudioDeviceName(int index,
miruga27 0:7fb6877b5d7c 328 int iscapture);
miruga27 0:7fb6877b5d7c 329
miruga27 0:7fb6877b5d7c 330
miruga27 0:7fb6877b5d7c 331 /**
miruga27 0:7fb6877b5d7c 332 * Open a specific audio device. Passing in a device name of NULL requests
miruga27 0:7fb6877b5d7c 333 * the most reasonable default (and is equivalent to calling SDL_OpenAudio()).
miruga27 0:7fb6877b5d7c 334 *
miruga27 0:7fb6877b5d7c 335 * The device name is a UTF-8 string reported by SDL_GetAudioDeviceName(), but
miruga27 0:7fb6877b5d7c 336 * some drivers allow arbitrary and driver-specific strings, such as a
miruga27 0:7fb6877b5d7c 337 * hostname/IP address for a remote audio server, or a filename in the
miruga27 0:7fb6877b5d7c 338 * diskaudio driver.
miruga27 0:7fb6877b5d7c 339 *
miruga27 0:7fb6877b5d7c 340 * \return 0 on error, a valid device ID that is >= 2 on success.
miruga27 0:7fb6877b5d7c 341 *
miruga27 0:7fb6877b5d7c 342 * SDL_OpenAudio(), unlike this function, always acts on device ID 1.
miruga27 0:7fb6877b5d7c 343 */
miruga27 0:7fb6877b5d7c 344 extern DECLSPEC SDL_AudioDeviceID SDLCALL SDL_OpenAudioDevice(const char
miruga27 0:7fb6877b5d7c 345 *device,
miruga27 0:7fb6877b5d7c 346 int iscapture,
miruga27 0:7fb6877b5d7c 347 const
miruga27 0:7fb6877b5d7c 348 SDL_AudioSpec *
miruga27 0:7fb6877b5d7c 349 desired,
miruga27 0:7fb6877b5d7c 350 SDL_AudioSpec *
miruga27 0:7fb6877b5d7c 351 obtained,
miruga27 0:7fb6877b5d7c 352 int
miruga27 0:7fb6877b5d7c 353 allowed_changes);
miruga27 0:7fb6877b5d7c 354
miruga27 0:7fb6877b5d7c 355
miruga27 0:7fb6877b5d7c 356
miruga27 0:7fb6877b5d7c 357 /**
miruga27 0:7fb6877b5d7c 358 * \name Audio state
miruga27 0:7fb6877b5d7c 359 *
miruga27 0:7fb6877b5d7c 360 * Get the current audio state.
miruga27 0:7fb6877b5d7c 361 */
miruga27 0:7fb6877b5d7c 362 /* @{ */
miruga27 0:7fb6877b5d7c 363 typedef enum
miruga27 0:7fb6877b5d7c 364 {
miruga27 0:7fb6877b5d7c 365 SDL_AUDIO_STOPPED = 0,
miruga27 0:7fb6877b5d7c 366 SDL_AUDIO_PLAYING,
miruga27 0:7fb6877b5d7c 367 SDL_AUDIO_PAUSED
miruga27 0:7fb6877b5d7c 368 } SDL_AudioStatus;
miruga27 0:7fb6877b5d7c 369 extern DECLSPEC SDL_AudioStatus SDLCALL SDL_GetAudioStatus(void);
miruga27 0:7fb6877b5d7c 370
miruga27 0:7fb6877b5d7c 371 extern DECLSPEC SDL_AudioStatus SDLCALL
miruga27 0:7fb6877b5d7c 372 SDL_GetAudioDeviceStatus(SDL_AudioDeviceID dev);
miruga27 0:7fb6877b5d7c 373 /* @} *//* Audio State */
miruga27 0:7fb6877b5d7c 374
miruga27 0:7fb6877b5d7c 375 /**
miruga27 0:7fb6877b5d7c 376 * \name Pause audio functions
miruga27 0:7fb6877b5d7c 377 *
miruga27 0:7fb6877b5d7c 378 * These functions pause and unpause the audio callback processing.
miruga27 0:7fb6877b5d7c 379 * They should be called with a parameter of 0 after opening the audio
miruga27 0:7fb6877b5d7c 380 * device to start playing sound. This is so you can safely initialize
miruga27 0:7fb6877b5d7c 381 * data for your callback function after opening the audio device.
miruga27 0:7fb6877b5d7c 382 * Silence will be written to the audio device during the pause.
miruga27 0:7fb6877b5d7c 383 */
miruga27 0:7fb6877b5d7c 384 /* @{ */
miruga27 0:7fb6877b5d7c 385 extern DECLSPEC void SDLCALL SDL_PauseAudio(int pause_on);
miruga27 0:7fb6877b5d7c 386 extern DECLSPEC void SDLCALL SDL_PauseAudioDevice(SDL_AudioDeviceID dev,
miruga27 0:7fb6877b5d7c 387 int pause_on);
miruga27 0:7fb6877b5d7c 388 /* @} *//* Pause audio functions */
miruga27 0:7fb6877b5d7c 389
miruga27 0:7fb6877b5d7c 390 /**
miruga27 0:7fb6877b5d7c 391 * This function loads a WAVE from the data source, automatically freeing
miruga27 0:7fb6877b5d7c 392 * that source if \c freesrc is non-zero. For example, to load a WAVE file,
miruga27 0:7fb6877b5d7c 393 * you could do:
miruga27 0:7fb6877b5d7c 394 * \code
miruga27 0:7fb6877b5d7c 395 * SDL_LoadWAV_RW(SDL_RWFromFile("sample.wav", "rb"), 1, ...);
miruga27 0:7fb6877b5d7c 396 * \endcode
miruga27 0:7fb6877b5d7c 397 *
miruga27 0:7fb6877b5d7c 398 * If this function succeeds, it returns the given SDL_AudioSpec,
miruga27 0:7fb6877b5d7c 399 * filled with the audio data format of the wave data, and sets
miruga27 0:7fb6877b5d7c 400 * \c *audio_buf to a malloc()'d buffer containing the audio data,
miruga27 0:7fb6877b5d7c 401 * and sets \c *audio_len to the length of that audio buffer, in bytes.
miruga27 0:7fb6877b5d7c 402 * You need to free the audio buffer with SDL_FreeWAV() when you are
miruga27 0:7fb6877b5d7c 403 * done with it.
miruga27 0:7fb6877b5d7c 404 *
miruga27 0:7fb6877b5d7c 405 * This function returns NULL and sets the SDL error message if the
miruga27 0:7fb6877b5d7c 406 * wave file cannot be opened, uses an unknown data format, or is
miruga27 0:7fb6877b5d7c 407 * corrupt. Currently raw and MS-ADPCM WAVE files are supported.
miruga27 0:7fb6877b5d7c 408 */
miruga27 0:7fb6877b5d7c 409 extern DECLSPEC SDL_AudioSpec *SDLCALL SDL_LoadWAV_RW(SDL_RWops * src,
miruga27 0:7fb6877b5d7c 410 int freesrc,
miruga27 0:7fb6877b5d7c 411 SDL_AudioSpec * spec,
miruga27 0:7fb6877b5d7c 412 Uint8 ** audio_buf,
miruga27 0:7fb6877b5d7c 413 Uint32 * audio_len);
miruga27 0:7fb6877b5d7c 414
miruga27 0:7fb6877b5d7c 415 /**
miruga27 0:7fb6877b5d7c 416 * Loads a WAV from a file.
miruga27 0:7fb6877b5d7c 417 * Compatibility convenience function.
miruga27 0:7fb6877b5d7c 418 */
miruga27 0:7fb6877b5d7c 419 #define SDL_LoadWAV(file, spec, audio_buf, audio_len) \
miruga27 0:7fb6877b5d7c 420 SDL_LoadWAV_RW(SDL_RWFromFile(file, "rb"),1, spec,audio_buf,audio_len)
miruga27 0:7fb6877b5d7c 421
miruga27 0:7fb6877b5d7c 422 /**
miruga27 0:7fb6877b5d7c 423 * This function frees data previously allocated with SDL_LoadWAV_RW()
miruga27 0:7fb6877b5d7c 424 */
miruga27 0:7fb6877b5d7c 425 extern DECLSPEC void SDLCALL SDL_FreeWAV(Uint8 * audio_buf);
miruga27 0:7fb6877b5d7c 426
miruga27 0:7fb6877b5d7c 427 /**
miruga27 0:7fb6877b5d7c 428 * This function takes a source format and rate and a destination format
miruga27 0:7fb6877b5d7c 429 * and rate, and initializes the \c cvt structure with information needed
miruga27 0:7fb6877b5d7c 430 * by SDL_ConvertAudio() to convert a buffer of audio data from one format
miruga27 0:7fb6877b5d7c 431 * to the other.
miruga27 0:7fb6877b5d7c 432 *
miruga27 0:7fb6877b5d7c 433 * \return -1 if the format conversion is not supported, 0 if there's
miruga27 0:7fb6877b5d7c 434 * no conversion needed, or 1 if the audio filter is set up.
miruga27 0:7fb6877b5d7c 435 */
miruga27 0:7fb6877b5d7c 436 extern DECLSPEC int SDLCALL SDL_BuildAudioCVT(SDL_AudioCVT * cvt,
miruga27 0:7fb6877b5d7c 437 SDL_AudioFormat src_format,
miruga27 0:7fb6877b5d7c 438 Uint8 src_channels,
miruga27 0:7fb6877b5d7c 439 int src_rate,
miruga27 0:7fb6877b5d7c 440 SDL_AudioFormat dst_format,
miruga27 0:7fb6877b5d7c 441 Uint8 dst_channels,
miruga27 0:7fb6877b5d7c 442 int dst_rate);
miruga27 0:7fb6877b5d7c 443
miruga27 0:7fb6877b5d7c 444 /**
miruga27 0:7fb6877b5d7c 445 * Once you have initialized the \c cvt structure using SDL_BuildAudioCVT(),
miruga27 0:7fb6877b5d7c 446 * created an audio buffer \c cvt->buf, and filled it with \c cvt->len bytes of
miruga27 0:7fb6877b5d7c 447 * audio data in the source format, this function will convert it in-place
miruga27 0:7fb6877b5d7c 448 * to the desired format.
miruga27 0:7fb6877b5d7c 449 *
miruga27 0:7fb6877b5d7c 450 * The data conversion may expand the size of the audio data, so the buffer
miruga27 0:7fb6877b5d7c 451 * \c cvt->buf should be allocated after the \c cvt structure is initialized by
miruga27 0:7fb6877b5d7c 452 * SDL_BuildAudioCVT(), and should be \c cvt->len*cvt->len_mult bytes long.
miruga27 0:7fb6877b5d7c 453 */
miruga27 0:7fb6877b5d7c 454 extern DECLSPEC int SDLCALL SDL_ConvertAudio(SDL_AudioCVT * cvt);
miruga27 0:7fb6877b5d7c 455
miruga27 0:7fb6877b5d7c 456 #define SDL_MIX_MAXVOLUME 128
miruga27 0:7fb6877b5d7c 457 /**
miruga27 0:7fb6877b5d7c 458 * This takes two audio buffers of the playing audio format and mixes
miruga27 0:7fb6877b5d7c 459 * them, performing addition, volume adjustment, and overflow clipping.
miruga27 0:7fb6877b5d7c 460 * The volume ranges from 0 - 128, and should be set to ::SDL_MIX_MAXVOLUME
miruga27 0:7fb6877b5d7c 461 * for full audio volume. Note this does not change hardware volume.
miruga27 0:7fb6877b5d7c 462 * This is provided for convenience -- you can mix your own audio data.
miruga27 0:7fb6877b5d7c 463 */
miruga27 0:7fb6877b5d7c 464 extern DECLSPEC void SDLCALL SDL_MixAudio(Uint8 * dst, const Uint8 * src,
miruga27 0:7fb6877b5d7c 465 Uint32 len, int volume);
miruga27 0:7fb6877b5d7c 466
miruga27 0:7fb6877b5d7c 467 /**
miruga27 0:7fb6877b5d7c 468 * This works like SDL_MixAudio(), but you specify the audio format instead of
miruga27 0:7fb6877b5d7c 469 * using the format of audio device 1. Thus it can be used when no audio
miruga27 0:7fb6877b5d7c 470 * device is open at all.
miruga27 0:7fb6877b5d7c 471 */
miruga27 0:7fb6877b5d7c 472 extern DECLSPEC void SDLCALL SDL_MixAudioFormat(Uint8 * dst,
miruga27 0:7fb6877b5d7c 473 const Uint8 * src,
miruga27 0:7fb6877b5d7c 474 SDL_AudioFormat format,
miruga27 0:7fb6877b5d7c 475 Uint32 len, int volume);
miruga27 0:7fb6877b5d7c 476
miruga27 0:7fb6877b5d7c 477 /**
miruga27 0:7fb6877b5d7c 478 * \name Audio lock functions
miruga27 0:7fb6877b5d7c 479 *
miruga27 0:7fb6877b5d7c 480 * The lock manipulated by these functions protects the callback function.
miruga27 0:7fb6877b5d7c 481 * During a SDL_LockAudio()/SDL_UnlockAudio() pair, you can be guaranteed that
miruga27 0:7fb6877b5d7c 482 * the callback function is not running. Do not call these from the callback
miruga27 0:7fb6877b5d7c 483 * function or you will cause deadlock.
miruga27 0:7fb6877b5d7c 484 */
miruga27 0:7fb6877b5d7c 485 /* @{ */
miruga27 0:7fb6877b5d7c 486 extern DECLSPEC void SDLCALL SDL_LockAudio(void);
miruga27 0:7fb6877b5d7c 487 extern DECLSPEC void SDLCALL SDL_LockAudioDevice(SDL_AudioDeviceID dev);
miruga27 0:7fb6877b5d7c 488 extern DECLSPEC void SDLCALL SDL_UnlockAudio(void);
miruga27 0:7fb6877b5d7c 489 extern DECLSPEC void SDLCALL SDL_UnlockAudioDevice(SDL_AudioDeviceID dev);
miruga27 0:7fb6877b5d7c 490 /* @} *//* Audio lock functions */
miruga27 0:7fb6877b5d7c 491
miruga27 0:7fb6877b5d7c 492 /**
miruga27 0:7fb6877b5d7c 493 * This function shuts down audio processing and closes the audio device.
miruga27 0:7fb6877b5d7c 494 */
miruga27 0:7fb6877b5d7c 495 extern DECLSPEC void SDLCALL SDL_CloseAudio(void);
miruga27 0:7fb6877b5d7c 496 extern DECLSPEC void SDLCALL SDL_CloseAudioDevice(SDL_AudioDeviceID dev);
miruga27 0:7fb6877b5d7c 497
miruga27 0:7fb6877b5d7c 498 /* Ends C function definitions when using C++ */
miruga27 0:7fb6877b5d7c 499 #ifdef __cplusplus
miruga27 0:7fb6877b5d7c 500 }
miruga27 0:7fb6877b5d7c 501 #endif
miruga27 0:7fb6877b5d7c 502 #include "close_code.h"
miruga27 0:7fb6877b5d7c 503
miruga27 0:7fb6877b5d7c 504 #endif /* _SDL_audio_h */
miruga27 0:7fb6877b5d7c 505
miruga27 0:7fb6877b5d7c 506 /* vi: set ts=4 sw=4 expandtab: */