Skip to content
Permalink
Browse files

Fixed bug #269

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 a7dc597a53c39034047d056e9c49f1c9b26b4689
Showing with 515 additions and 9 deletions.
  1. +2 −0 CHANGES
  2. +1 −1 Makefile.in
  3. +10 −2 README
  4. +2 −1 SDL_mixer.h
  5. +4 −4 SDL_mixer.spec.in
  6. +19 −0 configure.in
  7. +71 −1 music.c
  8. +333 −0 music_mad.c
  9. +73 −0 music_mad.h
@@ -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
@@ -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@
12 README
@@ -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.
@@ -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 */
@@ -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.
@@ -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
@@ -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'`

72 music.c
@@ -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;
@@ -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;
@@ -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?? */
@@ -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
@@ -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;
@@ -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?? */
@@ -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");
@@ -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 */
@@ -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?? */
@@ -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?? */
@@ -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;
@@ -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 ) {

0 comments on commit a7dc597

Please sign in to comment.