-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsdl_mixer.c
306 lines (228 loc) · 5.69 KB
/
sdl_mixer.c
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <gprolog.h>
#include <SDL.h>
#include <SDL_mixer.h>
#include "sdllib_common.h"
#define RETURN_MIX_FAIL(F) \
fprintf(stderr, "%s failed -> %s\n", #F, Mix_GetError()); \
return PL_FALSE;
#define SHOW_MIX_FAIL(F) fprintf(stderr, "%s failed -> %s\n", #F, Mix_GetError());
//--------------------------------------------------------------------
//
// Mixer functions
//
// "SDL_mixer"
//
//--------------------------------------------------------------------
PlBool gp_Mix_Linked_Version(PlLong *major, PlLong *minor, PlLong *patch)
{
SDL_version compile_version;
const SDL_version *link_version = Mix_Linked_Version();
SDL_MIXER_VERSION(&compile_version);
*major = (PlLong)compile_version.major;
*minor = (PlLong)compile_version.minor;
*patch = (PlLong)compile_version.patch;
return PL_TRUE;
}
PlBool gp_Mix_Init(PlLong flags)
{
int result = Mix_Init(flags);
if (result) {
RETURN_MIX_FAIL(Mix_Init);
}
return PL_TRUE;
}
PlBool gp_Mix_Quit()
{
Mix_Quit();
return PL_TRUE;
}
PlBool gp_Mix_OpenAudio(
PlLong frequency, PlLong format,
PlLong channels, PlLong chunks)
{
if (0 == format) {
format = MIX_DEFAULT_FORMAT;
}
if (Mix_OpenAudio((int)frequency, (int)format, (int)channels, (int)chunks)) {
RETURN_MIX_FAIL(Mix_OpenAudio);
}
return PL_TRUE;
}
PlBool gp_Mix_CloseAudio()
{
Mix_CloseAudio();
return PL_TRUE;
}
//--------------------------------------------------------------------
//
// "4.5 Music Playing"
//
//--------------------------------------------------------------------
PlBool gp_Mix_LoadMUS(char *filename, PlLong *handle)
{
Mix_Music *music = Mix_LoadMUS(filename);
if (0 == music) {
RETURN_MIX_FAIL(Mix_LoadMUS);
}
*handle = (PlLong)music;
return PL_TRUE;
}
PlBool gp_Mix_FreeMusic(PlLong *handle)
{
Mix_FreeMusic((Mix_Music*)handle);
return PL_TRUE;
}
PlBool gp_Mix_PlayMusic(PlLong handle, PlLong loops)
{
if (-1 == Mix_PlayMusic((Mix_Music*)handle, (int)loops)) {
RETURN_MIX_FAIL(Mix_PlayMusic);
}
return PL_TRUE;
}
PlBool gp_Mix_FadeInMusic(PlLong handle, PlLong loops, PlLong ms)
{
if (-1 == Mix_FadeInMusic((Mix_Music*)handle, (int)loops, (int)ms)) {
RETURN_MIX_FAIL(Mix_FadeInMusic);
}
return PL_TRUE;
}
PlBool gp_Mix_FadeOutMusic(PlLong ms)
{
if (-1 == Mix_FadeOutMusic((int)ms)) {
RETURN_MIX_FAIL(Mix_FadeOutMusic);
}
return PL_TRUE;
}
PlBool gp_Mix_FadeInMusicPos(PlLong handle, PlLong loops, PlLong ms, double pos)
{
if (-1 == Mix_FadeInMusicPos((Mix_Music*)handle, (int)loops, (int)ms, pos)) {
RETURN_MIX_FAIL(Mix_FadeInMusicPos);
}
return PL_TRUE;
}
PlBool gp_Mix_VolumeMusic(PlLong volume, PlLong *oldVolume)
{
*oldVolume = (PlLong)Mix_VolumeMusic((int)volume);
return PL_TRUE;
}
PlBool gp_Mix_HaltMusic()
{
Mix_HaltMusic();
return PL_TRUE;
}
PlBool gp_Mix_PauseMusic()
{
Mix_PauseMusic();
return PL_TRUE;
}
PlBool gp_Mix_ResumeMusic()
{
Mix_ResumeMusic();
return PL_TRUE;
}
PlBool gp_Mix_RewindMusic()
{
Mix_RewindMusic();
return PL_TRUE;
}
PlBool gp_Mix_QuerySpec(PlLong *frequency, PlLong *format, PlLong *channels, PlLong *opened)
{
int hz, chn;
Uint16 fmt;
int open = Mix_QuerySpec(&hz, &fmt, &chn);
if (0 == open) {
RETURN_MIX_FAIL(Mix_QuerySpec);
}
*frequency = (PlLong)hz;
*format = (PlLong)fmt;
*channels = (PlLong)chn;
*opened = (PlLong)open;
return PL_TRUE;
}
//--------------------------------------------------------------------
//
// "4.2 Samples"
//
//--------------------------------------------------------------------
PlBool gp_Mix_GetNumChunkDecoders(PlLong *count)
{
*count = (PlLong)Mix_GetNumChunkDecoders();
return PL_TRUE;
}
PlBool gp_Mix_GetChunkDecoder(PlLong index, PlTerm *name)
{
const char *decoderName = Mix_GetChunkDecoder((int)index);
if (decoderName) {
*name = Pl_Create_Atom(decoderName);
return PL_TRUE;
}
return PL_FALSE;
}
PlBool gp_Mix_LoadWAV(char* filename, PlLong *sample)
{
Mix_Chunk *chunk = Mix_LoadWAV(filename);
if (chunk) {
*sample = (PlLong)chunk;
return PL_TRUE;
}
RETURN_MIX_FAIL(Mix_LoadWAV);
}
PlBool gp_Mix_FreeChunk(PlLong chunk)
{
Mix_FreeChunk((Mix_Chunk*)chunk);
return PL_TRUE;
}
PlBool gp_Mix_VolumeChunk(PlLong chunk, PlLong volume, PlLong *oldVolume)
{
*oldVolume = (PlLong)Mix_VolumeChunk((Mix_Chunk*)chunk, (int)volume);
return PL_TRUE;
}
PlBool gp_Mix_Playing(PlLong channel, PlLong *status)
{
*status = (PlLong)Mix_Playing((int)channel);
return PL_TRUE;
}
PlBool gp_Mix_PlayingMusic(PlLong *status)
{
*status = (PlLong)Mix_PlayingMusic();
return PL_TRUE;
}
//--------------------------------------------------------------------
//
// "4.3 Channels"
//
//--------------------------------------------------------------------
PlBool gp_Mix_AllocateChannels(PlLong numchans, PlLong *actual)
{
*actual = (PlLong)Mix_AllocateChannels((int)numchans);
return PL_TRUE;
}
PlBool gp_Mix_Volume(PlLong channel, PlLong volume, PlLong *current)
{
*current = (PlLong)Mix_Volume((int)channel, (int)volume);
return PL_TRUE;
}
PlBool gp_Mix_PlayChannel(PlLong channel, PlLong chunk, PlLong loops, PlLong *out)
{
int output = Mix_PlayChannel((int)channel, (Mix_Chunk*)chunk, (int)loops);
if (-1 == output) {
RETURN_MIX_FAIL(Mix_PlayChannel);
}
*out = (PlLong)output;
return PL_TRUE;
}
PlBool gp_Mix_PlayChannelTimed(
PlLong channel, PlLong chunk,
PlLong loops, PlLong ticks,
PlLong *out)
{
int output = Mix_PlayChannelTimed((int)channel, (Mix_Chunk*)chunk, (int)loops, (int)ticks);
if (-1 == output) {
RETURN_MIX_FAIL(Mix_PlayChannelTimed);
}
*out = (PlLong)output;
return PL_TRUE;
}