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 dc5603176dfb SDL_mixer.h --- a/SDL_mixer.h Mon Jan 02 18:38:06 2012 -0500 +++ b/SDL_mixer.h Tue Jan 03 03:29:18 2012 +0200 @@ -154,6 +154,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 dc5603176dfb VisualC/smpeg/include/smpeg.h --- a/VisualC/smpeg/include/smpeg.h Mon Jan 02 18:38:06 2012 -0500 +++ b/VisualC/smpeg/include/smpeg.h Tue Jan 03 03:29:18 2012 +0200 @@ -83,18 +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. - 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 - whether or not there was a problem building the MPEG stream. - The sdl_audio parameter indicates if SMPEG should initialize the SDL audio - 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 */ +/* Create a new SMPEG object from an MPEG file descriptor. */ extern DECLSPEC SMPEG* SMPEG_new_descr(int file, SMPEG_Info* info, int sdl_audio); /* diff -r dc5603176dfb dynamic_mp3.c --- a/dynamic_mp3.c Mon Jan 02 18:38:06 2012 -0500 +++ b/dynamic_mp3.c Tue Jan 03 03:29:18 2012 +0200 @@ -65,13 +65,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"); @@ -151,7 +144,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 dc5603176dfb dynamic_mp3.h --- a/dynamic_mp3.h Mon Jan 02 18:38:06 2012 -0500 +++ b/dynamic_mp3.h Tue Jan 03 03:29:18 2012 +0200 @@ -29,7 +29,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 dc5603176dfb music.c --- a/music.c Mon Jan 02 18:38:06 2012 -0500 +++ b/music.c Tue Jan 03 03:29:18 2012 +0200 @@ -436,198 +436,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; } - } else + 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; + } #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 ) { -/*printf("Native MIDI\n");*/ - 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 ) { -/*printf("FluidSynth MIDI\n");*/ - music->data.fluidsynthmidi = fluidsynth_loadsong(file); - if ( music->data.fluidsynthmidi == NULL ) { - music->error = 1; - } - goto skip; - } -#endif -#ifdef USE_TIMIDITY_MIDI - if ( timidity_ok ) { -/*printf("Timidity MIDI\n");*/ - 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 */ @@ -1415,13 +1377,12 @@ 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; int freerw = 0; if (!rw) { @@ -1429,16 +1390,15 @@ 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)); @@ -1448,42 +1408,47 @@ } 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, freerw); - 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, freerw); + } + if (music->data.wave == NULL) { music->error = 1; } - - } else + break; #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, freerw); 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, freerw); 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; @@ -1497,21 +1462,19 @@ } 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, freerw); 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 ) { @@ -1520,7 +1483,7 @@ Mix_SetError("%s", native_midi_error()); music->error = 1; } - goto skip; + break; } #endif #ifdef USE_FLUIDSYNTH_MIDI @@ -1529,7 +1492,7 @@ if ( music->data.fluidsynthmidi == NULL ) { music->error = 1; } - goto skip; + break; } #endif #ifdef USE_TIMIDITY_MIDI @@ -1544,10 +1507,10 @@ 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 ) { @@ -1567,14 +1530,15 @@ } } #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 dc5603176dfb music_flac.c --- a/music_flac.c Mon Jan 02 18:38:06 2012 -0500 +++ b/music_flac.c Tue Jan 03 03:29:18 2012 +0200 @@ -50,19 +50,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, 1); -} - static FLAC__StreamDecoderReadStatus flac_read_music_cb( const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], diff -r dc5603176dfb music_flac.h --- a/music_flac.h Mon Jan 02 18:38:06 2012 -0500 +++ b/music_flac.h Tue Jan 03 03:29:18 2012 +0200 @@ -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, int freerw); diff -r dc5603176dfb music_mad.c --- a/music_mad.c Mon Jan 02 18:38:06 2012 -0500 +++ b/music_mad.c Tue Jan 03 03:29:18 2012 +0200 @@ -26,20 +26,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; - } - - return mad_openFileRW(rw, mixer, 1); -} - -mad_data * mad_openFileRW(SDL_RWops *rw, SDL_AudioSpec *mixer, int freerw) { mad_data *mp3_mad; diff -r dc5603176dfb music_mad.h --- a/music_mad.h Mon Jan 02 18:38:06 2012 -0500 +++ b/music_mad.h Tue Jan 03 03:29:18 2012 +0200 @@ -58,7 +58,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, int freerw); void mad_closeFile(mad_data *mp3_mad); diff -r dc5603176dfb music_mod.c --- a/music_mod.c Mon Jan 02 18:38:06 2012 -0500 +++ b/music_mod.c Tue Jan 03 03:29:18 2012 +0200 @@ -141,21 +141,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, 1); -} - - typedef struct { MREADER mr; diff -r dc5603176dfb music_mod.h --- a/music_mod.h Mon Jan 02 18:38:06 2012 -0500 +++ b/music_mod.h Tue Jan 03 03:29:18 2012 +0200 @@ -38,9 +38,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, int freerw); diff -r dc5603176dfb music_modplug.c --- a/music_modplug.c Mon Jan 02 18:38:06 2012 -0500 +++ b/music_modplug.c Tue Jan 03 03:29:18 2012 +0200 @@ -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, 1); - -} - /* Load a modplug stream from an SDL_RWops object */ modplug_data *modplug_new_RW(SDL_RWops *rw, int freerw) { diff -r dc5603176dfb music_modplug.h --- a/music_modplug.h Mon Jan 02 18:38:06 2012 -0500 +++ b/music_modplug.h Tue Jan 03 03:29:18 2012 +0200 @@ -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, int freerw); diff -r dc5603176dfb music_ogg.c --- a/music_ogg.c Mon Jan 02 18:38:06 2012 -0500 +++ b/music_ogg.c Tue Jan 03 03:29:18 2012 +0200 @@ -51,20 +51,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, 1); -} - - 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 dc5603176dfb music_ogg.h --- a/music_ogg.h Mon Jan 02 18:38:06 2012 -0500 +++ b/music_ogg.h Tue Jan 03 03:29:18 2012 +0200 @@ -51,9 +51,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, int freerw); diff -r dc5603176dfb native_midi/native_midi.h --- a/native_midi/native_midi.h Mon Jan 02 18:38:06 2012 -0500 +++ b/native_midi/native_midi.h Tue Jan 03 03:29:18 2012 +0200 @@ -27,7 +27,6 @@ typedef struct _NativeMidiSong NativeMidiSong; int native_midi_detect(); -NativeMidiSong *native_midi_loadsong(const char *midifile); NativeMidiSong *native_midi_loadsong_RW(SDL_RWops *rw, int freerw); void native_midi_freesong(NativeMidiSong *song); void native_midi_start(NativeMidiSong *song, int loops); diff -r dc5603176dfb native_midi/native_midi_haiku.cpp --- a/native_midi/native_midi_haiku.cpp Mon Jan 02 18:38:06 2012 -0500 +++ b/native_midi/native_midi_haiku.cpp Tue Jan 03 03:29:18 2012 +0200 @@ -238,13 +238,6 @@ return song; } -NativeMidiSong *native_midi_loadsong(const char *midifile) -{ - SDL_RWops *rw = SDL_RWFromFile(midifile, "rb"); - if (!rw) return NULL; - return native_midi_loadsong_RW(rw, 1); -} - void native_midi_freesong(NativeMidiSong *song) { if (song == NULL) return; diff -r dc5603176dfb native_midi/native_midi_mac.c --- a/native_midi/native_midi_mac.c Mon Jan 02 18:38:06 2012 -0500 +++ b/native_midi/native_midi_mac.c Tue Jan 03 03:29:18 2012 +0200 @@ -88,18 +88,6 @@ return 1; } -NativeMidiSong *native_midi_loadsong(const char *midifile) -{ - SDL_RWops *rw; - - /* Attempt to load the midi file */ - rw = SDL_RWFromFile(midifile, "rb"); - if (!rw) { - return NULL; - } - return native_midi_loadsong_RW(rw, 1); -} - NativeMidiSong *native_midi_loadsong_RW(SDL_RWops *rw, int freerw) { NativeMidiSong *song = NULL; diff -r dc5603176dfb native_midi/native_midi_macosx.c --- a/native_midi/native_midi_macosx.c Mon Jan 02 18:38:06 2012 -0500 +++ b/native_midi/native_midi_macosx.c Tue Jan 03 03:29:18 2012 +0200 @@ -145,17 +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, 1); - } - - return retval; -} - NativeMidiSong *native_midi_loadsong_RW(SDL_RWops *rw, int freerw) { NativeMidiSong *retval = NULL; diff -r dc5603176dfb native_midi/native_midi_win32.c --- a/native_midi/native_midi_win32.c Mon Jan 02 18:38:06 2012 -0500 +++ b/native_midi/native_midi_win32.c Tue Jan 03 03:29:18 2012 +0200 @@ -200,18 +200,6 @@ return 1; } -NativeMidiSong *native_midi_loadsong(const char *midifile) -{ - SDL_RWops *rw; - - /* Attempt to load the midi file */ - rw = SDL_RWFromFile(midifile, "rb"); - if (!rw) { - return NULL; - } - return native_midi_loadsong_RW(rw, 1); -} - NativeMidiSong *native_midi_loadsong_RW(SDL_RWops *rw, int freerw) { NativeMidiSong *newsong; diff -r dc5603176dfb timidity/playmidi.c --- a/timidity/playmidi.c Mon Jan 02 18:38:06 2012 -0500 +++ b/timidity/playmidi.c Tue Jan 03 03:29:18 2012 +0200 @@ -1676,33 +1676,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, int freerw) { MidiSong *song; diff -r dc5603176dfb timidity/timidity.h --- a/timidity/timidity.h Mon Jan 02 18:38:06 2012 -0500 +++ b/timidity/timidity.h Tue Jan 03 03:29:18 2012 +0200 @@ -12,7 +12,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, int freerw); extern void Timidity_Start(MidiSong *song); extern int Timidity_Active(void); diff -r dc5603176dfb wavestream.c --- a/wavestream.c Mon Jan 02 18:38:06 2012 -0500 +++ b/wavestream.c Tue Jan 03 03:29:18 2012 +0200 @@ -113,19 +113,7 @@ wavestream_volume = volume; } -WAVStream *WAVStream_LoadSong(const char *file, const char *magic) -{ - SDL_RWops *rw; - - rw = SDL_RWFromFile(file, "rb"); - if ( rw == NULL ) { - SDL_SetError("Couldn't open %s", file); - return NULL; - } - return WAVStream_LoadSong_RW(rw, magic, 1); -} - -/* Load a WAV stream from the given file */ +/* Load a WAV stream from the given RWops object */ WAVStream *WAVStream_LoadSong_RW(SDL_RWops *rw, const char *magic, int freerw) { WAVStream *wave; diff -r dc5603176dfb wavestream.h --- a/wavestream.h Mon Jan 02 18:38:06 2012 -0500 +++ b/wavestream.h Tue Jan 03 03:29:18 2012 +0200 @@ -41,9 +41,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, int freerw);