comparison SDL_sound.h @ 184:47cc2de2ae36

Changed reference to "LICENSE" file to "COPYING".
author Ryan C. Gordon <icculus@icculus.org>
date Wed, 26 Dec 2001 10:40:25 +0000
parents e91fb8d5bd62
children 70561bf8d5fd
comparison
equal deleted inserted replaced
183:26996236d790 184:47cc2de2ae36
16 * License along with this library; if not, write to the Free Software 16 * 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 17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */ 18 */
19 19
20 /** 20 /**
21 * @overview
22 *
21 * The basic gist of SDL_sound is that you use an SDL_RWops to get sound data 23 * The basic gist of SDL_sound is that you use an SDL_RWops to get sound data
22 * into this library, and SDL_sound will take that data, in one of several 24 * into this library, and SDL_sound will take that data, in one of several
23 * popular formats, and decode it into raw waveform data in the format of 25 * popular formats, and decode it into raw waveform data in the format of
24 * your choice. This gives you a nice abstraction for getting sound into your 26 * your choice. This gives you a nice abstraction for getting sound into your
25 * game or application; just feed it to SDL_sound, and it will handle 27 * game or application; just feed it to SDL_sound, and it will handle
44 * - .AU 46 * - .AU
45 * - .AIFF 47 * - .AIFF
46 * 48 *
47 * (...and more to come...) 49 * (...and more to come...)
48 * 50 *
49 * Please see the file LICENSE in the source's root directory. 51 * Please see the file COPYING in the source's root directory.
50 * 52 *
51 * This file written by Ryan C. Gordon. (icculus@clutteredmind.org) 53 * This file written by Ryan C. Gordon. (icculus@clutteredmind.org)
52 */ 54 */
53 55
54 #ifndef _INCLUDE_SDL_SOUND_H_ 56 #ifndef _INCLUDE_SDL_SOUND_H_
70 #define SOUND_VER_MAJOR 0 72 #define SOUND_VER_MAJOR 0
71 #define SOUND_VER_MINOR 1 73 #define SOUND_VER_MINOR 1
72 #define SOUND_VER_PATCH 3 74 #define SOUND_VER_PATCH 3
73 75
74 76
75 /* 77 /**
76 * These are flags that are used in a Sound_Sample (below) to show various 78 * These are flags that are used in a Sound_Sample to show various states.
77 * states.
78 * 79 *
79 * To use: "if (sample->flags & SOUND_SAMPLEFLAG_ERROR) { dosomething(); }" 80 * To use: "if (sample->flags & SOUND_SAMPLEFLAG_ERROR) { dosomething(); }"
81 *
82 * @param SOUND_SAMPLEFLAG_NONE null flag.
83 * @param SOUND_SAMPLEFLAG_NEEDSEEK SDL_RWops must be able to seek.
84 * @param SOUND_SAMPLEFLAG_EOF end of input stream.
85 * @param SOUND_SAMPLEFLAG_ERROR unrecoverable error.
86 * @param SOUND_SAMPLEFLAG_EAGAIN function would block, or temp error.
80 */ 87 */
81 typedef enum __SOUND_SAMPLEFLAGS__ 88 typedef enum __SOUND_SAMPLEFLAGS__
82 { 89 {
83 SOUND_SAMPLEFLAG_NONE = 0, /* Null flag. */ 90 SOUND_SAMPLEFLAG_NONE = 0,
84 91
85 /* these are set at sample creation time... */ 92 /* these are set at sample creation time... */
86 SOUND_SAMPLEFLAG_NEEDSEEK = 1, /* SDL_RWops must be able to seek. */ 93 SOUND_SAMPLEFLAG_NEEDSEEK = 1,
87 94
88 /* these are set during decoding... */ 95 /* these are set during decoding... */
89 SOUND_SAMPLEFLAG_EOF = 1 << 29, /* end of input stream. */ 96 SOUND_SAMPLEFLAG_EOF = 1 << 29,
90 SOUND_SAMPLEFLAG_ERROR = 1 << 30, /* unrecoverable error. */ 97 SOUND_SAMPLEFLAG_ERROR = 1 << 30,
91 SOUND_SAMPLEFLAG_EAGAIN = 1 << 31 /* would block, or temp error. */ 98 SOUND_SAMPLEFLAG_EAGAIN = 1 << 31
92 } Sound_SampleFlags; 99 } Sound_SampleFlags;
93 100
94 101
95 /* 102 /**
96 * Basics of a decoded sample's data structure: data format (see AUDIO_U8 and 103 * These are the basics of a decoded sample's data structure: data format
97 * friends in SDL_audio.h), number of channels, and sample rate. If you need 104 * (see AUDIO_U8 and friends in SDL_audio.h), number of channels, and sample
98 * more explanation than that, you should stop developing sound code right 105 * rate. If you need more explanation than that, you should stop developing
99 * now. 106 * sound code right now.
107 *
108 * @param format Equivalent of SDL_AudioSpec.format.
109 * @param channels Number of sound channels. 1 == mono, 2 == stereo.
110 * @param rate Sample rate; frequency of sample points per second (44100,
111 * 22050, 8000, etc.)
100 */ 112 */
101 typedef struct __SOUND_AUDIOINFO__ 113 typedef struct __SOUND_AUDIOINFO__
102 { 114 {
103 Uint16 format; 115 Uint16 format;
104 Uint8 channels; 116 Uint8 channels;
105 Uint32 rate; 117 Uint32 rate;
106 } Sound_AudioInfo; 118 } Sound_AudioInfo;
107 119
108 120
109 /* 121 /**
110 * Each decoder sets up one of these structs, which can be retrieved via 122 * Each decoder sets up one of these structs, which can be retrieved via
111 * the Sound_AvailableDecoders() function. EVERY FIELD IN THIS IS READ-ONLY. 123 * the Sound_AvailableDecoders() function. EVERY FIELD IN THIS IS READ-ONLY.
124 *
125 * @param extensions File extensions, list ends with NULL. Read it like this:
126 * const char **ext;
127 * for (ext = info->extensions; *ext != NULL; ext++)
128 * printf(" File extension \"%s\"\n", *ext);
129 * @param description Human readable description of decoder.
130 * @param author "Name Of Author <email@emailhost.dom>"
131 * @param url URL specific to this decoder.
112 */ 132 */
113 typedef struct __SOUND_DECODERINFO__ 133 typedef struct __SOUND_DECODERINFO__
114 { 134 {
115 const char **extensions; /* File extensions, list ends with NULL. */ 135 const char **extensions;
116 const char *description; /* Human readable description of decoder. */ 136 const char *description;
117 const char *author; /* "Name Of Author <email@emailhost.dom>" */ 137 const char *author;
118 const char *url; /* URL specific to this decoder. */ 138 const char *url;
119 } Sound_DecoderInfo; 139 } Sound_DecoderInfo;
120 140
121 141
122 142
123 /* 143 /**
124 * The Sound_Sample structure is the heart of SDL_sound. This holds 144 * The Sound_Sample structure is the heart of SDL_sound. This holds
125 * information about a source of sound data as it is being decoded. 145 * information about a source of sound data as it is being decoded.
126 * EVERY FIELD IN THIS IS READ-ONLY. Please use the API functions to 146 * EVERY FIELD IN THIS IS READ-ONLY. Please use the API functions to
127 * change them. 147 * change them.
148 *
149 * @param opaque Internal use only. Don't touch.
150 * @param decoder Decoder used for this sample.
151 * @param desired Desired audio format for conversion.
152 * @param actual Actual audio format of sample.
153 * @param buffer Decoded sound data lands in here.
154 * @param buffer_size Current size of (buffer), in bytes (Uint8).
155 * @param flags Flags relating to this sample.
128 */ 156 */
129 typedef struct __SOUND_SAMPLE__ 157 typedef struct __SOUND_SAMPLE__
130 { 158 {
131 void *opaque; /* Internal use only. */ 159 void *opaque;
132 const Sound_DecoderInfo *decoder; /* Decoder used for this sample. */ 160 const Sound_DecoderInfo *decoder;
133 Sound_AudioInfo desired; /* Desired audio format for conversion. */ 161 Sound_AudioInfo desired;
134 Sound_AudioInfo actual; /* Actual audio format of sample. */ 162 Sound_AudioInfo actual;
135 void *buffer; /* Decoded sound data lands in here. */ 163 void *buffer;
136 Uint32 buffer_size; /* Current size of (buffer), in bytes. */ 164 Uint32 buffer_size;
137 Sound_SampleFlags flags; /* Flags relating to this sample. */ 165 Sound_SampleFlags flags;
138 } Sound_Sample; 166 } Sound_Sample;
139 167
140 168
141 /* 169 /**
142 * Just what it says: a x.y.z style version number... 170 * Just what it says: a major.minor.patch style version number...
171 *
172 * @param major The major version number.
173 * @param minor The minor version number.
174 * @param patch The patchlevel version number.
143 */ 175 */
144 typedef struct __SOUND_VERSION__ 176 typedef struct __SOUND_VERSION__
145 { 177 {
146 int major; 178 int major;
147 int minor; 179 int minor;
175 * compiled.major, compiled.minor, compiled.patch); 207 * compiled.major, compiled.minor, compiled.patch);
176 * printf("But we linked against SDL_sound version %d.%d.%d.\n", 208 * printf("But we linked against SDL_sound version %d.%d.%d.\n",
177 * linked.major, linked.minor, linked.patch); 209 * linked.major, linked.minor, linked.patch);
178 * 210 *
179 * This function may be called safely at any time, even before Sound_Init(). 211 * This function may be called safely at any time, even before Sound_Init().
212 *
213 * @param ver Sound_Version structure to fill with shared library's version.
180 */ 214 */
181 extern DECLSPEC void Sound_GetLinkedVersion(Sound_Version *ver); 215 extern DECLSPEC void Sound_GetLinkedVersion(Sound_Version *ver);
182 216
183 217
184 /** 218 /**
186 * function (except perhaps Sound_GetLinkedVersion()). You should call 220 * function (except perhaps Sound_GetLinkedVersion()). You should call
187 * SDL_Init() before calling this. Sound_Init() will attempt to call 221 * SDL_Init() before calling this. Sound_Init() will attempt to call
188 * SDL_Init(SDL_INIT_AUDIO), just in case. This is a safe behaviour, but it 222 * SDL_Init(SDL_INIT_AUDIO), just in case. This is a safe behaviour, but it
189 * may not configure SDL to your liking by itself. 223 * may not configure SDL to your liking by itself.
190 * 224 *
191 * @return nonzero on success, zero on error. Specifics of the error can be 225 * @returns nonzero on success, zero on error. Specifics of the
192 * gleaned from Sound_GetLastError(). 226 * error can be gleaned from Sound_GetLastError().
193 */ 227 */
194 extern DECLSPEC int Sound_Init(void); 228 extern DECLSPEC int Sound_Init(void);
195 229
196 230
197 /** 231 /**
205 * point. 239 * point.
206 * 240 *
207 * You should call this BEFORE SDL_Quit(). This will NOT call SDL_Quit() 241 * You should call this BEFORE SDL_Quit(). This will NOT call SDL_Quit()
208 * for you! 242 * for you!
209 * 243 *
210 * @return nonzero on success, zero on error. Specifics of the error can be 244 * @returns nonzero on success, zero on error. Specifics of the error
211 * gleaned from Sound_GetLastError(). If failure, state of SDL_sound 245 * can be gleaned from Sound_GetLastError(). If failure, state of
212 * is undefined, and probably badly screwed up. 246 * SDL_sound is undefined, and probably badly screwed up.
213 */ 247 */
214 extern DECLSPEC int Sound_Quit(void); 248 extern DECLSPEC int Sound_Quit(void);
215 249
216 250
217 /** 251 /**
236 * } 270 * }
237 * 271 *
238 * The return values are pointers to static internal memory, and should 272 * The return values are pointers to static internal memory, and should
239 * be considered READ ONLY, and never freed. 273 * be considered READ ONLY, and never freed.
240 * 274 *
241 * @return READ ONLY Null-terminated array of READ ONLY structures. 275 * @returns READ ONLY Null-terminated array of READ ONLY structures.
242 */ 276 */
243 extern DECLSPEC const Sound_DecoderInfo **Sound_AvailableDecoders(void); 277 extern DECLSPEC const Sound_DecoderInfo **Sound_AvailableDecoders(void);
244 278
245 279
246 /** 280 /**
250 * Each thread has a unique error state associated with it, but each time 284 * Each thread has a unique error state associated with it, but each time
251 * a new error message is set, it will overwrite the previous one associated 285 * a new error message is set, it will overwrite the previous one associated
252 * with that thread. It is safe to call this function at anytime, even 286 * with that thread. It is safe to call this function at anytime, even
253 * before Sound_Init(). 287 * before Sound_Init().
254 * 288 *
255 * @return READ ONLY string of last error message. 289 * @returns READ ONLY string of last error message.
256 */ 290 */
257 extern DECLSPEC const char *Sound_GetError(void); 291 extern DECLSPEC const char *Sound_GetError(void);
258 292
259 293
260 /** 294 /**
311 * @param rw SDL_RWops with sound data. 345 * @param rw SDL_RWops with sound data.
312 * @param ext File extension normally associated with a data format. 346 * @param ext File extension normally associated with a data format.
313 * Can usually be NULL. 347 * Can usually be NULL.
314 * @param desired Format to convert sound data into. Can usually be NULL, 348 * @param desired Format to convert sound data into. Can usually be NULL,
315 * if you don't need conversion. 349 * if you don't need conversion.
316 * @return Sound_Sample pointer, which is used as a handle to several other 350 * @returns Sound_Sample pointer, which is used as a handle to several other
317 * SDL_sound APIs. NULL on error. If error, use 351 * SDL_sound APIs. NULL on error. If error, use
318 * Sound_GetLastError() to see what went wrong. 352 * Sound_GetLastError() to see what went wrong.
319 */ 353 */
320 extern DECLSPEC Sound_Sample *Sound_NewSample(SDL_RWops *rw, const char *ext, 354 extern DECLSPEC Sound_Sample *Sound_NewSample(SDL_RWops *rw, const char *ext,
321 Sound_AudioInfo *desired, 355 Sound_AudioInfo *desired,
331 * 365 *
332 * @param filename file containing sound data. 366 * @param filename file containing sound data.
333 * @param desired Format to convert sound data into. Can usually be NULL, 367 * @param desired Format to convert sound data into. Can usually be NULL,
334 * if you don't need conversion. 368 * if you don't need conversion.
335 * @param bufferSize size, in bytes, of initial read buffer. 369 * @param bufferSize size, in bytes, of initial read buffer.
336 * @return Sound_Sample pointer, which is used as a handle to several other 370 * @returns Sound_Sample pointer, which is used as a handle to several other
337 * SDL_sound APIs. NULL on error. If error, use 371 * SDL_sound APIs. NULL on error. If error, use
338 * Sound_GetLastError() to see what went wrong. 372 * Sound_GetLastError() to see what went wrong.
339 */ 373 */
340 extern DECLSPEC Sound_Sample *Sound_NewSampleFromFile(const char *filename, 374 extern DECLSPEC Sound_Sample *Sound_NewSampleFromFile(const char *filename,
341 Sound_AudioInfo *desired, 375 Sound_AudioInfo *desired,
369 * specify 128 or 132 bytes for a buffer, but not 129, 130, or 131, although 403 * specify 128 or 132 bytes for a buffer, but not 129, 130, or 131, although
370 * in reality, you'll want to specify a MUCH larger buffer. 404 * in reality, you'll want to specify a MUCH larger buffer.
371 * 405 *
372 * @param sample The Sound_Sample whose buffer to modify. 406 * @param sample The Sound_Sample whose buffer to modify.
373 * @param new_size The desired size, in bytes, of the new buffer. 407 * @param new_size The desired size, in bytes, of the new buffer.
374 * @return non-zero if buffer size changed, zero on failure. 408 * @returns non-zero if buffer size changed, zero on failure.
375 */ 409 */
376 extern DECLSPEC int Sound_SetBufferSize(Sound_Sample *sample, Uint32 new_size); 410 extern DECLSPEC int Sound_SetBufferSize(Sound_Sample *sample, Uint32 new_size);
377 411
378 412
379 /** 413 /**
382 * return the number of decoded bytes. 416 * return the number of decoded bytes.
383 * If sample->buffer_size bytes could not be decoded, then please refer to 417 * If sample->buffer_size bytes could not be decoded, then please refer to
384 * sample->flags to determine if this was an End-of-stream or error condition. 418 * sample->flags to determine if this was an End-of-stream or error condition.
385 * 419 *
386 * @param sample Do more decoding to this Sound_Sample. 420 * @param sample Do more decoding to this Sound_Sample.
387 * @return number of bytes decoded into sample->buffer. If it is less than 421 * @returns number of bytes decoded into sample->buffer. If it is less than
388 * sample->buffer_size, then you should check sample->flags to see 422 * sample->buffer_size, then you should check sample->flags to see
389 * what the current state of the sample is (EOF, error, read again). 423 * what the current state of the sample is (EOF, error, read again).
390 */ 424 */
391 extern DECLSPEC Uint32 Sound_Decode(Sound_Sample *sample); 425 extern DECLSPEC Uint32 Sound_Decode(Sound_Sample *sample);
392 426
413 * larger your buffer size, the less overhead this function needs, but beware 447 * larger your buffer size, the less overhead this function needs, but beware
414 * the possibility of paging to disk. Best to make this user-configurable if 448 * the possibility of paging to disk. Best to make this user-configurable if
415 * the sample isn't specific and small. 449 * the sample isn't specific and small.
416 * 450 *
417 * @param sample Do all decoding for this Sound_Sample. 451 * @param sample Do all decoding for this Sound_Sample.
418 * @return number of bytes decoded into sample->buffer. You should check 452 * @returns number of bytes decoded into sample->buffer. You should check
419 * sample->flags to see what the current state of the sample is 453 * sample->flags to see what the current state of the sample is
420 * (EOF, error, read again). 454 * (EOF, error, read again).
421 */ 455 */
422 extern DECLSPEC Uint32 Sound_DecodeAll(Sound_Sample *sample); 456 extern DECLSPEC Uint32 Sound_DecodeAll(Sound_Sample *sample);
423 457