Skip to content

Commit

Permalink
Added SDL_RWops support for reading MP3 files
Browse files Browse the repository at this point in the history
  • Loading branch information
slouken committed Dec 21, 2004
1 parent 04535e2 commit b3860d6
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGES
Expand Up @@ -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
Expand Down
19 changes: 16 additions & 3 deletions music.c
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
17 changes: 15 additions & 2 deletions playmus.c
Expand Up @@ -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] <musicfile>\n", argv0);
fprintf(stderr, "Usage: %s [-i] [-l] [-8] [-r rate] [-c channels] [-b buffers] [-v N] [-rwops] <musicfile>\n", argv0);
}

void Menu(void)
Expand Down Expand Up @@ -93,13 +93,15 @@ void IntHandler(int sig)

int main(int argc, char *argv[])
{
SDL_RWops *rwfp;
int audio_rate;
Uint16 audio_format;
int audio_channels;
int audio_buffers;
int audio_volume = MIX_MAX_VOLUME;
int looping = 0;
int interactive = 0;
int rwops = 0;
int i;

/* Initialize variables */
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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());
Expand All @@ -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. */
Expand Down

0 comments on commit b3860d6

Please sign in to comment.