Skip to content

Latest commit

 

History

History
235 lines (194 loc) · 8.64 KB

SDL_mixer.h

File metadata and controls

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