music.c
changeset 226 3691a375f2e6
parent 213 0cab09308739
child 237 5fb7a859f158
     1.1 --- a/music.c	Sat May 03 20:15:25 2003 +0000
     1.2 +++ b/music.c	Sat Jun 28 17:31:24 2003 +0000
     1.3 @@ -48,6 +48,9 @@
     1.4  #    define UNIMOD			MODULE
     1.5  #    define MikMod_Init()		MikMod_Init(NULL)
     1.6  #    define MikMod_LoadSong(a,b)	Player_Load(a,b,0)
     1.7 +#    ifdef USE_RWOPS
     1.8 +#      define MikMod_LoadSongRW(a,b)	Player_LoadRW(a,b,0)
     1.9 +#    endif
    1.10  #    define MikMod_FreeSong		Player_Free
    1.11       extern int MikMod_errno;
    1.12  #  else                                        /* old MikMod 3.0.3 */
    1.13 @@ -1115,3 +1118,50 @@
    1.14  #endif
    1.15  }
    1.16  
    1.17 +#ifdef USE_RWOPS
    1.18 +
    1.19 +Mix_Music *Mix_LoadMUS_RW(SDL_RWops *rw) {
    1.20 +	/*Uint8     magic[5]; Apparently there is no way to check if the file is really a MOD,*/
    1.21 +      /*		    or there are too many formats supported by MikMod or MikMod does */
    1.22 +      /*		    this check by itself. If someone implements other formats (e.g. MP3) */
    1.23 +      /*		    the check can be uncommented */
    1.24 +	Mix_Music *music;
    1.25 +
    1.26 +      /* Just skip the check */
    1.27 +	/* Figure out what kind of file this is */
    1.28 +	/*if (SDL_RWread(rw,magic,1,4)!=4) {
    1.29 +		Mix_SetError("Couldn't read from RWops");
    1.30 +		return NULL;
    1.31 +	}
    1.32 +	magic[4]='\0';*/
    1.33 +
    1.34 +	/* Allocate memory for the music structure */
    1.35 +	music=(Mix_Music *)malloc(sizeof(Mix_Music));
    1.36 +	if (music==NULL ) {
    1.37 +		Mix_SetError("Out of memory");
    1.38 +		return(NULL);
    1.39 +	}
    1.40 +	music->error = 0;
    1.41 +
    1.42 +#ifdef MOD_MUSIC
    1.43 +	if (1) {
    1.44 +		music->type=MUS_MOD;
    1.45 +		music->data.module=MikMod_LoadSongRW(rw,64);
    1.46 +		if (music->data.module==NULL) {
    1.47 +			Mix_SetError("%s",MikMod_strerror(MikMod_errno));
    1.48 +			music->error=1;
    1.49 +		}
    1.50 +	} else
    1.51 +#endif
    1.52 +	{
    1.53 +		Mix_SetError("Unrecognized music format");
    1.54 +		music->error=1;
    1.55 +	}
    1.56 +	if (music->error) {
    1.57 +		free(music);
    1.58 +		music=NULL;
    1.59 +	}
    1.60 +	return(music);
    1.61 +}
    1.62 +
    1.63 +#endif /* USE_RWOPS */