mixer.h
author Sam Lantinga <slouken@lokigames.com>
Thu, 21 Oct 1999 18:02:08 +0000
changeset 0 4ce2db4db959
child 1 4ef9250a6471
permissions -rw-r--r--
Initial revision
     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/SDL_types.h>
    29 #include <SDL/SDL_rwops.h>
    30 #include <SDL/SDL_audio.h>
    31 
    32 #include <SDL/begin_code.h>
    33 
    34 /* The default mixer has 8 simultaneous mixing channels */
    35 #ifndef MIX_CHANNELS
    36 #define MIX_CHANNELS	8
    37 #endif
    38 
    39 /* Good default values for a PC soundcard */
    40 #define MIX_DEFAULT_FREQUENCY	22050
    41 #define MIX_DEFAULT_FORMAT	AUDIO_S16
    42 #define MIX_DEFAULT_CHANNELS	2
    43 #define MIX_MAX_VOLUME		128	/* Volume of a chunk */
    44 
    45 /* The internal format for an audio chunk */
    46 typedef struct {
    47 	Uint8 *abuf;
    48 	Uint32 alen;
    49 	Uint8 volume;		/* Per-sample volume, 0-128 */
    50 } Mix_Chunk;
    51 
    52 /* The internal format for a music chunk interpreted via mikmod */
    53 typedef struct _Mix_Music Mix_Music;
    54 
    55 /* Open the mixer with a certain audio format */
    56 extern int Mix_OpenAudio(int frequency, Uint16 format, int channels,
    57 							int chunksize);
    58 
    59 /* Find out what the actual audio device parameters are.
    60    This function returns 1 if the audio has been opened, 0 otherwise.
    61  */
    62 extern int Mix_QuerySpec(int *frequency, Uint16 *format, int *channels);
    63 
    64 /* Load a wave file or a MOD (.mod .s3m .it .xm) file */
    65 extern Mix_Chunk *Mix_LoadWAV_RW(SDL_RWops *src, int freesrc);
    66 #define Mix_LoadWAV(file)	Mix_LoadWAV_RW(SDL_RWFromFile(file, "rb"), 1)
    67 extern Mix_Music *Mix_LoadMUS(const char *file);
    68 
    69 /* Free an audio chunk previously loaded */
    70 extern void Mix_FreeChunk(Mix_Chunk *chunk);
    71 extern void Mix_FreeMusic(Mix_Music *music);
    72 
    73 /* Add your own music player or additional mixer function.
    74    If 'mix_func' is NULL, the default music player is re-enabled.
    75  */
    76 extern void Mix_HookMusic(void (*mix_func)(void *udata, Uint8 *stream, int len),
    77                                                                 void *arg);
    78 
    79 /* Get a pointer to the user data for the current music hook */
    80 extern void *Mix_GetMusicHookData(void);
    81 
    82 /* Reserve the first channels (0 -> n-1) for the application, i.e. don't allocate
    83    them dynamically to the next sample if requested with a -1 value below.
    84    Returns the number of reserved channels.
    85  */
    86 extern int Mix_ReserveChannels(int num);
    87 
    88 /* Play an audio chunk on a specific channel.
    89    If the specified channel is -1, play on the first free channel.
    90    If 'loops' is greater than zero, loop the sound that many times.
    91    If 'loops' is -1, loop inifinitely (~65000 times).
    92    Returns which channel was used to play the sound.
    93 */
    94 extern int Mix_PlayChannel(int channel, Mix_Chunk *chunk, int loops);
    95 extern int Mix_PlayMusic(Mix_Music *music, int loops);
    96 
    97 /* Set the volume in the range of 0-128 of a specific channel or chunk.
    98    If the specified channel is -1, set volume for all channels.
    99    Returns the original volume.
   100    If the specified volume is -1, just return the current volume.
   101 */
   102 extern int Mix_Volume(int channel, int volume);
   103 extern int Mix_VolumeChunk(Mix_Chunk *chunk, int volume);
   104 extern int Mix_VolumeMusic(int volume);
   105 
   106 /* Halt playing of a particular channel */
   107 extern int Mix_HaltChannel(int channel);
   108 extern int Mix_HaltMusic(void);
   109 
   110 /* Pause/Resume a particular channel */
   111 extern void Mix_Pause(int channel);
   112 extern void Mix_Resume(int channel);
   113 
   114 /* Pause/Resume the music stream */
   115 extern void Mix_PauseMusic(void);
   116 extern void Mix_ResumeMusic(void);
   117 extern void Mix_RewindMusic(void);
   118 
   119 /* Check the status of a specific channel.
   120    If the specified channel is -1, check all channels.
   121 */
   122 extern int Mix_Playing(int channel);
   123 extern int Mix_PlayingMusic(void);
   124 
   125 /* Stop music and set external music playback command */
   126 extern int Mix_SetMusicCMD(const char *command);
   127 
   128 /* Close the mixer, halting all playing audio */
   129 extern void Mix_CloseAudio(void);
   130 
   131 /* We'll use SDL for reporting errors */
   132 #define Mix_SetError	SDL_SetError
   133 #define Mix_GetError	SDL_GetError
   134 
   135 #include <SDL/close_code.h>
   136 
   137 #endif /* _MIXER_H_ */