Added caching wave loading (needed by CivCTP)
authorSam Lantinga <slouken@lokigames.com>
Thu, 21 Oct 1999 19:12:17 +0000
changeset 14ef9250a6471
parent 0 4ce2db4db959
child 2 050365e21770
Added caching wave loading (needed by CivCTP)
Only link in the mikmod and timidity libraries if they are configured.
'make dist' works now
Makefile.am
Makefile.in
aclocal.m4
configure
configure.in
mixer.c
mixer.h
     1.1 --- a/Makefile.am	Thu Oct 21 18:02:08 1999 +0000
     1.2 +++ b/Makefile.am	Thu Oct 21 19:12:17 1999 +0000
     1.3 @@ -2,7 +2,8 @@
     1.4  
     1.5  lib_LTLIBRARIES = libmixer.la
     1.6  
     1.7 -SUBDIRS = mikmod timidity
     1.8 +SUBDIRS = @MUSIC_SUBDIRS@
     1.9 +DIST_SUBIDRS = mikmod timidity
    1.10  
    1.11  libmixerincludedir = $(includedir)
    1.12  libmixerinclude_HEADERS =	\
    1.13 @@ -17,12 +18,21 @@
    1.14  	wavestream.c		\
    1.15  	wavestream.h
    1.16  
    1.17 +if USE_MIKMOD
    1.18 +MIKMOD_LIB = mikmod/libmikmod.la
    1.19 +else
    1.20 +MIKMOD_LIB =
    1.21 +endif
    1.22 +if USE_TIMIDITY
    1.23 +TIMIDITY_LIB = timidity/libtimidity.la
    1.24 +else
    1.25 +TIMIDITY_LIB =
    1.26 +endif
    1.27 +
    1.28  libmixer_la_LDFLAGS = 		\
    1.29          -release $(LT_RELEASE)	\
    1.30  	-version-info $(LT_CURRENT):$(LT_REVISION):$(LT_AGE)
    1.31 -libmixer_la_LIBADD =		\
    1.32 -	mikmod/libmikmod.la	\
    1.33 -	timidity/libtimidity.la
    1.34 +libmixer_la_LIBADD = $(MIKMOD_LIB) $(TIMIDITY_LIB)
    1.35  
    1.36  bin_PROGRAMS = playwave playmus
    1.37  
     2.1 --- a/Makefile.in	Thu Oct 21 18:02:08 1999 +0000
     2.2 +++ b/Makefile.in	Thu Oct 21 19:12:17 1999 +0000
     2.3 @@ -78,6 +78,7 @@
     2.4  MAKEINFO = @MAKEINFO@
     2.5  MICRO_VERSION = @MICRO_VERSION@
     2.6  MINOR_VERSION = @MINOR_VERSION@
     2.7 +MUSIC_SUBDIRS = @MUSIC_SUBDIRS@
     2.8  NM = @NM@
     2.9  OBJDUMP = @OBJDUMP@
    2.10  PACKAGE = @PACKAGE@
    2.11 @@ -89,7 +90,8 @@
    2.12  
    2.13  lib_LTLIBRARIES = libmixer.la
    2.14  
    2.15 -SUBDIRS = mikmod timidity
    2.16 +SUBDIRS = @MUSIC_SUBDIRS@
    2.17 +DIST_SUBIDRS = mikmod timidity
    2.18  
    2.19  libmixerincludedir = $(includedir)
    2.20  libmixerinclude_HEADERS =  	mixer.h
    2.21 @@ -97,11 +99,14 @@
    2.22  
    2.23  libmixer_la_SOURCES =  	mixer.c				music.c				music_cmd.c			music_cmd.h			wave.h				wavestream.c			wavestream.h
    2.24  
    2.25 +@USE_MIKMOD_TRUE@MIKMOD_LIB = mikmod/libmikmod.la
    2.26 +@USE_MIKMOD_FALSE@MIKMOD_LIB = 
    2.27 +@USE_TIMIDITY_TRUE@TIMIDITY_LIB = timidity/libtimidity.la
    2.28 +@USE_TIMIDITY_FALSE@TIMIDITY_LIB = 
    2.29  
    2.30  libmixer_la_LDFLAGS =          -release $(LT_RELEASE)		-version-info $(LT_CURRENT):$(LT_REVISION):$(LT_AGE)
    2.31  
    2.32 -libmixer_la_LIBADD =  	mikmod/libmikmod.la		timidity/libtimidity.la
    2.33 -
    2.34 +libmixer_la_LIBADD = $(MIKMOD_LIB) $(TIMIDITY_LIB)
    2.35  
    2.36  bin_PROGRAMS = playwave playmus
    2.37  
    2.38 @@ -117,7 +122,14 @@
    2.39  CPPFLAGS = @CPPFLAGS@
    2.40  LDFLAGS = @LDFLAGS@
    2.41  LIBS = @LIBS@
    2.42 -libmixer_la_DEPENDENCIES =  mikmod/libmikmod.la timidity/libtimidity.la
    2.43 +@USE_TIMIDITY_FALSE@@USE_MIKMOD_FALSE@libmixer_la_DEPENDENCIES = 
    2.44 +@USE_TIMIDITY_TRUE@@USE_MIKMOD_TRUE@libmixer_la_DEPENDENCIES =  \
    2.45 +@USE_TIMIDITY_TRUE@@USE_MIKMOD_TRUE@mikmod/libmikmod.la \
    2.46 +@USE_TIMIDITY_TRUE@@USE_MIKMOD_TRUE@timidity/libtimidity.la
    2.47 +@USE_TIMIDITY_TRUE@@USE_MIKMOD_FALSE@libmixer_la_DEPENDENCIES =  \
    2.48 +@USE_TIMIDITY_TRUE@@USE_MIKMOD_FALSE@timidity/libtimidity.la
    2.49 +@USE_TIMIDITY_FALSE@@USE_MIKMOD_TRUE@libmixer_la_DEPENDENCIES =  \
    2.50 +@USE_TIMIDITY_FALSE@@USE_MIKMOD_TRUE@mikmod/libmikmod.la
    2.51  libmixer_la_OBJECTS =  mixer.lo music.lo music_cmd.lo wavestream.lo
    2.52  PROGRAMS =  $(bin_PROGRAMS)
    2.53  
     3.1 --- a/aclocal.m4	Thu Oct 21 18:02:08 1999 +0000
     3.2 +++ b/aclocal.m4	Thu Oct 21 19:12:17 1999 +0000
     3.3 @@ -711,3 +711,16 @@
     3.4  dnl This is just to silence aclocal about the macro not being used
     3.5  ifelse([AC_DISABLE_FAST_INSTALL])dnl
     3.6  
     3.7 +# Define a conditional.
     3.8 +
     3.9 +AC_DEFUN(AM_CONDITIONAL,
    3.10 +[AC_SUBST($1_TRUE)
    3.11 +AC_SUBST($1_FALSE)
    3.12 +if $2; then
    3.13 +  $1_TRUE=
    3.14 +  $1_FALSE='#'
    3.15 +else
    3.16 +  $1_TRUE='#'
    3.17 +  $1_FALSE=
    3.18 +fi])
    3.19 +
     4.1 --- a/configure	Thu Oct 21 18:02:08 1999 +0000
     4.2 +++ b/configure	Thu Oct 21 19:12:17 1999 +0000
     4.3 @@ -34,10 +34,10 @@
     4.4  ac_help="$ac_help
     4.5    --enable-music-wave     enable streaming WAVE music [default=yes]"
     4.6  ac_help="$ac_help
     4.7 +  --enable-music-mod      enable MOD music via mikmod [default=yes]"
     4.8 +ac_help="$ac_help
     4.9    --enable-music-midi     enable MIDI music via timidity [default=yes]"
    4.10  ac_help="$ac_help
    4.11 -  --enable-music-mod      enable MOD music via mikmod [default=yes]"
    4.12 -ac_help="$ac_help
    4.13    --enable-music-mp3      enable MP3 music via smpeg [default=yes]"
    4.14  
    4.15  # Initialize some variables set by options.
    4.16 @@ -1925,6 +1925,18 @@
    4.17  if test x$enable_music_wave = xyes; then
    4.18      CFLAGS="$CFLAGS -DWAV_MUSIC"
    4.19  fi
    4.20 +# Check whether --enable-music-mod or --disable-music-mod was given.
    4.21 +if test "${enable_music_mod+set}" = set; then
    4.22 +  enableval="$enable_music_mod"
    4.23 +  :
    4.24 +else
    4.25 +  enable_music_mod=yes
    4.26 +fi
    4.27 +
    4.28 +if test x$enable_music_mod = xyes; then
    4.29 +    CFLAGS="$CFLAGS -DMOD_MUSIC -I\$(top_srcdir)/mikmod"
    4.30 +    MUSIC_SUBDIRS="$MUSIC_SUBDIRS mikmod"
    4.31 +fi
    4.32  # Check whether --enable-music-midi or --disable-music-midi was given.
    4.33  if test "${enable_music_midi+set}" = set; then
    4.34    enableval="$enable_music_midi"
    4.35 @@ -1935,19 +1947,7 @@
    4.36  
    4.37  if test x$enable_music_midi = xyes; then
    4.38      CFLAGS="$CFLAGS -DMID_MUSIC -I\$(top_srcdir)/timidity"
    4.39 -    #MUSIC_SUBDIRS="$MUSIC_SUBDIRS timidity"
    4.40 -fi
    4.41 -# Check whether --enable-music-mod or --disable-music-mod was given.
    4.42 -if test "${enable_music_mod+set}" = set; then
    4.43 -  enableval="$enable_music_mod"
    4.44 -  :
    4.45 -else
    4.46 -  enable_music_mod=yes
    4.47 -fi
    4.48 -
    4.49 -if test x$enable_music_mod = xyes; then
    4.50 -    CFLAGS="$CFLAGS -DMOD_MUSIC -I\$(top_srcdir)/mikmod"
    4.51 -    #MUSIC_SUBDIRS="$MUSIC_SUBDIRS mikmod"
    4.52 +    MUSIC_SUBDIRS="$MUSIC_SUBDIRS timidity"
    4.53  fi
    4.54  # Check whether --enable-music-mp3 or --disable-music-mp3 was given.
    4.55  if test "${enable_music_mp3+set}" = set; then
    4.56 @@ -1989,6 +1989,26 @@
    4.57      fi
    4.58  fi
    4.59  
    4.60 +
    4.61 +
    4.62 +
    4.63 +if test x$enable_music_mod = xyes; then
    4.64 +  USE_MIKMOD_TRUE=
    4.65 +  USE_MIKMOD_FALSE='#'
    4.66 +else
    4.67 +  USE_MIKMOD_TRUE='#'
    4.68 +  USE_MIKMOD_FALSE=
    4.69 +fi
    4.70 +
    4.71 +
    4.72 +if test x$enable_music_midi = xyes; then
    4.73 +  USE_TIMIDITY_TRUE=
    4.74 +  USE_TIMIDITY_FALSE='#'
    4.75 +else
    4.76 +  USE_TIMIDITY_TRUE='#'
    4.77 +  USE_TIMIDITY_FALSE=
    4.78 +fi
    4.79 +
    4.80  # Finally create all the generated files
    4.81  trap '' 1 2 15
    4.82  cat > confcache <<\EOF
    4.83 @@ -2178,6 +2198,11 @@
    4.84  s%@SDL_CONFIG@%$SDL_CONFIG%g
    4.85  s%@SDL_CFLAGS@%$SDL_CFLAGS%g
    4.86  s%@SDL_LIBS@%$SDL_LIBS%g
    4.87 +s%@MUSIC_SUBDIRS@%$MUSIC_SUBDIRS%g
    4.88 +s%@USE_MIKMOD_TRUE@%$USE_MIKMOD_TRUE%g
    4.89 +s%@USE_MIKMOD_FALSE@%$USE_MIKMOD_FALSE%g
    4.90 +s%@USE_TIMIDITY_TRUE@%$USE_TIMIDITY_TRUE%g
    4.91 +s%@USE_TIMIDITY_FALSE@%$USE_TIMIDITY_FALSE%g
    4.92  
    4.93  CEOF
    4.94  EOF
     5.1 --- a/configure.in	Thu Oct 21 18:02:08 1999 +0000
     5.2 +++ b/configure.in	Thu Oct 21 19:12:17 1999 +0000
     5.3 @@ -64,19 +64,19 @@
     5.4  if test x$enable_music_wave = xyes; then
     5.5      CFLAGS="$CFLAGS -DWAV_MUSIC"
     5.6  fi
     5.7 +AC_ARG_ENABLE(music-mod,
     5.8 +[  --enable-music-mod      enable MOD music via mikmod [default=yes]],
     5.9 +              , enable_music_mod=yes)
    5.10 +if test x$enable_music_mod = xyes; then
    5.11 +    CFLAGS="$CFLAGS -DMOD_MUSIC -I\$(top_srcdir)/mikmod"
    5.12 +    MUSIC_SUBDIRS="$MUSIC_SUBDIRS mikmod"
    5.13 +fi
    5.14  AC_ARG_ENABLE(music-midi,
    5.15  [  --enable-music-midi     enable MIDI music via timidity [default=yes]],
    5.16                , enable_music_midi=yes)
    5.17  if test x$enable_music_midi = xyes; then
    5.18      CFLAGS="$CFLAGS -DMID_MUSIC -I\$(top_srcdir)/timidity"
    5.19 -    #MUSIC_SUBDIRS="$MUSIC_SUBDIRS timidity"
    5.20 -fi
    5.21 -AC_ARG_ENABLE(music-mod,
    5.22 -[  --enable-music-mod      enable MOD music via mikmod [default=yes]],
    5.23 -              , enable_music_mod=yes)
    5.24 -if test x$enable_music_mod = xyes; then
    5.25 -    CFLAGS="$CFLAGS -DMOD_MUSIC -I\$(top_srcdir)/mikmod"
    5.26 -    #MUSIC_SUBDIRS="$MUSIC_SUBDIRS mikmod"
    5.27 +    MUSIC_SUBDIRS="$MUSIC_SUBDIRS timidity"
    5.28  fi
    5.29  AC_ARG_ENABLE(music-mp3,
    5.30  [  --enable-music-mp3      enable MP3 music via smpeg [default=yes]],
    5.31 @@ -97,6 +97,11 @@
    5.32      fi
    5.33  fi
    5.34  
    5.35 +dnl Add Makefile conditionals
    5.36 +AC_SUBST(MUSIC_SUBDIRS)
    5.37 +AM_CONDITIONAL(USE_MIKMOD, test x$enable_music_mod = xyes)
    5.38 +AM_CONDITIONAL(USE_TIMIDITY, test x$enable_music_midi = xyes)
    5.39 +
    5.40  # Finally create all the generated files
    5.41  AC_OUTPUT([
    5.42  Makefile
     6.1 --- a/mixer.c	Thu Oct 21 18:02:08 1999 +0000
     6.2 +++ b/mixer.c	Thu Oct 21 19:12:17 1999 +0000
     6.3 @@ -232,12 +232,48 @@
     6.4  		free(chunk);
     6.5  		return(NULL);
     6.6  	}
     6.7 +	chunk->allocated = 1;
     6.8  	chunk->abuf = wavecvt.buf;
     6.9  	chunk->alen = wavecvt.len_cvt;
    6.10  	chunk->volume = MIX_MAX_VOLUME;
    6.11  	return(chunk);
    6.12  }
    6.13  
    6.14 +/* Load a wave file of the mixer format from a memory buffer */
    6.15 +Mix_Chunk *Mix_QuickLoad_WAV(Uint8 *mem)
    6.16 +{
    6.17 +	Mix_Chunk *chunk;
    6.18 +	Uint8 magic[4];
    6.19 +
    6.20 +	/* Make sure audio has been opened */
    6.21 +	if ( ! audio_opened ) {
    6.22 +		SDL_SetError("Audio device hasn't been opened");
    6.23 +		return(NULL);
    6.24 +	}
    6.25 +
    6.26 +	/* Allocate the chunk memory */
    6.27 +	chunk = (Mix_Chunk *)malloc(sizeof(Mix_Chunk));
    6.28 +	if ( chunk == NULL ) {
    6.29 +		SDL_SetError("Out of memory");
    6.30 +		return(NULL);
    6.31 +	}
    6.32 +
    6.33 +	/* Essentially just skip to the audio data (no error checking - fast) */
    6.34 +	chunk->allocated = 0;
    6.35 +	mem += 12; /* WAV header */
    6.36 +	do {
    6.37 +		memcpy(magic, mem, 4);
    6.38 +		mem += 4;
    6.39 +		chunk->alen = ((mem[3]<<24)|(mem[2]<<16)|(mem[1]<<8)|(mem[0]));
    6.40 +		mem += 4;
    6.41 +		chunk->abuf = mem;
    6.42 +		mem += chunk->alen;
    6.43 +	} while ( memcmp(magic, "data", 4) != 0 );
    6.44 +	chunk->volume = MIX_MAX_VOLUME;
    6.45 +
    6.46 +	return(chunk);
    6.47 +}
    6.48 +
    6.49  /* Free an audio chunk previously loaded */
    6.50  void Mix_FreeChunk(Mix_Chunk *chunk)
    6.51  {
    6.52 @@ -255,7 +291,9 @@
    6.53  		SDL_mutexV(mixer_lock);
    6.54  
    6.55  		/* Actually free the chunk */
    6.56 -		free(chunk->abuf);
    6.57 +		if ( chunk->allocated ) {
    6.58 +			free(chunk->abuf);
    6.59 +		}
    6.60  		free(chunk);
    6.61  	}
    6.62  }
     7.1 --- a/mixer.h	Thu Oct 21 18:02:08 1999 +0000
     7.2 +++ b/mixer.h	Thu Oct 21 19:12:17 1999 +0000
     7.3 @@ -44,6 +44,7 @@
     7.4  
     7.5  /* The internal format for an audio chunk */
     7.6  typedef struct {
     7.7 +	int allocated;
     7.8  	Uint8 *abuf;
     7.9  	Uint32 alen;
    7.10  	Uint8 volume;		/* Per-sample volume, 0-128 */
    7.11 @@ -61,11 +62,14 @@
    7.12   */
    7.13  extern int Mix_QuerySpec(int *frequency, Uint16 *format, int *channels);
    7.14  
    7.15 -/* Load a wave file or a MOD (.mod .s3m .it .xm) file */
    7.16 +/* Load a wave file or a music (.mod .s3m .it .xm) file */
    7.17  extern Mix_Chunk *Mix_LoadWAV_RW(SDL_RWops *src, int freesrc);
    7.18  #define Mix_LoadWAV(file)	Mix_LoadWAV_RW(SDL_RWFromFile(file, "rb"), 1)
    7.19  extern Mix_Music *Mix_LoadMUS(const char *file);
    7.20  
    7.21 +/* Load a wave file of the mixer format from a memory buffer */
    7.22 +extern Mix_Chunk *Mix_QuickLoad_WAV(Uint8 *mem);
    7.23 +
    7.24  /* Free an audio chunk previously loaded */
    7.25  extern void Mix_FreeChunk(Mix_Chunk *chunk);
    7.26  extern void Mix_FreeMusic(Mix_Music *music);