From 5cd8b9b48f00e2dedaf2da75cbc770990a135752 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Sun, 15 Jul 2007 03:38:33 +0000 Subject: [PATCH] Fixed bug #297 Philippe Simons - Sat Jul 14 20:33:17 PDT 2007 * Added support for Ogg Vorbis playback with Tremor (an integer decoder) --- CHANGES | 2 ++ README | 6 +++++- configure.in | 20 ++++++++++++++++++++ dynamic_ogg.h | 8 ++++++++ load_ogg.c | 6 ++++++ music_ogg.c | 4 ++++ music_ogg.h | 4 ++++ 7 files changed, 49 insertions(+), 1 deletion(-) diff --git a/CHANGES b/CHANGES index a9888b7a..33f78e3a 100644 --- a/CHANGES +++ b/CHANGES @@ -1,4 +1,6 @@ 1.2.8: +Philippe Simons - Sat Jul 14 20:33:17 PDT 2007 + * Added support for Ogg Vorbis playback with Tremor (an integer decoder) Sam Lantinga - Sat Jul 14 07:02:09 PDT 2007 * Fixed memory corruption in timidity resampling code Ryan Gordan - Tue Jul 3 10:44:29 2007 UTC diff --git a/README b/README index 07cc3983..e38f7cdc 100644 --- a/README +++ b/README @@ -15,9 +15,13 @@ for documentation on this mixer library. 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 the Ogg Vorbis libraries, +Ogg Vorbis streams as music if built with Ogg Vorbis or Tremor libraries, and finally it can load MP3 music using the SMPEG library. +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. + 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. diff --git a/configure.in b/configure.in index a6b39854..5d090f18 100644 --- a/configure.in +++ b/configure.in @@ -261,6 +261,26 @@ AC_HELP_STRING([--enable-music-ogg-shared], [dynamically load Ogg Vorbis support fi fi fi +AC_ARG_ENABLE(music-ogg-tremor, +[ --enable-music-ogg-tremor enable OGG music via libtremor [[default=no]]], + , enable_music_ogg_tremor=no) +if test x$enable_music_ogg_tremor = xyes; then + AC_MSG_CHECKING(for libtremor headers) + have_tremor=no + AC_TRY_COMPILE([ + #include + #include + ],[ + ],[ + have_tremor=yes + ]) + AC_MSG_RESULT($have_tremor) + if test x$have_tremor = xyes; then + SOURCES="$SOURCES $srcdir/*_ogg.c" + EXTRA_CFLAGS="$EXTRA_CFLAGS -DOGG_MUSIC -DOGG_USE_TREMOR" + EXTRA_LDFLAGS="$EXTRA_LDFLAGS -lvorbisidec" + fi +fi AC_ARG_ENABLE(music-mp3, [ --enable-music-mp3 enable MP3 music via smpeg [[default=yes]]], , enable_music_mp3=yes) diff --git a/dynamic_ogg.h b/dynamic_ogg.h index dd882607..ea31944e 100644 --- a/dynamic_ogg.h +++ b/dynamic_ogg.h @@ -21,7 +21,11 @@ */ #ifdef OGG_MUSIC +#ifdef OGG_USE_TREMOR +#include +#else #include +#endif typedef struct { int loaded; @@ -31,7 +35,11 @@ typedef struct { int (*ov_open)(FILE *f,OggVorbis_File *vf,char *initial,long ibytes); int (*ov_open_callbacks)(void *datasource, OggVorbis_File *vf, char *initial, long ibytes, ov_callbacks callbacks); ogg_int64_t (*ov_pcm_total)(OggVorbis_File *vf,int i); +#ifdef OGG_USE_TREMOR + long (*ov_read)(OggVorbis_File *vf,char *buffer,int length, int *bitstream); +#else long (*ov_read)(OggVorbis_File *vf,char *buffer,int length, int bigendianp,int word,int sgned,int *bitstream); +#endif int (*ov_time_seek)(OggVorbis_File *vf,double pos); } vorbis_loader; diff --git a/load_ogg.c b/load_ogg.c index 8fa6c54c..4eff8173 100644 --- a/load_ogg.c +++ b/load_ogg.c @@ -117,9 +117,15 @@ SDL_AudioSpec *Mix_LoadOGG_RW (SDL_RWops *src, int freesrc, buf = *audio_buf; to_read = *audio_len; +#ifdef OGG_USE_TREMOR + for (read = vorbis.ov_read(&vf, (char *)buf, to_read, &bitstream); + read > 0; + read = vorbis.ov_read(&vf, (char *)buf, to_read, &bitstream)) +#else for (read = vorbis.ov_read(&vf, (char *)buf, to_read, 0/*LE*/, 2/*16bit*/, 1/*signed*/, &bitstream); read > 0; read = vorbis.ov_read(&vf, (char *)buf, to_read, 0, 2, 1, &bitstream)) +#endif { if (read == OV_HOLE || read == OV_EBADLINK) break; /* error */ diff --git a/music_ogg.c b/music_ogg.c index d177dd93..71cb26bf 100644 --- a/music_ogg.c +++ b/music_ogg.c @@ -165,7 +165,11 @@ static void OGG_getsome(OGG_music *music) char data[4096]; SDL_AudioCVT *cvt; +#ifdef OGG_USE_TREMOR + len = vorbis.ov_read(&music->vf, data, sizeof(data), §ion); +#else len = vorbis.ov_read(&music->vf, data, sizeof(data), 0, 2, 1, §ion); +#endif if ( len <= 0 ) { if ( len == 0 ) { music->playing = 0; diff --git a/music_ogg.h b/music_ogg.h index e34f5ca0..9d7f1437 100644 --- a/music_ogg.h +++ b/music_ogg.h @@ -26,7 +26,11 @@ /* This file supports Ogg Vorbis music streams */ +#ifdef OGG_USE_TREMOR +#include +#else #include +#endif typedef struct { int playing;