Map filename-based Mix_Load* functions to RWops-based ones Mix_LoadMUS() and Mix_LoadWAV(), which take a filename argument, pretty much duplicate some functionality of what the RWops-based functions do. This patch cleans some of this up, using the RWops-based functions wherever possible. The following functions have been deleted entirely, as they're no longer needed: SMPEG_new(), FLAC_new(), map_openFile(), MOD_new(), modplug_new(), OGG_new(), native_midi_loadsong(), Timidity_LoadSong(), WAVStream_LoadSong(). In order to avoid code duplication when detecting the format of the loaded files, two new functions were introduced. An internal helper function: static Mix_MusicType detect_music_type(SDL_RWops *rw) and a new API function: Mix_Music *Mix_LoadMUSType_RW(SDL_RWops *rw, Mix_MusicType type) The new function allows to override SDL_mixer's auto-detection of the music format. Mix_LoadMUS_RW() is now a simple wrapper for Mix_LoadMUSType_RW(). Mix_LoadMUS() uses this in order to guess the file format from the file's extension. This patch should preserve source and binary backwards compatibility, as well as behavior. (And that means that RWops leaks that occured before will still occur; this patch doesn't fix those.) diff -r 3a4c352a9a00 SDL_mixer.h --- a/SDL_mixer.h Thu Jul 14 12:33:48 2011 -0700 +++ b/SDL_mixer.h Sun Jul 24 21:44:00 2011 +0300 @@ -155,6 +155,9 @@ Matt Campbell (matt@campbellhome.dhs.org) April 2000 */ extern DECLSPEC Mix_Music * SDLCALL Mix_LoadMUS_RW(SDL_RWops *rw); +/* Load a music file from an SDL_RWop object assuming a specific format */ +extern DECLSPEC Mix_Music * SDLCALL Mix_LoadMUSType_RW(SDL_RWops *rw, Mix_MusicType type); + /* Load a wave file of the mixer format from a memory buffer */ extern DECLSPEC Mix_Chunk * SDLCALL Mix_QuickLoad_WAV(Uint8 *mem); diff -r 3a4c352a9a00 VisualC/smpeg/include/smpeg.h --- a/VisualC/smpeg/include/smpeg.h Thu Jul 14 12:33:48 2011 -0700 +++ b/VisualC/smpeg/include/smpeg.h Sun Jul 24 21:44:00 2011 +0300 @@ -83,7 +83,7 @@ typedef void(*SMPEG_DisplayCallback)(SDL_Surface* dst, int x, int y, unsigned int w, unsigned int h); -/* Create a new SMPEG object from an MPEG file. +/* Create a new SMPEG object from an MPEG file descriptor. On return, if 'info' is not NULL, it will be filled with information about the MPEG object. This function returns a new SMPEG object. Use SMPEG_error() to find out @@ -92,9 +92,6 @@ subsystem. If not, you will have to use the SMPEG_playaudio() function below to extract the decoded data. */ -extern DECLSPEC SMPEG* SMPEG_new(const char *file, SMPEG_Info* info, int sdl_audio); - -/* The same as above for a file descriptor */ extern DECLSPEC SMPEG* SMPEG_new_descr(int file, SMPEG_Info* info, int sdl_audio); /* diff -r 3a4c352a9a00 dynamic_mp3.c --- a/dynamic_mp3.c Thu Jul 14 12:33:48 2011 -0700 +++ b/dynamic_mp3.c Sun Jul 24 21:44:00 2011 +0300 @@ -66,13 +66,6 @@ SDL_UnloadObject(smpeg.handle); return -1; } - smpeg.SMPEG_new = - (SMPEG* (*)(const char *, SMPEG_Info*, int)) - SDL_LoadFunction(smpeg.handle, "SMPEG_new"); - if ( smpeg.SMPEG_new == NULL ) { - SDL_UnloadObject(smpeg.handle); - return -1; - } smpeg.SMPEG_new_rwops = (SMPEG* (*)(SDL_RWops *, SMPEG_Info*, int)) SDL_LoadFunction(smpeg.handle, "SMPEG_new_rwops"); @@ -152,7 +145,6 @@ smpeg.SMPEG_delete = SMPEG_delete; smpeg.SMPEG_enableaudio = SMPEG_enableaudio; smpeg.SMPEG_enablevideo = SMPEG_enablevideo; - smpeg.SMPEG_new = SMPEG_new; smpeg.SMPEG_new_rwops = SMPEG_new_rwops; smpeg.SMPEG_play = SMPEG_play; smpeg.SMPEG_playAudio = SMPEG_playAudio; diff -r 3a4c352a9a00 dynamic_mp3.h --- a/dynamic_mp3.h Thu Jul 14 12:33:48 2011 -0700 +++ b/dynamic_mp3.h Sun Jul 24 21:44:00 2011 +0300 @@ -30,7 +30,6 @@ void (*SMPEG_delete)( SMPEG* mpeg ); void (*SMPEG_enableaudio)( SMPEG* mpeg, int enable ); void (*SMPEG_enablevideo)( SMPEG* mpeg, int enable ); - SMPEG* (*SMPEG_new)(const char *file, SMPEG_Info* info, int sdl_audio); SMPEG* (*SMPEG_new_rwops)(SDL_RWops *src, SMPEG_Info* info, int sdl_audio); void (*SMPEG_play)( SMPEG* mpeg ); int (*SMPEG_playAudio)( SMPEG *mpeg, Uint8 *stream, int len ); diff -r 3a4c352a9a00 music.c --- a/music.c Thu Jul 14 12:33:48 2011 -0700 +++ b/music.c Sun Jul 24 21:44:00 2011 +0300 @@ -424,195 +424,160 @@ return (!*str1 && !*str2); } +/* MUS_MOD can't be auto-detected. If no other format was detected, MOD is + * assumed and MUS_MOD will be returned, meaning that the format might not + * actually be MOD-based. + * + * Returns MUS_NONE in case of errors. */ +static Mix_MusicType detect_music_type(SDL_RWops *rw) +{ + Uint8 magic[5]; + Uint8 moremagic[9]; + + int start = SDL_RWtell(rw); + if (SDL_RWread(rw, magic, 1, 4) != 4 || SDL_RWread(rw, moremagic, 1, 8) != 8 ) { + Mix_SetError("Couldn't read from RWops"); + return MUS_NONE; + } + SDL_RWseek(rw, start, RW_SEEK_SET); + magic[4]='\0'; + moremagic[8] = '\0'; + + /* WAVE files have the magic four bytes "RIFF" + AIFF files have the magic 12 bytes "FORM" XXXX "AIFF" */ + if (((strcmp((char *)magic, "RIFF") == 0) && (strcmp((char *)(moremagic+4), "WAVE") == 0)) || + (strcmp((char *)magic, "FORM") == 0)) { + return MUS_WAV; + } + + /* Ogg Vorbis files have the magic four bytes "OggS" */ + if (strcmp((char *)magic, "OggS") == 0) { + return MUS_OGG; + } + + /* FLAC files have the magic four bytes "fLaC" */ + if (strcmp((char *)magic, "fLaC") == 0) { + return MUS_FLAC; + } + + /* MP3 files either have a 0xFF byte followed by a byte for which & 0xF0 + * yields 0xF0, or by the three bytes "ID3" when the file has ID3 metadata */ + if ((magic[0] == 0xFF && (magic[1] & 0xF0) == 0xF0) || (strncmp((char *)magic, "ID3", 3) == 0)) { + return MUS_MP3; + } + + /* MIDI files have the magic four bytes "MThd" */ + if (strcmp((char *)magic, "MThd") == 0) { + return MUS_MID; + } + + /* Assume MOD format. + * + * Apparently there is no way to check if the file is really a MOD, + * or there are too many formats supported by MikMod/ModPlug, or + * MikMod/ModPlug does this check by itself. */ + return MUS_MOD; +} + /* Load a music file */ Mix_Music *Mix_LoadMUS(const char *file) { - FILE *fp; - char *ext; - Uint8 magic[5], moremagic[9]; + SDL_RWops *rw; Mix_Music *music; - - /* Figure out what kind of file this is */ - fp = fopen(file, "rb"); - if ( (fp == NULL) || !fread(magic, 4, 1, fp) ) { - if ( fp != NULL ) { - fclose(fp); - } - Mix_SetError("Couldn't read from '%s'", file); - return(NULL); - } - if (!fread(moremagic, 8, 1, fp)) { - Mix_SetError("Couldn't read from '%s'", file); - return(NULL); - } - magic[4] = '\0'; - moremagic[8] = '\0'; - fclose(fp); - - /* Figure out the file extension, so we can determine the type */ - ext = strrchr(file, '.'); - if ( ext ) ++ext; /* skip the dot in the extension */ - - /* 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; + Mix_MusicType type; #ifdef CMD_MUSIC if ( music_cmd ) { + /* 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; music->type = MUS_CMD; music->data.cmd = MusicCMD_LoadSong(music_cmd, file); if ( music->data.cmd == NULL ) { - music->error = 1; + free(music); + music = NULL; } + return(music); + } +#endif + + rw = SDL_RWFromFile(file, "rb"); + if ( rw == NULL ) { + Mix_SetError("Couldn't open '%s'", file); + return NULL; + } + + type = detect_music_type(rw); + if ( type == MUS_MOD ) { + /* MUS_MOD really means "I have no idea", so in that case + * use the file extension to determine the type. */ + char *ext = strrchr(file, '.'); + /* No need to guard these with #ifdef *_MUSIC stuff, + * since we simply call Mix_LoadMUSType_RW() later */ + if ( ext ) { + ++ext; /* skip the dot in the extension */ + if ( MIX_string_equals(ext, "WAV") ) { + type = MUS_WAV; + } else if ( MIX_string_equals(ext, "MID") || + MIX_string_equals(ext, "MIDI") ) { + type = MUS_MID; + } else if ( MIX_string_equals(ext, "OGG") ) { + type = MUS_OGG; + } else if ( MIX_string_equals(ext, "FLAC") ) { + type = MUS_FLAC; + } else if ( MIX_string_equals(ext, "MPG") || + MIX_string_equals(ext, "MP3") || + MIX_string_equals(ext, "MPEG") || + MIX_string_equals(ext, "MAD") ) { + type = MUS_MP3; + } + } + } + +#if defined(MID_MUSIC) && defined(USE_FLUIDSYNTH_MIDI) + /* FIXME: + * We don't map filename-based FluidSynth MIDI to an RWops operation + * because I've no idea how FluidSynth actually works :-/ */ + if ( type == MUS_MID && fluidsynth_ok ) { + music->data.fluidsynthmidi = fluidsynth_loadsong(file); + if ( music->data.fluidsynthmidi == NULL ) { + free(music); + music = NULL; + } + return music; + } +#endif + + /* We need to know if a specific error occurs; if not, we'll set a + * generic one, so we clear the current one. */ + Mix_SetError(""); + music = Mix_LoadMUSType_RW(rw, type); + if ( music == NULL && Mix_GetError()[0] == '\0' ) { + SDL_FreeRW(rw); + Mix_SetError("Couldn't open '%s'", file); + } + + /* With MIDI, the RWops is not needed anymore */ + if ( type == MUS_MID ) { + SDL_RWclose(rw); + } + +#ifdef MP3_MAD_MUSIC + if (music->type == MUS_MP3_MAD) { + music->data.mp3_mad->freerw = SDL_TRUE; } else #endif #ifdef WAV_MUSIC - /* WAVE files have the magic four bytes "RIFF" - AIFF files have the magic 12 bytes "FORM" XXXX "AIFF" - */ - if ( (ext && MIX_string_equals(ext, "WAV")) || - ((strcmp((char *)magic, "RIFF") == 0) && (strcmp((char *)(moremagic+4), "WAVE") == 0)) || - (strcmp((char *)magic, "FORM") == 0) ) { - music->type = MUS_WAV; - music->data.wave = WAVStream_LoadSong(file, (char *)magic); - if ( music->data.wave == NULL ) { - Mix_SetError("Unable to load WAV file"); - music->error = 1; - } - } else + if (music->type == MUS_WAV) { + music->data.wave->freerw = SDL_TRUE; + } #endif -#ifdef MID_MUSIC - /* MIDI files have the magic four bytes "MThd" */ - if ( (ext && MIX_string_equals(ext, "MID")) || - (ext && MIX_string_equals(ext, "MIDI")) || - strcmp((char *)magic, "MThd") == 0 || - ( strcmp((char *)magic, "RIFF") == 0 && - strcmp((char *)(moremagic+4), "RMID") == 0 ) ) { - music->type = MUS_MID; -#ifdef USE_NATIVE_MIDI - if ( native_midi_ok ) { - music->data.nativemidi = native_midi_loadsong(file); - if ( music->data.nativemidi == NULL ) { - Mix_SetError("%s", native_midi_error()); - music->error = 1; - } - goto skip; - } -#endif -#ifdef USE_FLUIDSYNTH_MIDI - if ( fluidsynth_ok ) { - music->data.fluidsynthmidi = fluidsynth_loadsong(file); - if ( music->data.fluidsynthmidi == NULL ) { - music->error = 1; - } - goto skip; - } -#endif -#ifdef USE_TIMIDITY_MIDI - if ( timidity_ok ) { - music->data.midi = Timidity_LoadSong(file); - if ( music->data.midi == NULL ) { - Mix_SetError("%s", Timidity_Error()); - music->error = 1; - } - } else { - Mix_SetError("%s", Timidity_Error()); - music->error = 1; - } -#endif - } else -#endif -#ifdef OGG_MUSIC - /* Ogg Vorbis files have the magic four bytes "OggS" */ - if ( (ext && MIX_string_equals(ext, "OGG")) || - strcmp((char *)magic, "OggS") == 0 ) { - music->type = MUS_OGG; - music->data.ogg = OGG_new(file); - if ( music->data.ogg == NULL ) { - music->error = 1; - } - } else -#endif -#ifdef FLAC_MUSIC - /* FLAC files have the magic four bytes "fLaC" */ - if ( (ext && MIX_string_equals(ext, "FLAC")) || - strcmp((char *)magic, "fLaC") == 0 ) { - music->type = MUS_FLAC; - music->data.flac = FLAC_new(file); - if ( music->data.flac == NULL ) { - music->error = 1; - } - } else -#endif -#ifdef MP3_MUSIC - if ( (ext && MIX_string_equals(ext, "MPG")) || - (ext && MIX_string_equals(ext, "MP3")) || - (ext && MIX_string_equals(ext, "MPEG")) || - (magic[0] == 0xFF && (magic[1] & 0xF0) == 0xF0) || - (strncmp((char *)magic, "ID3", 3) == 0) ) { - if ( Mix_Init(MIX_INIT_MP3) ) { - SMPEG_Info info; - music->type = MUS_MP3; - music->data.mp3 = smpeg.SMPEG_new(file, &info, 0); - if ( !info.has_audio ) { - Mix_SetError("MPEG file does not have any audio stream."); - music->error = 1; - } else { - smpeg.SMPEG_actualSpec(music->data.mp3, &used_mixer); - } - } else { - music->error = 1; - } - } else -#endif -#ifdef MP3_MAD_MUSIC - if ( (ext && MIX_string_equals(ext, "MPG")) || - (ext && MIX_string_equals(ext, "MP3")) || - (ext && MIX_string_equals(ext, "MPEG")) || - (ext && MIX_string_equals(ext, "MAD")) || - (magic[0] == 0xFF && (magic[1] & 0xF0) == 0xF0) || - (strncmp((char *)magic, "ID3", 3) == 0) ) { - music->type = MUS_MP3_MAD; - music->data.mp3_mad = mad_openFile(file, &used_mixer); - if (music->data.mp3_mad == 0) { - Mix_SetError("Could not initialize MPEG stream."); - music->error = 1; - } - } else -#endif -#ifdef MODPLUG_MUSIC - if ( 1 ) { - music->type = MUS_MODPLUG; - music->data.modplug = modplug_new(file); - if ( music->data.modplug == NULL ) { - music->error = 1; - } - } else -#endif -#ifdef MOD_MUSIC - if ( 1 ) { - music->type = MUS_MOD; - music->data.module = MOD_new(file); - if ( music->data.module == NULL ) { - music->error = 1; - } - } else -#endif - { - Mix_SetError("Unrecognized music format"); - music->error = 1; - } - -skip: - if ( music->error ) { - free(music); - music = NULL; - } - return(music); + /* FIXME: Free rw on delete also for MUS_MODPLUG and MUS_MOD */ + return music; } /* Free a music chunk previously loaded */ @@ -1385,29 +1350,27 @@ 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 */ - Uint8 moremagic[9]; + return Mix_LoadMUSType_RW(rw, MUS_NONE); +} + +Mix_Music *Mix_LoadMUSType_RW(SDL_RWops *rw, Mix_MusicType type) +{ Mix_Music *music; - int start; if (!rw) { Mix_SetError("RWops pointer is NULL"); return NULL; } - /* Figure out what kind of file this is */ - start = SDL_RWtell(rw); - if ( SDL_RWread(rw,magic,1,4) != 4 || - SDL_RWread(rw,moremagic,1,8) != 8 ) { - Mix_SetError("Couldn't read from RWops"); - return NULL; + /* If the caller wants auto-detection, figure out what kind of file + * this is. */ + if (type == MUS_NONE) { + if ((type = detect_music_type(rw)) == MUS_NONE) { + /* Don't call Mix_SetError() here since detect_music_type() + * does that. */ + return NULL; + } } - SDL_RWseek(rw, start, RW_SEEK_SET); - magic[4]='\0'; - moremagic[8] = '\0'; /* Allocate memory for the music structure */ music=(Mix_Music *)malloc(sizeof(Mix_Music)); @@ -1417,42 +1380,50 @@ } music->error = 0; + switch (type) { #ifdef WAV_MUSIC - /* WAVE files have the magic four bytes "RIFF" - AIFF files have the magic 12 bytes "FORM" XXXX "AIFF" - */ - if ( ((strcmp((char *)magic, "RIFF") == 0) && (strcmp((char *)(moremagic+4), "WAVE") == 0)) || - (strcmp((char *)magic, "FORM") == 0) ) { - music->type = MUS_WAV; - music->data.wave = WAVStream_LoadSong_RW(rw, (char *)magic); - if ( music->data.wave == NULL ) { + case MUS_WAV: + /* The WAVE loader needs the first 4 bytes of the header */ + { + Uint8 magic[5]; + int start = SDL_RWtell(rw); + if (SDL_RWread(rw, magic, 1, 4) != 4) { + Mix_SetError("Couldn't read from RWops"); + return MUS_NONE; + } + SDL_RWseek(rw, start, RW_SEEK_SET); + magic[4] = '\0'; + music->type = MUS_WAV; + music->data.wave = WAVStream_LoadSong_RW(rw, (char *)magic); + } + if (music->data.wave == NULL) { music->error = 1; } + break; +#endif - } else -#endif #ifdef OGG_MUSIC - /* Ogg Vorbis files have the magic four bytes "OggS" */ - if ( strcmp((char *)magic, "OggS") == 0 ) { + case MUS_OGG: music->type = MUS_OGG; music->data.ogg = OGG_new_RW(rw); if ( music->data.ogg == NULL ) { music->error = 1; } - } else + break; #endif + #ifdef FLAC_MUSIC - /* FLAC files have the magic four bytes "fLaC" */ - if ( strcmp((char *)magic, "fLaC") == 0 ) { + case MUS_FLAC: music->type = MUS_FLAC; music->data.flac = FLAC_new_RW(rw); if ( music->data.flac == NULL ) { music->error = 1; } - } else + break; #endif + #ifdef MP3_MUSIC - if ( ( magic[0] == 0xFF && (magic[1] & 0xF0) == 0xF0) || ( strncmp((char *)magic, "ID3", 3) == 0 ) ) { + case MUS_MP3: if ( Mix_Init(MIX_INIT_MP3) ) { SMPEG_Info info; music->type = MUS_MP3; @@ -1466,21 +1437,20 @@ } else { music->error = 1; } - } else -#endif -#ifdef MP3_MAD_MUSIC - if ( ( magic[0] == 0xFF && (magic[1] & 0xF0) == 0xF0) || ( strncmp((char *)magic, "ID3", 3) == 0 ) ) { + break; +#elif defined(MP3_MAD_MUSIC) + case MUS_MP3: music->type = MUS_MP3_MAD; music->data.mp3_mad = mad_openFileRW(rw, &used_mixer); if (music->data.mp3_mad == 0) { Mix_SetError("Could not initialize MPEG stream."); music->error = 1; } - } else + break; #endif + #ifdef MID_MUSIC - /* MIDI files have the magic four bytes "MThd" */ - if ( strcmp((char *)magic, "MThd") == 0 ) { + case MUS_MID: music->type = MUS_MID; #ifdef USE_NATIVE_MIDI if ( native_midi_ok ) { @@ -1489,7 +1459,7 @@ Mix_SetError("%s", native_midi_error()); music->error = 1; } - goto skip; + break; } #endif #ifdef USE_FLUIDSYNTH_MIDI @@ -1498,7 +1468,7 @@ if ( music->data.fluidsynthmidi == NULL ) { music->error = 1; } - goto skip; + break; } #endif #ifdef USE_TIMIDITY_MIDI @@ -1513,10 +1483,11 @@ music->error = 1; } #endif - } else + break; #endif + #if defined(MODPLUG_MUSIC) || defined(MOD_MUSIC) - if (1) { + case MUS_MOD: music->error = 1; #ifdef MODPLUG_MUSIC if ( music->error ) { @@ -1536,14 +1507,14 @@ } } #endif - } else -#endif /* MODPLUG_MUSIC || MOD_MUSIC */ - { + break; +#endif + + default: Mix_SetError("Unrecognized music format"); music->error=1; - } + } /* switch (want) */ -skip: if (music->error) { free(music); music=NULL; diff -r 3a4c352a9a00 music_flac.c --- a/music_flac.c Thu Jul 14 12:33:48 2011 -0700 +++ b/music_flac.c Sun Jul 24 21:44:00 2011 +0300 @@ -52,19 +52,6 @@ music->volume = volume; } -/* Load an FLAC stream from the given file */ -FLAC_music *FLAC_new(const char *file) -{ - SDL_RWops *rw; - - rw = SDL_RWFromFile (file, "rb"); - if (rw == NULL) { - SDL_SetError ("Couldn't open %s", file); - return NULL; - } - return FLAC_new_RW (rw); -} - static FLAC__StreamDecoderReadStatus flac_read_music_cb( const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], diff -r 3a4c352a9a00 music_flac.h --- a/music_flac.h Thu Jul 14 12:33:48 2011 -0700 +++ b/music_flac.h Sun Jul 24 21:44:00 2011 +0300 @@ -66,9 +66,6 @@ /* Set the volume for a FLAC stream */ extern void FLAC_setvolume(FLAC_music *music, int volume); -/* Load a FLAC stream from the given file */ -extern FLAC_music *FLAC_new(const char *file); - /* Load an FLAC stream from an SDL_RWops object */ extern FLAC_music *FLAC_new_RW(SDL_RWops *rw); diff -r 3a4c352a9a00 music_mad.c --- a/music_mad.c Thu Jul 14 12:33:48 2011 -0700 +++ b/music_mad.c Sun Jul 24 21:44:00 2011 +0300 @@ -27,25 +27,6 @@ #include "music_mad.h" mad_data * -mad_openFile(const char *filename, SDL_AudioSpec *mixer) { - SDL_RWops *rw; - mad_data *mp3_mad; - - rw = SDL_RWFromFile(filename, "rb"); - if (rw == NULL) { - return NULL; - } - - mp3_mad = mad_openFileRW(rw, mixer); - if (mp3_mad == NULL) { - SDL_FreeRW(rw); - return NULL; - } - mp3_mad->freerw = SDL_TRUE; - return mp3_mad; -} - -mad_data * mad_openFileRW(SDL_RWops *rw, SDL_AudioSpec *mixer) { mad_data *mp3_mad; diff -r 3a4c352a9a00 music_mad.h --- a/music_mad.h Thu Jul 14 12:33:48 2011 -0700 +++ b/music_mad.h Sun Jul 24 21:44:00 2011 +0300 @@ -59,7 +59,6 @@ unsigned char output_buffer[MAD_OUTPUT_BUFFER_SIZE]; } mad_data; -mad_data *mad_openFile(const char *filename, SDL_AudioSpec *mixer); mad_data *mad_openFileRW(SDL_RWops *rw, SDL_AudioSpec *mixer); void mad_closeFile(mad_data *mp3_mad); diff -r 3a4c352a9a00 music_mod.c --- a/music_mod.c Thu Jul 14 12:33:48 2011 -0700 +++ b/music_mod.c Sun Jul 24 21:44:00 2011 +0300 @@ -142,21 +142,6 @@ mikmod.Player_SetVolume((SWORD)volume); } -/* Load a MOD stream from the given file */ -MODULE *MOD_new(const char *file) -{ - SDL_RWops *rw; - - rw = SDL_RWFromFile(file, "rb"); - if ( rw == NULL ) { - /* FIXME: Free rw, need to free on delete */ - SDL_SetError("Couldn't open %s", file); - return NULL; - } - return MOD_new_RW(rw); -} - - typedef struct { MREADER mr; diff -r 3a4c352a9a00 music_mod.h --- a/music_mod.h Thu Jul 14 12:33:48 2011 -0700 +++ b/music_mod.h Sun Jul 24 21:44:00 2011 +0300 @@ -39,9 +39,6 @@ /* Set the volume for a MOD stream */ extern void MOD_setvolume(struct MODULE *music, int volume); -/* Load a MOD stream from the given file */ -extern struct MODULE *MOD_new(const char *file); - /* Load a MOD stream from an SDL_RWops object */ extern struct MODULE *MOD_new_RW(SDL_RWops *rw); diff -r 3a4c352a9a00 music_modplug.c --- a/music_modplug.c Thu Jul 14 12:33:48 2011 -0700 +++ b/music_modplug.c Sun Jul 24 21:44:00 2011 +0300 @@ -74,21 +74,6 @@ ModPlug_SetMasterVolume(music->file, volume*4); } -/* Load a modplug stream from the given file */ -modplug_data *modplug_new(const char *file) -{ - SDL_RWops *rw; - - rw = SDL_RWFromFile(file, "rb"); - if ( rw == NULL ) { - /* FIXME: Free rw, need to free on delete */ - SDL_SetError("Couldn't open %s", file); - return NULL; - } - return modplug_new_RW(rw); - -} - /* Load a modplug stream from an SDL_RWops object */ modplug_data *modplug_new_RW(SDL_RWops *rw) { diff -r 3a4c352a9a00 music_modplug.h --- a/music_modplug.h Thu Jul 14 12:33:48 2011 -0700 +++ b/music_modplug.h Sun Jul 24 21:44:00 2011 +0300 @@ -18,9 +18,6 @@ /* Set the volume for a modplug stream */ void modplug_setvolume(modplug_data *music, int volume); -/* Load a modplug stream from the given file */ -modplug_data *modplug_new(const char *file); - /* Load a modplug stream from an SDL_RWops object */ modplug_data *modplug_new_RW(SDL_RWops *rw); diff -r 3a4c352a9a00 music_ogg.c --- a/music_ogg.c Thu Jul 14 12:33:48 2011 -0700 +++ b/music_ogg.c Sun Jul 24 21:44:00 2011 +0300 @@ -52,20 +52,6 @@ music->volume = volume; } -/* Load an OGG stream from the given file */ -OGG_music *OGG_new(const char *file) -{ - SDL_RWops *rw; - - rw = SDL_RWFromFile(file, "rb"); - if ( rw == NULL ) { - SDL_SetError("Couldn't open %s", file); - return NULL; - } - return OGG_new_RW(rw); -} - - static size_t sdl_read_func(void *ptr, size_t size, size_t nmemb, void *datasource) { return SDL_RWread((SDL_RWops*)datasource, ptr, size, nmemb); diff -r 3a4c352a9a00 music_ogg.h --- a/music_ogg.h Thu Jul 14 12:33:48 2011 -0700 +++ b/music_ogg.h Sun Jul 24 21:44:00 2011 +0300 @@ -50,9 +50,6 @@ /* Set the volume for an OGG stream */ extern void OGG_setvolume(OGG_music *music, int volume); -/* Load an OGG stream from the given file */ -extern OGG_music *OGG_new(const char *file); - /* Load an OGG stream from an SDL_RWops object */ extern OGG_music *OGG_new_RW(SDL_RWops *rw); diff -r 3a4c352a9a00 native_midi/native_midi.h --- a/native_midi/native_midi.h Thu Jul 14 12:33:48 2011 -0700 +++ b/native_midi/native_midi.h Sun Jul 24 21:44:00 2011 +0300 @@ -28,7 +28,6 @@ typedef struct _NativeMidiSong NativeMidiSong; int native_midi_detect(); -NativeMidiSong *native_midi_loadsong(const char *midifile); NativeMidiSong *native_midi_loadsong_RW(SDL_RWops *rw); void native_midi_freesong(NativeMidiSong *song); void native_midi_start(NativeMidiSong *song); diff -r 3a4c352a9a00 native_midi/native_midi_haiku.cpp --- a/native_midi/native_midi_haiku.cpp Thu Jul 14 12:33:48 2011 -0700 +++ b/native_midi/native_midi_haiku.cpp Sun Jul 24 21:44:00 2011 +0300 @@ -230,15 +230,6 @@ return song; } -NativeMidiSong *native_midi_loadsong(const char *midifile) -{ - SDL_RWops *rw = SDL_RWFromFile(midifile, "rb"); - if (!rw) return NULL; - NativeMidiSong *song = native_midi_loadsong_RW(rw); - SDL_RWclose(rw); - return song; -} - void native_midi_freesong(NativeMidiSong *song) { if (song == NULL) return; diff -r 3a4c352a9a00 native_midi/native_midi_mac.c --- a/native_midi/native_midi_mac.c Thu Jul 14 12:33:48 2011 -0700 +++ b/native_midi/native_midi_mac.c Sun Jul 24 21:44:00 2011 +0300 @@ -89,74 +89,6 @@ return 1; } -NativeMidiSong *native_midi_loadsong(const char *midifile) -{ - NativeMidiSong *song = NULL; - MIDIEvent *evntlist = NULL; - int part_to_inst[32]; - int part_poly_max[32]; - int numParts = 0; - Uint16 ppqn; - SDL_RWops *rw; - - /* Init the arrays */ - memset(part_poly_max,0,sizeof(part_poly_max)); - memset(part_to_inst,-1,sizeof(part_to_inst)); - - /* Attempt to load the midi file */ - rw = SDL_RWFromFile(midifile, "rb"); - if (rw) { - evntlist = CreateMIDIEventList(rw, &ppqn); - SDL_RWclose(rw); - if (!evntlist) - goto bail; - } - - /* Allocate memory for the song struct */ - song = malloc(sizeof(NativeMidiSong)); - if (!song) - goto bail; - - /* Build a tune sequence from the event list */ - song->tuneSequence = BuildTuneSequence(evntlist, ppqn, part_poly_max, part_to_inst, &numParts); - if(!song->tuneSequence) - goto bail; - - /* Now build a tune header from the data we collect above, create - all parts as needed and assign them the correct instrument. - */ - song->tuneHeader = BuildTuneHeader(part_poly_max, part_to_inst, numParts); - if(!song->tuneHeader) - goto bail; - - /* Increment the instance count */ - gInstaceCount++; - if (gTunePlayer == NULL) - gTunePlayer = OpenDefaultComponent(kTunePlayerComponentType, 0); - - /* Finally, free the event list */ - FreeMIDIEventList(evntlist); - - return song; - -bail: - if (evntlist) - FreeMIDIEventList(evntlist); - - if (song) - { - if(song->tuneSequence) - free(song->tuneSequence); - - if(song->tuneHeader) - DisposePtr((Ptr)song->tuneHeader); - - free(song); - } - - return NULL; -} - NativeMidiSong *native_midi_loadsong_RW(SDL_RWops *rw) { NativeMidiSong *song = NULL; diff -r 3a4c352a9a00 native_midi/native_midi_macosx.c --- a/native_midi/native_midi_macosx.c Thu Jul 14 12:33:48 2011 -0700 +++ b/native_midi/native_midi_macosx.c Sun Jul 24 21:44:00 2011 +0300 @@ -145,18 +145,6 @@ return 1; /* always available. */ } -NativeMidiSong *native_midi_loadsong(const char *midifile) -{ - NativeMidiSong *retval = NULL; - SDL_RWops *rw = SDL_RWFromFile(midifile, "rb"); - if (rw != NULL) { - retval = native_midi_loadsong_RW(rw); - SDL_RWclose(rw); - } - - return retval; -} - NativeMidiSong *native_midi_loadsong_RW(SDL_RWops *rw) { NativeMidiSong *retval = NULL; diff -r 3a4c352a9a00 native_midi/native_midi_win32.c --- a/native_midi/native_midi_win32.c Thu Jul 14 12:33:48 2011 -0700 +++ b/native_midi/native_midi_win32.c Sun Jul 24 21:44:00 2011 +0300 @@ -188,36 +188,6 @@ return 1; } -NativeMidiSong *native_midi_loadsong(const char *midifile) -{ - NativeMidiSong *newsong; - MIDIEvent *evntlist = NULL; - SDL_RWops *rw; - - newsong=malloc(sizeof(NativeMidiSong)); - if (!newsong) - return NULL; - memset(newsong,0,sizeof(NativeMidiSong)); - - /* Attempt to load the midi file */ - rw = SDL_RWFromFile(midifile, "rb"); - if (rw) { - evntlist = CreateMIDIEventList(rw, &newsong->ppqn); - SDL_RWclose(rw); - if (!evntlist) - { - free(newsong); - return NULL; - } - } - - MIDItoStream(newsong, evntlist); - - FreeMIDIEventList(evntlist); - - return newsong; -} - NativeMidiSong *native_midi_loadsong_RW(SDL_RWops *rw) { NativeMidiSong *newsong; diff -r 3a4c352a9a00 native_midi_gpl/native_midi_gpl.c --- a/native_midi_gpl/native_midi_gpl.c Thu Jul 14 12:33:48 2011 -0700 +++ b/native_midi_gpl/native_midi_gpl.c Sun Jul 24 21:44:00 2011 +0300 @@ -127,91 +127,6 @@ return ret; } -NativeMidiSong *native_midi_loadsong(const char *midifile) -{ - NativeMidiSong *song = NULL; - char *extra; - int piped = 0; - struct stat info; - - song = malloc(sizeof(NativeMidiSong)); - if (!song) - { - return NULL; - }; - if (stat(midifile, &info) == -1) - { - if ((extra = malloc(strlen(midifile) + 4)) == NULL) - { - goto end; - } - sprintf(extra, "%s.mid", midifile); - if (stat(extra, &info) == -1) - { - free(extra); - goto end; - } - if ((mfd = fopen(extra, "r")) == NULL) - { - free(extra); - goto end; - } - free(extra); - } else - { - char *ext = strrchr(midifile, '.'); - if (ext && strcmp(ext, ".gz") == 0) - { - char temp[1024]; - piped = 1; - sprintf(temp, "gzip -l %s", midifile); - if ((mfd = popen(temp, "r")) == NULL) - { - goto end; - } - fgets(temp, sizeof(temp), mfd); /* skip 1st line */ - fgets(temp, sizeof(temp), mfd); - strtok(temp, " "); /* compressed size */ - info.st_size = atoi(strtok(NULL, " ")); /* original size */ - pclose(mfd); - sprintf(temp, "gzip -d -c %s",midifile); - if ((mfd = popen(temp, "r")) == NULL) - { - goto end; - } - }else if ((mfd = fopen(midifile, "r")) == NULL) - { - goto end; - } - } - if ((song->filebuf = malloc(info.st_size)) == NULL) - { - if (piped) - { - pclose(mfd); - }else - { - fclose(mfd); - } - goto end; - } - song->file_size=info.st_size; - fread(song->filebuf, 1, info.st_size, mfd); - if (piped) - { - pclose(mfd); - } else - { - fclose(mfd); - } - - return song; - -end: - free(song); - return NULL; -} - NativeMidiSong *native_midi_loadsong_RW(SDL_RWops *rw) { NativeMidiSong *song = NULL; diff -r 3a4c352a9a00 timidity/playmidi.c --- a/timidity/playmidi.c Thu Jul 14 12:33:48 2011 -0700 +++ b/timidity/playmidi.c Sun Jul 24 21:44:00 2011 +0300 @@ -1691,33 +1691,6 @@ ctl->master_volume(amplification); } -MidiSong *Timidity_LoadSong(const char *midifile) -{ - MidiSong *song; - int32 events; - SDL_RWops *rw; - - /* Allocate memory for the song */ - song = (MidiSong *)safe_malloc(sizeof(*song)); - memset(song, 0, sizeof(*song)); - - /* Open the file */ - strcpy(midi_name, midifile); - - rw = SDL_RWFromFile(midifile, "rb"); - if ( rw != NULL ) { - song->events=read_midi_file(rw, &events, &song->samples); - SDL_RWclose(rw); - } - - /* Make sure everything is okay */ - if (!song->events) { - free(song); - song = NULL; - } - return(song); -} - MidiSong *Timidity_LoadSong_RW(SDL_RWops *rw) { MidiSong *song; diff -r 3a4c352a9a00 timidity/timidity.h --- a/timidity/timidity.h Thu Jul 14 12:33:48 2011 -0700 +++ b/timidity/timidity.h Sun Jul 24 21:44:00 2011 +0300 @@ -25,7 +25,6 @@ extern const char *Timidity_Error(void); extern void Timidity_SetVolume(int volume); extern int Timidity_PlaySome(void *stream, int samples); -extern MidiSong *Timidity_LoadSong(const char *midifile); extern MidiSong *Timidity_LoadSong_RW(SDL_RWops *rw); extern void Timidity_Start(MidiSong *song); extern int Timidity_Active(void); diff -r 3a4c352a9a00 wavestream.c --- a/wavestream.c Thu Jul 14 12:33:48 2011 -0700 +++ b/wavestream.c Sun Jul 24 21:44:00 2011 +0300 @@ -114,25 +114,7 @@ wavestream_volume = volume; } -WAVStream *WAVStream_LoadSong(const char *file, const char *magic) -{ - SDL_RWops *rw; - WAVStream *wave; - - rw = SDL_RWFromFile(file, "rb"); - if ( rw == NULL ) { - SDL_SetError("Couldn't open %s", file); - return NULL; - } - wave = WAVStream_LoadSong_RW(rw, magic); - if ( wave == NULL ) { - SDL_FreeRW(rw); - return NULL; - } - return wave; -} - -/* Load a WAV stream from the given file */ +/* Load a WAV stream from the given RWops */ WAVStream *WAVStream_LoadSong_RW(SDL_RWops *rw, const char *magic) { WAVStream *wave; diff -r 3a4c352a9a00 wavestream.h --- a/wavestream.h Thu Jul 14 12:33:48 2011 -0700 +++ b/wavestream.h Sun Jul 24 21:44:00 2011 +0300 @@ -42,9 +42,6 @@ /* Unimplemented */ extern void WAVStream_SetVolume(int volume); -/* Load a WAV stream from the given file */ -extern WAVStream *WAVStream_LoadSong(const char *file, const char *magic); - /* Load a WAV stream from an SDL_RWops object */ extern WAVStream *WAVStream_LoadSong_RW(SDL_RWops *rw, const char *magic);