Skip to content

Latest commit

 

History

History
1133 lines (994 loc) · 30.4 KB

music.c

File metadata and controls

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