music.c
changeset 381 2064088ea781
parent 357 d6d0cfdbea65
child 382 50501e45c57b
     1.1 --- a/music.c	Tue Feb 26 11:44:20 2008 +0000
     1.2 +++ b/music.c	Tue Feb 26 11:46:22 2008 +0000
     1.3 @@ -1416,11 +1416,13 @@
     1.4  }
     1.5  # endif
     1.6  
     1.7 -Mix_Music *Mix_LoadMUS_RW(SDL_RWops *rw) {
     1.8 +Mix_Music *Mix_LoadMUS_RW(SDL_RWops *rw)
     1.9 +{
    1.10  	Uint8 magic[5];	  /*Apparently there is no way to check if the file is really a MOD,*/
    1.11  	/*		    or there are too many formats supported by MikMod or MikMod does */
    1.12  	/*		    this check by itself. If someone implements other formats (e.g. MP3) */
    1.13  	/*		    the check can be uncommented */
    1.14 +	Uint8 moremagic[9];
    1.15  	Mix_Music *music;
    1.16  	int start;
    1.17  
    1.18 @@ -1431,12 +1433,14 @@
    1.19  
    1.20  	/* Figure out what kind of file this is */
    1.21  	start = SDL_RWtell(rw);
    1.22 -	if (SDL_RWread(rw,magic,1,4)!=4) {
    1.23 +	if ( SDL_RWread(rw,magic,1,4) != 4 ||
    1.24 +	     SDL_RWread(rw,moremagic,1,8) != 8 ) {
    1.25  		Mix_SetError("Couldn't read from RWops");
    1.26  		return NULL;
    1.27  	}
    1.28  	SDL_RWseek(rw, start, SEEK_SET);
    1.29  	magic[4]='\0';
    1.30 +	moremagic[8] = '\0';
    1.31  
    1.32  	/* Allocate memory for the music structure */
    1.33  	music=(Mix_Music *)malloc(sizeof(Mix_Music));
    1.34 @@ -1446,6 +1450,20 @@
    1.35  	}
    1.36  	music->error = 0;
    1.37  
    1.38 +#ifdef WAV_MUSIC
    1.39 +	/* WAVE files have the magic four bytes "RIFF"
    1.40 +	   AIFF files have the magic 12 bytes "FORM" XXXX "AIFF"
    1.41 +	 */
    1.42 +	if ( ((strcmp((char *)magic, "RIFF") == 0) && (strcmp((char *)(moremagic+4), "WAVE") == 0)) ||
    1.43 +	     (strcmp((char *)magic, "FORM") == 0) ) {
    1.44 +		music->type = MUS_WAV;
    1.45 +		music->data.wave = WAVStream_LoadSong_RW(rw, (char *)magic);
    1.46 +		if ( music->data.wave == NULL ) {
    1.47 +			music->error = 1;
    1.48 +		}
    1.49 +
    1.50 +	} else
    1.51 +#endif
    1.52  #ifdef OGG_MUSIC
    1.53  	/* Ogg Vorbis files have the magic four bytes "OggS" */
    1.54  	if ( strcmp((char *)magic, "OggS") == 0 ) {