Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Added SDL_RWops support for reading MP3 files
- Loading branch information
Showing
with
32 additions
and
5 deletions.
-
+1
−0
CHANGES
-
+16
−3
music.c
-
+15
−2
playmus.c
|
@@ -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 |
|
|
|
@@ -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; |
|
|
|
@@ -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) |
|
@@ -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 */ |
|
@@ -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. */ |
|
|