music.c
changeset 357 d6d0cfdbea65
parent 336 ab67d7115d3e
child 381 2064088ea781
     1.1 --- a/music.c	Sun Jul 15 04:41:22 2007 +0000
     1.2 +++ b/music.c	Sun Jul 15 05:33:35 2007 +0000
     1.3 @@ -85,10 +85,16 @@
     1.4  #endif
     1.5  #ifdef MP3_MUSIC
     1.6  #include "dynamic_mp3.h"
     1.7 +#endif
     1.8 +#ifdef MP3_MAD_MUSIC
     1.9 +#include "music_mad.h"
    1.10 +#endif
    1.11  
    1.12 +#if defined(MP3_MUSIC) || defined(MP3_MAD_MUSIC)
    1.13  static SDL_AudioSpec used_mixer;
    1.14  #endif
    1.15  
    1.16 +
    1.17  int volatile music_active = 1;
    1.18  static int volatile music_stopped = 0;
    1.19  static int music_loops = 0;
    1.20 @@ -124,6 +130,9 @@
    1.21  #ifdef MP3_MUSIC
    1.22  		SMPEG *mp3;
    1.23  #endif
    1.24 +#ifdef MP3_MAD_MUSIC
    1.25 +		mad_data *mp3_mad;
    1.26 +#endif
    1.27  	} data;
    1.28  	Mix_Fading fading;
    1.29  	int fade_step;
    1.30 @@ -341,6 +350,11 @@
    1.31  				smpeg.SMPEG_playAudio(music_playing->data.mp3, stream, len);
    1.32  				break;
    1.33  #endif
    1.34 +#ifdef MP3_MAD_MUSIC
    1.35 +			case MUS_MP3_MAD:
    1.36 +				mad_getSamples(music_playing->data.mp3_mad, stream, len);
    1.37 +				break;
    1.38 +#endif
    1.39  			default:
    1.40  				/* Unknown music type?? */
    1.41  				break;
    1.42 @@ -455,7 +469,7 @@
    1.43  		++music_error;
    1.44  	}
    1.45  #endif
    1.46 -#ifdef MP3_MUSIC
    1.47 +#if defined(MP3_MUSIC) || defined(MP3_MAD_MUSIC)
    1.48  	/* Keep a copy of the mixer */
    1.49  	used_mixer = *mixer;
    1.50  #endif
    1.51 @@ -608,6 +622,20 @@
    1.52  		}
    1.53  	} else
    1.54  #endif
    1.55 +#ifdef MP3_MAD_MUSIC
    1.56 +	if ( (ext && MIX_string_equals(ext, "MPG")) ||
    1.57 +	     (ext && MIX_string_equals(ext, "MP3")) ||
    1.58 +	     (ext && MIX_string_equals(ext, "MPEG")) ||
    1.59 +	     (ext && MIX_string_equals(ext, "MAD")) ||
    1.60 +	     (magic[0] == 0xFF && (magic[1] & 0xF0) == 0xF0) ) {
    1.61 +		music->type = MUS_MP3_MAD;
    1.62 +		music->data.mp3_mad = mad_openFile(file, &used_mixer);
    1.63 +		if (music->data.mp3_mad == 0) {
    1.64 +		    Mix_SetError("Could not initialize MPEG stream.");
    1.65 +			music->error = 1;
    1.66 +		}
    1.67 +	} else
    1.68 +#endif
    1.69  #if defined(MOD_MUSIC) || defined(LIBMIKMOD_MUSIC)
    1.70  	if ( 1 ) {
    1.71  		music->type = MUS_MOD;
    1.72 @@ -698,6 +726,11 @@
    1.73  				Mix_QuitMP3();
    1.74  				break;
    1.75  #endif
    1.76 +#ifdef MP3_MAD_MUSIC
    1.77 +			case MUS_MP3_MAD:
    1.78 +				mad_closeFile(music->data.mp3_mad);
    1.79 +				break;
    1.80 +#endif
    1.81  			default:
    1.82  				/* Unknown music type?? */
    1.83  				break;
    1.84 @@ -787,6 +820,11 @@
    1.85  		smpeg.SMPEG_play(music_playing->data.mp3);
    1.86  		break;
    1.87  #endif
    1.88 +#ifdef MP3_MAD_MUSIC
    1.89 +	    case MUS_MP3_MAD:
    1.90 +		mad_start(music->data.mp3_mad);
    1.91 +		break;
    1.92 +#endif
    1.93  	    default:
    1.94  		Mix_SetError("Can't play unknown music type");
    1.95  		retval = -1;
    1.96 @@ -880,6 +918,11 @@
    1.97  		}
    1.98  		break;
    1.99  #endif
   1.100 +#ifdef MP3_MAD_MUSIC
   1.101 +	    case MUS_MP3_MAD:
   1.102 +		mad_seek(music_playing->data.mp3_mad, position);
   1.103 +		break;
   1.104 +#endif
   1.105  	    default:
   1.106  		/* TODO: Implement this for other music backends */
   1.107  		retval = -1;
   1.108 @@ -959,6 +1002,11 @@
   1.109  		smpeg.SMPEG_setvolume(music_playing->data.mp3,(int)(((float)volume/(float)MIX_MAX_VOLUME)*100.0));
   1.110  		break;
   1.111  #endif
   1.112 +#ifdef MP3_MAD_MUSIC
   1.113 +	    case MUS_MP3_MAD:
   1.114 +		mad_setVolume(music_playing->data.mp3_mad, volume);
   1.115 +		break;
   1.116 +#endif
   1.117  	    default:
   1.118  		/* Unknown music type?? */
   1.119  		break;
   1.120 @@ -1027,6 +1075,11 @@
   1.121  		smpeg.SMPEG_stop(music_playing->data.mp3);
   1.122  		break;
   1.123  #endif
   1.124 +#ifdef MP3_MAD_MUSIC
   1.125 +	    case MUS_MP3_MAD:
   1.126 +		mad_stop(music_playing->data.mp3_mad);
   1.127 +		break;
   1.128 +#endif
   1.129  	    default:
   1.130  		/* Unknown music type?? */
   1.131  		return;
   1.132 @@ -1170,6 +1223,13 @@
   1.133  			playing = 0;
   1.134  		break;
   1.135  #endif
   1.136 +#ifdef MP3_MAD_MUSIC
   1.137 +	    case MUS_MP3_MAD:
   1.138 +		if (!mad_isPlaying(music_playing->data.mp3_mad)) {
   1.139 +			playing = 0;
   1.140 +		}
   1.141 +		break;
   1.142 +#endif
   1.143  	    default:
   1.144  		playing = 0;
   1.145  		break;
   1.146 @@ -1413,6 +1473,16 @@
   1.147  		}
   1.148  	} else
   1.149  #endif
   1.150 +#ifdef MP3_MAD_MUSIC
   1.151 +	if ( magic[0] == 0xFF && (magic[1] & 0xF0) == 0xF0 ) {
   1.152 +		music->type = MUS_MP3_MAD;
   1.153 +		music->data.mp3_mad = mad_openFileRW(rw, &used_mixer);
   1.154 +		if (music->data.mp3_mad == 0) {
   1.155 +			Mix_SetError("Could not initialize MPEG stream.");
   1.156 +			music->error = 1;
   1.157 +		}
   1.158 +	} else
   1.159 +#endif
   1.160  #ifdef MID_MUSIC
   1.161  	/* MIDI files have the magic four bytes "MThd" */
   1.162  	if ( strcmp((char *)magic, "MThd") == 0 ) {