Skip to content

Commit

Permalink
Fixed bug #269
Browse files Browse the repository at this point in the history
David Rose - Sat Jul 14 22:16:09 PDT 2007
 * Added support for MP3 playback with libmad (for GPL projects only!)
  • Loading branch information
slouken committed Jul 15, 2007
1 parent c6821a9 commit a7dc597
Show file tree
Hide file tree
Showing 9 changed files with 515 additions and 9 deletions.
2 changes: 2 additions & 0 deletions CHANGES
@@ -1,4 +1,6 @@
1.2.8:
David Rose - Sat Jul 14 22:16:09 PDT 2007
* Added support for MP3 playback with libmad (for GPL projects only!)
Sam Lantinga - Sat Jul 14 21:39:30 PDT 2007
* Fixed the final loop of audio samples of a certain size
Sam Lantinga - Sat Jul 14 21:05:09 PDT 2007
Expand Down
2 changes: 1 addition & 1 deletion Makefile.in
Expand Up @@ -35,7 +35,7 @@ TARGET = libSDL_mixer.la
SOURCES = @SOURCES@
OBJECTS = @OBJECTS@

DIST = CHANGES COPYING CWProjects.sea.bin MPWmake.sea.bin Makefile.in README SDL_mixer.h SDL_mixer.qpg.in SDL_mixer.spec SDL_mixer.spec.in VisualC.zip Watcom-OS2.zip Xcode.tar.gz acinclude autogen.sh build-scripts configure configure.in dynamic_mp3.c dynamic_mp3.h dynamic_ogg.c dynamic_ogg.h effect_position.c effect_stereoreverse.c effects_internal.c effects_internal.h gcc-fat.sh load_aiff.c load_aiff.h load_ogg.c load_ogg.h load_voc.c load_voc.h mikmod mixer.c music.c music_cmd.c music_cmd.h music_ogg.c music_ogg.h native_midi native_midi_gpl playmus.c playwave.c timidity wavestream.c wavestream.h
DIST = CHANGES COPYING CWProjects.sea.bin MPWmake.sea.bin Makefile.in README SDL_mixer.h SDL_mixer.qpg.in SDL_mixer.spec SDL_mixer.spec.in VisualC.zip Watcom-OS2.zip Xcode.tar.gz acinclude autogen.sh build-scripts configure configure.in dynamic_mp3.c dynamic_mp3.h dynamic_ogg.c dynamic_ogg.h effect_position.c effect_stereoreverse.c effects_internal.c effects_internal.h gcc-fat.sh load_aiff.c load_aiff.h load_ogg.c load_ogg.h load_voc.c load_voc.h mikmod mixer.c music.c music_cmd.c music_cmd.h music_mad.c music_mad.h music_ogg.c music_ogg.h native_midi native_midi_gpl playmus.c playwave.c timidity wavestream.c wavestream.h

LT_AGE = @LT_AGE@
LT_CURRENT = @LT_CURRENT@
Expand Down
12 changes: 10 additions & 2 deletions README
Expand Up @@ -16,12 +16,20 @@ The mixer can currently load Microsoft WAVE files and Creative Labs VOC
files as audio samples, and can load MIDI files via Timidity and the
following music formats via MikMod: .MOD .S3M .IT .XM. It can load
Ogg Vorbis streams as music if built with Ogg Vorbis or Tremor libraries,
and finally it can load MP3 music using the SMPEG library.
and finally it can load MP3 music using the SMPEG or libmad libraries.

Tremor decoding is disabled by default, you can enable it by passing
Tremor decoding is disabled by default; you can enable it by passing
--enable-music-ogg-tremor
to configure, or by defining OGG_MUSIC and OGG_USE_TREMOR.

libmad decoding is disabled by default; you can enable it by passing
--enable-music-mp3-mad
to configure, or by defining MP3_MAD_MUSIC
vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
WARNING: The license for libmad is GPL, which means that in order to
use it your application must also be GPL!
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

The process of mixing MIDI files to wave output is very CPU intensive,
so if playing regular WAVE files sound great, but playing MIDI files
sound choppy, try using 8-bit audio, mono audio, or lower frequencies.
Expand Down
3 changes: 2 additions & 1 deletion SDL_mixer.h
Expand Up @@ -103,7 +103,8 @@ typedef enum {
MUS_MOD,
MUS_MID,
MUS_OGG,
MUS_MP3
MUS_MP3,
MUS_MP3_MAD
} Mix_MusicType;

/* The internal format for a music chunk interpreted via mikmod */
Expand Down
8 changes: 4 additions & 4 deletions SDL_mixer.spec.in
Expand Up @@ -15,8 +15,8 @@ Prefix: %{_prefix}
%description
Due to popular demand, here is a simple multi-channel audio mixer.
It supports 4 channels of 16 bit stereo audio, plus a single channel
of music, mixed by the popular MikMod MOD, Timidity MIDI and SMPEG MP3
libraries.
of music, mixed by the popular MikMod MOD, Timidity MIDI, Ogg Vorbis,
Tremor, SMPEG MP3, and libmad MP3 libraries.

%package devel
Summary: Libraries, includes and more to develop SDL applications.
Expand All @@ -26,8 +26,8 @@ Requires: %{name}
%description devel
Due to popular demand, here is a simple multi-channel audio mixer.
It supports 4 channels of 16 bit stereo audio, plus a single channel
of music, mixed by the popular MikMod MOD, Timidity MIDI and SMPEG MP3
libraries.
of music, mixed by the popular MikMod MOD, Timidity MIDI, Ogg Vorbis,
Tremor, SMPEG MP3, and libmad MP3 libraries.

%prep
%setup
Expand Down
19 changes: 19 additions & 0 deletions configure.in
Expand Up @@ -320,6 +320,25 @@ AC_HELP_STRING([--enable-music-mp3-shared], [dynamically load MP3 support [[defa
fi
fi
fi
AC_ARG_ENABLE(music-mp3-mad-gpl,
AC_HELP_STRING([--enable-music-mp3-mad-gpl], [enable MP3 music via libmad GPL code [[default=no]]]),
[], [enable_music_mp3_mad_gpl=no])
if test x$enable_music_mp3_mad_gpl = xyes; then
AC_MSG_CHECKING(for libmad headers)
have_libmad=no
AC_TRY_COMPILE([
#include "mad.h"
],[
],[
have_libmad=yes
])
AC_MSG_RESULT($have_libmad)
if test x$have_libmad = xyes; then
SOURCES="$SOURCES $srcdir/music_mad.c"
EXTRA_CFLAGS="$EXTRA_CFLAGS -DMP3_MAD_MUSIC"
EXTRA_LDFLAGS="$EXTRA_LDFLAGS -lmad"
fi
fi

OBJECTS=`echo $SOURCES | sed 's,[[^ ]]*/\([[^ ]]*\)\.c,$(objects)/\1.lo,g'`

Expand Down
72 changes: 71 additions & 1 deletion music.c
Expand Up @@ -85,10 +85,16 @@
#endif
#ifdef MP3_MUSIC
#include "dynamic_mp3.h"
#endif
#ifdef MP3_MAD_MUSIC
#include "music_mad.h"
#endif

#if defined(MP3_MUSIC) || defined(MP3_MAD_MUSIC)
static SDL_AudioSpec used_mixer;
#endif


int volatile music_active = 1;
static int volatile music_stopped = 0;
static int music_loops = 0;
Expand Down Expand Up @@ -123,6 +129,9 @@ struct _Mix_Music {
#endif
#ifdef MP3_MUSIC
SMPEG *mp3;
#endif
#ifdef MP3_MAD_MUSIC
mad_data *mp3_mad;
#endif
} data;
Mix_Fading fading;
Expand Down Expand Up @@ -340,6 +349,11 @@ void music_mixer(void *udata, Uint8 *stream, int len)
case MUS_MP3:
smpeg.SMPEG_playAudio(music_playing->data.mp3, stream, len);
break;
#endif
#ifdef MP3_MAD_MUSIC
case MUS_MP3_MAD:
mad_getSamples(music_playing->data.mp3_mad, stream, len);
break;
#endif
default:
/* Unknown music type?? */
Expand Down Expand Up @@ -455,7 +469,7 @@ int open_music(SDL_AudioSpec *mixer)
++music_error;
}
#endif
#ifdef MP3_MUSIC
#if defined(MP3_MUSIC) || defined(MP3_MAD_MUSIC)
/* Keep a copy of the mixer */
used_mixer = *mixer;
#endif
Expand Down Expand Up @@ -608,6 +622,20 @@ Mix_Music *Mix_LoadMUS(const char *file)
}
} 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) ) {
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
#if defined(MOD_MUSIC) || defined(LIBMIKMOD_MUSIC)
if ( 1 ) {
music->type = MUS_MOD;
Expand Down Expand Up @@ -697,6 +725,11 @@ void Mix_FreeMusic(Mix_Music *music)
smpeg.SMPEG_delete(music->data.mp3);
Mix_QuitMP3();
break;
#endif
#ifdef MP3_MAD_MUSIC
case MUS_MP3_MAD:
mad_closeFile(music->data.mp3_mad);
break;
#endif
default:
/* Unknown music type?? */
Expand Down Expand Up @@ -786,6 +819,11 @@ static int music_internal_play(Mix_Music *music, double position)
smpeg.SMPEG_enablevideo(music->data.mp3,0);
smpeg.SMPEG_play(music_playing->data.mp3);
break;
#endif
#ifdef MP3_MAD_MUSIC
case MUS_MP3_MAD:
mad_start(music->data.mp3_mad);
break;
#endif
default:
Mix_SetError("Can't play unknown music type");
Expand Down Expand Up @@ -879,6 +917,11 @@ int music_internal_position(double position)
smpeg.SMPEG_play(music_playing->data.mp3);
}
break;
#endif
#ifdef MP3_MAD_MUSIC
case MUS_MP3_MAD:
mad_seek(music_playing->data.mp3_mad, position);
break;
#endif
default:
/* TODO: Implement this for other music backends */
Expand Down Expand Up @@ -958,6 +1001,11 @@ static void music_internal_volume(int volume)
case MUS_MP3:
smpeg.SMPEG_setvolume(music_playing->data.mp3,(int)(((float)volume/(float)MIX_MAX_VOLUME)*100.0));
break;
#endif
#ifdef MP3_MAD_MUSIC
case MUS_MP3_MAD:
mad_setVolume(music_playing->data.mp3_mad, volume);
break;
#endif
default:
/* Unknown music type?? */
Expand Down Expand Up @@ -1026,6 +1074,11 @@ static void music_internal_halt(void)
case MUS_MP3:
smpeg.SMPEG_stop(music_playing->data.mp3);
break;
#endif
#ifdef MP3_MAD_MUSIC
case MUS_MP3_MAD:
mad_stop(music_playing->data.mp3_mad);
break;
#endif
default:
/* Unknown music type?? */
Expand Down Expand Up @@ -1169,6 +1222,13 @@ static int music_internal_playing()
if ( smpeg.SMPEG_status(music_playing->data.mp3) != SMPEG_PLAYING )
playing = 0;
break;
#endif
#ifdef MP3_MAD_MUSIC
case MUS_MP3_MAD:
if (!mad_isPlaying(music_playing->data.mp3_mad)) {
playing = 0;
}
break;
#endif
default:
playing = 0;
Expand Down Expand Up @@ -1413,6 +1473,16 @@ Mix_Music *Mix_LoadMUS_RW(SDL_RWops *rw) {
}
} else
#endif
#ifdef MP3_MAD_MUSIC
if ( magic[0] == 0xFF && (magic[1] & 0xF0) == 0xF0 ) {
music->type = MUS_MP3_MAD;
music->data.mp3_mad = mad_openFileRW(rw, &used_mixer);
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 ) {
Expand Down

0 comments on commit a7dc597

Please sign in to comment.