From cd5cec96bf1f775060f99ecb95eacc856ddc5b4f Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Sat, 28 Jun 2003 17:31:24 +0000 Subject: [PATCH] 1.2.6: Andre Leiradella - Fri, 30 May 2003 16:12:03 -0300 * Added SDL_RWops support for reading MOD files --- CHANGES | 2 ++ SDL_mixer.h | 4 ++-- music.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 54 insertions(+), 2 deletions(-) diff --git a/CHANGES b/CHANGES index ba43df72..bb808e73 100644 --- a/CHANGES +++ b/CHANGES @@ -1,4 +1,6 @@ 1.2.6: +Andre Leiradella - Fri, 30 May 2003 16:12:03 -0300 + * Added SDL_RWops support for reading MOD files Kyle Davenport - Sat, 19 Apr 2003 17:13:31 -0500 * Added .la files to the development RPM, fixing RPM build on RedHat 8 diff --git a/SDL_mixer.h b/SDL_mixer.h index 3862cd3b..38076459 100644 --- a/SDL_mixer.h +++ b/SDL_mixer.h @@ -125,10 +125,10 @@ extern DECLSPEC Mix_Chunk * SDLCALL Mix_LoadWAV_RW(SDL_RWops *src, int freesrc); #define Mix_LoadWAV(file) Mix_LoadWAV_RW(SDL_RWFromFile(file, "rb"), 1) extern DECLSPEC Mix_Music * SDLCALL Mix_LoadMUS(const char *file); -#if 0 /* This hasn't been hooked into music.c yet */ +#ifdef USE_RWOPS /* This hasn't been hooked into music.c yet */ /* Load a music file from an SDL_RWop object (MikMod-specific currently) Matt Campbell (matt@campbellhome.dhs.org) April 2000 */ -extern no_parse_DECLSPEC Mix_Music * SDLCALL Mix_LoadMUS_RW(SDL_RWops *rw); +extern DECLSPEC Mix_Music * SDLCALL Mix_LoadMUS_RW(SDL_RWops *rw); #endif /* Load a wave file of the mixer format from a memory buffer */ diff --git a/music.c b/music.c index 7c8383fc..0a202971 100644 --- a/music.c +++ b/music.c @@ -48,6 +48,9 @@ # define UNIMOD MODULE # define MikMod_Init() MikMod_Init(NULL) # define MikMod_LoadSong(a,b) Player_Load(a,b,0) +# ifdef USE_RWOPS +# define MikMod_LoadSongRW(a,b) Player_LoadRW(a,b,0) +# endif # define MikMod_FreeSong Player_Free extern int MikMod_errno; # else /* old MikMod 3.0.3 */ @@ -1115,3 +1118,50 @@ void close_music(void) #endif } +#ifdef USE_RWOPS + +Mix_Music *Mix_LoadMUS_RW(SDL_RWops *rw) { + /*Uint8 magic[5]; Apparently there is no way to check if the file is really a MOD,*/ + /* or there are too many formats supported by MikMod or MikMod does */ + /* this check by itself. If someone implements other formats (e.g. MP3) */ + /* the check can be uncommented */ + Mix_Music *music; + + /* Just skip the check */ + /* Figure out what kind of file this is */ + /*if (SDL_RWread(rw,magic,1,4)!=4) { + Mix_SetError("Couldn't read from RWops"); + return NULL; + } + magic[4]='\0';*/ + + /* Allocate memory for the music structure */ + music=(Mix_Music *)malloc(sizeof(Mix_Music)); + if (music==NULL ) { + Mix_SetError("Out of memory"); + return(NULL); + } + music->error = 0; + +#ifdef MOD_MUSIC + if (1) { + music->type=MUS_MOD; + music->data.module=MikMod_LoadSongRW(rw,64); + if (music->data.module==NULL) { + Mix_SetError("%s",MikMod_strerror(MikMod_errno)); + music->error=1; + } + } else +#endif + { + Mix_SetError("Unrecognized music format"); + music->error=1; + } + if (music->error) { + free(music); + music=NULL; + } + return(music); +} + +#endif /* USE_RWOPS */