music.c
changeset 246 9fa5d0f9d042
parent 245 63b3650714de
child 249 3a26a4b9ab13
     1.1 --- a/music.c	Sat Aug 21 12:27:02 2004 +0000
     1.2 +++ b/music.c	Sun Aug 22 07:55:14 2004 +0000
     1.3 @@ -1203,19 +1203,21 @@
     1.4  #ifdef USE_RWOPS
     1.5  
     1.6  Mix_Music *Mix_LoadMUS_RW(SDL_RWops *rw) {
     1.7 -	/*Uint8     magic[5]; Apparently there is no way to check if the file is really a MOD,*/
     1.8 -      /*		    or there are too many formats supported by MikMod or MikMod does */
     1.9 -      /*		    this check by itself. If someone implements other formats (e.g. MP3) */
    1.10 -      /*		    the check can be uncommented */
    1.11 +	Uint8 magic[5];	  /*Apparently there is no way to check if the file is really a MOD,*/
    1.12 +	/*		    or there are too many formats supported by MikMod or MikMod does */
    1.13 +	/*		    this check by itself. If someone implements other formats (e.g. MP3) */
    1.14 +	/*		    the check can be uncommented */
    1.15  	Mix_Music *music;
    1.16 +	int start;
    1.17  
    1.18 -      /* Just skip the check */
    1.19  	/* Figure out what kind of file this is */
    1.20 -	/*if (SDL_RWread(rw,magic,1,4)!=4) {
    1.21 +	start = SDL_RWtell(rw);
    1.22 +	if (SDL_RWread(rw,magic,1,4)!=4) {
    1.23  		Mix_SetError("Couldn't read from RWops");
    1.24  		return NULL;
    1.25  	}
    1.26 -	magic[4]='\0';*/
    1.27 +	SDL_RWseek(rw, start, SEEK_SET);
    1.28 +	magic[4]='\0';
    1.29  
    1.30  	/* Allocate memory for the music structure */
    1.31  	music=(Mix_Music *)malloc(sizeof(Mix_Music));
    1.32 @@ -1225,6 +1227,16 @@
    1.33  	}
    1.34  	music->error = 0;
    1.35  
    1.36 +#ifdef OGG_MUSIC
    1.37 +	/* Ogg Vorbis files have the magic four bytes "OggS" */
    1.38 +	if ( strcmp((char *)magic, "OggS") == 0 ) {
    1.39 +		music->type = MUS_OGG;
    1.40 +		music->data.ogg = OGG_new_RW(rw);
    1.41 +		if ( music->data.ogg == NULL ) {
    1.42 +			music->error = 1;
    1.43 +		}
    1.44 +	} else
    1.45 +#endif
    1.46  #ifdef MOD_MUSIC
    1.47  	if (1) {
    1.48  		music->type=MUS_MOD;