comparison SDL_sound.h @ 357:b3ac77d08e79

More documentation cleanups and enhancements.
author Ryan C. Gordon <icculus@icculus.org>
date Fri, 07 Jun 2002 23:09:24 +0000
parents 2740fad98dfe
children 8c8ecd1008c9
comparison
equal deleted inserted replaced
356:ea5c61aeb891 357:b3ac77d08e79
89 * 89 *
90 * To use: 90 * To use:
91 * \code 91 * \code
92 * if (sample->flags & SOUND_SAMPLEFLAG_ERROR) { dosomething(); } 92 * if (sample->flags & SOUND_SAMPLEFLAG_ERROR) { dosomething(); }
93 * \endcode 93 * \endcode
94 *
95 * \sa Sound_SampleNew
96 * \sa Sound_SampleNewFromFile
97 * \sa Sound_SampleDecode
98 * \sa Sound_SampleDecodeAll
99 * \sa Sound_SampleSeek
94 */ 100 */
95 typedef enum 101 typedef enum
96 { 102 {
97 SOUND_SAMPLEFLAG_NONE = 0, /**< No special attributes. */ 103 SOUND_SAMPLEFLAG_NONE = 0, /**< No special attributes. */
98 104
99 /* these are set at sample creation time... */ 105 /* these are set at sample creation time... */
100 SOUND_SAMPLEFLAG_CANSEEK = 1, /**< sample can seek to arbitrary points. */ 106 SOUND_SAMPLEFLAG_CANSEEK = 1, /**< Sample can seek to arbitrary points. */
101 107
102 /* these are set during decoding... */ 108 /* these are set during decoding... */
103 SOUND_SAMPLEFLAG_EOF = 1 << 29, /**< end of input stream. */ 109 SOUND_SAMPLEFLAG_EOF = 1 << 29, /**< End of input stream. */
104 SOUND_SAMPLEFLAG_ERROR = 1 << 30, /**< unrecoverable error. */ 110 SOUND_SAMPLEFLAG_ERROR = 1 << 30, /**< Unrecoverable error. */
105 SOUND_SAMPLEFLAG_EAGAIN = 1 << 31 /**< function would block, or temp error. */ 111 SOUND_SAMPLEFLAG_EAGAIN = 1 << 31 /**< Function would block, or temp error. */
106 } Sound_SampleFlags; 112 } Sound_SampleFlags;
107 113
108 114
109 /** 115 /**
110 * \struct Sound_AudioInfo 116 * \struct Sound_AudioInfo
112 * 118 *
113 * These are the basics of a decoded sample's data structure: data format 119 * These are the basics of a decoded sample's data structure: data format
114 * (see AUDIO_U8 and friends in SDL_audio.h), number of channels, and sample 120 * (see AUDIO_U8 and friends in SDL_audio.h), number of channels, and sample
115 * rate. If you need more explanation than that, you should stop developing 121 * rate. If you need more explanation than that, you should stop developing
116 * sound code right now. 122 * sound code right now.
123 *
124 * \sa Sound_SampleNew
125 * \sa Sound_SampleNewFromFile
117 */ 126 */
118 typedef struct 127 typedef struct
119 { 128 {
120 Uint16 format; /**< Equivalent of SDL_AudioSpec.format. */ 129 Uint16 format; /**< Equivalent of SDL_AudioSpec.format. */
121 Uint8 channels; /**< Number of sound channels. 1 == mono, 2 == stereo. */ 130 Uint8 channels; /**< Number of sound channels. 1 == mono, 2 == stereo. */
138 * for (ext = info->extensions; *ext != NULL; ext++) { 147 * for (ext = info->extensions; *ext != NULL; ext++) {
139 * printf(" File extension \"%s\"\n", *ext); 148 * printf(" File extension \"%s\"\n", *ext);
140 * } 149 * }
141 * \endcode 150 * \endcode
142 * 151 *
152 * \sa Sound_AvailableDecoders
143 */ 153 */
144 typedef struct 154 typedef struct
145 { 155 {
146 const char **extensions; /**< File extensions, list ends with NULL. */ 156 const char **extensions; /**< File extensions, list ends with NULL. */
147 const char *description; /**< Human readable description of decoder. */ 157 const char *description; /**< Human readable description of decoder. */
242 * \endcode 252 * \endcode
243 * 253 *
244 * This function may be called safely at any time, even before Sound_Init(). 254 * This function may be called safely at any time, even before Sound_Init().
245 * 255 *
246 * \param ver Sound_Version structure to fill with shared library's version. 256 * \param ver Sound_Version structure to fill with shared library's version.
257 *
258 * \sa Sound_Version
259 * \sa SOUND_VERSION
247 */ 260 */
248 DECLSPEC void Sound_GetLinkedVersion(Sound_Version *ver); 261 DECLSPEC void Sound_GetLinkedVersion(Sound_Version *ver);
249 262
250 263
251 /** 264 /**
256 * Sound_GetLinkedVersion()). You should call SDL_Init() before calling this. 269 * Sound_GetLinkedVersion()). You should call SDL_Init() before calling this.
257 * Sound_Init() will attempt to call SDL_Init(SDL_INIT_AUDIO), just in case. 270 * Sound_Init() will attempt to call SDL_Init(SDL_INIT_AUDIO), just in case.
258 * This is a safe behaviour, but it may not configure SDL to your liking by 271 * This is a safe behaviour, but it may not configure SDL to your liking by
259 * itself. 272 * itself.
260 * 273 *
261 * \return nonzero on success, zero on error. Specifics of the 274 * \return nonzero on success, zero on error. Specifics of the
262 * error can be gleaned from Sound_GetError(). 275 * error can be gleaned from Sound_GetError().
276 *
277 * \sa Sound_Quit
263 */ 278 */
264 DECLSPEC int Sound_Init(void); 279 DECLSPEC int Sound_Init(void);
265 280
266 281
267 /** 282 /**
279 * 294 *
280 * You should call this BEFORE SDL_Quit(). This will NOT call SDL_Quit() 295 * You should call this BEFORE SDL_Quit(). This will NOT call SDL_Quit()
281 * for you! 296 * for you!
282 * 297 *
283 * \return nonzero on success, zero on error. Specifics of the error 298 * \return nonzero on success, zero on error. Specifics of the error
284 * can be gleaned from Sound_GetError(). If failure, state of 299 * can be gleaned from Sound_GetError(). If failure, state of
285 * SDL_sound is undefined, and probably badly screwed up. 300 * SDL_sound is undefined, and probably badly screwed up.
301 *
302 * \sa Sound_Init
286 */ 303 */
287 DECLSPEC int Sound_Quit(void); 304 DECLSPEC int Sound_Quit(void);
288 305
289 306
290 /** 307 /**
313 * \endcode 330 * \endcode
314 * 331 *
315 * The return values are pointers to static internal memory, and should 332 * The return values are pointers to static internal memory, and should
316 * be considered READ ONLY, and never freed. 333 * be considered READ ONLY, and never freed.
317 * 334 *
318 * \return READ ONLY Null-terminated array of READ ONLY structures. 335 * \return READ ONLY Null-terminated array of READ ONLY structures.
336 *
337 * \sa Sound_DecoderInfo
319 */ 338 */
320 DECLSPEC const Sound_DecoderInfo **Sound_AvailableDecoders(void); 339 DECLSPEC const Sound_DecoderInfo **Sound_AvailableDecoders(void);
321 340
322 341
323 /** 342 /**
329 * and should not be deallocated. Each thread has a unique error state 348 * and should not be deallocated. Each thread has a unique error state
330 * associated with it, but each time a new error message is set, it will 349 * associated with it, but each time a new error message is set, it will
331 * overwrite the previous one associated with that thread. It is safe to call 350 * overwrite the previous one associated with that thread. It is safe to call
332 * this function at anytime, even before Sound_Init(). 351 * this function at anytime, even before Sound_Init().
333 * 352 *
334 * \return READ ONLY string of last error message. 353 * \return READ ONLY string of last error message.
354 *
355 * \sa Sound_ClearError
335 */ 356 */
336 DECLSPEC const char *Sound_GetError(void); 357 DECLSPEC const char *Sound_GetError(void);
337 358
338 359
339 /** 360 /**
340 * \fn void Sound_ClearError(void) 361 * \fn void Sound_ClearError(void)
341 * \brief Clear the current error message. 362 * \brief Clear the current error message.
342 * 363 *
343 * The next call to Sound_GetError() after Sound_ClearError() will return NULL. 364 * The next call to Sound_GetError() after Sound_ClearError() will return NULL.
365 *
366 * \sa Sound_GetError
344 */ 367 */
345 DECLSPEC void Sound_ClearError(void); 368 DECLSPEC void Sound_ClearError(void);
346 369
347 370
348 /** 371 /**
404 * Can usually be NULL. 427 * Can usually be NULL.
405 * \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,
406 * if you don't need conversion. 429 * if you don't need conversion.
407 * \param bufferSize Size, in bytes, to allocate for the decoding buffer. 430 * \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 431 * \return Sound_Sample pointer, which is used as a handle to several other
409 * SDL_sound APIs. NULL on error. If error, use 432 * SDL_sound APIs. NULL on error. If error, use
410 * Sound_GetError() to see what went wrong. 433 * Sound_GetError() to see what went wrong.
434 *
435 * \sa Sound_NewSampleFromFile
436 * \sa Sound_SetBufferSize
437 * \sa Sound_Decode
438 * \sa Sound_DecodeAll
439 * \sa Sound_Seek
440 * \sa Sound_Rewind
441 * \sa Sound_FreeSample
411 */ 442 */
412 DECLSPEC Sound_Sample *Sound_NewSample(SDL_RWops *rw, const char *ext, 443 DECLSPEC Sound_Sample *Sound_NewSample(SDL_RWops *rw, const char *ext,
413 Sound_AudioInfo *desired, 444 Sound_AudioInfo *desired,
414 Uint32 bufferSize); 445 Uint32 bufferSize);
415 446
427 * \param filename file containing sound data. 458 * \param filename file containing sound data.
428 * \param desired Format to convert sound data into. Can usually be NULL, 459 * \param desired Format to convert sound data into. Can usually be NULL,
429 * if you don't need conversion. 460 * if you don't need conversion.
430 * \param bufferSize size, in bytes, of initial read buffer. 461 * \param bufferSize size, in bytes, of initial read buffer.
431 * \return Sound_Sample pointer, which is used as a handle to several other 462 * \return Sound_Sample pointer, which is used as a handle to several other
432 * SDL_sound APIs. NULL on error. If error, use 463 * SDL_sound APIs. NULL on error. If error, use
433 * Sound_GetError() to see what went wrong. 464 * Sound_GetError() to see what went wrong.
465 *
466 * \sa Sound_NewSample
467 * \sa Sound_SetBufferSize
468 * \sa Sound_Decode
469 * \sa Sound_DecodeAll
470 * \sa Sound_Seek
471 * \sa Sound_Rewind
472 * \sa Sound_FreeSample
434 */ 473 */
435 DECLSPEC Sound_Sample *Sound_NewSampleFromFile(const char *filename, 474 DECLSPEC Sound_Sample *Sound_NewSampleFromFile(const char *filename,
436 Sound_AudioInfo *desired, 475 Sound_AudioInfo *desired,
437 Uint32 bufferSize); 476 Uint32 bufferSize);
438 477
444 * time, so there's no need to keep a reference to that around. 483 * time, so there's no need to keep a reference to that around.
445 * The Sound_Sample pointer is invalid after this call, and will almost 484 * The Sound_Sample pointer is invalid after this call, and will almost
446 * certainly result in a crash if you attempt to keep using it. 485 * certainly result in a crash if you attempt to keep using it.
447 * 486 *
448 * \param sample The Sound_Sample to delete. 487 * \param sample The Sound_Sample to delete.
488 *
489 * \sa Sound_NewSample
490 * \sa Sound_NewSampleFromFile
449 */ 491 */
450 DECLSPEC void Sound_FreeSample(Sound_Sample *sample); 492 DECLSPEC void Sound_FreeSample(Sound_Sample *sample);
451 493
452 494
453 /** 495 /**
469 * MUCH larger buffer). 511 * MUCH larger buffer).
470 * 512 *
471 * \param sample The Sound_Sample whose buffer to modify. 513 * \param sample The Sound_Sample whose buffer to modify.
472 * \param new_size The desired size, in bytes, of the new buffer. 514 * \param new_size The desired size, in bytes, of the new buffer.
473 * \return non-zero if buffer size changed, zero on failure. 515 * \return non-zero if buffer size changed, zero on failure.
516 *
517 * \sa Sound_Decode
518 * \sa Sound_DecodeAll
474 */ 519 */
475 DECLSPEC int Sound_SetBufferSize(Sound_Sample *sample, Uint32 new_size); 520 DECLSPEC int Sound_SetBufferSize(Sound_Sample *sample, Uint32 new_size);
476 521
477 522
478 /** 523 /**
480 * \brief Decode more of the sound data in a Sound_Sample. 525 * \brief Decode more of the sound data in a Sound_Sample.
481 * 526 *
482 * It will decode at most sample->buffer_size bytes into sample->buffer in the 527 * It will decode at most sample->buffer_size bytes into sample->buffer in the
483 * desired format, and return the number of decoded bytes. 528 * desired format, and return the number of decoded bytes.
484 * If sample->buffer_size bytes could not be decoded, then please refer to 529 * If sample->buffer_size bytes could not be decoded, then please refer to
485 * sample->flags to determine if this was an End-of-stream or error condition. 530 * sample->flags to determine if this was an end-of-stream or error condition.
486 * 531 *
487 * \param sample Do more decoding to this Sound_Sample. 532 * \param sample Do more decoding to this Sound_Sample.
488 * \return number of bytes decoded into sample->buffer. If it is less than 533 * \return number of bytes decoded into sample->buffer. If it is less than
489 * sample->buffer_size, then you should check sample->flags to see 534 * sample->buffer_size, then you should check sample->flags to see
490 * what the current state of the sample is (EOF, error, read again). 535 * what the current state of the sample is (EOF, error, read again).
536 *
537 * \sa Sound_DecodeAll
538 * \sa Sound_SetBufferSize
539 * \sa Sound_Seek
540 * \sa Sound_Rewind
491 */ 541 */
492 DECLSPEC Uint32 Sound_Decode(Sound_Sample *sample); 542 DECLSPEC Uint32 Sound_Decode(Sound_Sample *sample);
493 543
494 544
495 /** 545 /**
519 * 569 *
520 * \param sample Do all decoding for this Sound_Sample. 570 * \param sample Do all decoding for this Sound_Sample.
521 * \return number of bytes decoded into sample->buffer. You should check 571 * \return number of bytes decoded into sample->buffer. You should check
522 * sample->flags to see what the current state of the sample is 572 * sample->flags to see what the current state of the sample is
523 * (EOF, error, read again). 573 * (EOF, error, read again).
574 *
575 * \sa Sound_Decode
576 * \sa Sound_SetBufferSize
524 */ 577 */
525 DECLSPEC Uint32 Sound_DecodeAll(Sound_Sample *sample); 578 DECLSPEC Uint32 Sound_DecodeAll(Sound_Sample *sample);
526 579
527 580
528 /** 581 /**
551 * ERROR flag is set on error. 604 * ERROR flag is set on error.
552 * 605 *
553 * \param sample The Sound_Sample to rewind. 606 * \param sample The Sound_Sample to rewind.
554 * \return nonzero on success, zero on error. Specifics of the 607 * \return nonzero on success, zero on error. Specifics of the
555 * error can be gleaned from Sound_GetError(). 608 * error can be gleaned from Sound_GetError().
609 *
610 * \sa Sound_Seek
556 */ 611 */
557 DECLSPEC int Sound_Rewind(Sound_Sample *sample); 612 DECLSPEC int Sound_Rewind(Sound_Sample *sample);
558 613
559 614
560 /** 615 /**
594 * 649 *
595 * \param sample The Sound_Sample to seek. 650 * \param sample The Sound_Sample to seek.
596 * \param ms The new position, in milliseconds from start of sample. 651 * \param ms The new position, in milliseconds from start of sample.
597 * \return nonzero on success, zero on error. Specifics of the 652 * \return nonzero on success, zero on error. Specifics of the
598 * error can be gleaned from Sound_GetError(). 653 * error can be gleaned from Sound_GetError().
654 *
655 * \sa Sound_Rewind
599 */ 656 */
600 DECLSPEC int Sound_Seek(Sound_Sample *sample, Uint32 ms); 657 DECLSPEC int Sound_Seek(Sound_Sample *sample, Uint32 ms);
601 658
602 659
603 #ifdef __cplusplus 660 #ifdef __cplusplus