Skip to content

Commit

Permalink
Added caching wave loading (needed by CivCTP)
Browse files Browse the repository at this point in the history
Only link in the mikmod and timidity libraries if they are configured.
'make dist' works now
  • Loading branch information
Sam Lantinga committed Oct 21, 1999
1 parent 91b7bf1 commit 953d066
Show file tree
Hide file tree
Showing 7 changed files with 140 additions and 33 deletions.
18 changes: 14 additions & 4 deletions Makefile.am
Expand Up @@ -2,7 +2,8 @@

lib_LTLIBRARIES = libmixer.la

SUBDIRS = mikmod timidity
SUBDIRS = @MUSIC_SUBDIRS@
DIST_SUBIDRS = mikmod timidity

libmixerincludedir = $(includedir)
libmixerinclude_HEADERS = \
Expand All @@ -17,12 +18,21 @@ libmixer_la_SOURCES = \
wavestream.c \
wavestream.h

if USE_MIKMOD
MIKMOD_LIB = mikmod/libmikmod.la
else
MIKMOD_LIB =
endif
if USE_TIMIDITY
TIMIDITY_LIB = timidity/libtimidity.la
else
TIMIDITY_LIB =
endif

libmixer_la_LDFLAGS = \
-release $(LT_RELEASE) \
-version-info $(LT_CURRENT):$(LT_REVISION):$(LT_AGE)
libmixer_la_LIBADD = \
mikmod/libmikmod.la \
timidity/libtimidity.la
libmixer_la_LIBADD = $(MIKMOD_LIB) $(TIMIDITY_LIB)

bin_PROGRAMS = playwave playmus

Expand Down
20 changes: 16 additions & 4 deletions Makefile.in
Expand Up @@ -78,6 +78,7 @@ MAJOR_VERSION = @MAJOR_VERSION@
MAKEINFO = @MAKEINFO@
MICRO_VERSION = @MICRO_VERSION@
MINOR_VERSION = @MINOR_VERSION@
MUSIC_SUBDIRS = @MUSIC_SUBDIRS@
NM = @NM@
OBJDUMP = @OBJDUMP@
PACKAGE = @PACKAGE@
Expand All @@ -89,19 +90,23 @@ VERSION = @VERSION@

lib_LTLIBRARIES = libmixer.la

SUBDIRS = mikmod timidity
SUBDIRS = @MUSIC_SUBDIRS@
DIST_SUBIDRS = mikmod timidity

libmixerincludedir = $(includedir)
libmixerinclude_HEADERS = mixer.h


libmixer_la_SOURCES = mixer.c music.c music_cmd.c music_cmd.h wave.h wavestream.c wavestream.h

@USE_MIKMOD_TRUE@MIKMOD_LIB = mikmod/libmikmod.la
@USE_MIKMOD_FALSE@MIKMOD_LIB =
@USE_TIMIDITY_TRUE@TIMIDITY_LIB = timidity/libtimidity.la
@USE_TIMIDITY_FALSE@TIMIDITY_LIB =

libmixer_la_LDFLAGS = -release $(LT_RELEASE) -version-info $(LT_CURRENT):$(LT_REVISION):$(LT_AGE)

libmixer_la_LIBADD = mikmod/libmikmod.la timidity/libtimidity.la

libmixer_la_LIBADD = $(MIKMOD_LIB) $(TIMIDITY_LIB)

bin_PROGRAMS = playwave playmus

Expand All @@ -117,7 +122,14 @@ DEFS = @DEFS@ -I. -I$(srcdir)
CPPFLAGS = @CPPFLAGS@
LDFLAGS = @LDFLAGS@
LIBS = @LIBS@
libmixer_la_DEPENDENCIES = mikmod/libmikmod.la timidity/libtimidity.la
@USE_TIMIDITY_FALSE@@USE_MIKMOD_FALSE@libmixer_la_DEPENDENCIES =
@USE_TIMIDITY_TRUE@@USE_MIKMOD_TRUE@libmixer_la_DEPENDENCIES = \
@USE_TIMIDITY_TRUE@@USE_MIKMOD_TRUE@mikmod/libmikmod.la \
@USE_TIMIDITY_TRUE@@USE_MIKMOD_TRUE@timidity/libtimidity.la
@USE_TIMIDITY_TRUE@@USE_MIKMOD_FALSE@libmixer_la_DEPENDENCIES = \
@USE_TIMIDITY_TRUE@@USE_MIKMOD_FALSE@timidity/libtimidity.la
@USE_TIMIDITY_FALSE@@USE_MIKMOD_TRUE@libmixer_la_DEPENDENCIES = \
@USE_TIMIDITY_FALSE@@USE_MIKMOD_TRUE@mikmod/libmikmod.la
libmixer_la_OBJECTS = mixer.lo music.lo music_cmd.lo wavestream.lo
PROGRAMS = $(bin_PROGRAMS)

Expand Down
13 changes: 13 additions & 0 deletions aclocal.m4
Expand Up @@ -711,3 +711,16 @@ AC_DEFUN(AM_PROG_NM, [indir([AC_PROG_NM])])dnl
dnl This is just to silence aclocal about the macro not being used
ifelse([AC_DISABLE_FAST_INSTALL])dnl

# Define a conditional.

AC_DEFUN(AM_CONDITIONAL,
[AC_SUBST($1_TRUE)
AC_SUBST($1_FALSE)
if $2; then
$1_TRUE=
$1_FALSE='#'
else
$1_TRUE='#'
$1_FALSE=
fi])

55 changes: 40 additions & 15 deletions configure
Expand Up @@ -33,10 +33,10 @@ ac_help="$ac_help
--enable-music-cmd support an external music player [default=yes]"
ac_help="$ac_help
--enable-music-wave enable streaming WAVE music [default=yes]"
ac_help="$ac_help
--enable-music-midi enable MIDI music via timidity [default=yes]"
ac_help="$ac_help
--enable-music-mod enable MOD music via mikmod [default=yes]"
ac_help="$ac_help
--enable-music-midi enable MIDI music via timidity [default=yes]"
ac_help="$ac_help
--enable-music-mp3 enable MP3 music via smpeg [default=yes]"

Expand Down Expand Up @@ -1925,18 +1925,6 @@ fi
if test x$enable_music_wave = xyes; then
CFLAGS="$CFLAGS -DWAV_MUSIC"
fi
# Check whether --enable-music-midi or --disable-music-midi was given.
if test "${enable_music_midi+set}" = set; then
enableval="$enable_music_midi"
:
else
enable_music_midi=yes
fi

if test x$enable_music_midi = xyes; then
CFLAGS="$CFLAGS -DMID_MUSIC -I\$(top_srcdir)/timidity"
#MUSIC_SUBDIRS="$MUSIC_SUBDIRS timidity"
fi
# Check whether --enable-music-mod or --disable-music-mod was given.
if test "${enable_music_mod+set}" = set; then
enableval="$enable_music_mod"
Expand All @@ -1947,7 +1935,19 @@ fi

if test x$enable_music_mod = xyes; then
CFLAGS="$CFLAGS -DMOD_MUSIC -I\$(top_srcdir)/mikmod"
#MUSIC_SUBDIRS="$MUSIC_SUBDIRS mikmod"
MUSIC_SUBDIRS="$MUSIC_SUBDIRS mikmod"
fi
# Check whether --enable-music-midi or --disable-music-midi was given.
if test "${enable_music_midi+set}" = set; then
enableval="$enable_music_midi"
:
else
enable_music_midi=yes
fi

if test x$enable_music_midi = xyes; then
CFLAGS="$CFLAGS -DMID_MUSIC -I\$(top_srcdir)/timidity"
MUSIC_SUBDIRS="$MUSIC_SUBDIRS timidity"
fi
# Check whether --enable-music-mp3 or --disable-music-mp3 was given.
if test "${enable_music_mp3+set}" = set; then
Expand Down Expand Up @@ -1989,6 +1989,26 @@ rm -f conftest*
fi
fi




if test x$enable_music_mod = xyes; then
USE_MIKMOD_TRUE=
USE_MIKMOD_FALSE='#'
else
USE_MIKMOD_TRUE='#'
USE_MIKMOD_FALSE=
fi


if test x$enable_music_midi = xyes; then
USE_TIMIDITY_TRUE=
USE_TIMIDITY_FALSE='#'
else
USE_TIMIDITY_TRUE='#'
USE_TIMIDITY_FALSE=
fi

# Finally create all the generated files
trap '' 1 2 15
cat > confcache <<\EOF
Expand Down Expand Up @@ -2178,6 +2198,11 @@ s%@LIBTOOL@%$LIBTOOL%g
s%@SDL_CONFIG@%$SDL_CONFIG%g
s%@SDL_CFLAGS@%$SDL_CFLAGS%g
s%@SDL_LIBS@%$SDL_LIBS%g
s%@MUSIC_SUBDIRS@%$MUSIC_SUBDIRS%g
s%@USE_MIKMOD_TRUE@%$USE_MIKMOD_TRUE%g
s%@USE_MIKMOD_FALSE@%$USE_MIKMOD_FALSE%g
s%@USE_TIMIDITY_TRUE@%$USE_TIMIDITY_TRUE%g
s%@USE_TIMIDITY_FALSE@%$USE_TIMIDITY_FALSE%g
CEOF
EOF
Expand Down
21 changes: 13 additions & 8 deletions configure.in
Expand Up @@ -64,19 +64,19 @@ AC_ARG_ENABLE(music-wave,
if test x$enable_music_wave = xyes; then
CFLAGS="$CFLAGS -DWAV_MUSIC"
fi
AC_ARG_ENABLE(music-midi,
[ --enable-music-midi enable MIDI music via timidity [default=yes]],
, enable_music_midi=yes)
if test x$enable_music_midi = xyes; then
CFLAGS="$CFLAGS -DMID_MUSIC -I\$(top_srcdir)/timidity"
#MUSIC_SUBDIRS="$MUSIC_SUBDIRS timidity"
fi
AC_ARG_ENABLE(music-mod,
[ --enable-music-mod enable MOD music via mikmod [default=yes]],
, enable_music_mod=yes)
if test x$enable_music_mod = xyes; then
CFLAGS="$CFLAGS -DMOD_MUSIC -I\$(top_srcdir)/mikmod"
#MUSIC_SUBDIRS="$MUSIC_SUBDIRS mikmod"
MUSIC_SUBDIRS="$MUSIC_SUBDIRS mikmod"
fi
AC_ARG_ENABLE(music-midi,
[ --enable-music-midi enable MIDI music via timidity [default=yes]],
, enable_music_midi=yes)
if test x$enable_music_midi = xyes; then
CFLAGS="$CFLAGS -DMID_MUSIC -I\$(top_srcdir)/timidity"
MUSIC_SUBDIRS="$MUSIC_SUBDIRS timidity"
fi
AC_ARG_ENABLE(music-mp3,
[ --enable-music-mp3 enable MP3 music via smpeg [default=yes]],
Expand All @@ -97,6 +97,11 @@ if test x$enable_music_mp3 = xyes; then
fi
fi

dnl Add Makefile conditionals
AC_SUBST(MUSIC_SUBDIRS)
AM_CONDITIONAL(USE_MIKMOD, test x$enable_music_mod = xyes)
AM_CONDITIONAL(USE_TIMIDITY, test x$enable_music_midi = xyes)

# Finally create all the generated files
AC_OUTPUT([
Makefile
Expand Down
40 changes: 39 additions & 1 deletion mixer.c
Expand Up @@ -232,12 +232,48 @@ Mix_Chunk *Mix_LoadWAV_RW(SDL_RWops *src, int freesrc)
free(chunk);
return(NULL);
}
chunk->allocated = 1;
chunk->abuf = wavecvt.buf;
chunk->alen = wavecvt.len_cvt;
chunk->volume = MIX_MAX_VOLUME;
return(chunk);
}

/* Load a wave file of the mixer format from a memory buffer */
Mix_Chunk *Mix_QuickLoad_WAV(Uint8 *mem)
{
Mix_Chunk *chunk;
Uint8 magic[4];

/* Make sure audio has been opened */
if ( ! audio_opened ) {
SDL_SetError("Audio device hasn't been opened");
return(NULL);
}

/* Allocate the chunk memory */
chunk = (Mix_Chunk *)malloc(sizeof(Mix_Chunk));
if ( chunk == NULL ) {
SDL_SetError("Out of memory");
return(NULL);
}

/* Essentially just skip to the audio data (no error checking - fast) */
chunk->allocated = 0;
mem += 12; /* WAV header */
do {
memcpy(magic, mem, 4);
mem += 4;
chunk->alen = ((mem[3]<<24)|(mem[2]<<16)|(mem[1]<<8)|(mem[0]));
mem += 4;
chunk->abuf = mem;
mem += chunk->alen;
} while ( memcmp(magic, "data", 4) != 0 );
chunk->volume = MIX_MAX_VOLUME;

return(chunk);
}

/* Free an audio chunk previously loaded */
void Mix_FreeChunk(Mix_Chunk *chunk)
{
Expand All @@ -255,7 +291,9 @@ void Mix_FreeChunk(Mix_Chunk *chunk)
SDL_mutexV(mixer_lock);

/* Actually free the chunk */
free(chunk->abuf);
if ( chunk->allocated ) {
free(chunk->abuf);
}
free(chunk);
}
}
Expand Down
6 changes: 5 additions & 1 deletion mixer.h
Expand Up @@ -44,6 +44,7 @@

/* The internal format for an audio chunk */
typedef struct {
int allocated;
Uint8 *abuf;
Uint32 alen;
Uint8 volume; /* Per-sample volume, 0-128 */
Expand All @@ -61,11 +62,14 @@ extern int Mix_OpenAudio(int frequency, Uint16 format, int channels,
*/
extern int Mix_QuerySpec(int *frequency, Uint16 *format, int *channels);

/* Load a wave file or a MOD (.mod .s3m .it .xm) file */
/* Load a wave file or a music (.mod .s3m .it .xm) file */
extern Mix_Chunk *Mix_LoadWAV_RW(SDL_RWops *src, int freesrc);
#define Mix_LoadWAV(file) Mix_LoadWAV_RW(SDL_RWFromFile(file, "rb"), 1)
extern Mix_Music *Mix_LoadMUS(const char *file);

/* Load a wave file of the mixer format from a memory buffer */
extern Mix_Chunk *Mix_QuickLoad_WAV(Uint8 *mem);

/* Free an audio chunk previously loaded */
extern void Mix_FreeChunk(Mix_Chunk *chunk);
extern void Mix_FreeMusic(Mix_Music *music);
Expand Down

0 comments on commit 953d066

Please sign in to comment.