Skip to content

Latest commit

 

History

History
1063 lines (928 loc) · 27.9 KB

music.c

File metadata and controls

1063 lines (928 loc) · 27.9 KB
 
Oct 21, 1999
Oct 21, 1999
1
/*
Dec 31, 2011
Dec 31, 2011
2
SDL_mixer: An audio mixer library based on the SDL library
Jan 2, 2017
Jan 2, 2017
3
Copyright (C) 1997-2017 Sam Lantinga <slouken@libsdl.org>
Dec 31, 2011
Dec 31, 2011
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
Oct 21, 1999
Oct 21, 1999
20
*/
Oct 17, 2017
Oct 17, 2017
21
#include <string.h> /* for strtok() and strtok_s() */
Oct 21, 1999
Oct 21, 1999
22
Oct 17, 2017
Oct 17, 2017
23
#include "SDL_hints.h"
Oct 21, 2017
Oct 21, 2017
24
#include "SDL_log.h"
Dec 27, 1999
Dec 27, 1999
25
#include "SDL_timer.h"
Oct 21, 1999
Oct 21, 1999
26
Jan 14, 2000
Jan 14, 2000
27
#include "SDL_mixer.h"
Jan 29, 2016
Jan 29, 2016
28
#include "mixer.h"
Oct 17, 2017
Oct 17, 2017
29
#include "music.h"
Oct 21, 1999
Oct 21, 1999
30
31
#include "music_cmd.h"
Oct 17, 2017
Oct 17, 2017
32
33
#include "music_wav.h"
#include "music_mikmod.h"
Nov 16, 2009
Nov 16, 2009
34
#include "music_modplug.h"
Oct 17, 2017
Oct 17, 2017
35
36
37
#include "music_nativemidi.h"
#include "music_fluidsynth.h"
#include "music_timidity.h"
Jul 3, 2000
Jul 3, 2000
38
#include "music_ogg.h"
Oct 17, 2017
Oct 17, 2017
39
#include "music_mpg123.h"
Jul 15, 2007
Jul 15, 2007
40
#include "music_mad.h"
Oct 17, 2017
Oct 17, 2017
41
#include "music_smpeg.h"
Feb 27, 2008
Feb 27, 2008
42
#include "music_flac.h"
Oct 17, 2017
Oct 17, 2017
43
#include "native_midi/native_midi.h"
Oct 21, 1999
Oct 21, 1999
44
Jul 15, 2007
Jul 15, 2007
45
Oct 17, 2017
Oct 17, 2017
46
char *music_cmd = NULL;
Oct 21, 2017
Oct 21, 2017
47
48
static SDL_bool music_active = SDL_TRUE;
static int music_volume = MIX_MAX_VOLUME;
Feb 1, 2000
Feb 1, 2000
49
static Mix_Music * volatile music_playing = NULL;
Oct 17, 2017
Oct 17, 2017
50
SDL_AudioSpec music_spec;
Oct 23, 1999
Oct 23, 1999
51
Oct 21, 1999
Oct 21, 1999
52
struct _Mix_Music {
Oct 17, 2017
Oct 17, 2017
53
54
55
56
Mix_MusicInterface *interface;
void *context;
SDL_bool playing;
May 22, 2013
May 22, 2013
57
58
59
Mix_Fading fading;
int fade_step;
int fade_steps;
Oct 21, 1999
Oct 21, 1999
60
61
};
Nov 11, 1999
Nov 11, 1999
62
63
64
/* Used to calculate fading steps */
static int ms_per_step;
Jun 5, 2009
Jun 5, 2009
65
66
67
68
/* rcg06042009 report available decoders at runtime. */
static const char **music_decoders = NULL;
static int num_decoders = 0;
Mar 20, 2011
Mar 20, 2011
69
/* Semicolon-separated SoundFont paths */
Oct 21, 2017
Oct 21, 2017
70
static char* soundfont_paths = NULL;
Mar 20, 2011
Mar 20, 2011
71
Oct 17, 2017
Oct 17, 2017
72
73
74
75
76
77
78
79
80
/* Interfaces for the various music interfaces, ordered by priority */
static Mix_MusicInterface *s_music_interfaces[] =
{
#ifdef MUSIC_CMD
&Mix_MusicInterface_CMD,
#endif
#ifdef MUSIC_WAV
&Mix_MusicInterface_WAV,
#endif
Oct 22, 2017
Oct 22, 2017
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#ifdef MUSIC_FLAC
&Mix_MusicInterface_FLAC,
#endif
#ifdef MUSIC_OGG
&Mix_MusicInterface_OGG,
#endif
#ifdef MUSIC_MP3_MPG123
&Mix_MusicInterface_MPG123,
#endif
#ifdef MUSIC_MP3_MAD
&Mix_MusicInterface_MAD,
#endif
#ifdef MUSIC_MP3_SMPEG
&Mix_MusicInterface_SMPEG,
#endif
Oct 17, 2017
Oct 17, 2017
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
#ifdef MUSIC_MOD_MODPLUG
&Mix_MusicInterface_MODPLUG,
#endif
#ifdef MUSIC_MOD_MIKMOD
&Mix_MusicInterface_MIKMOD,
#endif
#ifdef MUSIC_MID_FLUIDSYNTH
&Mix_MusicInterface_FLUIDSYNTH,
#endif
#ifdef MUSIC_MID_TIMIDITY
&Mix_MusicInterface_TIMIDITY,
#endif
#ifdef MUSIC_MID_NATIVE
&Mix_MusicInterface_NATIVEMIDI,
#endif
};
int get_num_music_interfaces(void)
{
return SDL_arraysize(s_music_interfaces);
}
Mix_MusicInterface *get_music_interface(int index)
{
return s_music_interfaces[index];
}
Nov 5, 2009
Nov 5, 2009
123
int Mix_GetNumMusicDecoders(void)
Jun 5, 2009
Jun 5, 2009
124
{
May 22, 2013
May 22, 2013
125
return(num_decoders);
Jun 5, 2009
Jun 5, 2009
126
127
128
129
}
const char *Mix_GetMusicDecoder(int index)
{
May 22, 2013
May 22, 2013
130
131
132
133
if ((index < 0) || (index >= num_decoders)) {
return NULL;
}
return(music_decoders[index]);
Jun 5, 2009
Jun 5, 2009
134
135
136
137
}
static void add_music_decoder(const char *decoder)
{
Jun 18, 2013
Jun 18, 2013
138
void *ptr = SDL_realloc((void *)music_decoders, (num_decoders + 1) * sizeof (const char *));
May 22, 2013
May 22, 2013
139
140
141
142
143
if (ptr == NULL) {
return; /* oh well, go on without it. */
}
music_decoders = (const char **) ptr;
music_decoders[num_decoders++] = decoder;
Jun 5, 2009
Jun 5, 2009
144
145
}
Oct 30, 1999
Oct 30, 1999
146
/* Local low-level functions prototypes */
Nov 9, 2003
Nov 9, 2003
147
static void music_internal_initialize_volume(void);
May 16, 2002
May 16, 2002
148
static void music_internal_volume(int volume);
Oct 21, 2017
Oct 21, 2017
149
static int music_internal_play(Mix_Music *music, int play_count, double position);
May 16, 2002
May 16, 2002
150
static int music_internal_position(double position);
Oct 17, 2017
Oct 17, 2017
151
static SDL_bool music_internal_playing(void);
May 16, 2002
May 16, 2002
152
static void music_internal_halt(void);
Oct 26, 1999
Oct 26, 1999
153
Dec 27, 1999
Dec 27, 1999
154
155
/* Support for hooking when the music has finished */
Oct 21, 2017
Oct 21, 2017
156
static void (SDLCALL *music_finished_hook)(void) = NULL;
Dec 27, 1999
Dec 27, 1999
157
Oct 21, 2017
Oct 21, 2017
158
void Mix_HookMusicFinished(void (SDLCALL *music_finished)(void))
Dec 27, 1999
Dec 27, 1999
159
{
Jan 29, 2016
Jan 29, 2016
160
Mix_LockAudio();
May 22, 2013
May 22, 2013
161
music_finished_hook = music_finished;
Jan 29, 2016
Jan 29, 2016
162
Mix_UnlockAudio();
Dec 27, 1999
Dec 27, 1999
163
164
}
Oct 21, 2017
Oct 21, 2017
165
166
167
168
169
/* Convenience function to fill audio and mix at the specified volume
This is called from many music player's GetAudio callback.
*/
int music_pcm_getaudio(void *context, void *data, int bytes, int volume,
int (*GetSome)(void *context, void *data, int bytes, SDL_bool *done))
Nov 19, 2005
Nov 19, 2005
170
{
Oct 21, 2017
Oct 21, 2017
171
172
173
174
Uint8 *snd = (Uint8 *)data;
Uint8 *dst;
int len = bytes;
SDL_bool done = SDL_FALSE;
May 22, 2013
May 22, 2013
175
Oct 21, 2017
Oct 21, 2017
176
177
178
179
180
181
182
183
184
if (volume == MIX_MAX_VOLUME) {
dst = snd;
} else {
dst = SDL_stack_alloc(Uint8, bytes);
}
while (len > 0 && !done) {
int consumed = GetSome(context, dst, len, &done);
if (consumed < 0) {
break;
May 22, 2013
May 22, 2013
185
186
}
Oct 21, 2017
Oct 21, 2017
187
188
189
190
191
if (volume == MIX_MAX_VOLUME) {
dst += consumed;
} else {
SDL_MixAudioFormat(snd, dst, music_spec.format, (Uint32)consumed, volume);
snd += consumed;
May 22, 2013
May 22, 2013
192
}
Oct 21, 2017
Oct 21, 2017
193
len -= consumed;
May 22, 2013
May 22, 2013
194
}
Oct 21, 2017
Oct 21, 2017
195
196
197
198
if (volume != MIX_MAX_VOLUME) {
SDL_stack_free(dst);
}
return len;
Nov 19, 2005
Nov 19, 2005
199
200
}
Oct 21, 1999
Oct 21, 1999
201
/* Mixing function */
Oct 21, 2017
Oct 21, 2017
202
void SDLCALL music_mixer(void *udata, Uint8 *stream, int len)
Oct 21, 1999
Oct 21, 1999
203
{
Oct 21, 2017
Oct 21, 2017
204
while (music_playing && music_active && len > 0) {
May 22, 2013
May 22, 2013
205
/* Handle fading */
Oct 17, 2017
Oct 17, 2017
206
207
if (music_playing->fading != MIX_NO_FADING) {
if (music_playing->fade_step++ < music_playing->fade_steps) {
May 22, 2013
May 22, 2013
208
209
210
211
int volume;
int fade_step = music_playing->fade_step;
int fade_steps = music_playing->fade_steps;
Oct 17, 2017
Oct 17, 2017
212
if (music_playing->fading == MIX_FADING_OUT) {
May 22, 2013
May 22, 2013
213
214
215
216
217
218
volume = (music_volume * (fade_steps-fade_step)) / fade_steps;
} else { /* Fading in */
volume = (music_volume * fade_step) / fade_steps;
}
music_internal_volume(volume);
} else {
Oct 17, 2017
Oct 17, 2017
219
if (music_playing->fading == MIX_FADING_OUT) {
May 22, 2013
May 22, 2013
220
music_internal_halt();
Oct 17, 2017
Oct 17, 2017
221
if (music_finished_hook) {
May 22, 2013
May 22, 2013
222
223
224
225
226
227
228
229
music_finished_hook();
}
return;
}
music_playing->fading = MIX_NO_FADING;
}
}
Oct 17, 2017
Oct 17, 2017
230
231
if (music_playing->interface->GetAudio) {
int left = music_playing->interface->GetAudio(music_playing->context, stream, len);
Oct 21, 2017
Oct 21, 2017
232
233
if (left != 0) {
/* Either an error or finished playing with data left */
Oct 17, 2017
Oct 17, 2017
234
235
music_playing->playing = SDL_FALSE;
}
Oct 21, 2017
Oct 21, 2017
236
237
238
239
240
241
242
243
244
if (left > 0) {
stream += (len - left);
len = left;
} else {
len = 0;
}
} else {
len = 0;
}
May 22, 2013
May 22, 2013
245
Oct 21, 2017
Oct 21, 2017
246
247
248
249
if (!music_internal_playing()) {
music_internal_halt();
if (music_finished_hook) {
music_finished_hook();
Oct 17, 2017
Oct 17, 2017
250
}
May 22, 2013
May 22, 2013
251
252
}
}
Oct 21, 1999
Oct 21, 1999
253
254
}
Oct 17, 2017
Oct 17, 2017
255
256
/* Load the music interface libraries */
int load_music(void)
Oct 21, 1999
Oct 21, 1999
257
{
Oct 17, 2017
Oct 17, 2017
258
char hint[128];
Jun 5, 2009
Jun 5, 2009
259
Oct 17, 2017
Oct 17, 2017
260
261
262
263
264
265
int i;
for (i = 0; i < SDL_arraysize(s_music_interfaces); ++i) {
Mix_MusicInterface *interface = s_music_interfaces[i];
if (interface->loaded) {
continue;
}
Oct 21, 1999
Oct 21, 1999
266
Oct 17, 2017
Oct 17, 2017
267
268
269
270
SDL_snprintf(hint, sizeof(hint), "SDL_MIXER_DISABLE_%s", interface->tag);
if (SDL_GetHintBoolean(hint, SDL_FALSE)) {
continue;
}
Nov 11, 1999
Nov 11, 1999
271
Oct 17, 2017
Oct 17, 2017
272
273
274
275
276
if (!interface->Load || interface->Load() == 0) {
interface->loaded = SDL_TRUE;
}
}
return 0;
Oct 21, 1999
Oct 21, 1999
277
278
}
Oct 17, 2017
Oct 17, 2017
279
280
/* Return SDL_TRUE if the music type is available */
SDL_bool has_music(Mix_MusicType type)
Oct 16, 2001
Oct 16, 2001
281
{
Oct 17, 2017
Oct 17, 2017
282
283
284
285
286
287
288
289
290
int i;
for (i = 0; i < SDL_arraysize(s_music_interfaces); ++i) {
Mix_MusicInterface *interface = s_music_interfaces[i];
if (interface->type != type) {
continue;
}
if (interface->opened) {
return SDL_TRUE;
}
May 22, 2013
May 22, 2013
291
}
Oct 17, 2017
Oct 17, 2017
292
return SDL_FALSE;
Oct 16, 2001
Oct 16, 2001
293
294
}
Oct 17, 2017
Oct 17, 2017
295
296
/* Initialize the music interfaces with a certain desired audio format */
int open_music(const SDL_AudioSpec *spec)
Jan 4, 2012
Jan 4, 2012
297
{
Oct 17, 2017
Oct 17, 2017
298
299
int i;
SDL_bool use_native_midi = SDL_FALSE;
May 22, 2013
May 22, 2013
300
Oct 21, 2017
Oct 21, 2017
301
302
303
304
305
306
307
#ifdef MIX_INIT_SOUNDFONT_PATHS
if (!soundfont_paths) {
soundfont_paths = SDL_strdup(MIX_INIT_SOUNDFONT_PATHS);
}
#endif
Oct 17, 2017
Oct 17, 2017
308
#ifdef MUSIC_MID_NATIVE
Oct 17, 2017
Oct 17, 2017
309
310
if (SDL_GetHintBoolean("SDL_NATIVE_MUSIC", SDL_FALSE) && native_midi_detect()) {
use_native_midi = SDL_TRUE;
May 22, 2013
May 22, 2013
311
}
Oct 17, 2017
Oct 17, 2017
312
#endif
Jan 4, 2012
Jan 4, 2012
313
Oct 17, 2017
Oct 17, 2017
314
315
316
317
318
319
music_spec = *spec;
for (i = 0; i < SDL_arraysize(s_music_interfaces); ++i) {
Mix_MusicInterface *interface = s_music_interfaces[i];
if (!interface->loaded) {
continue;
}
May 22, 2013
May 22, 2013
320
Oct 17, 2017
Oct 17, 2017
321
322
323
324
325
326
327
328
if (interface->type == MUS_MID && use_native_midi && interface->api != MIX_MUSIC_NATIVEMIDI) {
continue;
}
if (!interface->Open || interface->Open(spec) == 0) {
interface->opened = SDL_TRUE;
add_music_decoder(interface->tag);
}
May 22, 2013
May 22, 2013
329
330
}
Oct 17, 2017
Oct 17, 2017
331
332
333
334
335
336
337
338
if (has_music(MUS_MOD)) {
add_music_decoder("MOD");
}
if (has_music(MUS_MID)) {
add_music_decoder("MIDI");
}
if (has_music(MUS_MP3)) {
add_music_decoder("MP3");
May 22, 2013
May 22, 2013
339
340
}
Oct 17, 2017
Oct 17, 2017
341
342
343
344
345
346
347
348
349
350
Mix_VolumeMusic(MIX_MAX_VOLUME);
/* Calculate the number of ms for each callback */
ms_per_step = (int) (((float)spec->samples * 1000.0) / spec->freq);
return 0;
}
Mix_MusicType detect_music_type_from_magic(const Uint8 *magic)
{
May 22, 2013
May 22, 2013
351
/* Ogg Vorbis files have the magic four bytes "OggS" */
Oct 17, 2017
Oct 17, 2017
352
if (SDL_memcmp(magic, "OggS", 4) == 0) {
May 22, 2013
May 22, 2013
353
354
355
356
return MUS_OGG;
}
/* FLAC files have the magic four bytes "fLaC" */
Oct 17, 2017
Oct 17, 2017
357
if (SDL_memcmp(magic, "fLaC", 4) == 0) {
May 22, 2013
May 22, 2013
358
359
360
361
return MUS_FLAC;
}
/* MIDI files have the magic four bytes "MThd" */
Oct 17, 2017
Oct 17, 2017
362
if (SDL_memcmp(magic, "MThd", 4) == 0) {
May 22, 2013
May 22, 2013
363
364
365
return MUS_MID;
}
Oct 17, 2017
Oct 17, 2017
366
367
if (SDL_memcmp(magic, "ID3", 3) == 0 ||
(magic[0] == 0xFF && (magic[1] & 0xFE) == 0xFA)) {
May 22, 2013
May 22, 2013
368
369
370
371
372
373
374
375
376
return MUS_MP3;
}
/* Assume MOD format.
*
* Apparently there is no way to check if the file is really a MOD,
* or there are too many formats supported by MikMod/ModPlug, or
* MikMod/ModPlug does this check by itself. */
return MUS_MOD;
Jan 4, 2012
Jan 4, 2012
377
378
}
Oct 17, 2017
Oct 17, 2017
379
380
static Mix_MusicType detect_music_type(SDL_RWops *src)
{
Oct 17, 2017
Oct 17, 2017
381
Uint8 magic[12];
Oct 17, 2017
Oct 17, 2017
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
if (SDL_RWread(src, magic, 1, 12) != 12) {
Mix_SetError("Couldn't read first 12 bytes of audio data");
return MUS_NONE;
}
SDL_RWseek(src, -12, RW_SEEK_CUR);
/* WAVE files have the magic four bytes "RIFF"
AIFF files have the magic 12 bytes "FORM" XXXX "AIFF" */
if (((SDL_memcmp(magic, "RIFF", 4) == 0) && (SDL_memcmp((magic+8), "WAVE", 4) == 0)) ||
(SDL_memcmp(magic, "FORM", 4) == 0)) {
return MUS_WAV;
}
return detect_music_type_from_magic(magic);
}
Oct 21, 1999
Oct 21, 1999
399
400
401
/* Load a music file */
Mix_Music *Mix_LoadMUS(const char *file)
{
Oct 17, 2017
Oct 17, 2017
402
403
404
int i;
void *context;
char *ext;
May 22, 2013
May 22, 2013
405
Mix_MusicType type;
Oct 17, 2017
Oct 17, 2017
406
407
408
409
410
411
SDL_RWops *src;
for (i = 0; i < SDL_arraysize(s_music_interfaces); ++i) {
Mix_MusicInterface *interface = s_music_interfaces[i];
if (!interface->opened || !interface->CreateFromFile) {
continue;
May 22, 2013
May 22, 2013
412
}
Oct 17, 2017
Oct 17, 2017
413
414
415
416
417
418
419
420
421
422
423
424
context = interface->CreateFromFile(file);
if (context) {
/* Allocate memory for the music structure */
Mix_Music *music = (Mix_Music *)SDL_calloc(1, sizeof(Mix_Music));
if (music == NULL) {
Mix_SetError("Out of memory");
return NULL;
}
music->interface = interface;
music->context = context;
return music;
May 22, 2013
May 22, 2013
425
426
427
}
}
Jun 2, 2013
Jun 2, 2013
428
src = SDL_RWFromFile(file, "rb");
Oct 17, 2017
Oct 17, 2017
429
if (src == NULL) {
May 22, 2013
May 22, 2013
430
431
432
433
434
435
436
Mix_SetError("Couldn't open '%s'", file);
return NULL;
}
/* Use the extension as a first guess on the file type */
type = MUS_NONE;
ext = strrchr(file, '.');
Oct 17, 2017
Oct 17, 2017
437
if (ext) {
May 22, 2013
May 22, 2013
438
++ext; /* skip the dot in the extension */
Oct 17, 2017
Oct 17, 2017
439
if (SDL_strcasecmp(ext, "WAV") == 0) {
May 22, 2013
May 22, 2013
440
type = MUS_WAV;
Oct 17, 2017
Oct 17, 2017
441
442
443
} else if (SDL_strcasecmp(ext, "MID") == 0 ||
SDL_strcasecmp(ext, "MIDI") == 0 ||
SDL_strcasecmp(ext, "KAR") == 0) {
May 22, 2013
May 22, 2013
444
type = MUS_MID;
Oct 17, 2017
Oct 17, 2017
445
} else if (SDL_strcasecmp(ext, "OGG") == 0) {
May 22, 2013
May 22, 2013
446
type = MUS_OGG;
Oct 17, 2017
Oct 17, 2017
447
} else if (SDL_strcasecmp(ext, "FLAC") == 0) {
May 22, 2013
May 22, 2013
448
type = MUS_FLAC;
Oct 17, 2017
Oct 17, 2017
449
450
451
452
} else if (SDL_strcasecmp(ext, "MPG") == 0 ||
SDL_strcasecmp(ext, "MPEG") == 0 ||
SDL_strcasecmp(ext, "MP3") == 0 ||
SDL_strcasecmp(ext, "MAD") == 0) {
May 22, 2013
May 22, 2013
453
type = MUS_MP3;
Oct 17, 2017
Oct 17, 2017
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
} else if (SDL_strcasecmp(ext, "669") == 0 ||
SDL_strcasecmp(ext, "AMF") == 0 ||
SDL_strcasecmp(ext, "AMS") == 0 ||
SDL_strcasecmp(ext, "DBM") == 0 ||
SDL_strcasecmp(ext, "DSM") == 0 ||
SDL_strcasecmp(ext, "FAR") == 0 ||
SDL_strcasecmp(ext, "IT") == 0 ||
SDL_strcasecmp(ext, "MED") == 0 ||
SDL_strcasecmp(ext, "MDL") == 0 ||
SDL_strcasecmp(ext, "MOD") == 0 ||
SDL_strcasecmp(ext, "MOL") == 0 ||
SDL_strcasecmp(ext, "MTM") == 0 ||
SDL_strcasecmp(ext, "NST") == 0 ||
SDL_strcasecmp(ext, "OKT") == 0 ||
SDL_strcasecmp(ext, "PTM") == 0 ||
SDL_strcasecmp(ext, "S3M") == 0 ||
SDL_strcasecmp(ext, "STM") == 0 ||
SDL_strcasecmp(ext, "ULT") == 0 ||
SDL_strcasecmp(ext, "UMX") == 0 ||
SDL_strcasecmp(ext, "WOW") == 0 ||
SDL_strcasecmp(ext, "XM") == 0) {
type = MUS_MOD;
May 22, 2013
May 22, 2013
476
477
}
}
Oct 17, 2017
Oct 17, 2017
478
return Mix_LoadMUSType_RW(src, type, SDL_TRUE);
Jan 4, 2012
Jan 4, 2012
479
480
}
Jun 2, 2013
Jun 2, 2013
481
Mix_Music *Mix_LoadMUS_RW(SDL_RWops *src, int freesrc)
Jan 4, 2012
Jan 4, 2012
482
{
Jun 2, 2013
Jun 2, 2013
483
return Mix_LoadMUSType_RW(src, MUS_NONE, freesrc);
Jan 4, 2012
Jan 4, 2012
484
485
}
Jun 2, 2013
Jun 2, 2013
486
Mix_Music *Mix_LoadMUSType_RW(SDL_RWops *src, Mix_MusicType type, int freesrc)
Jan 4, 2012
Jan 4, 2012
487
{
Oct 17, 2017
Oct 17, 2017
488
489
int i;
void *context;
Jun 2, 2013
Jun 2, 2013
490
Sint64 start;
May 22, 2013
May 22, 2013
491
Jun 2, 2013
Jun 2, 2013
492
if (!src) {
May 22, 2013
May 22, 2013
493
494
495
Mix_SetError("RWops pointer is NULL");
return NULL;
}
Jun 2, 2013
Jun 2, 2013
496
start = SDL_RWtell(src);
May 22, 2013
May 22, 2013
497
498
499
500
/* If the caller wants auto-detection, figure out what kind of file
* this is. */
if (type == MUS_NONE) {
Jun 2, 2013
Jun 2, 2013
501
if ((type = detect_music_type(src)) == MUS_NONE) {
Oct 17, 2017
Oct 17, 2017
502
/* Don't call Mix_SetError() since detect_music_type() does that. */
Jun 2, 2013
Jun 2, 2013
503
504
505
if (freesrc) {
SDL_RWclose(src);
}
May 22, 2013
May 22, 2013
506
507
508
509
return NULL;
}
}
Oct 17, 2017
Oct 17, 2017
510
Mix_ClearError();
May 22, 2013
May 22, 2013
511
Oct 17, 2017
Oct 17, 2017
512
513
514
515
for (i = 0; i < SDL_arraysize(s_music_interfaces); ++i) {
Mix_MusicInterface *interface = s_music_interfaces[i];
if (!interface->opened || type != interface->type || !interface->CreateFromRW) {
continue;
Jul 20, 2017
Jul 20, 2017
516
}
Oct 17, 2017
Oct 17, 2017
517
518
519
520
521
522
523
524
525
context = interface->CreateFromRW(src, freesrc);
if (context) {
/* Allocate memory for the music structure */
Mix_Music *music = (Mix_Music *)SDL_calloc(1, sizeof(Mix_Music));
if (music == NULL) {
interface->Delete(context);
Mix_SetError("Out of memory");
return NULL;
May 22, 2013
May 22, 2013
526
}
Oct 17, 2017
Oct 17, 2017
527
528
music->interface = interface;
music->context = context;
Oct 21, 2017
Oct 21, 2017
529
530
531
532
#ifdef DEBUG_MUSIC
/* This would be useful to expose via an API */
SDL_Log("Music playing with %s\n", interface->tag);
#endif
Oct 17, 2017
Oct 17, 2017
533
return music;
May 22, 2013
May 22, 2013
534
}
Oct 17, 2017
Oct 17, 2017
535
536
537
538
/* Reset the stream for the next decoder */
SDL_RWseek(src, start, RW_SEEK_SET);
}
Mar 20, 2011
Mar 20, 2011
539
Oct 17, 2017
Oct 17, 2017
540
541
if (!*Mix_GetError()) {
Mix_SetError("Unrecognized audio format");
May 22, 2013
May 22, 2013
542
}
Oct 17, 2017
Oct 17, 2017
543
544
545
546
547
548
if (freesrc) {
SDL_RWclose(src);
} else {
SDL_RWseek(src, start, RW_SEEK_SET);
}
return NULL;
Oct 21, 1999
Oct 21, 1999
549
550
551
552
553
}
/* Free a music chunk previously loaded */
void Mix_FreeMusic(Mix_Music *music)
{
Oct 17, 2017
Oct 17, 2017
554
if (music) {
May 22, 2013
May 22, 2013
555
/* Stop the music if it's currently playing */
Jan 29, 2016
Jan 29, 2016
556
Mix_LockAudio();
Oct 17, 2017
Oct 17, 2017
557
if (music == music_playing) {
May 22, 2013
May 22, 2013
558
/* Wait for any fade out to finish */
Oct 17, 2017
Oct 17, 2017
559
while (music->fading == MIX_FADING_OUT) {
Jan 29, 2016
Jan 29, 2016
560
Mix_UnlockAudio();
May 22, 2013
May 22, 2013
561
SDL_Delay(100);
Jan 29, 2016
Jan 29, 2016
562
Mix_LockAudio();
May 22, 2013
May 22, 2013
563
}
Oct 17, 2017
Oct 17, 2017
564
if (music == music_playing) {
May 22, 2013
May 22, 2013
565
566
567
music_internal_halt();
}
}
Jan 29, 2016
Jan 29, 2016
568
Mix_UnlockAudio();
Mar 20, 2011
Mar 20, 2011
569
Oct 17, 2017
Oct 17, 2017
570
music->interface->Delete(music->context);
May 22, 2013
May 22, 2013
571
572
SDL_free(music);
}
Oct 21, 1999
Oct 21, 1999
573
574
}
May 19, 2002
May 19, 2002
575
576
577
578
579
/* Find out the music format of a mixer music, or the currently playing
music, if 'music' is NULL.
*/
Mix_MusicType Mix_GetMusicType(const Mix_Music *music)
{
May 22, 2013
May 22, 2013
580
581
Mix_MusicType type = MUS_NONE;
Oct 17, 2017
Oct 17, 2017
582
583
if (music) {
type = music->interface->type;
May 22, 2013
May 22, 2013
584
} else {
Jan 29, 2016
Jan 29, 2016
585
Mix_LockAudio();
Oct 17, 2017
Oct 17, 2017
586
587
if (music_playing) {
type = music_playing->interface->type;
May 22, 2013
May 22, 2013
588
}
Jan 29, 2016
Jan 29, 2016
589
Mix_UnlockAudio();
May 22, 2013
May 22, 2013
590
591
}
return(type);
May 19, 2002
May 19, 2002
592
593
}
May 16, 2002
May 16, 2002
594
595
/* Play a music chunk. Returns 0, or -1 if there was an error.
*/
Oct 21, 2017
Oct 21, 2017
596
static int music_internal_play(Mix_Music *music, int play_count, double position)
Oct 21, 1999
Oct 21, 1999
597
{
May 22, 2013
May 22, 2013
598
int retval = 0;
May 16, 2002
May 16, 2002
599
Oct 17, 2017
Oct 17, 2017
600
#if defined(__MACOSX__) && defined(MID_MUSIC_NATIVE)
May 22, 2013
May 22, 2013
601
602
603
/* This fixes a bug with native MIDI on Mac OS X, where you
can't really stop and restart MIDI from the audio callback.
*/
Oct 17, 2017
Oct 17, 2017
604
if (music == music_playing && music->api == MIX_MUSIC_NATIVEMIDI) {
May 22, 2013
May 22, 2013
605
606
607
608
609
610
611
/* Just a seek suffices to restart playing */
music_internal_position(position);
return 0;
}
#endif
/* Note the music we're playing */
Oct 17, 2017
Oct 17, 2017
612
if (music_playing) {
May 22, 2013
May 22, 2013
613
614
615
music_internal_halt();
}
music_playing = music;
Oct 17, 2017
Oct 17, 2017
616
music_playing->playing = SDL_TRUE;
May 22, 2013
May 22, 2013
617
618
/* Set the initial volume */
Oct 17, 2017
Oct 17, 2017
619
music_internal_initialize_volume();
May 22, 2013
May 22, 2013
620
621
/* Set up for playback */
Oct 21, 2017
Oct 21, 2017
622
retval = music->interface->Play(music->context, play_count);
Oct 30, 1999
Oct 30, 1999
623
May 22, 2013
May 22, 2013
624
/* Set the playback position, note any errors if an offset is used */
Oct 17, 2017
Oct 17, 2017
625
626
627
if (retval == 0) {
if (position > 0.0) {
if (music_internal_position(position) < 0) {
May 22, 2013
May 22, 2013
628
629
630
631
632
633
634
635
636
Mix_SetError("Position not implemented for music type");
retval = -1;
}
} else {
music_internal_position(0.0);
}
}
/* If the setup failed, we're not playing any music anymore */
Oct 17, 2017
Oct 17, 2017
637
if (retval < 0) {
Oct 21, 2017
Oct 21, 2017
638
music->playing = SDL_FALSE;
May 22, 2013
May 22, 2013
639
640
641
music_playing = NULL;
}
return(retval);
May 16, 2002
May 16, 2002
642
}
Oct 17, 2017
Oct 17, 2017
643
May 16, 2002
May 16, 2002
644
int Mix_FadeInMusicPos(Mix_Music *music, int loops, int ms, double position)
Oct 30, 1999
Oct 30, 1999
645
{
May 22, 2013
May 22, 2013
646
647
int retval;
Oct 17, 2017
Oct 17, 2017
648
if (ms_per_step == 0) {
May 22, 2013
May 22, 2013
649
650
651
652
653
SDL_SetError("Audio device hasn't been opened");
return(-1);
}
/* Don't play null pointers :-) */
Oct 17, 2017
Oct 17, 2017
654
if (music == NULL) {
May 22, 2013
May 22, 2013
655
656
657
658
659
Mix_SetError("music parameter was NULL");
return(-1);
}
/* Setup the data */
Oct 17, 2017
Oct 17, 2017
660
if (ms) {
May 22, 2013
May 22, 2013
661
662
663
664
665
666
667
668
music->fading = MIX_FADING_IN;
} else {
music->fading = MIX_NO_FADING;
}
music->fade_step = 0;
music->fade_steps = ms/ms_per_step;
/* Play the puppy */
Jan 29, 2016
Jan 29, 2016
669
Mix_LockAudio();
May 22, 2013
May 22, 2013
670
/* If the current music is fading out, wait for the fade to complete */
Oct 17, 2017
Oct 17, 2017
671
while (music_playing && (music_playing->fading == MIX_FADING_OUT)) {
Jan 29, 2016
Jan 29, 2016
672
Mix_UnlockAudio();
May 22, 2013
May 22, 2013
673
SDL_Delay(100);
Jan 29, 2016
Jan 29, 2016
674
Mix_LockAudio();
May 22, 2013
May 22, 2013
675
}
Oct 21, 2017
Oct 21, 2017
676
if (loops == 0) {
May 22, 2013
May 22, 2013
677
/* Loop is the number of times to play the audio */
Oct 21, 2017
Oct 21, 2017
678
loops = 1;
May 22, 2013
May 22, 2013
679
}
Oct 21, 2017
Oct 21, 2017
680
retval = music_internal_play(music, loops, position);
Jan 29, 2016
Jan 29, 2016
681
Mix_UnlockAudio();
May 22, 2013
May 22, 2013
682
683
return(retval);
May 16, 2002
May 16, 2002
684
685
686
}
int Mix_FadeInMusic(Mix_Music *music, int loops, int ms)
{
May 22, 2013
May 22, 2013
687
return Mix_FadeInMusicPos(music, loops, ms, 0.0);
May 16, 2002
May 16, 2002
688
689
690
}
int Mix_PlayMusic(Mix_Music *music, int loops)
{
May 22, 2013
May 22, 2013
691
return Mix_FadeInMusicPos(music, loops, 0, 0.0);
Oct 23, 1999
Oct 23, 1999
692
693
}
May 16, 2002
May 16, 2002
694
695
/* Set the playing music position */
int music_internal_position(double position)
Dec 19, 2001
Dec 19, 2001
696
{
Oct 17, 2017
Oct 17, 2017
697
698
if (music_playing->interface->Seek) {
return music_playing->interface->Seek(music_playing->context, position);
May 22, 2013
May 22, 2013
699
}
Oct 17, 2017
Oct 17, 2017
700
return -1;
Dec 19, 2001
Dec 19, 2001
701
}
May 16, 2002
May 16, 2002
702
int Mix_SetMusicPosition(double position)
Oct 23, 1999
Oct 23, 1999
703
{
May 22, 2013
May 22, 2013
704
705
int retval;
Jan 29, 2016
Jan 29, 2016
706
Mix_LockAudio();
Oct 17, 2017
Oct 17, 2017
707
if (music_playing) {
May 22, 2013
May 22, 2013
708
retval = music_internal_position(position);
Oct 17, 2017
Oct 17, 2017
709
if (retval < 0) {
May 22, 2013
May 22, 2013
710
711
712
713
714
715
Mix_SetError("Position not implemented for music type");
}
} else {
Mix_SetError("Music isn't playing");
retval = -1;
}
Jan 29, 2016
Jan 29, 2016
716
Mix_UnlockAudio();
May 22, 2013
May 22, 2013
717
718
return(retval);
Dec 19, 2001
Dec 19, 2001
719
720
}
Nov 9, 2003
Nov 9, 2003
721
722
723
/* Set the music's initial volume */
static void music_internal_initialize_volume(void)
{
Oct 17, 2017
Oct 17, 2017
724
if (music_playing->fading == MIX_FADING_IN) {
May 22, 2013
May 22, 2013
725
726
727
728
music_internal_volume(0);
} else {
music_internal_volume(music_volume);
}
Nov 9, 2003
Nov 9, 2003
729
730
}
Oct 21, 1999
Oct 21, 1999
731
/* Set the music volume */
May 16, 2002
May 16, 2002
732
static void music_internal_volume(int volume)
Oct 21, 1999
Oct 21, 1999
733
{
Oct 17, 2017
Oct 17, 2017
734
735
if (music_playing->interface->SetVolume) {
music_playing->interface->SetVolume(music_playing->context, volume);
May 22, 2013
May 22, 2013
736
}
May 16, 2002
May 16, 2002
737
738
739
}
int Mix_VolumeMusic(int volume)
{
May 22, 2013
May 22, 2013
740
741
742
int prev_volume;
prev_volume = music_volume;
Oct 17, 2017
Oct 17, 2017
743
if (volume < 0) {
May 22, 2013
May 22, 2013
744
745
return prev_volume;
}
Oct 17, 2017
Oct 17, 2017
746
if (volume > SDL_MIX_MAXVOLUME) {
May 22, 2013
May 22, 2013
747
748
749
volume = SDL_MIX_MAXVOLUME;
}
music_volume = volume;
Jan 29, 2016
Jan 29, 2016
750
Mix_LockAudio();
Oct 17, 2017
Oct 17, 2017
751
if (music_playing) {
May 22, 2013
May 22, 2013
752
753
music_internal_volume(music_volume);
}
Jan 29, 2016
Jan 29, 2016
754
Mix_UnlockAudio();
May 22, 2013
May 22, 2013
755
return(prev_volume);
Oct 21, 1999
Oct 21, 1999
756
757
}
May 16, 2002
May 16, 2002
758
759
/* Halt playing of music */
static void music_internal_halt(void)
Oct 21, 1999
Oct 21, 1999
760
{
Oct 17, 2017
Oct 17, 2017
761
762
if (music_playing->interface->Stop) {
music_playing->interface->Stop(music_playing->context);
May 22, 2013
May 22, 2013
763
}
Mar 20, 2011
Mar 20, 2011
764
Oct 17, 2017
Oct 17, 2017
765
music_playing->playing = SDL_FALSE;
May 22, 2013
May 22, 2013
766
767
music_playing->fading = MIX_NO_FADING;
music_playing = NULL;
Oct 26, 1999
Oct 26, 1999
768
769
770
}
int Mix_HaltMusic(void)
{
Jan 29, 2016
Jan 29, 2016
771
Mix_LockAudio();
Oct 17, 2017
Oct 17, 2017
772
if (music_playing) {
May 22, 2013
May 22, 2013
773
music_internal_halt();
Oct 17, 2017
Oct 17, 2017
774
if (music_finished_hook) {
May 22, 2013
May 22, 2013
775
776
777
music_finished_hook();
}
}
Jan 29, 2016
Jan 29, 2016
778
Mix_UnlockAudio();
May 22, 2013
May 22, 2013
779
780
return(0);
Oct 21, 1999
Oct 21, 1999
781
782
}
Oct 23, 1999
Oct 23, 1999
783
784
785
/* Progressively stop the music */
int Mix_FadeOutMusic(int ms)
{
May 22, 2013
May 22, 2013
786
int retval = 0;
May 16, 2002
May 16, 2002
787
Oct 17, 2017
Oct 17, 2017
788
if (ms_per_step == 0) {
May 22, 2013
May 22, 2013
789
790
791
SDL_SetError("Audio device hasn't been opened");
return 0;
}
Jan 24, 2011
Jan 24, 2011
792
May 22, 2013
May 22, 2013
793
794
795
796
if (ms <= 0) { /* just halt immediately. */
Mix_HaltMusic();
return 1;
}
Nov 19, 2005
Nov 19, 2005
797
Jan 29, 2016
Jan 29, 2016
798
Mix_LockAudio();
Oct 17, 2017
Oct 17, 2017
799
800
801
802
803
804
805
806
807
808
809
810
811
812
if (music_playing) {
int fade_steps = (ms + ms_per_step - 1) / ms_per_step;
if (music_playing->fading == MIX_NO_FADING) {
music_playing->fade_step = 0;
} else {
int step;
int old_fade_steps = music_playing->fade_steps;
if (music_playing->fading == MIX_FADING_OUT) {
step = music_playing->fade_step;
} else {
step = old_fade_steps - music_playing->fade_step + 1;
}
music_playing->fade_step = (step * fade_steps) / old_fade_steps;
}
May 22, 2013
May 22, 2013
813
814
815
816
music_playing->fading = MIX_FADING_OUT;
music_playing->fade_steps = fade_steps;
retval = 1;
}
Jan 29, 2016
Jan 29, 2016
817
Mix_UnlockAudio();
May 16, 2002
May 16, 2002
818
May 22, 2013
May 22, 2013
819
return(retval);
Oct 23, 1999
Oct 23, 1999
820
821
822
823
}
Mix_Fading Mix_FadingMusic(void)
{
May 22, 2013
May 22, 2013
824
Mix_Fading fading = MIX_NO_FADING;
May 16, 2002
May 16, 2002
825
Jan 29, 2016
Jan 29, 2016
826
Mix_LockAudio();
Oct 17, 2017
Oct 17, 2017
827
if (music_playing) {
May 22, 2013
May 22, 2013
828
829
fading = music_playing->fading;
}
Jan 29, 2016
Jan 29, 2016
830
Mix_UnlockAudio();
May 16, 2002
May 16, 2002
831
May 22, 2013
May 22, 2013
832
return(fading);
Oct 23, 1999
Oct 23, 1999
833
834
}
Oct 21, 1999
Oct 21, 1999
835
836
837
/* Pause/Resume the music stream */
void Mix_PauseMusic(void)
{
Oct 17, 2017
Oct 17, 2017
838
Mix_LockAudio();
Oct 21, 2017
Oct 21, 2017
839
840
841
842
if (music_playing) {
if (music_playing->interface->Pause) {
music_playing->interface->Pause(music_playing->context);
}
Oct 17, 2017
Oct 17, 2017
843
}
Oct 21, 2017
Oct 21, 2017
844
music_active = SDL_FALSE;
Oct 17, 2017
Oct 17, 2017
845
Mix_UnlockAudio();
Oct 21, 1999
Oct 21, 1999
846
}
Oct 23, 1999
Oct 23, 1999
847
Oct 21, 1999
Oct 21, 1999
848
849
void Mix_ResumeMusic(void)
{
Oct 17, 2017
Oct 17, 2017
850
Mix_LockAudio();
Oct 21, 2017
Oct 21, 2017
851
852
853
854
if (music_playing) {
if (music_playing->interface->Resume) {
music_playing->interface->Resume(music_playing->context);
}
Oct 17, 2017
Oct 17, 2017
855
}
Oct 21, 2017
Oct 21, 2017
856
music_active = SDL_TRUE;
Oct 17, 2017
Oct 17, 2017
857
Mix_UnlockAudio();
Oct 21, 1999
Oct 21, 1999
858
859
860
861
}
void Mix_RewindMusic(void)
{
May 22, 2013
May 22, 2013
862
Mix_SetMusicPosition(0.0);
Oct 21, 1999
Oct 21, 1999
863
864
}
Nov 1, 1999
Nov 1, 1999
865
866
int Mix_PausedMusic(void)
{
Oct 21, 2017
Oct 21, 2017
867
return (music_active == SDL_FALSE);
Nov 1, 1999
Nov 1, 1999
868
869
}
Oct 21, 1999
Oct 21, 1999
870
/* Check the status of the music */
Oct 17, 2017
Oct 17, 2017
871
static SDL_bool music_internal_playing(void)
Oct 21, 1999
Oct 21, 1999
872
{
Oct 21, 2017
Oct 21, 2017
873
if (!music_playing) {
Oct 17, 2017
Oct 17, 2017
874
return SDL_FALSE;
May 22, 2013
May 22, 2013
875
}
Jul 14, 2011
Jul 14, 2011
876
Oct 17, 2017
Oct 17, 2017
877
if (music_playing->interface->IsPlaying) {
Oct 21, 2017
Oct 21, 2017
878
music_playing->playing = music_playing->interface->IsPlaying(music_playing->context);
May 22, 2013
May 22, 2013
879
}
Oct 17, 2017
Oct 17, 2017
880
return music_playing->playing;
May 16, 2002
May 16, 2002
881
882
883
}
int Mix_PlayingMusic(void)
{
Oct 21, 2017
Oct 21, 2017
884
SDL_bool playing;
May 16, 2002
May 16, 2002
885
Jan 29, 2016
Jan 29, 2016
886
Mix_LockAudio();
Oct 21, 2017
Oct 21, 2017
887
playing = music_internal_playing();
Jan 29, 2016
Jan 29, 2016
888
Mix_UnlockAudio();
May 16, 2002
May 16, 2002
889
Oct 21, 2017
Oct 21, 2017
890
return playing ? 1 : 0;
Oct 21, 1999
Oct 21, 1999
891
892
893
894
895
}
/* Set the external music playback command */
int Mix_SetMusicCMD(const char *command)
{
May 22, 2013
May 22, 2013
896
Mix_HaltMusic();
Oct 17, 2017
Oct 17, 2017
897
if (music_cmd) {
May 22, 2013
May 22, 2013
898
899
900
SDL_free(music_cmd);
music_cmd = NULL;
}
Oct 17, 2017
Oct 17, 2017
901
902
903
904
905
if (command) {
size_t length = SDL_strlen(command) + 1;
music_cmd = (char *)SDL_malloc(length);
if (music_cmd == NULL) {
return SDL_OutOfMemory();
May 22, 2013
May 22, 2013
906
}
Oct 17, 2017
Oct 17, 2017
907
SDL_memcpy(music_cmd, command, length);
May 22, 2013
May 22, 2013
908
}
Oct 17, 2017
Oct 17, 2017
909
return 0;
Oct 21, 1999
Oct 21, 1999
910
911
}
Dec 19, 2001
Dec 19, 2001
912
913
int Mix_SetSynchroValue(int i)
{
May 22, 2013
May 22, 2013
914
915
/* Not supported by any players at this time */
return(-1);
Dec 19, 2001
Dec 19, 2001
916
917
918
919
}
int Mix_GetSynchroValue(void)
{
May 22, 2013
May 22, 2013
920
921
/* Not supported by any players at this time */
return(-1);
Dec 19, 2001
Dec 19, 2001
922
923
924
}
Oct 17, 2017
Oct 17, 2017
925
/* Uninitialize the music interfaces */
Oct 21, 1999
Oct 21, 1999
926
927
void close_music(void)
{
Oct 17, 2017
Oct 17, 2017
928
929
int i;
May 22, 2013
May 22, 2013
930
Mix_HaltMusic();
Oct 17, 2017
Oct 17, 2017
931
932
933
934
935
936
937
938
939
940
941
942
for (i = 0; i < SDL_arraysize(s_music_interfaces); ++i) {
Mix_MusicInterface *interface = s_music_interfaces[i];
if (!interface || !interface->opened) {
continue;
}
if (interface->Close) {
interface->Close();
}
interface->opened = SDL_FALSE;
}
Jun 5, 2009
Jun 5, 2009
943
Oct 21, 2017
Oct 21, 2017
944
945
946
947
948
if (soundfont_paths) {
SDL_free(soundfont_paths);
soundfont_paths = NULL;
}
May 22, 2013
May 22, 2013
949
/* rcg06042009 report available decoders at runtime. */
Oct 21, 2017
Oct 21, 2017
950
951
952
953
if (music_decoders) {
SDL_free((void *)music_decoders);
music_decoders = NULL;
}
May 22, 2013
May 22, 2013
954
num_decoders = 0;
Jan 24, 2011
Jan 24, 2011
955
May 22, 2013
May 22, 2013
956
ms_per_step = 0;
Oct 21, 1999
Oct 21, 1999
957
958
}
Oct 17, 2017
Oct 17, 2017
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
/* Unload the music interface libraries */
void unload_music(void)
{
int i;
for (i = 0; i < SDL_arraysize(s_music_interfaces); ++i) {
Mix_MusicInterface *interface = s_music_interfaces[i];
if (!interface || !interface->loaded) {
continue;
}
if (interface->Unload) {
interface->Unload();
}
interface->loaded = SDL_FALSE;
}
}
Mar 20, 2011
Mar 20, 2011
976
977
int Mix_SetSoundFonts(const char *paths)
{
May 22, 2013
May 22, 2013
978
979
980
981
982
983
984
985
986
987
988
989
if (soundfont_paths) {
SDL_free(soundfont_paths);
soundfont_paths = NULL;
}
if (paths) {
if (!(soundfont_paths = SDL_strdup(paths))) {
Mix_SetError("Insufficient memory to set SoundFonts");
return 0;
}
}
return 1;
Mar 20, 2011
Mar 20, 2011
990
991
}
Jun 5, 2011
Jun 5, 2011
992
const char* Mix_GetSoundFonts(void)
Mar 20, 2011
Mar 20, 2011
993
{
Oct 21, 2017
Oct 21, 2017
994
995
996
997
998
999
const char *env_paths = SDL_getenv("SDL_SOUNDFONTS");
SDL_bool force_env_paths = SDL_GetHintBoolean("SDL_FORCE_SOUNDFONTS", SDL_FALSE);
if (force_env_paths && (!env_paths || !*env_paths)) {
force_env_paths = SDL_FALSE;
}
if (soundfont_paths && *soundfont_paths && !force_env_paths) {
May 22, 2013
May 22, 2013
1000
return soundfont_paths;