From 89c8c0a849b7e561fddf6686bd1c1912f9ba52f9 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Wed, 4 Jan 2012 00:16:03 -0500 Subject: [PATCH] Fixed bug 1252 - Added Mix_LoadMUSType_RW() so you can tell SDL_mixer what type the music is This involved a complete refactoring of the music loading so it's entirely rwops based and has improved music type detection code. --- CHANGES | 2 + SDL_mixer.h | 3 + configure | 2 +- configure.in | 2 +- dynamic_mp3.c | 8 - dynamic_mp3.h | 1 - fluidsynth.c | 21 +- fluidsynth.h | 1 - music.c | 543 ++++++++++++++---------------- music_flac.c | 13 - music_flac.h | 3 - music_mad.c | 14 - music_mad.h | 1 - music_mod.c | 15 - music_mod.h | 3 - music_modplug.c | 15 - music_modplug.h | 3 - music_ogg.c | 14 - music_ogg.h | 3 - native_midi/native_midi.h | 1 - native_midi/native_midi_haiku.cpp | 7 - native_midi/native_midi_mac.c | 12 - native_midi/native_midi_macosx.c | 11 - native_midi/native_midi_win32.c | 12 - timidity/playmidi.c | 27 -- timidity/timidity.h | 1 - wavestream.c | 14 +- wavestream.h | 3 - 28 files changed, 257 insertions(+), 498 deletions(-) diff --git a/CHANGES b/CHANGES index f138e844..0b137038 100644 --- a/CHANGES +++ b/CHANGES @@ -1,6 +1,8 @@ 1.2.12: Sam Lantinga - Tue Jan 3 01:36:33 EST 2012 * The Mac OS X framework name changed to SDLmixer, to meet Apple's requirements +Nikos Chantziaras - 2012-01-02 17:37:36 PST + * Added Mix_LoadMUSType_RW() so you can tell SDL_mixer what type the music is Sam Lantinga - Sat Dec 31 19:11:59 EST 2011 * Fixed dropping audio in the FLAC audio decoding Sam Lantinga - Sat Dec 31 18:32:05 EST 2011 diff --git a/SDL_mixer.h b/SDL_mixer.h index 838de461..d96f48d0 100644 --- a/SDL_mixer.h +++ b/SDL_mixer.h @@ -154,6 +154,9 @@ extern DECLSPEC Mix_Music * SDLCALL Mix_LoadMUS(const char *file); 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, int freesrc); + /* Load a wave file of the mixer format from a memory buffer */ extern DECLSPEC Mix_Chunk * SDLCALL Mix_QuickLoad_WAV(Uint8 *mem); diff --git a/configure b/configure index d8dcdce0..1fe9b2c1 100755 --- a/configure +++ b/configure @@ -1995,7 +1995,7 @@ ac_configure="$SHELL $ac_aux_dir/configure" # Please don't use this var. MAJOR_VERSION=1 MINOR_VERSION=2 MICRO_VERSION=12 -INTERFACE_AGE=2 +INTERFACE_AGE=0 BINARY_AGE=12 VERSION=$MAJOR_VERSION.$MINOR_VERSION.$MICRO_VERSION diff --git a/configure.in b/configure.in index 77d1d0d4..2397c11d 100644 --- a/configure.in +++ b/configure.in @@ -15,7 +15,7 @@ dnl Set various version strings - taken gratefully from the GTk sources MAJOR_VERSION=1 MINOR_VERSION=2 MICRO_VERSION=12 -INTERFACE_AGE=2 +INTERFACE_AGE=0 BINARY_AGE=12 VERSION=$MAJOR_VERSION.$MINOR_VERSION.$MICRO_VERSION diff --git a/dynamic_mp3.c b/dynamic_mp3.c index 8deb43a1..83a3e309 100644 --- a/dynamic_mp3.c +++ b/dynamic_mp3.c @@ -65,13 +65,6 @@ int Mix_InitMP3() 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 @@ int Mix_InitMP3() 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 --git a/dynamic_mp3.h b/dynamic_mp3.h index e44e6a27..03cbbbf9 100644 --- a/dynamic_mp3.h +++ b/dynamic_mp3.h @@ -29,7 +29,6 @@ typedef struct { 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 --git a/fluidsynth.c b/fluidsynth.c index 144b01ba..d7a72d1a 100644 --- a/fluidsynth.c +++ b/fluidsynth.c @@ -66,7 +66,7 @@ int fluidsynth_init(SDL_AudioSpec *mixer) return 0; } -FluidSynthMidiSong *fluidsynth_loadsong_common(int (*function)(FluidSynthMidiSong*, void*), void *data) +static FluidSynthMidiSong *fluidsynth_loadsong_common(int (*function)(FluidSynthMidiSong*, void*), void *data) { FluidSynthMidiSong *song; fluid_settings_t *settings = NULL; @@ -105,19 +105,7 @@ FluidSynthMidiSong *fluidsynth_loadsong_common(int (*function)(FluidSynthMidiSon return NULL; } -int fluidsynth_loadsong_internal(FluidSynthMidiSong *song, void *data) -{ - const char* path = (const char*) data; - - if (fluidsynth.fluid_player_add(song->player, path) == FLUID_OK) { - return 1; - } else { - Mix_SetError("FluidSynth failed to load %s", path); - return 0; - } -} - -int fluidsynth_loadsong_RW_internal(FluidSynthMidiSong *song, void *data) +static int fluidsynth_loadsong_RW_internal(FluidSynthMidiSong *song, void *data) { off_t offset; size_t size; @@ -146,11 +134,6 @@ int fluidsynth_loadsong_RW_internal(FluidSynthMidiSong *song, void *data) return 0; } -FluidSynthMidiSong *fluidsynth_loadsong(const char *midifile) -{ - return fluidsynth_loadsong_common(fluidsynth_loadsong_internal, (void*) midifile); -} - FluidSynthMidiSong *fluidsynth_loadsong_RW(SDL_RWops *rw, int freerw) { FluidSynthMidiSong *song; diff --git a/fluidsynth.h b/fluidsynth.h index df9403ed..47538bbc 100644 --- a/fluidsynth.h +++ b/fluidsynth.h @@ -38,7 +38,6 @@ typedef struct { } FluidSynthMidiSong; int fluidsynth_init(SDL_AudioSpec *mixer); -FluidSynthMidiSong *fluidsynth_loadsong(const char *midifile); FluidSynthMidiSong *fluidsynth_loadsong_RW(SDL_RWops *rw, int freerw); void fluidsynth_freesong(FluidSynthMidiSong *song); void fluidsynth_start(FluidSynthMidiSong *song); diff --git a/music.c b/music.c index 083d906a..556882fe 100755 --- a/music.c +++ b/music.c @@ -438,141 +438,226 @@ int MIX_string_equals(const char *str1, const char *str2) return (!*str1 && !*str2); } +static int detect_mp3(Uint8 *magic) +{ + if ( strncmp((char *)magic, "ID3", 3) == 0 ) { + return 1; + } + + /* Detection code lifted from SMPEG */ + if(((magic[0] & 0xff) != 0xff) || // No sync bits + ((magic[1] & 0xf0) != 0xf0) || // + ((magic[2] & 0xf0) == 0x00) || // Bitrate is 0 + ((magic[2] & 0xf0) == 0xf0) || // Bitrate is 15 + ((magic[2] & 0x0c) == 0x0c) || // Frequency is 3 + ((magic[1] & 0x06) == 0x00)) { // Layer is 4 + return(0); + } + return 1; +} + +/* 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; + } + + /* MIDI files have the magic four bytes "MThd" */ + if (strcmp((char *)magic, "MThd") == 0) { + return MUS_MID; + } + + if (detect_mp3(magic)) { + return MUS_MP3; + } + + /* 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; + Mix_MusicType type; + char *ext = strrchr(file, '.'); - /* 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); +#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); } - Mix_SetError("Couldn't read from '%s'", file); - return(NULL); + music->error = 0; + music->type = MUS_CMD; + music->data.cmd = MusicCMD_LoadSong(music_cmd, file); + if ( music->data.cmd == NULL ) { + free(music); + music == NULL; + } + return music; } - if (!fread(moremagic, 8, 1, fp)) { - Mix_SetError("Couldn't read from '%s'", file); - return(NULL); +#endif + + rw = SDL_RWFromFile(file, "rb"); + if ( rw == NULL ) { + Mix_SetError("Couldn't open '%s'", file); + return NULL; } - magic[4] = '\0'; - moremagic[8] = '\0'; - fclose(fp); - /* Figure out the file extension, so we can determine the type */ + /* Use the extension as a first guess on the file type */ + type = MUS_NONE; ext = strrchr(file, '.'); - if ( ext ) ++ext; /* skip the dot in the extension */ + /* 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") || + MIX_string_equals(ext, "KAR") ) { + 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, "MPEG") || + MIX_string_equals(ext, "MP3") || + MIX_string_equals(ext, "MAD") ) { + type = MUS_MP3; + } + } + if ( type == MUS_NONE ) { + type = detect_music_type(rw); + } + + /* 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, SDL_TRUE); + if ( music == NULL && Mix_GetError()[0] == '\0' ) { + SDL_FreeRW(rw); + Mix_SetError("Couldn't open '%s'", file); + } + return music; +} + +Mix_Music *Mix_LoadMUS_RW(SDL_RWops *rw) +{ + return Mix_LoadMUSType_RW(rw, MUS_NONE, SDL_FALSE); +} + +Mix_Music *Mix_LoadMUSType_RW(SDL_RWops *rw, Mix_MusicType type, int freesrc) +{ + Mix_Music *music; + + if (!rw) { + Mix_SetError("RWops pointer is NULL"); + 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; + } + } /* Allocate memory for the music structure */ music = (Mix_Music *)malloc(sizeof(Mix_Music)); - if ( music == NULL ) { + if (music == NULL ) { Mix_SetError("Out of memory"); - return(NULL); + return NULL; } music->error = 0; -#ifdef CMD_MUSIC - if ( music_cmd ) { - music->type = MUS_CMD; - music->data.cmd = MusicCMD_LoadSong(music_cmd, file); - if ( music->data.cmd == NULL ) { - music->error = 1; - } - } else -#endif + switch (type) { #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 -#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; + 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; } - goto skip; + SDL_RWseek(rw, start, RW_SEEK_SET); + magic[4] = '\0'; + music->type = MUS_WAV; + music->data.wave = WAVStream_LoadSong_RW(rw, (char *)magic, freesrc); } -#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()); + if (music->data.wave == NULL) { music->error = 1; } -#endif - } else + break; #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 ) { + case MUS_OGG: music->type = MUS_OGG; - music->data.ogg = OGG_new(file); + music->data.ogg = OGG_new_RW(rw, freesrc); if ( music->data.ogg == NULL ) { music->error = 1; } - } else + break; #endif #ifdef FLAC_MUSIC - /* FLAC files have the magic four bytes "fLaC" */ - if ( (ext && MIX_string_equals(ext, "FLAC")) || - strcmp((char *)magic, "fLaC") == 0 ) { + case MUS_FLAC: music->type = MUS_FLAC; - music->data.flac = FLAC_new(file); + music->data.flac = FLAC_new_RW(rw, freesrc); if ( music->data.flac == NULL ) { music->error = 1; } - } else + break; #endif #ifdef MP3_MUSIC - if ( (ext && MIX_string_equals(ext, "MPG")) || - (ext && MIX_string_equals(ext, "MP3")) || - (ext && MIX_string_equals(ext, "MPEG")) ) { + case MUS_MP3: if ( Mix_Init(MIX_INIT_MP3) ) { SMPEG_Info info; music->type = MUS_MP3; - music->data.mp3 = smpeg.SMPEG_new(file, &info, 0); + music->data.mp3 = smpeg.SMPEG_new_rwops(rw, &info, 0); if ( !info.has_audio ) { Mix_SetError("MPEG file does not have any audio stream."); music->error = 1; @@ -582,51 +667,86 @@ Mix_Music *Mix_LoadMUS(const char *file) } 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")) || - /* Don't check the magic. Lots of bogus but usable MP3s out there... - (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_openFile(file, &used_mixer); + music->data.mp3_mad = mad_openFileRW(rw, &used_mixer, freesrc); if (music->data.mp3_mad == 0) { - Mix_SetError("Could not initialize MPEG stream."); + Mix_SetError("Could not initialize MPEG stream."); music->error = 1; } - } else + break; #endif -#ifdef MODPLUG_MUSIC - if ( 1 ) { - music->type = MUS_MODPLUG; - music->data.modplug = modplug_new(file); - if ( music->data.modplug == NULL ) { +#ifdef MID_MUSIC + case MUS_MID: + music->type = MUS_MID; +#ifdef USE_NATIVE_MIDI + if ( native_midi_ok ) { + music->data.nativemidi = native_midi_loadsong_RW(rw, freesrc); + if ( music->data.nativemidi == NULL ) { + Mix_SetError("%s", native_midi_error()); + music->error = 1; + } + break; + } +#endif +#ifdef USE_FLUIDSYNTH_MIDI + if ( fluidsynth_ok ) { + music->data.fluidsynthmidi = fluidsynth_loadsong_RW(rw, freesrc); + if ( music->data.fluidsynthmidi == NULL ) { + music->error = 1; + } + break; + } +#endif +#ifdef USE_TIMIDITY_MIDI + if ( timidity_ok ) { + music->data.midi = Timidity_LoadSong_RW(rw, freesrc); + if ( music->data.midi == NULL ) { + Mix_SetError("%s", Timidity_Error()); + music->error = 1; + } + } else { + Mix_SetError("%s", Timidity_Error()); music->error = 1; } - } else +#endif + break; +#endif +#if defined(MODPLUG_MUSIC) || defined(MOD_MUSIC) + case MUS_MOD: + music->error = 1; +#ifdef MODPLUG_MUSIC + if ( music->error ) { + music->type = MUS_MODPLUG; + music->data.modplug = modplug_new_RW(rw, freesrc); + if ( music->data.modplug ) { + music->error = 0; + } + } #endif #ifdef MOD_MUSIC - if ( 1 ) { - music->type = MUS_MOD; - music->data.module = MOD_new(file); - if ( music->data.module == NULL ) { - music->error = 1; + if ( music->error ) { + music->type = MUS_MOD; + music->data.module = MOD_new_RW(rw, freesrc); + if ( music->data.module ) { + music->error = 0; + } } - } else #endif - { + break; +#endif + + default: Mix_SetError("Unrecognized music format"); - music->error = 1; - } + music->error=1; + } /* switch (want) */ -skip: - if ( music->error ) { + + if (music->error) { free(music); - music = NULL; + music=NULL; } return(music); } @@ -1414,175 +1534,6 @@ void close_music(void) ms_per_step = 0; } -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]; - Mix_Music *music; - int start; - int freerw = 0; - - 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; - } - 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)); - if (music==NULL ) { - Mix_SetError("Out of memory"); - return(NULL); - } - music->error = 0; - -#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 ) { - music->error = 1; - } - - } else -#endif -#ifdef OGG_MUSIC - /* Ogg Vorbis files have the magic four bytes "OggS" */ - if ( strcmp((char *)magic, "OggS") == 0 ) { - music->type = MUS_OGG; - music->data.ogg = OGG_new_RW(rw, freerw); - if ( music->data.ogg == NULL ) { - music->error = 1; - } - } else -#endif -#ifdef FLAC_MUSIC - /* FLAC files have the magic four bytes "fLaC" */ - if ( strcmp((char *)magic, "fLaC") == 0 ) { - music->type = MUS_FLAC; - music->data.flac = FLAC_new_RW(rw, freerw); - if ( music->data.flac == NULL ) { - music->error = 1; - } - } else -#endif -#ifdef MP3_MUSIC - if ( ( 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_rwops(rw, &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 ( ( magic[0] == 0xFF && (magic[1] & 0xF0) == 0xF0) || ( strncmp((char *)magic, "ID3", 3) == 0 ) ) { - 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 -#endif -#ifdef MID_MUSIC - /* MIDI files have the magic four bytes "MThd" */ - if ( strcmp((char *)magic, "MThd") == 0 ) { - music->type = MUS_MID; -#ifdef USE_NATIVE_MIDI - if ( native_midi_ok ) { - music->data.nativemidi = native_midi_loadsong_RW(rw, freerw); - 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_RW(rw, freerw); - if ( music->data.fluidsynthmidi == NULL ) { - music->error = 1; - } - goto skip; - } -#endif -#ifdef USE_TIMIDITY_MIDI - if ( timidity_ok ) { - music->data.midi = Timidity_LoadSong_RW(rw, freerw); - 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 -#if defined(MODPLUG_MUSIC) || defined(MOD_MUSIC) - if (1) { - music->error = 1; -#ifdef MODPLUG_MUSIC - if ( music->error ) { - music->type = MUS_MODPLUG; - music->data.modplug = modplug_new_RW(rw, freerw); - if ( music->data.modplug ) { - music->error = 0; - } - } -#endif -#ifdef MOD_MUSIC - if ( music->error ) { - music->type = MUS_MOD; - music->data.module = MOD_new_RW(rw, freerw); - if ( music->data.module ) { - music->error = 0; - } - } -#endif - } else -#endif /* MODPLUG_MUSIC || MOD_MUSIC */ - { - Mix_SetError("Unrecognized music format"); - music->error=1; - } - -skip: - if (music->error) { - free(music); - music=NULL; - } - return(music); -} - int Mix_SetSoundFonts(const char *paths) { #ifdef MID_MUSIC diff --git a/music_flac.c b/music_flac.c index fde15b55..c80900b2 100644 --- a/music_flac.c +++ b/music_flac.c @@ -50,19 +50,6 @@ void FLAC_setvolume(FLAC_music *music, int volume) 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 --git a/music_flac.h b/music_flac.h index 5696b5d0..c87dc9ea 100644 --- a/music_flac.h +++ b/music_flac.h @@ -66,9 +66,6 @@ extern int FLAC_init(SDL_AudioSpec *mixer); /* 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 --git a/music_mad.c b/music_mad.c index f0cfc6bc..ce6c0b87 100644 --- a/music_mad.c +++ b/music_mad.c @@ -25,20 +25,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) { diff --git a/music_mad.h b/music_mad.h index fe2a4276..af93c8df 100644 --- a/music_mad.h +++ b/music_mad.h @@ -58,7 +58,6 @@ typedef struct { 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 --git a/music_mod.c b/music_mod.c index 63774f23..be179022 100644 --- a/music_mod.c +++ b/music_mod.c @@ -141,21 +141,6 @@ void MOD_setvolume(MODULE *music, int volume) 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 --git a/music_mod.h b/music_mod.h index a934240f..4328e2b2 100644 --- a/music_mod.h +++ b/music_mod.h @@ -38,9 +38,6 @@ extern void MOD_exit(void); /* 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 --git a/music_modplug.c b/music_modplug.c index 221d6205..0ed94952 100644 --- a/music_modplug.c +++ b/music_modplug.c @@ -74,21 +74,6 @@ void modplug_setvolume(modplug_data *music, int volume) 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 --git a/music_modplug.h b/music_modplug.h index 76cdfdc6..92cbafd0 100644 --- a/music_modplug.h +++ b/music_modplug.h @@ -18,9 +18,6 @@ void modplug_exit(void); /* 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 --git a/music_ogg.c b/music_ogg.c index 3f4d2c99..3fbba04c 100644 --- a/music_ogg.c +++ b/music_ogg.c @@ -51,20 +51,6 @@ void OGG_setvolume(OGG_music *music, int volume) 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 --git a/music_ogg.h b/music_ogg.h index af70e01c..4d93a2bc 100644 --- a/music_ogg.h +++ b/music_ogg.h @@ -51,9 +51,6 @@ extern int OGG_init(SDL_AudioSpec *mixer); /* 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 --git a/native_midi/native_midi.h b/native_midi/native_midi.h index 7209925b..17e4769d 100644 --- a/native_midi/native_midi.h +++ b/native_midi/native_midi.h @@ -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 --git a/native_midi/native_midi_haiku.cpp b/native_midi/native_midi_haiku.cpp index e86c4af1..67710754 100644 --- a/native_midi/native_midi_haiku.cpp +++ b/native_midi/native_midi_haiku.cpp @@ -238,13 +238,6 @@ NativeMidiSong *native_midi_loadsong_RW(SDL_RWops *rw, int freerw) 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 --git a/native_midi/native_midi_mac.c b/native_midi/native_midi_mac.c index 55b8c02b..01e78774 100644 --- a/native_midi/native_midi_mac.c +++ b/native_midi/native_midi_mac.c @@ -88,18 +88,6 @@ int native_midi_detect() 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 --git a/native_midi/native_midi_macosx.c b/native_midi/native_midi_macosx.c index ee184b3d..8fefbc96 100644 --- a/native_midi/native_midi_macosx.c +++ b/native_midi/native_midi_macosx.c @@ -145,17 +145,6 @@ int native_midi_detect() 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 --git a/native_midi/native_midi_win32.c b/native_midi/native_midi_win32.c index fe3d92f9..187d989f 100644 --- a/native_midi/native_midi_win32.c +++ b/native_midi/native_midi_win32.c @@ -200,18 +200,6 @@ int native_midi_detect() 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 --git a/timidity/playmidi.c b/timidity/playmidi.c index 0238547f..3327db6c 100644 --- a/timidity/playmidi.c +++ b/timidity/playmidi.c @@ -1676,33 +1676,6 @@ void Timidity_SetVolume(int volume) 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 --git a/timidity/timidity.h b/timidity/timidity.h index 72d61d02..ec1dbe8b 100644 --- a/timidity/timidity.h +++ b/timidity/timidity.h @@ -12,7 +12,6 @@ extern int Timidity_Init(int rate, int format, int channels, int samples); 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 --git a/wavestream.c b/wavestream.c index 265caca0..bad1009f 100644 --- a/wavestream.c +++ b/wavestream.c @@ -113,19 +113,7 @@ void WAVStream_SetVolume(int volume) 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 --git a/wavestream.h b/wavestream.h index 4d1e7db2..9d119dc1 100644 --- a/wavestream.h +++ b/wavestream.h @@ -41,9 +41,6 @@ extern int WAVStream_Init(SDL_AudioSpec *mixer); /* 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);