From b3860d6143ce96120c104e0897c5fbabd269bec4 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Tue, 21 Dec 2004 20:08:57 +0000 Subject: [PATCH] Added SDL_RWops support for reading MP3 files --- CHANGES | 1 + music.c | 19 ++++++++++++++++--- playmus.c | 17 +++++++++++++++-- 3 files changed, 32 insertions(+), 5 deletions(-) diff --git a/CHANGES b/CHANGES index 262341ab..b544ca67 100644 --- a/CHANGES +++ b/CHANGES @@ -2,6 +2,7 @@ Sam Lantinga - Tue Dec 21 09:51:29 PST 2004 * Fixed building mikmod support on UNIX * Always build SDL_RWops music support + * Added SDL_RWops support for reading MP3 files 1.2.6: Jonathan Atkins - Wed, 15 Sep 2004 23:26:42 -0500 diff --git a/music.c b/music.c index 36bf4712..5c61fff8 100644 --- a/music.c +++ b/music.c @@ -560,14 +560,14 @@ Mix_Music *Mix_LoadMUS(const char *file) 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) { + (magic[0] == 0xFF && (magic[1] & 0xF0) == 0xF0) ) { SMPEG_Info info; music->type = MUS_MP3; music->data.mp3 = SMPEG_new(file, &info, 0); - if(!info.has_audio){ + if ( !info.has_audio ) { Mix_SetError("MPEG file does not have any audio stream."); music->error = 1; - }else{ + } else { SMPEG_actualSpec(music->data.mp3, &used_mixer); } } else @@ -1330,6 +1330,19 @@ Mix_Music *Mix_LoadMUS_RW(SDL_RWops *rw) { } } else #endif +#ifdef MP3_MUSIC + if ( magic[0] == 0xFF && (magic[1] & 0xF0) == 0xF0 ) { + SMPEG_Info info; + music->type = MUS_MP3; + music->data.mp3 = 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_actualSpec(music->data.mp3, &used_mixer); + } + } else +#endif #if defined(MOD_MUSIC) || defined(LIBMIKMOD_MUSIC) if (1) { music->type=MUS_MOD; diff --git a/playmus.c b/playmus.c index 46cba6d5..745fa96d 100644 --- a/playmus.c +++ b/playmus.c @@ -57,7 +57,7 @@ void CleanUp(void) void Usage(char *argv0) { - fprintf(stderr, "Usage: %s [-i] [-l] [-8] [-r rate] [-c channels] [-b buffers] [-v N] \n", argv0); + fprintf(stderr, "Usage: %s [-i] [-l] [-8] [-r rate] [-c channels] [-b buffers] [-v N] [-rwops] \n", argv0); } void Menu(void) @@ -93,6 +93,7 @@ void IntHandler(int sig) int main(int argc, char *argv[]) { + SDL_RWops *rwfp; int audio_rate; Uint16 audio_format; int audio_channels; @@ -100,6 +101,7 @@ int main(int argc, char *argv[]) int audio_volume = MIX_MAX_VOLUME; int looping = 0; int interactive = 0; + int rwops = 0; int i; /* Initialize variables */ @@ -137,6 +139,9 @@ int main(int argc, char *argv[]) } else if ( strcmp(argv[i], "-8") == 0 ) { audio_format = AUDIO_U8; + } else + if ( strcmp(argv[i], "-rwops") == 0 ) { + rwops = 1; } else { Usage(argv[0]); return(1); @@ -180,7 +185,12 @@ int main(int argc, char *argv[]) next_track = 0; /* Load the requested music file */ - music = Mix_LoadMUS(argv[i]); + if ( rwops ) { + rwfp = SDL_RWFromFile(argv[i], "rb"); + music = Mix_LoadMUS(argv[i]); + } else { + music = Mix_LoadMUS(argv[i]); + } if ( music == NULL ) { fprintf(stderr, "Couldn't load %s: %s\n", argv[i], SDL_GetError()); @@ -197,6 +207,9 @@ int main(int argc, char *argv[]) SDL_Delay(100); } Mix_FreeMusic(music); + if ( rwops ) { + SDL_FreeRW(rwfp); + } music = NULL; /* If the user presses Ctrl-C more than once, exit. */