home *** CD-ROM | disk | FTP | other *** search
/ Mac Magazin/MacEasy 79 / maccd 79.iso / multimedial / GL Tron / Source / Project / include / SDL / SDL_mixer.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-11-22  |  8.5 KB  |  231 lines  |  [TEXT/CWIE]

  1. /*
  2.     MIXERLIB:  An audio mixer library based on the SDL library
  3.     Copyright (C) 1997-1999  Sam Lantinga
  4.  
  5.     This library is free software; you can redistribute it and/or
  6.     modify it under the terms of the GNU Library General Public
  7.     License as published by the Free Software Foundation; either
  8.     version 2 of the License, or (at your option) any later version.
  9.  
  10.     This library is distributed in the hope that it will be useful,
  11.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13.     Library General Public License for more details.
  14.  
  15.     You should have received a copy of the GNU Library General Public
  16.     License along with this library; if not, write to the Free
  17.     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  18.  
  19.     Sam Lantinga
  20.     5635-34 Springhouse Dr.
  21.     Pleasanton, CA 94588 (USA)
  22.     slouken@devolution.com
  23. */
  24.  
  25. #ifndef _MIXER_H_
  26. #define _MIXER_H_
  27.  
  28. #include "SDL_types.h"
  29. #include "SDL_rwops.h"
  30. #include "SDL_audio.h"
  31. #include "begin_code.h"
  32.  
  33. /* Set up for C function definitions, even when using C++ */
  34. #ifdef __cplusplus
  35. extern "C" {
  36. #endif
  37.  
  38. /* The default mixer has 8 simultaneous mixing channels */
  39. #ifndef MIX_CHANNELS
  40. #define MIX_CHANNELS    8
  41. #endif
  42.  
  43. /* Good default values for a PC soundcard */
  44. #define MIX_DEFAULT_FREQUENCY    22050
  45. #define MIX_DEFAULT_FORMAT    AUDIO_S16
  46. #define MIX_DEFAULT_CHANNELS    2
  47. #define MIX_MAX_VOLUME        128    /* Volume of a chunk */
  48.  
  49. /* The internal format for an audio chunk */
  50. typedef struct {
  51.     int allocated;
  52.     Uint8 *abuf;
  53.     Uint32 alen;
  54.     Uint8 volume;        /* Per-sample volume, 0-128 */
  55. } Mix_Chunk;
  56.  
  57. /* The different fading types supported */
  58. typedef enum {
  59.     MIX_NO_FADING,
  60.     MIX_FADING_OUT,
  61.     MIX_FADING_IN
  62. } Mix_Fading;
  63.  
  64. /* The internal format for a music chunk interpreted via mikmod */
  65. typedef struct _Mix_Music Mix_Music;
  66.  
  67. /* Open the mixer with a certain audio format */
  68. extern DECLSPEC int Mix_OpenAudio(int frequency, Uint16 format, int channels,
  69.                             int chunksize);
  70.  
  71. /* Dynamically change the number of channels managed by the mixer.
  72.    If decreasing the number of channels, the upper channels are
  73.    stopped.
  74.    This function returns the new number of allocated channels.
  75.  */
  76. extern DECLSPEC int Mix_AllocateChannels(int numchans);
  77.  
  78. /* Find out what the actual audio device parameters are.
  79.    This function returns 1 if the audio has been opened, 0 otherwise.
  80.  */
  81. extern DECLSPEC int Mix_QuerySpec(int *frequency,Uint16 *format,int *channels);
  82.  
  83. /* Load a wave file or a music (.mod .s3m .it .xm) file */
  84. extern DECLSPEC Mix_Chunk *Mix_LoadWAV_RW(SDL_RWops *src, int freesrc);
  85. #define Mix_LoadWAV(file)    Mix_LoadWAV_RW(SDL_RWFromFile(file, "rb"), 1)
  86. extern DECLSPEC Mix_Music *Mix_LoadMUS(const char *file);
  87.  
  88. #if 0 /* This hasn't been hooked into music.c yet */
  89. /* Load a music file from an SDL_RWop object (MikMod-specific currently)
  90.    Matt Campbell (matt@campbellhome.dhs.org) April 2000 */
  91. extern DECLSPEC Mix_Music *Mix_LoadMUS_RW(SDL_RWops *rw);
  92. #endif
  93.  
  94. /* Load a wave file of the mixer format from a memory buffer */
  95. extern DECLSPEC Mix_Chunk *Mix_QuickLoad_WAV(Uint8 *mem);
  96.  
  97. /* Free an audio chunk previously loaded */
  98. extern DECLSPEC void Mix_FreeChunk(Mix_Chunk *chunk);
  99. extern DECLSPEC void Mix_FreeMusic(Mix_Music *music);
  100.  
  101. /* Set a function that is called after all mixing is performed.
  102.    This can be used to provide real-time visual display of the audio stream
  103.    or add a custom mixer filter for the stream data.
  104. */
  105. extern DECLSPEC void Mix_SetPostMix(void (*mix_func)
  106.                              (void *udata, Uint8 *stream, int len), void *arg);
  107.  
  108. /* Add your own music player or additional mixer function.
  109.    If 'mix_func' is NULL, the default music player is re-enabled.
  110.  */
  111. extern DECLSPEC void Mix_HookMusic(void (*mix_func)
  112.                           (void *udata, Uint8 *stream, int len), void *arg);
  113.  
  114. /* Add your own callback when the music has finished playing.
  115.  */
  116. extern DECLSPEC void Mix_HookMusicFinished(void (*music_finished)(void));
  117.  
  118. /* Get a pointer to the user data for the current music hook */
  119. extern DECLSPEC void *Mix_GetMusicHookData(void);
  120.  
  121. /* Reserve the first channels (0 -> n-1) for the application, i.e. don't allocate
  122.    them dynamically to the next sample if requested with a -1 value below.
  123.    Returns the number of reserved channels.
  124.  */
  125. extern DECLSPEC int Mix_ReserveChannels(int num);
  126.  
  127. /* Channel grouping functions */
  128.  
  129. /* Attach a tag to a channel. A tag can be assigned to several mixer
  130.    channels, to form groups of channels.
  131.    If 'tag' is -1, the tag is removed (actually -1 is the tag used to
  132.    represent the group of all the channels).
  133.    Returns true if everything was OK.
  134.  */
  135. extern DECLSPEC int Mix_GroupChannel(int which, int tag);
  136. /* Assign several consecutive channels to a group */
  137. extern DECLSPEC int Mix_GroupChannels(int from, int to, int tag);
  138. /* Finds the first available channel in a group of channels */
  139. extern DECLSPEC int Mix_GroupAvailable(int tag);
  140. /* Returns the number of channels in a group. This is also a subtle
  141.    way to get the total number of channels when 'tag' is -1
  142.  */
  143. extern DECLSPEC int Mix_GroupCount(int tag);
  144. /* Finds the "oldest" sample playing in a group of channels */
  145. extern DECLSPEC int Mix_GroupOldest(int tag);
  146. /* Finds the "most recent" (i.e. last) sample playing in a group of channels */
  147. extern DECLSPEC int Mix_GroupNewer(int tag);
  148.  
  149. /* Play an audio chunk on a specific channel.
  150.    If the specified channel is -1, play on the first free channel.
  151.    If 'loops' is greater than zero, loop the sound that many times.
  152.    If 'loops' is -1, loop inifinitely (~65000 times).
  153.    Returns which channel was used to play the sound.
  154. */
  155. #define Mix_PlayChannel(channel,chunk,loops) Mix_PlayChannelTimed(channel,chunk,loops,-1)
  156. /* The same as above, but the sound is played at most 'ticks' milliseconds */
  157. extern DECLSPEC int Mix_PlayChannelTimed(int channel, Mix_Chunk *chunk, int loops, int ticks);
  158. extern DECLSPEC int Mix_PlayMusic(Mix_Music *music, int loops);
  159.  
  160. /* Fade in music or a channel over "ms" milliseconds, same semantics as the "Play" functions */
  161. extern DECLSPEC int Mix_FadeInMusic(Mix_Music *music, int loops, int ms);
  162. #define Mix_FadeInChannel(channel,chunk,loops,ms) Mix_FadeInChannelTimed(channel,chunk,loops,ms,-1)
  163. extern DECLSPEC int Mix_FadeInChannelTimed(int channel, Mix_Chunk *chunk, int loops, int ms, int ticks);
  164.  
  165. /* Set the volume in the range of 0-128 of a specific channel or chunk.
  166.    If the specified channel is -1, set volume for all channels.
  167.    Returns the original volume.
  168.    If the specified volume is -1, just return the current volume.
  169. */
  170. extern DECLSPEC int Mix_Volume(int channel, int volume);
  171. extern DECLSPEC int Mix_VolumeChunk(Mix_Chunk *chunk, int volume);
  172. extern DECLSPEC int Mix_VolumeMusic(int volume);
  173.  
  174. /* Halt playing of a particular channel */
  175. extern DECLSPEC int Mix_HaltChannel(int channel);
  176. extern DECLSPEC int Mix_HaltGroup(int tag);
  177. extern DECLSPEC int Mix_HaltMusic(void);
  178.  
  179. /* Change the expiration delay for a particular channel.
  180.    The sample will stop playing after the 'ticks' milliseconds have elapsed,
  181.    or remove the expiration if 'ticks' is -1
  182. */
  183. extern DECLSPEC int Mix_ExpireChannel(int channel, int ticks);
  184.  
  185. /* Halt a channel, fading it out progressively till it's silent
  186.    The ms parameter indicates the number of milliseconds the fading
  187.    will take.
  188.  */
  189. extern DECLSPEC int Mix_FadeOutChannel(int which, int ms);
  190. extern DECLSPEC int Mix_FadeOutGroup(int tag, int ms);
  191. extern DECLSPEC int Mix_FadeOutMusic(int ms);
  192.  
  193. /* Query the fading status of a channel */
  194. extern DECLSPEC Mix_Fading Mix_FadingMusic(void);
  195. extern DECLSPEC Mix_Fading Mix_FadingChannel(int which);
  196.  
  197. /* Pause/Resume a particular channel */
  198. extern DECLSPEC void Mix_Pause(int channel);
  199. extern DECLSPEC void Mix_Resume(int channel);
  200. extern DECLSPEC int  Mix_Paused(int channel);
  201.  
  202. /* Pause/Resume the music stream */
  203. extern DECLSPEC void Mix_PauseMusic(void);
  204. extern DECLSPEC void Mix_ResumeMusic(void);
  205. extern DECLSPEC void Mix_RewindMusic(void);
  206. extern DECLSPEC int  Mix_PausedMusic(void);
  207.  
  208. /* Check the status of a specific channel.
  209.    If the specified channel is -1, check all channels.
  210. */
  211. extern DECLSPEC int Mix_Playing(int channel);
  212. extern DECLSPEC int Mix_PlayingMusic(void);
  213.  
  214. /* Stop music and set external music playback command */
  215. extern DECLSPEC int Mix_SetMusicCMD(const char *command);
  216.  
  217. /* Close the mixer, halting all playing audio */
  218. extern DECLSPEC void Mix_CloseAudio(void);
  219.  
  220. /* We'll use SDL for reporting errors */
  221. #define Mix_SetError    SDL_SetError
  222. #define Mix_GetError    SDL_GetError
  223.  
  224. /* Ends C function definitions when using C++ */
  225. #ifdef __cplusplus
  226. };
  227. #endif
  228. #include "close_code.h"
  229.  
  230. #endif /* _MIXER_H_ */
  231.