home *** CD-ROM | disk | FTP | other *** search
/ RISCWORLD 7 / RISCWORLD_VOL7.iso / Software / Issue6 / SDL.ZIP / !SDL / include / SDL / h / SDL_sound < prev    next >
Encoding:
Text File  |  2006-09-22  |  25.2 KB  |  675 lines

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