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