comparison SDL_sound.h @ 353:2740fad98dfe

Tweaked and enhanced for Doxygen support.
author Ryan C. Gordon <icculus@icculus.org>
date Fri, 07 Jun 2002 13:23:59 +0000
parents c345a40a8a99
children b3ac77d08e79
comparison
equal deleted inserted replaced
352:f0eb99670fa8 353:2740fad98dfe
1 /** \file SDL_sound.h */
2
1 /* 3 /*
2 * SDL_sound -- An abstract sound format decoding API. 4 * SDL_sound -- An abstract sound format decoding API.
3 * Copyright (C) 2001 Ryan C. Gordon. 5 * Copyright (C) 2001 Ryan C. Gordon.
4 * 6 *
5 * This library is free software; you can redistribute it and/or 7 * This library is free software; you can redistribute it and/or
16 * License along with this library; if not, write to the Free Software 18 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */ 20 */
19 21
20 /** 22 /**
21 * @overview 23 * \mainpage SDL_sound
24 *
25 * The latest version of SDL_sound can be found at:
26 * http://icculus.org/SDL_sound/
22 * 27 *
23 * The basic gist of SDL_sound is that you use an SDL_RWops to get sound data 28 * The basic gist of SDL_sound is that you use an SDL_RWops to get sound data
24 * into this library, and SDL_sound will take that data, in one of several 29 * into this library, and SDL_sound will take that data, in one of several
25 * popular formats, and decode it into raw waveform data in the format of 30 * popular formats, and decode it into raw waveform data in the format of
26 * your choice. This gives you a nice abstraction for getting sound into your 31 * your choice. This gives you a nice abstraction for getting sound into your
49 * 54 *
50 * (...and more to come...) 55 * (...and more to come...)
51 * 56 *
52 * Please see the file COPYING in the source's root directory. 57 * Please see the file COPYING in the source's root directory.
53 * 58 *
54 * This file written by Ryan C. Gordon. (icculus@clutteredmind.org) 59 * \author Ryan C. Gordon (icculus@clutteredmind.org)
60 * \author many others, please see CREDITS in the source's root directory.
55 */ 61 */
56 62
57 #ifndef _INCLUDE_SDL_SOUND_H_ 63 #ifndef _INCLUDE_SDL_SOUND_H_
58 #define _INCLUDE_SDL_SOUND_H_ 64 #define _INCLUDE_SDL_SOUND_H_
59 65
62 68
63 #ifdef __cplusplus 69 #ifdef __cplusplus
64 extern "C" { 70 extern "C" {
65 #endif 71 #endif
66 72
73 /* !!! FIXME: Use SDLCALL instead. */
74 #ifndef DOXYGEN_SHOULD_IGNORE_THIS
67 #ifdef SDL_SOUND_DLL_EXPORTS 75 #ifdef SDL_SOUND_DLL_EXPORTS
68 # undef DECLSPEC 76 # undef DECLSPEC
69 # define DECLSPEC __declspec(dllexport) 77 # define DECLSPEC __declspec(dllexport)
70 #endif 78 #endif
71 79
72
73 #define SOUND_VER_MAJOR 0 80 #define SOUND_VER_MAJOR 0
74 #define SOUND_VER_MINOR 1 81 #define SOUND_VER_MINOR 1
75 #define SOUND_VER_PATCH 5 82 #define SOUND_VER_PATCH 5
76 83 #endif
77 84
78 /** 85
79 * These are flags that are used in a Sound_Sample to show various states. 86 /**
80 * 87 * \enum Sound_SampleFlags
81 * To use: "if (sample->flags & SOUND_SAMPLEFLAG_ERROR) { dosomething(); }" 88 * \brief Flags that are used in a Sound_Sample to show various states.
82 * 89 *
83 * @param SOUND_SAMPLEFLAG_NONE null flag. 90 * To use:
84 * @param SOUND_SAMPLEFLAG_CANSEEK sample can seek to arbitrary points. 91 * \code
85 * @param SOUND_SAMPLEFLAG_EOF end of input stream. 92 * if (sample->flags & SOUND_SAMPLEFLAG_ERROR) { dosomething(); }
86 * @param SOUND_SAMPLEFLAG_ERROR unrecoverable error. 93 * \endcode
87 * @param SOUND_SAMPLEFLAG_EAGAIN function would block, or temp error. 94 */
88 */ 95 typedef enum
89 typedef enum __SOUND_SAMPLEFLAGS__
90 { 96 {
91 SOUND_SAMPLEFLAG_NONE = 0, 97 SOUND_SAMPLEFLAG_NONE = 0, /**< No special attributes. */
92 98
93 /* these are set at sample creation time... */ 99 /* these are set at sample creation time... */
94 SOUND_SAMPLEFLAG_CANSEEK = 1, 100 SOUND_SAMPLEFLAG_CANSEEK = 1, /**< sample can seek to arbitrary points. */
95 101
96 /* these are set during decoding... */ 102 /* these are set during decoding... */
97 SOUND_SAMPLEFLAG_EOF = 1 << 29, 103 SOUND_SAMPLEFLAG_EOF = 1 << 29, /**< end of input stream. */
98 SOUND_SAMPLEFLAG_ERROR = 1 << 30, 104 SOUND_SAMPLEFLAG_ERROR = 1 << 30, /**< unrecoverable error. */
99 SOUND_SAMPLEFLAG_EAGAIN = 1 << 31 105 SOUND_SAMPLEFLAG_EAGAIN = 1 << 31 /**< function would block, or temp error. */
100 } Sound_SampleFlags; 106 } Sound_SampleFlags;
101 107
102 108
103 /** 109 /**
110 * \struct Sound_AudioInfo
111 * \brief Information about an existing sample's format.
112 *
104 * These are the basics of a decoded sample's data structure: data format 113 * These are the basics of a decoded sample's data structure: data format
105 * (see AUDIO_U8 and friends in SDL_audio.h), number of channels, and sample 114 * (see AUDIO_U8 and friends in SDL_audio.h), number of channels, and sample
106 * rate. If you need more explanation than that, you should stop developing 115 * rate. If you need more explanation than that, you should stop developing
107 * sound code right now. 116 * sound code right now.
108 * 117 */
109 * @param format Equivalent of SDL_AudioSpec.format. 118 typedef struct
110 * @param channels Number of sound channels. 1 == mono, 2 == stereo.
111 * @param rate Sample rate; frequency of sample points per second (44100,
112 * 22050, 8000, etc.)
113 */
114 typedef struct __SOUND_AUDIOINFO__
115 { 119 {
116 Uint16 format; 120 Uint16 format; /**< Equivalent of SDL_AudioSpec.format. */
117 Uint8 channels; 121 Uint8 channels; /**< Number of sound channels. 1 == mono, 2 == stereo. */
118 Uint32 rate; 122 Uint32 rate; /**< Sample rate; frequency of sample points per second. */
119 } Sound_AudioInfo; 123 } Sound_AudioInfo;
120 124
121 125
122 /** 126 /**
127 * \struct Sound_DecoderInfo
128 * \brief Information about available soudn decoders.
129 *
123 * Each decoder sets up one of these structs, which can be retrieved via 130 * Each decoder sets up one of these structs, which can be retrieved via
124 * the Sound_AvailableDecoders() function. EVERY FIELD IN THIS IS READ-ONLY. 131 * the Sound_AvailableDecoders() function. EVERY FIELD IN THIS IS READ-ONLY.
125 * 132 *
126 * @param extensions File extensions, list ends with NULL. Read it like this: 133 * The extensions field is a NULL-terminated list of ASCIZ strings. You
127 * const char **ext; 134 * should read it like this:
128 * for (ext = info->extensions; *ext != NULL; ext++) 135 *
129 * printf(" File extension \"%s\"\n", *ext); 136 * \code
130 * @param description Human readable description of decoder. 137 * const char **ext;
131 * @param author "Name Of Author <email@emailhost.dom>" 138 * for (ext = info->extensions; *ext != NULL; ext++) {
132 * @param url URL specific to this decoder. 139 * printf(" File extension \"%s\"\n", *ext);
133 */ 140 * }
134 typedef struct __SOUND_DECODERINFO__ 141 * \endcode
142 *
143 */
144 typedef struct
135 { 145 {
136 const char **extensions; 146 const char **extensions; /**< File extensions, list ends with NULL. */
137 const char *description; 147 const char *description; /**< Human readable description of decoder. */
138 const char *author; 148 const char *author; /**< "Name Of Author \<email@emailhost.dom\>" */
139 const char *url; 149 const char *url; /**< URL specific to this decoder. */
140 } Sound_DecoderInfo; 150 } Sound_DecoderInfo;
141 151
142 152
143 153
144 /** 154 /**
155 * \struct Sound_Sample
156 * \brief Represents sound data in the process of being decoded.
157 *
145 * The Sound_Sample structure is the heart of SDL_sound. This holds 158 * The Sound_Sample structure is the heart of SDL_sound. This holds
146 * information about a source of sound data as it is being decoded. 159 * information about a source of sound data as it is being decoded.
147 * EVERY FIELD IN THIS IS READ-ONLY. Please use the API functions to 160 * EVERY FIELD IN THIS IS READ-ONLY. Please use the API functions to
148 * change them. 161 * change them.
149 * 162 */
150 * @param opaque Internal use only. Don't touch. 163 typedef struct
151 * @param decoder Decoder used for this sample.
152 * @param desired Desired audio format for conversion.
153 * @param actual Actual audio format of sample.
154 * @param buffer Decoded sound data lands in here.
155 * @param buffer_size Current size of (buffer), in bytes (Uint8).
156 * @param flags Flags relating to this sample.
157 */
158 typedef struct __SOUND_SAMPLE__
159 { 164 {
160 void *opaque; 165 void *opaque; /**< Internal use only. Don't touch. */
161 const Sound_DecoderInfo *decoder; 166 const Sound_DecoderInfo *decoder; /**< Decoder used for this sample. */
162 Sound_AudioInfo desired; 167 Sound_AudioInfo desired; /**< Desired audio format for conversion. */
163 Sound_AudioInfo actual; 168 Sound_AudioInfo actual; /**< Actual audio format of sample. */
164 void *buffer; 169 void *buffer; /**< Decoded sound data lands in here. */
165 Uint32 buffer_size; 170 Uint32 buffer_size; /**< Current size of (buffer), in bytes (Uint8). */
166 Sound_SampleFlags flags; 171 Sound_SampleFlags flags; /**< Flags relating to this sample. */
167 } Sound_Sample; 172 } Sound_Sample;
168 173
169 174
170 /** 175 /**
171 * Just what it says: a major.minor.patch style version number... 176 * \struct Sound_Version
172 * 177 * \brief Information the version of SDL_sound in use.
173 * @param major The major version number. 178 *
174 * @param minor The minor version number. 179 * Represents the library's version as three levels: major revision
175 * @param patch The patchlevel version number. 180 * (increments with massive changes, additions, and enhancements),
176 */ 181 * minor revision (increments with backwards-compatible changes to the
177 typedef struct __SOUND_VERSION__ 182 * major revision), and patchlevel (increments with fixes to the minor
183 * revision).
184 *
185 * \sa SOUND_VERSION
186 * \sa Sound_GetLinkedVersion
187 */
188 typedef struct
178 { 189 {
179 int major; 190 int major; /**< major revision */
180 int minor; 191 int minor; /**< minor revision */
181 int patch; 192 int patch; /**< patchlevel */
182 } Sound_Version; 193 } Sound_Version;
183 194
184 195
185
186 /* functions and macros... */ 196 /* functions and macros... */
187 197
188 #define SOUND_VERSION(x) { \ 198 /**
189 (x)->major = SOUND_VER_MAJOR; \ 199 * \def SOUND_VERSION(x)
190 (x)->minor = SOUND_VER_MINOR; \ 200 * \brief Macro to determine SDL_sound version program was compiled against.
191 (x)->patch = SOUND_VER_PATCH; \ 201 *
192 } 202 * This macro fills in a Sound_Version structure with the version of the
193 203 * library you compiled against. This is determined by what header the
194 /** 204 * compiler uses. Note that if you dynamically linked the library, you might
195 * Get the version of SDL_sound that is linked against your program. If you 205 * have a slightly newer or older version at runtime. That version can be
196 * are using a shared library (DLL) version of SDL_sound, then it is possible 206 * determined with Sound_GetLinkedVersion(), which, unlike SOUND_VERSION,
197 * that it will be different than the version you compiled against. 207 * is not a macro.
208 *
209 * \param x A pointer to a Sound_Version struct to initialize.
210 *
211 * \sa Sound_Version
212 * \sa Sound_GetLinkedVersion
213 */
214 #define SOUND_VERSION(x) \
215 { \
216 (x)->major = SOUND_VER_MAJOR; \
217 (x)->minor = SOUND_VER_MINOR; \
218 (x)->patch = SOUND_VER_PATCH; \
219 }
220
221
222 /**
223 * \fn void Sound_GetLinkedVersion(Sound_Version *ver)
224 * \brief Get the version of SDL_sound that is linked against your program.
225 *
226 * If you are using a shared library (DLL) version of SDL_sound, then it is
227 * possible that it will be different than the version you compiled against.
198 * 228 *
199 * This is a real function; the macro SOUND_VERSION tells you what version 229 * This is a real function; the macro SOUND_VERSION tells you what version
200 * of SDL_sound you compiled against: 230 * of SDL_sound you compiled against:
201 * 231 *
232 * \code
202 * Sound_Version compiled; 233 * Sound_Version compiled;
203 * Sound_Version linked; 234 * Sound_Version linked;
204 * 235 *
205 * SOUND_VERSION(&compiled); 236 * SOUND_VERSION(&compiled);
206 * Sound_GetLinkedVersion(&linked); 237 * Sound_GetLinkedVersion(&linked);
207 * printf("We compiled against SDL_sound version %d.%d.%d ...\n", 238 * printf("We compiled against SDL_sound version %d.%d.%d ...\n",
208 * compiled.major, compiled.minor, compiled.patch); 239 * compiled.major, compiled.minor, compiled.patch);
209 * printf("But we linked against SDL_sound version %d.%d.%d.\n", 240 * printf("But we linked against SDL_sound version %d.%d.%d.\n",
210 * linked.major, linked.minor, linked.patch); 241 * linked.major, linked.minor, linked.patch);
242 * \endcode
211 * 243 *
212 * This function may be called safely at any time, even before Sound_Init(). 244 * This function may be called safely at any time, even before Sound_Init().
213 * 245 *
214 * @param ver Sound_Version structure to fill with shared library's version. 246 * \param ver Sound_Version structure to fill with shared library's version.
215 */ 247 */
216 extern DECLSPEC void Sound_GetLinkedVersion(Sound_Version *ver); 248 DECLSPEC void Sound_GetLinkedVersion(Sound_Version *ver);
217 249
218 250
219 /** 251 /**
220 * Initialize SDL_sound. This must be called before any other SDL_sound 252 * \fn Sound_Init(void)
221 * function (except perhaps Sound_GetLinkedVersion()). You should call 253 * \brief Initialize SDL_sound.
222 * SDL_Init() before calling this. Sound_Init() will attempt to call 254 *
223 * SDL_Init(SDL_INIT_AUDIO), just in case. This is a safe behaviour, but it 255 * This must be called before any other SDL_sound function (except perhaps
224 * may not configure SDL to your liking by itself. 256 * Sound_GetLinkedVersion()). You should call SDL_Init() before calling this.
225 * 257 * Sound_Init() will attempt to call SDL_Init(SDL_INIT_AUDIO), just in case.
226 * @returns nonzero on success, zero on error. Specifics of the 258 * This is a safe behaviour, but it may not configure SDL to your liking by
259 * itself.
260 *
261 * \return nonzero on success, zero on error. Specifics of the
227 * error can be gleaned from Sound_GetError(). 262 * error can be gleaned from Sound_GetError().
228 */ 263 */
229 extern DECLSPEC int Sound_Init(void); 264 DECLSPEC int Sound_Init(void);
230 265
231 266
232 /** 267 /**
233 * Shutdown SDL_sound. This closes any SDL_RWops that were being used as 268 * \fn Sound_Quit(void)
234 * sound sources, and frees any resources in use by SDL_sound. 269 * \brief Shutdown SDL_sound.
270 *
271 * This closes any SDL_RWops that were being used as sound sources, and frees
272 * any resources in use by SDL_sound.
235 * 273 *
236 * All Sound_Sample pointers you had prior to this call are INVALIDATED. 274 * All Sound_Sample pointers you had prior to this call are INVALIDATED.
237 * 275 *
238 * Once successfully deinitialized, Sound_Init() can be called again to 276 * Once successfully deinitialized, Sound_Init() can be called again to
239 * restart the subsystem. All default API states are restored at this 277 * restart the subsystem. All default API states are restored at this
240 * point. 278 * point.
241 * 279 *
242 * You should call this BEFORE SDL_Quit(). This will NOT call SDL_Quit() 280 * You should call this BEFORE SDL_Quit(). This will NOT call SDL_Quit()
243 * for you! 281 * for you!
244 * 282 *
245 * @returns nonzero on success, zero on error. Specifics of the error 283 * \return nonzero on success, zero on error. Specifics of the error
246 * can be gleaned from Sound_GetError(). If failure, state of 284 * can be gleaned from Sound_GetError(). If failure, state of
247 * SDL_sound is undefined, and probably badly screwed up. 285 * SDL_sound is undefined, and probably badly screwed up.
248 */ 286 */
249 extern DECLSPEC int Sound_Quit(void); 287 DECLSPEC int Sound_Quit(void);
250 288
251 289
252 /** 290 /**
253 * Get a list of sound formats supported by this implementation of SDL_sound. 291 * \fn const Sound_DecoderInfo **Sound_AvailableDecoders(void)
254 * This is for informational purposes only. Note that the extension listed is 292 * \brief Get a list of sound formats supported by this version of SDL_sound.
293 *
294 * This is for informational purposes only. Note that the extension listed is
255 * merely convention: if we list "MP3", you can open an MPEG-1 Layer 3 audio 295 * merely convention: if we list "MP3", you can open an MPEG-1 Layer 3 audio
256 * file with an extension of "XYZ", if you like. The file extensions are 296 * file with an extension of "XYZ", if you like. The file extensions are
257 * informational, and only required as a hint to choosing the correct 297 * informational, and only required as a hint to choosing the correct
258 * decoder, since the sound data may not be coming from a file at all, thanks 298 * decoder, since the sound data may not be coming from a file at all, thanks
259 * to the abstraction that an SDL_RWops provides. 299 * to the abstraction that an SDL_RWops provides.
260 * 300 *
261 * The returned value is an array of pointers to Sound_DecoderInfo structures, 301 * The returned value is an array of pointers to Sound_DecoderInfo structures,
262 * with a NULL entry to signify the end of the list: 302 * with a NULL entry to signify the end of the list:
263 * 303 *
304 * \code
264 * Sound_DecoderInfo **i; 305 * Sound_DecoderInfo **i;
265 * 306 *
266 * for (i = Sound_AvailableDecoders(); *i != NULL; i++) 307 * for (i = Sound_AvailableDecoders(); *i != NULL; i++)
267 * { 308 * {
268 * printf("Supported sound format: [%s], which is [%s].\n", 309 * printf("Supported sound format: [%s], which is [%s].\n",
269 * i->extension, i->description); 310 * i->extension, i->description);
270 * // ...and other fields... 311 * // ...and other fields...
271 * } 312 * }
313 * \endcode
272 * 314 *
273 * The return values are pointers to static internal memory, and should 315 * The return values are pointers to static internal memory, and should
274 * be considered READ ONLY, and never freed. 316 * be considered READ ONLY, and never freed.
275 * 317 *
276 * @returns READ ONLY Null-terminated array of READ ONLY structures. 318 * \return READ ONLY Null-terminated array of READ ONLY structures.
277 */ 319 */
278 extern DECLSPEC const Sound_DecoderInfo **Sound_AvailableDecoders(void); 320 DECLSPEC const Sound_DecoderInfo **Sound_AvailableDecoders(void);
279 321
280 322
281 /** 323 /**
282 * Get the last SDL_sound error message as a null-terminated string. 324 * \fn const char *Sound_GetError(void)
283 * This will be NULL if there's been no error since the last call to this 325 * \brief Get the last SDL_sound error message as a null-terminated string.
284 * function. The pointer returned by this call points to an internal buffer. 326 *
285 * Each thread has a unique error state associated with it, but each time 327 * This will be NULL if there's been no error since the last call to this
286 * a new error message is set, it will overwrite the previous one associated 328 * function. The pointer returned by this call points to an internal buffer,
287 * with that thread. It is safe to call this function at anytime, even 329 * and should not be deallocated. Each thread has a unique error state
288 * before Sound_Init(). 330 * associated with it, but each time a new error message is set, it will
289 * 331 * overwrite the previous one associated with that thread. It is safe to call
290 * @returns READ ONLY string of last error message. 332 * this function at anytime, even before Sound_Init().
291 */ 333 *
292 extern DECLSPEC const char *Sound_GetError(void); 334 * \return READ ONLY string of last error message.
293 335 */
294 336 DECLSPEC const char *Sound_GetError(void);
295 /** 337
296 * Clear the current error message, so the next call to Sound_GetError() will 338
297 * return NULL. 339 /**
298 */ 340 * \fn void Sound_ClearError(void)
299 extern DECLSPEC void Sound_ClearError(void); 341 * \brief Clear the current error message.
300 342 *
301 343 * The next call to Sound_GetError() after Sound_ClearError() will return NULL.
302 /** 344 */
303 * Start decoding a new sound sample. The data is read via an SDL_RWops 345 DECLSPEC void Sound_ClearError(void);
304 * structure (see SDL_rwops.h in the SDL include directory), so it may be 346
305 * coming from memory, disk, network stream, etc. The (ext) parameter is 347
306 * merely a hint to determining the correct decoder; if you specify, for 348 /**
307 * example, "mp3" for an extension, and one of the decoders lists that 349 * \fn Sound_Sample *Sound_NewSample(SDL_RWops *rw, const char *ext, Sound_AudioInfo *desired, Uint32 bufferSize)
308 * as a handled extension, then that decoder is given first shot at trying 350 * \brief Start decoding a new sound sample.
309 * to claim the data for decoding. If none of the extensions match (or the 351 *
310 * extension is NULL), then every decoder examines the data to determine if 352 * The data is read via an SDL_RWops structure (see SDL_rwops.h in the SDL
311 * it can handle it, until one accepts it. In such a case your SDL_RWops will 353 * include directory), so it may be coming from memory, disk, network stream,
312 * need to be capable of rewinding to the start of the stream. 354 * etc. The (ext) parameter is merely a hint to determining the correct
355 * decoder; if you specify, for example, "mp3" for an extension, and one of
356 * the decoders lists that as a handled extension, then that decoder is given
357 * first shot at trying to claim the data for decoding. If none of the
358 * extensions match (or the extension is NULL), then every decoder examines
359 * the data to determine if it can handle it, until one accepts it. In such a
360 * case your SDL_RWops will need to be capable of rewinding to the start of
361 * the stream.
362 *
313 * If no decoders can handle the data, a NULL value is returned, and a human 363 * If no decoders can handle the data, a NULL value is returned, and a human
314 * readable error message can be fetched from Sound_GetError(). 364 * readable error message can be fetched from Sound_GetError().
365 *
315 * Optionally, a desired audio format can be specified. If the incoming data 366 * Optionally, a desired audio format can be specified. If the incoming data
316 * is in a different format, SDL_sound will convert it to the desired format 367 * is in a different format, SDL_sound will convert it to the desired format
317 * on the fly. Note that this can be an expensive operation, so it may be 368 * on the fly. Note that this can be an expensive operation, so it may be
318 * wise to convert data before you need to play it back, if possible, or 369 * wise to convert data before you need to play it back, if possible, or
319 * make sure your data is initially in the format that you need it in. 370 * make sure your data is initially in the format that you need it in.
320 * If you don't want to convert the data, you can specify NULL for a desired 371 * If you don't want to convert the data, you can specify NULL for a desired
321 * format. The incoming format of the data, preconversion, can be found 372 * format. The incoming format of the data, preconversion, can be found
322 * in the Sound_Sample structure. 373 * in the Sound_Sample structure.
374 *
323 * Note that the raw sound data "decoder" needs you to specify both the 375 * Note that the raw sound data "decoder" needs you to specify both the
324 * extension "RAW" and a "desired" format, or it will refuse to handle 376 * extension "RAW" and a "desired" format, or it will refuse to handle
325 * the data. This is to prevent it from catching all formats unsupported 377 * the data. This is to prevent it from catching all formats unsupported
326 * by the other decoders. 378 * by the other decoders.
379 *
327 * Finally, specify an initial buffer size; this is the number of bytes that 380 * Finally, specify an initial buffer size; this is the number of bytes that
328 * will be allocated to store each read from the sound buffer. The more you 381 * will be allocated to store each read from the sound buffer. The more you
329 * can safely allocate, the more decoding can be done in one block, but the 382 * can safely allocate, the more decoding can be done in one block, but the
330 * more resources you have to use up, and the longer each decoding call will 383 * more resources you have to use up, and the longer each decoding call will
331 * take. Note that different data formats require more or less space to 384 * take. Note that different data formats require more or less space to
332 * store. This buffer can be resized via Sound_SetBufferSize() ... 385 * store. This buffer can be resized via Sound_SetBufferSize() ...
386 *
333 * The buffer size specified must be a multiple of the size of a single 387 * The buffer size specified must be a multiple of the size of a single
334 * sample point. So, if you want 16-bit, stereo samples, then your sample 388 * sample point. So, if you want 16-bit, stereo samples, then your sample
335 * point size is (2 channels * 16 bits), or 32 bits per sample, which is four 389 * point size is (2 channels * 16 bits), or 32 bits per sample, which is four
336 * bytes. In such a case, you could specify 128 or 132 bytes for a buffer, 390 * bytes. In such a case, you could specify 128 or 132 bytes for a buffer,
337 * but not 129, 130, or 131 (although in reality, you'll want to specify a 391 * but not 129, 130, or 131 (although in reality, you'll want to specify a
338 * MUCH larger buffer). 392 * MUCH larger buffer).
393 *
339 * When you are done with this Sound_Sample pointer, you can dispose of it 394 * When you are done with this Sound_Sample pointer, you can dispose of it
340 * via Sound_FreeSample(). 395 * via Sound_FreeSample().
396 *
341 * You do not have to keep a reference to (rw) around. If this function 397 * You do not have to keep a reference to (rw) around. If this function
342 * suceeds, it stores (rw) internally (and disposes of it during the call 398 * suceeds, it stores (rw) internally (and disposes of it during the call
343 * to Sound_FreeSample()). If this function fails, it will dispose of the 399 * to Sound_FreeSample()). If this function fails, it will dispose of the
344 * SDL_RWops for you. 400 * SDL_RWops for you.
345 * 401 *
346 * @param rw SDL_RWops with sound data. 402 * \param rw SDL_RWops with sound data.
347 * @param ext File extension normally associated with a data format. 403 * \param ext File extension normally associated with a data format.
348 * Can usually be NULL. 404 * Can usually be NULL.
349 * @param desired Format to convert sound data into. Can usually be NULL, 405 * \param desired Format to convert sound data into. Can usually be NULL,
350 * if you don't need conversion. 406 * if you don't need conversion.
351 * @returns Sound_Sample pointer, which is used as a handle to several other 407 * \param bufferSize Size, in bytes, to allocate for the decoding buffer.
408 * \return Sound_Sample pointer, which is used as a handle to several other
352 * SDL_sound APIs. NULL on error. If error, use 409 * SDL_sound APIs. NULL on error. If error, use
353 * Sound_GetError() to see what went wrong. 410 * Sound_GetError() to see what went wrong.
354 */ 411 */
355 extern DECLSPEC Sound_Sample *Sound_NewSample(SDL_RWops *rw, const char *ext, 412 DECLSPEC Sound_Sample *Sound_NewSample(SDL_RWops *rw, const char *ext,
356 Sound_AudioInfo *desired, 413 Sound_AudioInfo *desired,
357 Uint32 bufferSize); 414 Uint32 bufferSize);
358 415
359 /** 416 /**
417 * \fn Sound_Sample *Sound_NewSampleFromFile(const char *filename, Sound_AudioInfo *desired, Uint32 bufferSize)
418 * \brief Start decoding a new sound sample from a file on disk.
419 *
360 * This is identical to Sound_NewSample(), but it creates an SDL_RWops for you 420 * This is identical to Sound_NewSample(), but it creates an SDL_RWops for you
361 * from the file located in (filename). Note that (filename) is specified in 421 * from the file located in (filename). Note that (filename) is specified in
362 * platform-dependent notation. ("C:\\music\\mysong.mp3" on windows, and 422 * platform-dependent notation. ("C:\\music\\mysong.mp3" on windows, and
363 * "/home/icculus/music/mysong.mp3" or whatever on Unix, etc.) 423 * "/home/icculus/music/mysong.mp3" or whatever on Unix, etc.)
364 * Sound_NewSample()'s "ext" parameter is gleaned from the contents of 424 * Sound_NewSample()'s "ext" parameter is gleaned from the contents of
365 * (filename). 425 * (filename).
366 * 426 *
367 * @param filename file containing sound data. 427 * \param filename file containing sound data.
368 * @param desired Format to convert sound data into. Can usually be NULL, 428 * \param desired Format to convert sound data into. Can usually be NULL,
369 * if you don't need conversion. 429 * if you don't need conversion.
370 * @param bufferSize size, in bytes, of initial read buffer. 430 * \param bufferSize size, in bytes, of initial read buffer.
371 * @returns Sound_Sample pointer, which is used as a handle to several other 431 * \return Sound_Sample pointer, which is used as a handle to several other
372 * SDL_sound APIs. NULL on error. If error, use 432 * SDL_sound APIs. NULL on error. If error, use
373 * Sound_GetError() to see what went wrong. 433 * Sound_GetError() to see what went wrong.
374 */ 434 */
375 extern DECLSPEC Sound_Sample *Sound_NewSampleFromFile(const char *filename, 435 DECLSPEC Sound_Sample *Sound_NewSampleFromFile(const char *filename,
376 Sound_AudioInfo *desired, 436 Sound_AudioInfo *desired,
377 Uint32 bufferSize); 437 Uint32 bufferSize);
378 438
379 /** 439 /**
380 * Dispose of a Sound_Sample pointer that was returned from Sound_NewSample(). 440 * \fn void Sound_FreeSample(Sound_Sample *sample)
381 * This will also close/dispose of the SDL_RWops that was used at creation 441 * \brief Dispose of a Dispose of a Sound_Sample.
442 *
443 * This will also close/dispose of the SDL_RWops that was used at creation
382 * time, so there's no need to keep a reference to that around. 444 * time, so there's no need to keep a reference to that around.
383 * The Sound_Sample pointer is invalid after this call, and will almost 445 * The Sound_Sample pointer is invalid after this call, and will almost
384 * certainly result in a crash if you attempt to keep using it. 446 * certainly result in a crash if you attempt to keep using it.
385 * 447 *
386 * @param sample The Sound_Sample to delete. 448 * \param sample The Sound_Sample to delete.
387 */ 449 */
388 extern DECLSPEC void Sound_FreeSample(Sound_Sample *sample); 450 DECLSPEC void Sound_FreeSample(Sound_Sample *sample);
389 451
390 452
391 /** 453 /**
392 * Change the current buffer size for a sample. If the buffer size could 454 * \fn int Sound_SetBufferSize(Sound_Sample *sample, Uint32 new_size)
393 * be changed, then the sample->buffer and sample->buffer_size fields will 455 * \brief Change the current buffer size for a sample.
394 * reflect that. If they could not be changed, then your original sample 456 *
395 * state is preserved. If the buffer is shrinking, the data at the end of 457 * If the buffer size could be changed, then the sample->buffer and
396 * buffer is truncated. If the buffer is growing, the contents of the new 458 * sample->buffer_size fields will reflect that. If they could not be
397 * space at the end is undefined until you decode more into it or initialize 459 * changed, then your original sample state is preserved. If the buffer is
398 * it yourself. 460 * shrinking, the data at the end of buffer is truncated. If the buffer is
461 * growing, the contents of the new space at the end is undefined until you
462 * decode more into it or initialize it yourself.
399 * 463 *
400 * The buffer size specified must be a multiple of the size of a single 464 * The buffer size specified must be a multiple of the size of a single
401 * sample point. So, if you want 16-bit, stereo samples, then your sample 465 * sample point. So, if you want 16-bit, stereo samples, then your sample
402 * point size is (2 channels * 16 bits), or 32 bits per sample, which is four 466 * point size is (2 channels * 16 bits), or 32 bits per sample, which is four
403 * bytes. In such a case, you could specify 128 or 132 bytes for a buffer, 467 * bytes. In such a case, you could specify 128 or 132 bytes for a buffer,
404 * but not 129, 130, or 131 (although in reality, you'll want to specify a 468 * but not 129, 130, or 131 (although in reality, you'll want to specify a
405 * MUCH larger buffer). 469 * MUCH larger buffer).
406 * 470 *
407 * @param sample The Sound_Sample whose buffer to modify. 471 * \param sample The Sound_Sample whose buffer to modify.
408 * @param new_size The desired size, in bytes, of the new buffer. 472 * \param new_size The desired size, in bytes, of the new buffer.
409 * @returns non-zero if buffer size changed, zero on failure. 473 * \return non-zero if buffer size changed, zero on failure.
410 */ 474 */
411 extern DECLSPEC int Sound_SetBufferSize(Sound_Sample *sample, Uint32 new_size); 475 DECLSPEC int Sound_SetBufferSize(Sound_Sample *sample, Uint32 new_size);
412 476
413 477
414 /** 478 /**
415 * Decode more of the sound data in a Sound_Sample. It will decode at most 479 * \fn Uint32 Sound_Decode(Sound_Sample *sample)
416 * sample->buffer_size bytes into sample->buffer in the desired format, and 480 * \brief Decode more of the sound data in a Sound_Sample.
417 * return the number of decoded bytes. 481 *
482 * It will decode at most sample->buffer_size bytes into sample->buffer in the
483 * desired format, and return the number of decoded bytes.
418 * If sample->buffer_size bytes could not be decoded, then please refer to 484 * If sample->buffer_size bytes could not be decoded, then please refer to
419 * sample->flags to determine if this was an End-of-stream or error condition. 485 * sample->flags to determine if this was an End-of-stream or error condition.
420 * 486 *
421 * @param sample Do more decoding to this Sound_Sample. 487 * \param sample Do more decoding to this Sound_Sample.
422 * @returns number of bytes decoded into sample->buffer. If it is less than 488 * \return number of bytes decoded into sample->buffer. If it is less than
423 * sample->buffer_size, then you should check sample->flags to see 489 * sample->buffer_size, then you should check sample->flags to see
424 * what the current state of the sample is (EOF, error, read again). 490 * what the current state of the sample is (EOF, error, read again).
425 */ 491 */
426 extern DECLSPEC Uint32 Sound_Decode(Sound_Sample *sample); 492 DECLSPEC Uint32 Sound_Decode(Sound_Sample *sample);
427 493
428 494
429 /** 495 /**
430 * Decode the remainder of the sound data in a Sound_Sample. This will 496 * \fn Uint32 Sound_DecodeAll(Sound_Sample *sample)
431 * dynamically allocate memory for the ENTIRE remaining sample. 497 * \brief Decode the remainder of the sound data in a Sound_Sample.
498 *
499 * This will dynamically allocate memory for the ENTIRE remaining sample.
432 * sample->buffer_size and sample->buffer will be updated to reflect the 500 * sample->buffer_size and sample->buffer will be updated to reflect the
433 * new buffer. Please refer to sample->flags to determine if the decoding 501 * new buffer. Please refer to sample->flags to determine if the decoding
434 * finished due to an End-of-stream or error condition. 502 * finished due to an End-of-stream or error condition.
435 * 503 *
436 * Be aware that sound data can take a large amount of memory, and that 504 * Be aware that sound data can take a large amount of memory, and that
447 * sample->buffer_size bytes plus the complete decoded sample at most. The 515 * sample->buffer_size bytes plus the complete decoded sample at most. The
448 * larger your buffer size, the less overhead this function needs, but beware 516 * larger your buffer size, the less overhead this function needs, but beware
449 * the possibility of paging to disk. Best to make this user-configurable if 517 * the possibility of paging to disk. Best to make this user-configurable if
450 * the sample isn't specific and small. 518 * the sample isn't specific and small.
451 * 519 *
452 * @param sample Do all decoding for this Sound_Sample. 520 * \param sample Do all decoding for this Sound_Sample.
453 * @returns number of bytes decoded into sample->buffer. You should check 521 * \return number of bytes decoded into sample->buffer. You should check
454 * sample->flags to see what the current state of the sample is 522 * sample->flags to see what the current state of the sample is
455 * (EOF, error, read again). 523 * (EOF, error, read again).
456 */ 524 */
457 extern DECLSPEC Uint32 Sound_DecodeAll(Sound_Sample *sample); 525 DECLSPEC Uint32 Sound_DecodeAll(Sound_Sample *sample);
458 526
459 527
460 /** 528 /**
461 * Restart a sample at the start of its waveform data, as if newly 529 * \fn int Sound_Rewind(Sound_Sample *sample)
462 * created with Sound_NewSample(). If successful, the next call to 530 * \brief Rewind a sample to the start.
463 * Sound_Decode[All]() will give audio data from the earliest point 531 *
464 * in the stream. 532 * Restart a sample at the start of its waveform data, as if newly
465 * 533 * created with Sound_NewSample(). If successful, the next call to
466 * Beware that this function will fail if the SDL_RWops that feeds the 534 * Sound_Decode[All]() will give audio data from the earliest point
467 * decoder can not be rewound via it's seek method, but this can 535 * in the stream.
468 * theoretically be avoided by wrapping it in some sort of buffering 536 *
469 * SDL_RWops. 537 * Beware that this function will fail if the SDL_RWops that feeds the
470 * 538 * decoder can not be rewound via it's seek method, but this can
471 * This function should ONLY fail if the RWops is not seekable, or 539 * theoretically be avoided by wrapping it in some sort of buffering
472 * SDL_sound is not initialized. Both can be controlled by the application, 540 * SDL_RWops.
473 * and thus, it is up to the developer's paranoia to dictate whether this 541 *
474 * function's return value need be checked at all. 542 * This function should ONLY fail if the RWops is not seekable, or
475 * 543 * SDL_sound is not initialized. Both can be controlled by the application,
476 * If this function fails, the state of the sample is undefined, but it 544 * and thus, it is up to the developer's paranoia to dictate whether this
477 * is still safe to call Sound_FreeSample() to dispose of it. 545 * function's return value need be checked at all.
478 * 546 *
479 * On success, ERROR, EOF, and EAGAIN are cleared from sample->flags. The 547 * If this function fails, the state of the sample is undefined, but it
480 * ERROR flag is set on error. 548 * is still safe to call Sound_FreeSample() to dispose of it.
481 * 549 *
482 * @param sample The Sound_Sample to rewind. 550 * On success, ERROR, EOF, and EAGAIN are cleared from sample->flags. The
483 * @return nonzero on success, zero on error. Specifics of the 551 * ERROR flag is set on error.
484 * error can be gleaned from Sound_GetError(). 552 *
485 */ 553 * \param sample The Sound_Sample to rewind.
486 extern DECLSPEC int Sound_Rewind(Sound_Sample *sample); 554 * \return nonzero on success, zero on error. Specifics of the
487 555 * error can be gleaned from Sound_GetError().
488 556 */
489 /** 557 DECLSPEC int Sound_Rewind(Sound_Sample *sample);
490 * Reposition a sample's stream. If successful, the next call to 558
491 * Sound_Decode[All]() will give audio data from the offset you 559
492 * specified. 560 /**
493 * 561 * \fn int Sound_Seek(Sound_Sample *sample, Uint32 ms)
494 * The offset is specified in milliseconds from the start of the 562 * \brief Seek to a different point in a sample.
495 * sample. 563 *
496 * 564 * Reposition a sample's stream. If successful, the next call to
497 * Beware that this function can fail for several reasons. If the 565 * Sound_Decode[All]() will give audio data from the offset you
498 * SDL_RWops that feeds the decoder can not seek, this call will almost 566 * specified.
499 * certainly fail, but this can theoretically be avoided by wrapping it 567 *
500 * in some sort of buffering SDL_RWops. Some decoders can never seek, 568 * The offset is specified in milliseconds from the start of the
501 * others can only seek with certain files. The decoders will set a flag 569 * sample.
502 * in the sample at creation time to help you determine this. 570 *
503 * 571 * Beware that this function can fail for several reasons. If the
504 * You should check sample->flags & SOUND_SAMPLEFLAG_CANSEEK 572 * SDL_RWops that feeds the decoder can not seek, this call will almost
505 * before attempting. Sound_Seek() reports failure immediately if this 573 * certainly fail, but this can theoretically be avoided by wrapping it
506 * flag isn't set. This function can still fail for other reasons if the 574 * in some sort of buffering SDL_RWops. Some decoders can never seek,
507 * flag is set. 575 * others can only seek with certain files. The decoders will set a flag
508 * 576 * in the sample at creation time to help you determine this.
509 * This function can be emulated in the application with Sound_Rewind() 577 *
510 * and predecoding a specific amount of the sample, but this can be 578 * You should check sample->flags & SOUND_SAMPLEFLAG_CANSEEK
511 * extremely inefficient. Sound_Seek() accelerates the seek on a 579 * before attempting. Sound_Seek() reports failure immediately if this
512 * with decoder-specific code. 580 * flag isn't set. This function can still fail for other reasons if the
513 * 581 * flag is set.
514 * If this function fails, the sample should continue to function as if 582 *
515 * this call was never made. If there was an unrecoverable error, 583 * This function can be emulated in the application with Sound_Rewind()
516 * sample->flags & SOUND_SAMPLEFLAG_ERROR will be set, which you regular 584 * and predecoding a specific amount of the sample, but this can be
517 * decoding loop can pick up. 585 * extremely inefficient. Sound_Seek() accelerates the seek on a
518 * 586 * with decoder-specific code.
519 * On success, ERROR, EOF, and EAGAIN are cleared from sample->flags. 587 *
520 * 588 * If this function fails, the sample should continue to function as if
521 * @param sample The Sound_Sample to seek. 589 * this call was never made. If there was an unrecoverable error,
522 * @param ms The new position, in milliseconds from start of sample. 590 * sample->flags & SOUND_SAMPLEFLAG_ERROR will be set, which you regular
523 * @return nonzero on success, zero on error. Specifics of the 591 * decoding loop can pick up.
524 * error can be gleaned from Sound_GetError(). 592 *
525 */ 593 * On success, ERROR, EOF, and EAGAIN are cleared from sample->flags.
526 extern DECLSPEC int Sound_Seek(Sound_Sample *sample, Uint32 ms); 594 *
595 * \param sample The Sound_Sample to seek.
596 * \param ms The new position, in milliseconds from start of sample.
597 * \return nonzero on success, zero on error. Specifics of the
598 * error can be gleaned from Sound_GetError().
599 */
600 DECLSPEC int Sound_Seek(Sound_Sample *sample, Uint32 ms);
527 601
528 602
529 #ifdef __cplusplus 603 #ifdef __cplusplus
530 } 604 }
531 #endif 605 #endif