music.c
author Sam Lantinga <slouken@libsdl.org>
Sun, 24 Mar 2002 02:06:12 +0000
changeset 163 1e195b569764
parent 161 2a4946fc5a62
child 168 6bc3db482570
permissions -rw-r--r--
jean-julien Filatriau - Sat Mar 23 18:05:37 PST 2002
* Fixed setting invalid volume when querying mixer and music volumes
slouken@0
     1
/*
slouken@138
     2
    SDL_mixer:  An audio mixer library based on the SDL library
slouken@138
     3
    Copyright (C) 1997, 1998, 1999, 2000, 2001  Sam Lantinga
slouken@0
     4
slouken@138
     5
    This library is free software; you can redistribute it and/or
slouken@138
     6
    modify it under the terms of the GNU Library General Public
slouken@138
     7
    License as published by the Free Software Foundation; either
slouken@138
     8
    version 2 of the License, or (at your option) any later version.
slouken@0
     9
slouken@138
    10
    This library is distributed in the hope that it will be useful,
slouken@138
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
slouken@138
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
slouken@138
    13
    Library General Public License for more details.
slouken@0
    14
slouken@138
    15
    You should have received a copy of the GNU Library General Public
slouken@138
    16
    License along with this library; if not, write to the Free
slouken@138
    17
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
slouken@0
    18
slouken@138
    19
    Sam Lantinga
slouken@138
    20
    slouken@libsdl.org
slouken@0
    21
*/
slouken@0
    22
slouken@140
    23
/* $Id$ */
slouken@138
    24
slouken@3
    25
#include <stdlib.h>
slouken@3
    26
#include <string.h>
slouken@125
    27
#include <ctype.h>
slouken@24
    28
#include "SDL_endian.h"
slouken@24
    29
#include "SDL_audio.h"
slouken@29
    30
#include "SDL_timer.h"
slouken@0
    31
slouken@34
    32
#include "SDL_mixer.h"
slouken@0
    33
slouken@0
    34
/* The music command hack is UNIX specific */
slouken@0
    35
#ifndef unix
slouken@0
    36
#undef CMD_MUSIC
slouken@0
    37
#endif
slouken@0
    38
slouken@0
    39
#ifdef CMD_MUSIC
slouken@0
    40
#include "music_cmd.h"
slouken@0
    41
#endif
slouken@0
    42
#ifdef WAV_MUSIC
slouken@0
    43
#include "wavestream.h"
slouken@0
    44
#endif
slouken@0
    45
#ifdef MOD_MUSIC
slouken@29
    46
#  include "mikmod.h"
slouken@29
    47
#  if defined(LIBMIKMOD_VERSION)                /* libmikmod 3.1.8 */
slouken@29
    48
#    define UNIMOD			MODULE
slouken@29
    49
#    define MikMod_Init()		MikMod_Init(NULL)
slouken@29
    50
#    define MikMod_LoadSong(a,b)	Player_Load(a,b,0)
slouken@29
    51
#    define MikMod_FreeSong		Player_Free
slouken@29
    52
     extern int MikMod_errno;
slouken@29
    53
#  else                                        /* old MikMod 3.0.3 */
slouken@29
    54
#    define MikMod_strerror(x)		_mm_errmsg[x])
slouken@29
    55
#    define MikMod_errno		_mm_errno
slouken@29
    56
#  endif
slouken@0
    57
#endif
slouken@0
    58
#ifdef MID_MUSIC
slouken@106
    59
#  ifdef USE_TIMIDITY_MIDI
slouken@106
    60
#    include "timidity.h"
slouken@106
    61
#  endif
slouken@106
    62
#  ifdef USE_NATIVE_MIDI
slouken@106
    63
#    include "native_midi.h"
slouken@106
    64
#  endif
slouken@106
    65
#  if defined(USE_TIMIDITY_MIDI) && defined(USE_NATIVE_MIDI)
slouken@106
    66
#    define MIDI_ELSE	else
slouken@106
    67
#  else
slouken@106
    68
#    define MIDI_ELSE
slouken@106
    69
#  endif
slouken@0
    70
#endif
slouken@63
    71
#ifdef OGG_MUSIC
slouken@63
    72
#include "music_ogg.h"
slouken@63
    73
#endif
slouken@0
    74
#ifdef MP3_MUSIC
slouken@83
    75
#include "smpeg.h"
slouken@0
    76
slouken@0
    77
static SDL_AudioSpec used_mixer;
slouken@0
    78
#endif
slouken@0
    79
slouken@42
    80
int volatile music_active = 1;
slouken@42
    81
static int volatile music_stopped = 0;
slouken@0
    82
static int music_loops = 0;
slouken@0
    83
static char *music_cmd = NULL;
slouken@42
    84
static Mix_Music * volatile music_playing = NULL;
slouken@17
    85
static int music_volume = MIX_MAX_VOLUME;
slouken@0
    86
static int music_swap8;
slouken@0
    87
static int music_swap16;
megastep@4
    88
slouken@0
    89
struct _Mix_Music {
slouken@0
    90
	enum {
slouken@0
    91
		MUS_CMD,
slouken@0
    92
		MUS_WAV,
slouken@0
    93
		MUS_MOD,
slouken@0
    94
		MUS_MID,
slouken@63
    95
		MUS_OGG,
slouken@0
    96
		MUS_MP3
slouken@0
    97
	} type;
slouken@0
    98
	union {
slouken@0
    99
#ifdef CMD_MUSIC
slouken@0
   100
		MusicCMD *cmd;
slouken@0
   101
#endif
slouken@0
   102
#ifdef WAV_MUSIC
slouken@0
   103
		WAVStream *wave;
slouken@0
   104
#endif
slouken@0
   105
#ifdef MOD_MUSIC
slouken@0
   106
		UNIMOD *module;
slouken@0
   107
#endif
slouken@0
   108
#ifdef MID_MUSIC
slouken@106
   109
#ifdef USE_TIMIDITY_MIDI
slouken@0
   110
		MidiSong *midi;
slouken@106
   111
#endif
slouken@98
   112
#ifdef USE_NATIVE_MIDI
slouken@98
   113
		NativeMidiSong *nativemidi;
slouken@98
   114
#endif
slouken@0
   115
#endif
slouken@63
   116
#ifdef OGG_MUSIC
slouken@63
   117
		OGG_music *ogg;
slouken@63
   118
#endif
slouken@0
   119
#ifdef MP3_MUSIC
slouken@0
   120
		SMPEG *mp3;
slouken@0
   121
#endif
slouken@0
   122
	} data;
megastep@4
   123
	Mix_Fading fading;
megastep@4
   124
	int fade_volume;
slouken@17
   125
	int fade_step;
slouken@17
   126
	int fade_steps;
slouken@0
   127
	int error;
slouken@0
   128
};
slouken@29
   129
#ifdef MID_MUSIC
slouken@106
   130
#ifdef USE_TIMIDITY_MIDI
slouken@0
   131
static int timidity_ok;
slouken@142
   132
static int samplesize;
slouken@106
   133
#endif
slouken@98
   134
#ifdef USE_NATIVE_MIDI
slouken@98
   135
static int native_midi_ok;
slouken@98
   136
#endif
slouken@29
   137
#endif
slouken@0
   138
slouken@17
   139
/* Used to calculate fading steps */
slouken@17
   140
static int ms_per_step;
slouken@17
   141
megastep@10
   142
/* Local low-level functions prototypes */
megastep@7
   143
static void lowlevel_halt(void);
megastep@10
   144
static int  lowlevel_play(Mix_Music *music);
megastep@7
   145
slouken@29
   146
slouken@29
   147
/* Support for hooking when the music has finished */
slouken@29
   148
static void (*music_finished_hook)(void) = NULL;
slouken@29
   149
slouken@29
   150
void Mix_HookMusicFinished(void (*music_finished)(void))
slouken@29
   151
{
slouken@29
   152
	SDL_LockAudio();
slouken@29
   153
	music_finished_hook = music_finished;
slouken@29
   154
	SDL_UnlockAudio();
slouken@29
   155
}
slouken@29
   156
slouken@29
   157
slouken@0
   158
/* Mixing function */
slouken@0
   159
void music_mixer(void *udata, Uint8 *stream, int len)
slouken@0
   160
{
slouken@0
   161
	if ( music_playing ) {
megastep@7
   162
		if ( music_stopped ) {
megastep@7
   163
			/* To avoid concurrency problems and the use of mutexes,
megastep@7
   164
			   the music is always stopped from the sound thread */
megastep@7
   165
			lowlevel_halt(); /* This function sets music_playing to NULL */
megastep@7
   166
			return;
slouken@29
   167
		}
megastep@13
   168
		/* Handle fading */
slouken@17
   169
		if ( music_playing->fading != MIX_NO_FADING ) {
slouken@17
   170
			if ( music_playing->fade_step++ < music_playing->fade_steps ) {
slouken@26
   171
				int fade_volume = music_playing->fade_volume;
slouken@26
   172
				int fade_step = music_playing->fade_step;
slouken@26
   173
				int fade_steps = music_playing->fade_steps;
slouken@17
   174
megastep@4
   175
				if ( music_playing->fading == MIX_FADING_OUT ) {
slouken@29
   176
					Mix_VolumeMusic((fade_volume * (fade_steps-fade_step))
slouken@17
   177
									/ fade_steps);
slouken@17
   178
				} else { /* Fading in */
slouken@17
   179
					Mix_VolumeMusic((fade_volume * fade_step) / fade_steps);
slouken@17
   180
				}
slouken@17
   181
			} else {
slouken@17
   182
				if ( music_playing->fading == MIX_FADING_OUT ) {
slouken@17
   183
					lowlevel_halt();
megastep@4
   184
					return;
megastep@4
   185
				}
megastep@4
   186
				music_playing->fading = MIX_NO_FADING;
megastep@4
   187
			}
megastep@4
   188
		}
megastep@13
   189
		/* Restart music if it has to loop */
slouken@29
   190
		if ( !Mix_PlayingMusic() ) {
slouken@29
   191
			/* Restart music if it has to loop */
slouken@29
   192
			if ( music_loops && --music_loops ) {
megastep@11
   193
				Mix_RewindMusic();
megastep@11
   194
				if ( lowlevel_play(music_playing) < 0 ) {
megastep@11
   195
					fprintf(stderr,"Warning: Music restart failed.\n");
megastep@11
   196
					music_stopped = 1; /* Something went wrong */
megastep@11
   197
					music_playing->fading = MIX_NO_FADING;
megastep@11
   198
				}
megastep@11
   199
			}
slouken@29
   200
			else if (music_finished_hook) {
slouken@29
   201
			    lowlevel_halt();
slouken@29
   202
			    music_finished_hook();
slouken@29
   203
			    return;
slouken@29
   204
			}
megastep@11
   205
		}
megastep@16
   206
		if ( music_volume <= 0 ) { /* Don't mix if volume is null */
megastep@16
   207
			return;
megastep@16
   208
		}
slouken@0
   209
		switch (music_playing->type) {
slouken@0
   210
#ifdef CMD_MUSIC
slouken@0
   211
			case MUS_CMD:
slouken@0
   212
				/* The playing is done externally */
slouken@0
   213
				break;
slouken@0
   214
#endif
slouken@0
   215
#ifdef WAV_MUSIC
slouken@0
   216
			case MUS_WAV:
slouken@64
   217
				WAVStream_PlaySome(stream, len);
slouken@0
   218
				break;
slouken@0
   219
#endif
slouken@0
   220
#ifdef MOD_MUSIC
slouken@0
   221
			case MUS_MOD:
slouken@0
   222
				VC_WriteBytes((SBYTE *)stream, len);
slouken@0
   223
				if ( music_swap8 ) {
slouken@0
   224
					Uint8 *dst;
slouken@42
   225
					int i;
slouken@0
   226
slouken@0
   227
					dst = stream;
slouken@0
   228
					for ( i=len; i; --i ) {
slouken@0
   229
						*dst++ ^= 0x80;
slouken@0
   230
					}
slouken@0
   231
				} else
slouken@0
   232
				if ( music_swap16 ) {
slouken@0
   233
					Uint8 *dst, tmp;
slouken@42
   234
					int i;
slouken@0
   235
slouken@0
   236
					dst = stream;
slouken@0
   237
					for ( i=(len/2); i; --i ) {
slouken@0
   238
						tmp = dst[0];
slouken@0
   239
						dst[0] = dst[1];
slouken@0
   240
						dst[1] = tmp;
slouken@0
   241
						dst += 2;
slouken@0
   242
					}
slouken@0
   243
				}
slouken@0
   244
				break;
slouken@0
   245
#endif
slouken@0
   246
#ifdef MID_MUSIC
slouken@106
   247
#ifdef USE_TIMIDITY_MIDI
slouken@0
   248
			case MUS_MID:
slouken@98
   249
				if ( timidity_ok ) {
slouken@98
   250
					int samples = len / samplesize;
slouken@98
   251
  					Timidity_PlaySome(stream, samples);
slouken@98
   252
				}
slouken@0
   253
				break;
slouken@0
   254
#endif
slouken@106
   255
#endif
slouken@63
   256
#ifdef OGG_MUSIC
slouken@63
   257
			case MUS_OGG:
slouken@63
   258
				OGG_playAudio(music_playing->data.ogg, stream, len);
slouken@63
   259
				break;
slouken@63
   260
#endif
slouken@0
   261
#ifdef MP3_MUSIC
slouken@26
   262
			case MUS_MP3:
slouken@26
   263
				SMPEG_playAudio(music_playing->data.mp3, stream, len);
slouken@0
   264
				break;
slouken@0
   265
#endif
slouken@0
   266
			default:
slouken@0
   267
				/* Unknown music type?? */
slouken@0
   268
				break;
slouken@0
   269
		}
slouken@0
   270
	}
slouken@0
   271
}
slouken@0
   272
slouken@0
   273
/* Initialize the music players with a certain desired audio format */
slouken@0
   274
int open_music(SDL_AudioSpec *mixer)
slouken@0
   275
{
slouken@0
   276
	int music_error;
slouken@0
   277
slouken@0
   278
	music_error = 0;
slouken@0
   279
#ifdef WAV_MUSIC
slouken@0
   280
	if ( WAVStream_Init(mixer) < 0 ) {
slouken@0
   281
		++music_error;
slouken@0
   282
	}
slouken@0
   283
#endif
slouken@0
   284
#ifdef MOD_MUSIC
slouken@0
   285
	/* Set the MikMod music format */
slouken@0
   286
	music_swap8 = 0;
slouken@0
   287
	music_swap16 = 0;
slouken@0
   288
	switch (mixer->format) {
slouken@0
   289
slouken@0
   290
		case AUDIO_U8:
slouken@0
   291
		case AUDIO_S8: {
slouken@0
   292
			if ( mixer->format == AUDIO_S8 ) {
slouken@0
   293
				music_swap8 = 1;
slouken@0
   294
			}
slouken@0
   295
			md_mode = 0;
slouken@0
   296
		}
slouken@0
   297
		break;
slouken@0
   298
slouken@0
   299
		case AUDIO_S16LSB:
slouken@0
   300
		case AUDIO_S16MSB: {
slouken@0
   301
			/* See if we need to correct MikMod mixing */
slouken@0
   302
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
slouken@0
   303
			if ( mixer->format == AUDIO_S16MSB ) {
slouken@0
   304
#else
slouken@0
   305
			if ( mixer->format == AUDIO_S16LSB ) {
slouken@0
   306
#endif
slouken@0
   307
				music_swap16 = 1;
slouken@0
   308
			}
slouken@0
   309
			md_mode = DMODE_16BITS;
slouken@0
   310
		}
slouken@0
   311
		break;
slouken@0
   312
slouken@0
   313
		default: {
slouken@26
   314
			Mix_SetError("Unknown hardware audio format");
slouken@0
   315
			++music_error;
slouken@0
   316
		}
slouken@0
   317
	}
slouken@0
   318
	if ( mixer->channels > 1 ) {
slouken@0
   319
		if ( mixer->channels > 2 ) {
slouken@26
   320
			Mix_SetError("Hardware uses more channels than mixer");
slouken@0
   321
			++music_error;
slouken@0
   322
		}
slouken@0
   323
		md_mode |= DMODE_STEREO;
slouken@0
   324
	}
slouken@26
   325
	md_mixfreq	 = mixer->freq;
slouken@26
   326
	md_device	  = 0;
slouken@26
   327
	md_volume	  = 96;
slouken@0
   328
	md_musicvolume = 128;
slouken@0
   329
	md_sndfxvolume = 128;
slouken@26
   330
	md_pansep	  = 128;
slouken@26
   331
	md_reverb	  = 0;
slouken@0
   332
	MikMod_RegisterAllLoaders();
slouken@0
   333
	MikMod_RegisterAllDrivers();
slouken@0
   334
	if ( MikMod_Init() ) {
slouken@29
   335
		Mix_SetError("%s", MikMod_strerror(MikMod_errno));
slouken@0
   336
		++music_error;
slouken@0
   337
	}
slouken@0
   338
#endif
slouken@0
   339
#ifdef MID_MUSIC
slouken@106
   340
#ifdef USE_TIMIDITY_MIDI
slouken@142
   341
	samplesize = mixer->size / mixer->samples;
slouken@100
   342
	if ( Timidity_Init(mixer->freq, mixer->format,
slouken@102
   343
	                    mixer->channels, mixer->samples) == 0 ) {
slouken@100
   344
		timidity_ok = 1;
slouken@0
   345
	} else {
slouken@0
   346
		timidity_ok = 0;
slouken@0
   347
	}
slouken@106
   348
#endif
slouken@100
   349
#ifdef USE_NATIVE_MIDI
slouken@106
   350
#ifdef USE_TIMIDITY_MIDI
slouken@100
   351
	native_midi_ok = !timidity_ok;
slouken@106
   352
	if ( native_midi_ok )
slouken@106
   353
#endif
slouken@101
   354
		native_midi_ok = native_midi_detect();
slouken@100
   355
#endif
slouken@0
   356
#endif
slouken@63
   357
#ifdef OGG_MUSIC
slouken@63
   358
	if ( OGG_init(mixer) < 0 ) {
slouken@63
   359
		++music_error;
slouken@63
   360
	}
slouken@63
   361
#endif
slouken@0
   362
#ifdef MP3_MUSIC
slouken@0
   363
	/* Keep a copy of the mixer */
slouken@0
   364
	used_mixer = *mixer;
slouken@0
   365
#endif
slouken@42
   366
	music_playing = NULL;
megastep@7
   367
	music_stopped = 0;
slouken@0
   368
	if ( music_error ) {
slouken@0
   369
		return(-1);
slouken@0
   370
	}
slouken@0
   371
	Mix_VolumeMusic(SDL_MIX_MAXVOLUME);
slouken@0
   372
slouken@26
   373
	/* Calculate the number of ms for each callback */
slouken@44
   374
	ms_per_step = (int) (((float)mixer->samples * 1000.0) / mixer->freq);
slouken@17
   375
slouken@0
   376
	return(0);
slouken@0
   377
}
slouken@0
   378
slouken@125
   379
/* Portable case-insensitive string compare function */
slouken@125
   380
int MIX_string_equals(const char *str1, const char *str2)
slouken@125
   381
{
slouken@125
   382
	while ( *str1 && *str2 ) {
slouken@125
   383
		if ( toupper((unsigned char)*str1) !=
slouken@125
   384
		     toupper((unsigned char)*str2) )
slouken@125
   385
			break;
slouken@125
   386
		++str1;
slouken@125
   387
		++str2;
slouken@125
   388
	}
slouken@125
   389
	return (!*str1 && !*str2);
slouken@125
   390
}
slouken@125
   391
slouken@0
   392
/* Load a music file */
slouken@0
   393
Mix_Music *Mix_LoadMUS(const char *file)
slouken@0
   394
{
slouken@0
   395
	FILE *fp;
slouken@125
   396
	char *ext;
slouken@52
   397
	Uint8 magic[5];
slouken@0
   398
	Mix_Music *music;
slouken@0
   399
slouken@0
   400
	/* Figure out what kind of file this is */
slouken@0
   401
	fp = fopen(file, "rb");
slouken@0
   402
	if ( (fp == NULL) || !fread(magic, 4, 1, fp) ) {
slouken@0
   403
		if ( fp != NULL ) {
slouken@0
   404
			fclose(fp);
slouken@0
   405
		}
slouken@26
   406
		Mix_SetError("Couldn't read from '%s'", file);
slouken@0
   407
		return(NULL);
slouken@0
   408
	}
slouken@0
   409
	magic[4] = '\0';
slouken@0
   410
	fclose(fp);
slouken@0
   411
slouken@125
   412
	/* Figure out the file extension, so we can determine the type */
slouken@125
   413
	ext = strrchr(file, '.');
slouken@125
   414
	if ( ext ) ++ext; /* skip the dot in the extension */
slouken@125
   415
slouken@0
   416
	/* Allocate memory for the music structure */
slouken@0
   417
	music = (Mix_Music *)malloc(sizeof(Mix_Music));
slouken@0
   418
	if ( music == NULL ) {
slouken@26
   419
		Mix_SetError("Out of memory");
slouken@0
   420
		return(NULL);
slouken@0
   421
	}
slouken@0
   422
	music->error = 0;
slouken@0
   423
slouken@0
   424
#ifdef CMD_MUSIC
slouken@0
   425
	if ( music_cmd ) {
slouken@0
   426
		music->type = MUS_CMD;
slouken@0
   427
		music->data.cmd = MusicCMD_LoadSong(music_cmd, file);
slouken@0
   428
		if ( music->data.cmd == NULL ) {
slouken@0
   429
			music->error = 1;
slouken@0
   430
		}
slouken@0
   431
	} else
slouken@0
   432
#endif
slouken@0
   433
#ifdef WAV_MUSIC
slouken@0
   434
	/* WAVE files have the magic four bytes "RIFF"
slouken@0
   435
	   AIFF files have the magic 12 bytes "FORM" XXXX "AIFF"
slouken@0
   436
	 */
slouken@135
   437
	if ( (ext && MIX_string_equals(ext, "WAV")) ||
slouken@125
   438
	     (strcmp((char *)magic, "RIFF") == 0) ||
slouken@57
   439
	     (strcmp((char *)magic, "FORM") == 0) ) {
slouken@0
   440
		music->type = MUS_WAV;
slouken@57
   441
		music->data.wave = WAVStream_LoadSong(file, (char *)magic);
slouken@0
   442
		if ( music->data.wave == NULL ) {
slouken@135
   443
		  	Mix_SetError("Unable to load WAV file");
slouken@0
   444
			music->error = 1;
slouken@0
   445
		}
slouken@0
   446
	} else
slouken@0
   447
#endif
slouken@0
   448
#ifdef MID_MUSIC
slouken@0
   449
	/* MIDI files have the magic four bytes "MThd" */
slouken@135
   450
	if ( (ext && MIX_string_equals(ext, "MID")) ||
slouken@135
   451
	     (ext && MIX_string_equals(ext, "MIDI")) ||
slouken@133
   452
	     strcmp((char *)magic, "MThd") == 0 ) {
slouken@0
   453
		music->type = MUS_MID;
slouken@98
   454
#ifdef USE_NATIVE_MIDI
slouken@98
   455
  		if ( native_midi_ok ) {
slouken@98
   456
  			music->data.nativemidi = native_midi_loadsong((char *)file);
slouken@98
   457
	  		if ( music->data.nativemidi == NULL ) {
slouken@98
   458
		  		Mix_SetError("%s", native_midi_error());
slouken@98
   459
			  	music->error = 1;
slouken@98
   460
			}
slouken@106
   461
	  	} MIDI_ELSE
slouken@98
   462
#endif
slouken@106
   463
#ifdef USE_TIMIDITY_MIDI
slouken@0
   464
		if ( timidity_ok ) {
slouken@0
   465
			music->data.midi = Timidity_LoadSong((char *)file);
slouken@0
   466
			if ( music->data.midi == NULL ) {
slouken@26
   467
				Mix_SetError("%s", Timidity_Error());
slouken@0
   468
				music->error = 1;
slouken@0
   469
			}
slouken@98
   470
		} else {
slouken@26
   471
			Mix_SetError("%s", Timidity_Error());
slouken@0
   472
			music->error = 1;
slouken@0
   473
		}
slouken@106
   474
#endif
slouken@0
   475
	} else
slouken@0
   476
#endif
slouken@63
   477
#ifdef OGG_MUSIC
slouken@63
   478
	/* Ogg Vorbis files have the magic four bytes "OggS" */
slouken@135
   479
	if ( (ext && MIX_string_equals(ext, "OGG")) ||
slouken@133
   480
	     strcmp((char *)magic, "OggS") == 0 ) {
slouken@63
   481
		music->type = MUS_OGG;
slouken@63
   482
		music->data.ogg = OGG_new(file);
slouken@63
   483
		if ( music->data.ogg == NULL ) {
slouken@63
   484
			music->error = 1;
slouken@63
   485
		}
slouken@63
   486
	} else
slouken@63
   487
#endif
slouken@0
   488
#ifdef MP3_MUSIC
slouken@135
   489
	if ( (ext && MIX_string_equals(ext, "MPG")) ||
slouken@135
   490
	     (ext && MIX_string_equals(ext, "MPEG")) ||
slouken@125
   491
	     magic[0]==0xFF && (magic[1]&0xF0)==0xF0) {
slouken@0
   492
		SMPEG_Info info;
slouken@0
   493
		music->type = MUS_MP3;
slouken@0
   494
		music->data.mp3 = SMPEG_new(file, &info, 0);
slouken@0
   495
		if(!info.has_audio){
slouken@26
   496
			Mix_SetError("MPEG file does not have any audio stream.");
slouken@0
   497
			music->error = 1;
slouken@0
   498
		}else{
slouken@0
   499
			SMPEG_actualSpec(music->data.mp3, &used_mixer);
slouken@0
   500
		}
slouken@0
   501
	} else
slouken@0
   502
#endif
slouken@0
   503
#ifdef MOD_MUSIC
slouken@0
   504
	if ( 1 ) {
slouken@0
   505
		music->type = MUS_MOD;
slouken@0
   506
		music->data.module = MikMod_LoadSong((char *)file, 64);
slouken@0
   507
		if ( music->data.module == NULL ) {
slouken@29
   508
			Mix_SetError("%s", MikMod_strerror(MikMod_errno));
slouken@0
   509
			music->error = 1;
slouken@126
   510
		} else {
slouken@126
   511
			/* Stop implicit looping, fade out and other flags. */
slouken@126
   512
			music->data.module->extspd  = 1;
slouken@126
   513
			music->data.module->panflag = 1;
slouken@126
   514
			music->data.module->wrap    = 0;
slouken@126
   515
			music->data.module->loop    = 0;
slouken@129
   516
#if 0 /* Don't set fade out by default - unfortunately there's no real way
slouken@129
   517
         to query the status of the song or set trigger actions.  Hum. */
slouken@126
   518
			music->data.module->fadeout = 1;
slouken@129
   519
#endif
slouken@0
   520
		}
slouken@0
   521
	} else
slouken@0
   522
#endif
slouken@0
   523
	{
slouken@26
   524
		Mix_SetError("Unrecognized music format");
slouken@0
   525
		music->error = 1;
slouken@0
   526
	}
slouken@0
   527
	if ( music->error ) {
slouken@0
   528
		free(music);
slouken@0
   529
		music = NULL;
slouken@0
   530
	}
slouken@0
   531
	return(music);
slouken@0
   532
}
slouken@0
   533
slouken@0
   534
/* Free a music chunk previously loaded */
slouken@0
   535
void Mix_FreeMusic(Mix_Music *music)
slouken@0
   536
{
slouken@0
   537
	if ( music ) {
slouken@0
   538
		/* Caution: If music is playing, mixer will crash */
megastep@7
   539
		if ( music == music_playing && !music_stopped ) {
megastep@4
   540
			if ( music->fading == MIX_FADING_OUT ) {
megastep@4
   541
				/* Wait for the fade out to finish */
slouken@17
   542
				while ( music_playing && !music_stopped && (music_playing->fading == MIX_FADING_OUT) )
megastep@4
   543
					SDL_Delay(100);
megastep@4
   544
			} else {
megastep@4
   545
				Mix_HaltMusic(); /* Stop it immediately */
megastep@4
   546
			}
slouken@0
   547
		}
slouken@0
   548
		switch (music->type) {
slouken@0
   549
#ifdef CMD_MUSIC
slouken@0
   550
			case MUS_CMD:
slouken@0
   551
				MusicCMD_FreeSong(music->data.cmd);
slouken@0
   552
				break;
slouken@0
   553
#endif
slouken@0
   554
#ifdef WAV_MUSIC
slouken@0
   555
			case MUS_WAV:
slouken@0
   556
				WAVStream_FreeSong(music->data.wave);
slouken@0
   557
				break;
slouken@0
   558
#endif
slouken@0
   559
#ifdef MOD_MUSIC
slouken@0
   560
			case MUS_MOD:
slouken@0
   561
				MikMod_FreeSong(music->data.module);
slouken@0
   562
				break;
slouken@0
   563
#endif
slouken@0
   564
#ifdef MID_MUSIC
slouken@0
   565
			case MUS_MID:
slouken@98
   566
#ifdef USE_NATIVE_MIDI
slouken@98
   567
  				if ( native_midi_ok ) {
slouken@98
   568
					native_midi_freesong(music->data.nativemidi);
slouken@106
   569
				} MIDI_ELSE
slouken@98
   570
#endif
slouken@106
   571
#ifdef USE_TIMIDITY_MIDI
slouken@98
   572
				if ( timidity_ok ) {
slouken@98
   573
					Timidity_FreeSong(music->data.midi);
slouken@98
   574
				}
slouken@106
   575
#endif
slouken@0
   576
				break;
slouken@0
   577
#endif
slouken@63
   578
#ifdef OGG_MUSIC
slouken@63
   579
			case MUS_OGG:
slouken@63
   580
				OGG_delete(music->data.ogg);
slouken@63
   581
				break;
slouken@63
   582
#endif
slouken@0
   583
#ifdef MP3_MUSIC
slouken@26
   584
			case MUS_MP3:
slouken@0
   585
				SMPEG_delete(music->data.mp3);
slouken@0
   586
				break;
slouken@0
   587
#endif
slouken@0
   588
			default:
slouken@0
   589
				/* Unknown music type?? */
slouken@0
   590
				break;
slouken@0
   591
		}
slouken@0
   592
		free(music);
slouken@0
   593
	}
slouken@0
   594
}
slouken@0
   595
megastep@10
   596
static int lowlevel_play(Mix_Music *music)
slouken@0
   597
{
megastep@10
   598
	if(!music)
slouken@0
   599
		return(-1);
megastep@10
   600
slouken@0
   601
	switch (music->type) {
slouken@0
   602
#ifdef CMD_MUSIC
slouken@0
   603
		case MUS_CMD:
slouken@0
   604
			MusicCMD_SetVolume(music_volume);
slouken@0
   605
			MusicCMD_Start(music->data.cmd);
slouken@0
   606
			break;
slouken@0
   607
#endif
slouken@0
   608
#ifdef WAV_MUSIC
slouken@0
   609
		case MUS_WAV:
slouken@0
   610
			WAVStream_SetVolume(music_volume);
slouken@0
   611
			WAVStream_Start(music->data.wave);
slouken@0
   612
			break;
slouken@0
   613
#endif
slouken@0
   614
#ifdef MOD_MUSIC
slouken@0
   615
		case MUS_MOD:
slouken@42
   616
			Player_SetVolume((SWORD)music_volume);
slouken@0
   617
			Player_Start(music->data.module);
slouken@0
   618
			Player_SetPosition(0);
slouken@0
   619
			break;
slouken@0
   620
#endif
slouken@0
   621
#ifdef MID_MUSIC
slouken@0
   622
		case MUS_MID:
slouken@98
   623
#ifdef USE_NATIVE_MIDI
slouken@98
   624
  			if ( native_midi_ok ) {
slouken@98
   625
				native_midi_setvolume(music_volume);
slouken@98
   626
				native_midi_start(music->data.nativemidi);
slouken@106
   627
			} MIDI_ELSE
slouken@98
   628
#endif
slouken@106
   629
#ifdef USE_TIMIDITY_MIDI
slouken@98
   630
			if ( timidity_ok ) {
slouken@98
   631
				Timidity_SetVolume(music_volume);
slouken@98
   632
				Timidity_Start(music->data.midi);
slouken@98
   633
			}
slouken@106
   634
#endif
slouken@0
   635
			break;
slouken@0
   636
#endif
slouken@63
   637
#ifdef OGG_MUSIC
slouken@63
   638
		case MUS_OGG:
slouken@63
   639
			OGG_setvolume(music->data.ogg, music_volume);
slouken@63
   640
			OGG_play(music->data.ogg);
slouken@63
   641
			break;
slouken@63
   642
#endif
slouken@0
   643
#ifdef MP3_MUSIC
slouken@26
   644
		case MUS_MP3:
slouken@0
   645
			SMPEG_enableaudio(music->data.mp3,1);
slouken@0
   646
			SMPEG_enablevideo(music->data.mp3,0);
slouken@83
   647
			SMPEG_setvolume(music->data.mp3,(int)(((float)music_volume/(float)MIX_MAX_VOLUME)*100.0));
slouken@0
   648
			SMPEG_play(music->data.mp3);
slouken@0
   649
			break;
slouken@0
   650
#endif
slouken@0
   651
		default:
slouken@0
   652
			/* Unknown music type?? */
slouken@0
   653
			return(-1);
slouken@0
   654
	}
megastep@10
   655
	return(0);
megastep@10
   656
}
megastep@10
   657
megastep@10
   658
/* Play a music chunk.  Returns 0, or -1 if there was an error.
megastep@10
   659
*/
megastep@10
   660
int Mix_PlayMusic(Mix_Music *music, int loops)
megastep@10
   661
{
megastep@10
   662
	/* Don't play null pointers :-) */
megastep@10
   663
	if ( music == NULL ) {
megastep@10
   664
		return(-1);
megastep@10
   665
	}
megastep@10
   666
	/* If the current music is fading out, wait for the fade to complete */
megastep@10
   667
	while ( music_playing && !music_stopped && music_playing->fading==MIX_FADING_OUT ) {
megastep@10
   668
		SDL_Delay(100);
megastep@10
   669
	}
megastep@10
   670
slouken@17
   671
	if ( lowlevel_play(music) < 0 ) {
megastep@10
   672
		return(-1);
slouken@26
   673
	}
slouken@0
   674
	music_active = 1;
megastep@7
   675
	music_stopped = 0;
megastep@10
   676
	music_loops = loops;
slouken@0
   677
	music_playing = music;
megastep@4
   678
	music_playing->fading = MIX_NO_FADING;
megastep@4
   679
	return(0);
megastep@4
   680
}
megastep@4
   681
slouken@155
   682
int Mix_SetMusicPosition(double position)
slouken@154
   683
{
slouken@154
   684
	if ( music_playing && !music_stopped ) {
slouken@154
   685
		switch ( music_playing->type ) {
slouken@154
   686
#ifdef MOD_MUSIC
slouken@154
   687
		case MUS_MOD:
slouken@154
   688
			Player_SetPosition(position);
slouken@154
   689
			return(0);
slouken@154
   690
			break;
slouken@154
   691
#endif
slouken@155
   692
#ifdef OGG_MUSIC
slouken@155
   693
		case MUS_OGG:
slouken@155
   694
			OGG_jump_to_time(music_playing->data.ogg, position);
slouken@155
   695
			return(0);
slouken@155
   696
			break;
slouken@155
   697
#endif
slouken@158
   698
#ifdef MP3_MUSIC
slouken@158
   699
		case MUS_MP3:
slouken@158
   700
			SMPEG_skip(music_playing->data.mp3, position);
slouken@158
   701
			return(0);
slouken@158
   702
			break;
slouken@158
   703
#endif
slouken@154
   704
		default:
slouken@154
   705
			/* TODO: Implement this for other music backends */
slouken@154
   706
			break;
slouken@154
   707
		}
slouken@154
   708
	}
slouken@155
   709
	return(-1);
slouken@154
   710
}
slouken@154
   711
megastep@4
   712
/* Fade in a music over "ms" milliseconds */
slouken@155
   713
int Mix_FadeInMusicPos(Mix_Music *music, int loops, int ms, double position)
megastep@4
   714
{
megastep@4
   715
	if ( music && music_volume > 0 ) { /* No need to fade if we can't hear it */
megastep@4
   716
		music->fade_volume = music_volume;
megastep@4
   717
		music_volume = 0;
slouken@17
   718
		if ( Mix_PlayMusic(music, loops) < 0 ) {
megastep@4
   719
			return(-1);
slouken@26
   720
		}
slouken@154
   721
		if ( position ) {
slouken@154
   722
			if ( Mix_SetMusicPosition(position) < 0 ) {
slouken@154
   723
				Mix_HaltMusic();
slouken@154
   724
				return(-1);
slouken@154
   725
			}
slouken@154
   726
		}
slouken@17
   727
		music_playing->fade_step = 0;
slouken@17
   728
		music_playing->fade_steps = ms/ms_per_step;
megastep@4
   729
		music_playing->fading = MIX_FADING_IN;
megastep@4
   730
	}
slouken@0
   731
	return(0);
slouken@0
   732
}
slouken@0
   733
slouken@154
   734
int Mix_FadeInMusic(Mix_Music *music, int loops, int ms)
slouken@154
   735
{
slouken@154
   736
	return Mix_FadeInMusicPos(music, loops, ms, 0);
slouken@154
   737
}
slouken@154
   738
slouken@0
   739
/* Set the music volume */
slouken@0
   740
int Mix_VolumeMusic(int volume)
slouken@0
   741
{
slouken@0
   742
	int prev_volume;
slouken@0
   743
slouken@0
   744
	prev_volume = music_volume;
megastep@4
   745
	if ( volume < 0 ) {
slouken@163
   746
		return prev_volume;
megastep@4
   747
	}
megastep@4
   748
	if ( volume > SDL_MIX_MAXVOLUME ) {
megastep@4
   749
		volume = SDL_MIX_MAXVOLUME;
megastep@4
   750
	}
megastep@4
   751
	music_volume = volume;
megastep@7
   752
	if ( music_playing && !music_stopped ) {
megastep@4
   753
		switch (music_playing->type) {
slouken@0
   754
#ifdef CMD_MUSIC
megastep@4
   755
		case MUS_CMD:
megastep@4
   756
			MusicCMD_SetVolume(music_volume);
megastep@4
   757
			break;
slouken@0
   758
#endif
slouken@0
   759
#ifdef WAV_MUSIC
megastep@4
   760
		case MUS_WAV:
megastep@4
   761
			WAVStream_SetVolume(music_volume);
megastep@4
   762
			break;
slouken@0
   763
#endif
slouken@0
   764
#ifdef MOD_MUSIC
megastep@4
   765
		case MUS_MOD:
slouken@42
   766
			Player_SetVolume((SWORD)music_volume);
megastep@4
   767
			break;
slouken@0
   768
#endif
slouken@0
   769
#ifdef MID_MUSIC
megastep@4
   770
		case MUS_MID:
slouken@98
   771
#ifdef USE_NATIVE_MIDI
slouken@98
   772
			if ( native_midi_ok ) {
slouken@98
   773
				native_midi_setvolume(music_volume);
slouken@106
   774
			} MIDI_ELSE
slouken@98
   775
#endif
slouken@106
   776
#ifdef USE_TIMIDITY_MIDI
slouken@98
   777
			if ( timidity_ok ) {
slouken@98
   778
				Timidity_SetVolume(music_volume);
slouken@98
   779
			}
slouken@106
   780
#endif
megastep@4
   781
			break;
slouken@0
   782
#endif
slouken@63
   783
#ifdef OGG_MUSIC
slouken@63
   784
		case MUS_OGG:
slouken@63
   785
			OGG_setvolume(music_playing->data.ogg, music_volume);
slouken@63
   786
			break;
slouken@63
   787
#endif
slouken@0
   788
#ifdef MP3_MUSIC
megastep@4
   789
		case MUS_MP3:
slouken@83
   790
			SMPEG_setvolume(music_playing->data.mp3,(int)(((float)music_volume/(float)MIX_MAX_VOLUME)*100.0));
megastep@4
   791
			break;
slouken@0
   792
#endif
megastep@4
   793
		default:
megastep@4
   794
			/* Unknown music type?? */
megastep@4
   795
			break;
slouken@0
   796
		}
slouken@0
   797
	}
slouken@0
   798
	return(prev_volume);
slouken@0
   799
}
slouken@0
   800
megastep@7
   801
static void lowlevel_halt(void)
megastep@7
   802
{
megastep@7
   803
	switch (music_playing->type) {
megastep@7
   804
#ifdef CMD_MUSIC
megastep@7
   805
	case MUS_CMD:
megastep@7
   806
		MusicCMD_Stop(music_playing->data.cmd);
megastep@7
   807
		break;
megastep@7
   808
#endif
megastep@7
   809
#ifdef WAV_MUSIC
megastep@7
   810
	case MUS_WAV:
megastep@7
   811
		WAVStream_Stop();
megastep@7
   812
		break;
megastep@7
   813
#endif
megastep@7
   814
#ifdef MOD_MUSIC
megastep@7
   815
	case MUS_MOD:
megastep@7
   816
		Player_Stop();
megastep@7
   817
		break;
megastep@7
   818
#endif
megastep@7
   819
#ifdef MID_MUSIC
megastep@7
   820
	case MUS_MID:
slouken@98
   821
#ifdef USE_NATIVE_MIDI
slouken@98
   822
		if ( native_midi_ok ) {
slouken@98
   823
			native_midi_stop();
slouken@106
   824
		} MIDI_ELSE
slouken@98
   825
#endif
slouken@106
   826
#ifdef USE_TIMIDITY_MIDI
slouken@98
   827
		if ( timidity_ok ) {
slouken@98
   828
			Timidity_Stop();
slouken@98
   829
		}
slouken@106
   830
#endif
megastep@7
   831
		break;
megastep@7
   832
#endif
slouken@63
   833
#ifdef OGG_MUSIC
slouken@63
   834
	case MUS_OGG:
slouken@63
   835
		OGG_stop(music_playing->data.ogg);
slouken@63
   836
		break;
slouken@63
   837
#endif
megastep@7
   838
#ifdef MP3_MUSIC
megastep@7
   839
	case MUS_MP3:
megastep@7
   840
		SMPEG_stop(music_playing->data.mp3);
megastep@7
   841
		break;
megastep@7
   842
#endif
megastep@7
   843
	default:
megastep@7
   844
		/* Unknown music type?? */
megastep@7
   845
		return;
megastep@7
   846
	}
slouken@17
   847
	if ( music_playing->fading != MIX_NO_FADING ) /* Restore volume */
megastep@7
   848
		music_volume = music_playing->fade_volume;
megastep@7
   849
	music_playing->fading = MIX_NO_FADING;
slouken@17
   850
	music_playing = NULL;
megastep@7
   851
	music_active = 0;
megastep@11
   852
	music_loops = 0;
megastep@7
   853
	music_stopped = 0;
megastep@7
   854
}
megastep@7
   855
slouken@0
   856
/* Halt playing of music */
slouken@0
   857
int Mix_HaltMusic(void)
slouken@0
   858
{
megastep@7
   859
	if ( music_playing && !music_stopped ) {
megastep@7
   860
		/* Mark the music to be stopped from the sound thread */
megastep@7
   861
		music_stopped = 1;
megastep@7
   862
		/* Wait for it to be actually stopped */
slouken@42
   863
		while ( music_playing && music_active )
megastep@7
   864
			SDL_Delay(10);
slouken@0
   865
	}
slouken@0
   866
	return(0);
slouken@0
   867
}
slouken@0
   868
megastep@4
   869
/* Progressively stop the music */
megastep@4
   870
int Mix_FadeOutMusic(int ms)
megastep@4
   871
{
slouken@26
   872
	if ( music_playing && !music_stopped &&
slouken@26
   873
	     (music_playing->fading == MIX_NO_FADING) ) {
slouken@17
   874
		if ( music_volume > 0 ) {
megastep@4
   875
			music_playing->fading = MIX_FADING_OUT;
megastep@4
   876
			music_playing->fade_volume = music_volume;
slouken@26
   877
			music_playing->fade_step = 0;
slouken@26
   878
			music_playing->fade_steps = ms/ms_per_step;
megastep@4
   879
			return(1);
megastep@4
   880
		}
megastep@4
   881
	}
megastep@4
   882
	return(0);
megastep@4
   883
}
megastep@4
   884
megastep@4
   885
Mix_Fading Mix_FadingMusic(void)
megastep@4
   886
{
megastep@7
   887
	if( music_playing && !music_stopped )
megastep@4
   888
		return music_playing->fading;
megastep@4
   889
	return MIX_NO_FADING;
megastep@4
   890
}
megastep@4
   891
slouken@0
   892
/* Pause/Resume the music stream */
slouken@0
   893
void Mix_PauseMusic(void)
slouken@0
   894
{
slouken@17
   895
	if ( music_playing && !music_stopped ) {
megastep@13
   896
		music_active = 0;
slouken@0
   897
	}
slouken@0
   898
}
megastep@4
   899
slouken@0
   900
void Mix_ResumeMusic(void)
slouken@0
   901
{
slouken@17
   902
	if ( music_playing && !music_stopped ) {
megastep@13
   903
		music_active = 1;
slouken@0
   904
	}
slouken@0
   905
}
slouken@0
   906
slouken@0
   907
void Mix_RewindMusic(void)
slouken@0
   908
{
megastep@7
   909
	if ( music_playing && !music_stopped ) {
slouken@0
   910
		switch ( music_playing->type ) {
slouken@29
   911
#ifdef MOD_MUSIC
slouken@29
   912
		case MUS_MOD:
slouken@29
   913
			Player_Start(music_playing->data.module);
slouken@29
   914
			Player_SetPosition(0);
slouken@29
   915
			break;
slouken@29
   916
#endif
slouken@0
   917
#ifdef MP3_MUSIC
slouken@0
   918
		case MUS_MP3:
slouken@0
   919
			SMPEG_rewind(music_playing->data.mp3);
slouken@0
   920
			break;
slouken@0
   921
#endif
slouken@161
   922
#ifdef OGG_MUSIC
slouken@161
   923
		case MUS_OGG:
slouken@161
   924
			OGG_jump_to_time(music_playing->data.ogg, 0);
slouken@161
   925
			break;
slouken@161
   926
#endif
slouken@98
   927
#ifdef MID_MUSIC
slouken@98
   928
		case MUS_MID:
slouken@98
   929
#ifdef USE_NATIVE_MIDI
slouken@98
   930
			if ( native_midi_ok ) {
slouken@98
   931
				native_midi_stop();
slouken@98
   932
			}
slouken@98
   933
#endif
slouken@98
   934
			break;
slouken@98
   935
#endif
slouken@29
   936
		default:
megastep@7
   937
			/* TODO: Implement this for other music backends */
slouken@29
   938
			break;
slouken@0
   939
		}
slouken@0
   940
	}
slouken@0
   941
}
slouken@0
   942
megastep@13
   943
int Mix_PausedMusic(void)
megastep@13
   944
{
slouken@17
   945
	return (music_active == 0);
megastep@13
   946
}
megastep@13
   947
slouken@0
   948
/* Check the status of the music */
megastep@13
   949
int Mix_PlayingMusic(void)
slouken@0
   950
{
megastep@13
   951
	if ( music_playing && ! music_stopped ) {
slouken@0
   952
		switch (music_playing->type) {
slouken@0
   953
#ifdef CMD_MUSIC
slouken@0
   954
			case MUS_CMD:
slouken@0
   955
				if (!MusicCMD_Active(music_playing->data.cmd)) {
megastep@10
   956
					return(0);
slouken@0
   957
				}
slouken@0
   958
				break;
slouken@0
   959
#endif
slouken@0
   960
#ifdef WAV_MUSIC
slouken@0
   961
			case MUS_WAV:
slouken@64
   962
				if ( ! WAVStream_Active() ) {
megastep@10
   963
					return(0);
slouken@0
   964
				}
slouken@0
   965
				break;
slouken@0
   966
#endif
slouken@0
   967
#ifdef MOD_MUSIC
slouken@0
   968
			case MUS_MOD:
slouken@0
   969
				if ( ! Player_Active() ) {
megastep@10
   970
					return(0);
slouken@0
   971
				}
slouken@0
   972
				break;
slouken@0
   973
#endif
slouken@0
   974
#ifdef MID_MUSIC
slouken@0
   975
			case MUS_MID:
slouken@98
   976
#ifdef USE_NATIVE_MIDI
slouken@98
   977
				if ( native_midi_ok ) {
slouken@98
   978
					if ( ! native_midi_active() )
slouken@98
   979
						return(0);
slouken@106
   980
				} MIDI_ELSE
slouken@98
   981
#endif
slouken@106
   982
#ifdef USE_TIMIDITY_MIDI
slouken@98
   983
				if ( timidity_ok ) {
slouken@98
   984
					if ( ! Timidity_Active() )
slouken@98
   985
						return(0);
slouken@0
   986
				}
slouken@106
   987
#endif
slouken@0
   988
				break;
slouken@0
   989
#endif
slouken@63
   990
#ifdef OGG_MUSIC
slouken@63
   991
			case MUS_OGG:
slouken@63
   992
				if ( ! OGG_playing(music_playing->data.ogg) ) {
slouken@63
   993
					return(0);
slouken@63
   994
				}
slouken@63
   995
				break;
slouken@63
   996
#endif
slouken@0
   997
#ifdef MP3_MUSIC
slouken@0
   998
			case MUS_MP3:
slouken@98
   999
				if ( SMPEG_status(music_playing->data.mp3) != SMPEG_PLAYING )
megastep@10
  1000
					return(0);
slouken@0
  1001
				break;
slouken@0
  1002
#endif
slouken@29
  1003
			default:
slouken@29
  1004
				break;
slouken@0
  1005
		}
megastep@13
  1006
		return(1);
slouken@0
  1007
	}
megastep@13
  1008
	return(0);
slouken@0
  1009
}
slouken@0
  1010
slouken@0
  1011
/* Set the external music playback command */
slouken@0
  1012
int Mix_SetMusicCMD(const char *command)
slouken@0
  1013
{
slouken@0
  1014
	Mix_HaltMusic();
slouken@0
  1015
	if ( music_cmd ) {
slouken@0
  1016
		free(music_cmd);
slouken@0
  1017
		music_cmd = NULL;
slouken@0
  1018
	}
slouken@0
  1019
	if ( command ) {
slouken@0
  1020
		music_cmd = (char *)malloc(strlen(command)+1);
slouken@0
  1021
		if ( music_cmd == NULL ) {
slouken@0
  1022
			return(-1);
slouken@0
  1023
		}
slouken@0
  1024
		strcpy(music_cmd, command);
slouken@0
  1025
	}
slouken@0
  1026
	return(0);
slouken@0
  1027
}
slouken@0
  1028
slouken@154
  1029
int Mix_SetSynchroValue(int i)
slouken@154
  1030
{
slouken@154
  1031
	if ( music_playing && ! music_stopped ) {
slouken@154
  1032
		switch (music_playing->type) {
slouken@154
  1033
#ifdef MOD_MUSIC
slouken@154
  1034
			case MUS_MOD:
slouken@154
  1035
				if ( ! Player_Active() ) {
slouken@154
  1036
					return(-1);
slouken@154
  1037
				}
slouken@154
  1038
				Player_SetSynchroValue(i);
slouken@154
  1039
				return 0;
slouken@154
  1040
				break;
slouken@154
  1041
#endif
slouken@154
  1042
			default:
slouken@154
  1043
				return(-1);
slouken@154
  1044
				break;
slouken@154
  1045
		}
slouken@154
  1046
		return(-1);
slouken@154
  1047
	}
slouken@154
  1048
	return(-1);
slouken@154
  1049
}
slouken@154
  1050
slouken@154
  1051
int Mix_GetSynchroValue(void)
slouken@154
  1052
{
slouken@154
  1053
	if ( music_playing && ! music_stopped ) {
slouken@154
  1054
		switch (music_playing->type) {
slouken@154
  1055
#ifdef MOD_MUSIC
slouken@154
  1056
			case MUS_MOD:
slouken@154
  1057
				if ( ! Player_Active() ) {
slouken@154
  1058
					return(-1);
slouken@154
  1059
				}
slouken@154
  1060
				return Player_GetSynchroValue();
slouken@154
  1061
				break;
slouken@154
  1062
#endif
slouken@154
  1063
			default:
slouken@154
  1064
				return(-1);
slouken@154
  1065
				break;
slouken@154
  1066
		}
slouken@154
  1067
		return(-1);
slouken@154
  1068
	}
slouken@154
  1069
	return(-1);
slouken@154
  1070
}
slouken@154
  1071
slouken@154
  1072
slouken@0
  1073
/* Uninitialize the music players */
slouken@0
  1074
void close_music(void)
slouken@0
  1075
{
slouken@0
  1076
	Mix_HaltMusic();
slouken@0
  1077
#ifdef CMD_MUSIC
slouken@0
  1078
	Mix_SetMusicCMD(NULL);
slouken@0
  1079
#endif
slouken@0
  1080
#ifdef MOD_MUSIC
slouken@0
  1081
	MikMod_Exit();
slouken@101
  1082
	MikMod_UnregisterAllLoaders();
slouken@101
  1083
	MikMod_UnregisterAllDrivers();
slouken@0
  1084
#endif
slouken@0
  1085
}
slouken@0
  1086