Sam Lantinga - Sun Jul 2 14:16:44 PDT 2000
authorSam Lantinga <slouken@lokigames.com>
Mon, 03 Jul 2000 00:25:20 +0000
changeset 6392b13db7d0a5
parent 62 28b520525898
child 64 00b28153c609
Sam Lantinga - Sun Jul 2 14:16:44 PDT 2000
* Added support for the Ogg Vorbis music format: http://www.vorbis.org/
* Cleaned up the streaming wave code a bit
CHANGES
Makefile.am
autogen.sh
configure.in
music.c
music_ogg.c
music_ogg.h
wavestream.c
wavestream.h
     1.1 --- a/CHANGES	Wed Jun 28 19:02:06 2000 +0000
     1.2 +++ b/CHANGES	Mon Jul 03 00:25:20 2000 +0000
     1.3 @@ -1,5 +1,7 @@
     1.4  
     1.5  1.0.6:
     1.6 +Sam Lantinga - Sun Jul  2 14:16:44 PDT 2000
     1.7 + * Added support for the Ogg Vorbis music format: http://www.vorbis.org/
     1.8  Darrell Walisser - Wed Jun 28 11:59:40 PDT 2000
     1.9   * Added Codewarrior projects for MacOS
    1.10  Sam Lantinga - Mon Jun 26 12:01:11 PDT 2000
     2.1 --- a/Makefile.am	Wed Jun 28 19:02:06 2000 +0000
     2.2 +++ b/Makefile.am	Mon Jul 03 00:25:20 2000 +0000
     2.3 @@ -14,6 +14,8 @@
     2.4  	music.c			\
     2.5  	music_cmd.c		\
     2.6  	music_cmd.h		\
     2.7 +	music_ogg.c		\
     2.8 +	music_ogg.h		\
     2.9  	wave.h			\
    2.10  	wavestream.c		\
    2.11  	wavestream.h
     3.1 --- a/autogen.sh	Wed Jun 28 19:02:06 2000 +0000
     3.2 +++ b/autogen.sh	Mon Jul 03 00:25:20 2000 +0000
     3.3 @@ -4,4 +4,5 @@
     3.4  automake --foreign
     3.5  autoconf
     3.6  
     3.7 -./configure $*
     3.8 +#./configure $*
     3.9 +echo "Now you are ready to run ./configure"
     4.1 --- a/configure.in	Wed Jun 28 19:02:06 2000 +0000
     4.2 +++ b/configure.in	Mon Jul 03 00:25:20 2000 +0000
     4.3 @@ -95,6 +95,24 @@
     4.4      CFLAGS="$CFLAGS -DMID_MUSIC -I\$(top_srcdir)/timidity"
     4.5      MUSIC_SUBDIRS="$MUSIC_SUBDIRS timidity"
     4.6  fi
     4.7 +AC_ARG_ENABLE(music-ogg,
     4.8 +[  --enable-music-ogg      enable Ogg Vorbis music [default=yes]],
     4.9 +              , enable_music_ogg=yes)
    4.10 +if test x$enable_music_ogg = xyes; then
    4.11 +    AC_MSG_CHECKING(for Ogg Vorbis headers and libraries)
    4.12 +    have_vorbis=no
    4.13 +    AC_TRY_COMPILE([
    4.14 +     #include <vorbis/vorbisfile.h>
    4.15 +    ],[
    4.16 +    ],[
    4.17 +    have_vorbis=yes
    4.18 +    ])
    4.19 +    AC_MSG_RESULT($have_vorbis)
    4.20 +    if test x$have_vorbis = xyes; then
    4.21 +        CFLAGS="$CFLAGS -DOGG_MUSIC"
    4.22 +        LIBS="$LIBS -lvorbisfile -lvorbis"
    4.23 +    fi
    4.24 +fi
    4.25  AC_ARG_ENABLE(music-mp3,
    4.26  [  --enable-music-mp3      enable MP3 music via smpeg [default=yes]],
    4.27                , enable_music_mp3=yes)
     5.1 --- a/music.c	Wed Jun 28 19:02:06 2000 +0000
     5.2 +++ b/music.c	Mon Jul 03 00:25:20 2000 +0000
     5.3 @@ -57,6 +57,9 @@
     5.4  #ifdef MID_MUSIC
     5.5  #include "timidity.h"
     5.6  #endif
     5.7 +#ifdef OGG_MUSIC
     5.8 +#include "music_ogg.h"
     5.9 +#endif
    5.10  #ifdef MP3_MUSIC
    5.11  #include <smpeg/smpeg.h>
    5.12  
    5.13 @@ -79,6 +82,7 @@
    5.14  		MUS_WAV,
    5.15  		MUS_MOD,
    5.16  		MUS_MID,
    5.17 +		MUS_OGG,
    5.18  		MUS_MP3
    5.19  	} type;
    5.20  	union {
    5.21 @@ -94,6 +98,9 @@
    5.22  #ifdef MID_MUSIC
    5.23  		MidiSong *midi;
    5.24  #endif
    5.25 +#ifdef OGG_MUSIC
    5.26 +		OGG_music *ogg;
    5.27 +#endif
    5.28  #ifdef MP3_MUSIC
    5.29  		SMPEG *mp3;
    5.30  #endif
    5.31 @@ -186,7 +193,7 @@
    5.32  #endif
    5.33  #ifdef WAV_MUSIC
    5.34  			case MUS_WAV:
    5.35 -				WAVStream_PlaySome(stream, len);
    5.36 +				WAVStream_PlaySome(music_playing->data.wave, stream, len);
    5.37  				break;
    5.38  #endif
    5.39  #ifdef MOD_MUSIC
    5.40 @@ -220,6 +227,11 @@
    5.41  				Timidity_PlaySome(stream, len/samplesize);
    5.42  				break;
    5.43  #endif
    5.44 +#ifdef OGG_MUSIC
    5.45 +			case MUS_OGG:
    5.46 +				OGG_playAudio(music_playing->data.ogg, stream, len);
    5.47 +				break;
    5.48 +#endif
    5.49  #ifdef MP3_MUSIC
    5.50  			case MUS_MP3:
    5.51  				SMPEG_playAudio(music_playing->data.mp3, stream, len);
    5.52 @@ -308,6 +320,11 @@
    5.53  		timidity_ok = 0;
    5.54  	}
    5.55  #endif
    5.56 +#ifdef OGG_MUSIC
    5.57 +	if ( OGG_init(mixer) < 0 ) {
    5.58 +		++music_error;
    5.59 +	}
    5.60 +#endif
    5.61  #ifdef MP3_MUSIC
    5.62  	/* Keep a copy of the mixer */
    5.63  	used_mixer = *mixer;
    5.64 @@ -391,6 +408,16 @@
    5.65  		}
    5.66  	} else
    5.67  #endif
    5.68 +#ifdef OGG_MUSIC
    5.69 +	/* Ogg Vorbis files have the magic four bytes "OggS" */
    5.70 +	if ( strcmp(magic, "OggS") == 0 ) {
    5.71 +		music->type = MUS_OGG;
    5.72 +		music->data.ogg = OGG_new(file);
    5.73 +		if ( music->data.ogg == NULL ) {
    5.74 +			music->error = 1;
    5.75 +		}
    5.76 +	} else
    5.77 +#endif
    5.78  #ifdef MP3_MUSIC
    5.79  	if ( magic[0]==0xFF && (magic[1]&0xF0)==0xF0) {
    5.80  		SMPEG_Info info;
    5.81 @@ -460,6 +487,11 @@
    5.82  				Timidity_FreeSong(music->data.midi);
    5.83  				break;
    5.84  #endif
    5.85 +#ifdef OGG_MUSIC
    5.86 +			case MUS_OGG:
    5.87 +				OGG_delete(music->data.ogg);
    5.88 +				break;
    5.89 +#endif
    5.90  #ifdef MP3_MUSIC
    5.91  			case MUS_MP3:
    5.92  				SMPEG_delete(music->data.mp3);
    5.93 @@ -504,6 +536,12 @@
    5.94  			Timidity_Start(music->data.midi);
    5.95  			break;
    5.96  #endif
    5.97 +#ifdef OGG_MUSIC
    5.98 +		case MUS_OGG:
    5.99 +			OGG_setvolume(music->data.ogg, music_volume);
   5.100 +			OGG_play(music->data.ogg);
   5.101 +			break;
   5.102 +#endif
   5.103  #ifdef MP3_MUSIC
   5.104  		case MUS_MP3:
   5.105  			SMPEG_enableaudio(music->data.mp3,1);
   5.106 @@ -594,6 +632,11 @@
   5.107  			Timidity_SetVolume(music_volume);
   5.108  			break;
   5.109  #endif
   5.110 +#ifdef OGG_MUSIC
   5.111 +		case MUS_OGG:
   5.112 +			OGG_setvolume(music_playing->data.ogg, music_volume);
   5.113 +			break;
   5.114 +#endif
   5.115  #ifdef MP3_MUSIC
   5.116  		case MUS_MP3:
   5.117  			SMPEG_setvolume(music_playing->data.mp3,((float)music_volume/(float)MIX_MAX_VOLUME)*100.0);
   5.118 @@ -630,6 +673,11 @@
   5.119  		Timidity_Stop();
   5.120  		break;
   5.121  #endif
   5.122 +#ifdef OGG_MUSIC
   5.123 +	case MUS_OGG:
   5.124 +		OGG_stop(music_playing->data.ogg);
   5.125 +		break;
   5.126 +#endif
   5.127  #ifdef MP3_MUSIC
   5.128  	case MUS_MP3:
   5.129  		SMPEG_stop(music_playing->data.mp3);
   5.130 @@ -740,7 +788,7 @@
   5.131  #endif
   5.132  #ifdef WAV_MUSIC
   5.133  			case MUS_WAV:
   5.134 -				if ( ! WAVStream_Active() ) {
   5.135 +				if ( ! WAVStream_Active(music_playing->data.wave) ) {
   5.136  					return(0);
   5.137  				}
   5.138  				break;
   5.139 @@ -759,6 +807,13 @@
   5.140  				}
   5.141  				break;
   5.142  #endif
   5.143 +#ifdef OGG_MUSIC
   5.144 +			case MUS_OGG:
   5.145 +				if ( ! OGG_playing(music_playing->data.ogg) ) {
   5.146 +					return(0);
   5.147 +				}
   5.148 +				break;
   5.149 +#endif
   5.150  #ifdef MP3_MUSIC
   5.151  			case MUS_MP3:
   5.152  				if(SMPEG_status(music_playing->data.mp3)!=SMPEG_PLAYING)
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/music_ogg.c	Mon Jul 03 00:25:20 2000 +0000
     6.3 @@ -0,0 +1,185 @@
     6.4 +/*
     6.5 +    MIXERLIB:  An audio mixer library based on the SDL library
     6.6 +    Copyright (C) 1997-1999  Sam Lantinga
     6.7 +
     6.8 +    This library is free software; you can redistribute it and/or
     6.9 +    modify it under the terms of the GNU Library General Public
    6.10 +    License as published by the Free Software Foundation; either
    6.11 +    version 2 of the License, or (at your option) any later version.
    6.12 +
    6.13 +    This library is distributed in the hope that it will be useful,
    6.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    6.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    6.16 +    Library General Public License for more details.
    6.17 +
    6.18 +    You should have received a copy of the GNU Library General Public
    6.19 +    License along with this library; if not, write to the Free
    6.20 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    6.21 +
    6.22 +    Sam Lantinga
    6.23 +    5635-34 Springhouse Dr.
    6.24 +    Pleasanton, CA 94588 (USA)
    6.25 +    slouken@devolution.com
    6.26 +*/
    6.27 +
    6.28 +#ifdef OGG_MUSIC
    6.29 +
    6.30 +/* This file supports Ogg Vorbis music streams */
    6.31 +
    6.32 +#include <stdio.h>
    6.33 +#include <string.h>
    6.34 +
    6.35 +#include "SDL_mixer.h"
    6.36 +#include "music_ogg.h"
    6.37 +
    6.38 +/* This is the format of the audio mixer data */
    6.39 +static SDL_AudioSpec mixer;
    6.40 +
    6.41 +/* Initialize the Ogg Vorbis player, with the given mixer settings
    6.42 +   This function returns 0, or -1 if there was an error.
    6.43 + */
    6.44 +int OGG_init(SDL_AudioSpec *mixerfmt)
    6.45 +{
    6.46 +	mixer = *mixerfmt;
    6.47 +	return(0);
    6.48 +}
    6.49 +
    6.50 +/* Set the volume for an OGG stream */
    6.51 +void OGG_setvolume(OGG_music *music, int volume)
    6.52 +{
    6.53 +	music->volume = volume;
    6.54 +}
    6.55 +
    6.56 +/* Load an OGG stream from the given file */
    6.57 +OGG_music *OGG_new(const char *file)
    6.58 +{
    6.59 +	OGG_music *music;
    6.60 +	FILE *fp;
    6.61 +
    6.62 +	music = (OGG_music *)malloc(sizeof *music);
    6.63 +	if ( music ) {
    6.64 +		/* Initialize the music structure */
    6.65 +		memset(music, 0, (sizeof *music));
    6.66 +		OGG_stop(music);
    6.67 +		OGG_setvolume(music, MIX_MAX_VOLUME);
    6.68 +		music->section = -1;
    6.69 +
    6.70 +		fp = fopen(file, "rb");
    6.71 +		if ( fp == NULL ) {
    6.72 +			SDL_SetError("Couldn't open %s", file);
    6.73 +			free(music);
    6.74 +			return(NULL);
    6.75 +		}
    6.76 +		if ( ov_open(fp, &music->vf, NULL, 0) < 0 ) {
    6.77 +			SDL_SetError("Not an Ogg Vorbis audio stream");
    6.78 +			free(music);
    6.79 +			fclose(fp);
    6.80 +			return(NULL);
    6.81 +		}
    6.82 +	} else {
    6.83 +		SDL_OutOfMemory();
    6.84 +	}
    6.85 +	return(music);
    6.86 +}
    6.87 +
    6.88 +/* Start playback of a given OGG stream */
    6.89 +void OGG_play(OGG_music *music)
    6.90 +{
    6.91 +	music->playing = 1;
    6.92 +}
    6.93 +
    6.94 +/* Return non-zero if a stream is currently playing */
    6.95 +int OGG_playing(OGG_music *music)
    6.96 +{
    6.97 +	return(music->playing);
    6.98 +}
    6.99 +
   6.100 +/* Read some Ogg stream data and convert it for output */
   6.101 +static void OGG_getsome(OGG_music *music)
   6.102 +{
   6.103 +	int section;
   6.104 +	int len;
   6.105 +	char data[4096];
   6.106 +	SDL_AudioCVT *cvt;
   6.107 +
   6.108 +	len = ov_read(&music->vf, data, sizeof(data), 0, 2, 1, &section);
   6.109 +	if ( len <= 0 ) {
   6.110 +		if ( len == 0 ) {
   6.111 +			music->playing = 0;
   6.112 +		}
   6.113 +		return;
   6.114 +	}
   6.115 +	cvt = &music->cvt;
   6.116 +	if ( section != music->section ) {
   6.117 +		vorbis_info *vi;
   6.118 +
   6.119 +		vi = ov_info(&music->vf, -1);
   6.120 +		SDL_BuildAudioCVT(cvt, AUDIO_S16, vi->channels, vi->rate,
   6.121 +		                       mixer.format,mixer.channels,mixer.freq);
   6.122 +		if ( cvt->buf ) {
   6.123 +			free(cvt->buf);
   6.124 +		}
   6.125 +		cvt->buf = (Uint8 *)malloc(sizeof(data)*cvt->len_mult);
   6.126 +		music->section = section;
   6.127 +	}
   6.128 +	if ( cvt->buf ) {
   6.129 +		memcpy(cvt->buf, data, len);
   6.130 +		if ( cvt->needed ) {
   6.131 +			cvt->len = len;
   6.132 +			SDL_ConvertAudio(cvt);
   6.133 +		} else {
   6.134 +			cvt->len_cvt = len;
   6.135 +		}
   6.136 +		music->len_available = music->cvt.len_cvt;
   6.137 +		music->snd_available = music->cvt.buf;
   6.138 +	} else {
   6.139 +		SDL_OutOfMemory();
   6.140 +		music->playing = 0;
   6.141 +	}
   6.142 +}
   6.143 +
   6.144 +/* Play some of a stream previously started with OGG_play() */
   6.145 +void OGG_playAudio(OGG_music *music, Uint8 *snd, int len)
   6.146 +{
   6.147 +	int mixable;
   6.148 +
   6.149 +	while ( (len > 0) && music->playing ) {
   6.150 +		if ( ! music->len_available ) {
   6.151 +			OGG_getsome(music);
   6.152 +		}
   6.153 +		mixable = len;
   6.154 +		if ( mixable > music->len_available ) {
   6.155 +			mixable = music->len_available;
   6.156 +		}
   6.157 +		if ( music->volume == MIX_MAX_VOLUME ) {
   6.158 +			memcpy(snd, music->snd_available, mixable);
   6.159 +		} else {
   6.160 +			SDL_MixAudio(snd, music->snd_available, mixable,
   6.161 +			                              music->volume);
   6.162 +		}
   6.163 +		music->len_available -= mixable;
   6.164 +		music->snd_available += mixable;
   6.165 +		len -= mixable;
   6.166 +		snd += mixable;
   6.167 +	}
   6.168 +}
   6.169 +
   6.170 +/* Stop playback of a stream previously started with OGG_play() */
   6.171 +void OGG_stop(OGG_music *music)
   6.172 +{
   6.173 +	music->playing = 0;
   6.174 +}
   6.175 +
   6.176 +/* Close the given OGG stream */
   6.177 +void OGG_delete(OGG_music *music)
   6.178 +{
   6.179 +	if ( music ) {
   6.180 +		if ( music->cvt.buf ) {
   6.181 +			free(music->cvt.buf);
   6.182 +		}
   6.183 +		ov_clear(&music->vf);
   6.184 +		free(music);
   6.185 +	}
   6.186 +}
   6.187 +
   6.188 +#endif /* OGG_MUSIC */
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/music_ogg.h	Mon Jul 03 00:25:20 2000 +0000
     7.3 @@ -0,0 +1,67 @@
     7.4 +/*
     7.5 +    MIXERLIB:  An audio mixer library based on the SDL library
     7.6 +    Copyright (C) 1997-1999  Sam Lantinga
     7.7 +
     7.8 +    This library is free software; you can redistribute it and/or
     7.9 +    modify it under the terms of the GNU Library General Public
    7.10 +    License as published by the Free Software Foundation; either
    7.11 +    version 2 of the License, or (at your option) any later version.
    7.12 +
    7.13 +    This library is distributed in the hope that it will be useful,
    7.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    7.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    7.16 +    Library General Public License for more details.
    7.17 +
    7.18 +    You should have received a copy of the GNU Library General Public
    7.19 +    License along with this library; if not, write to the Free
    7.20 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    7.21 +
    7.22 +    Sam Lantinga
    7.23 +    5635-34 Springhouse Dr.
    7.24 +    Pleasanton, CA 94588 (USA)
    7.25 +    slouken@devolution.com
    7.26 +*/
    7.27 +
    7.28 +#ifdef OGG_MUSIC
    7.29 +
    7.30 +/* This file supports Ogg Vorbis music streams */
    7.31 +
    7.32 +#include <vorbis/vorbisfile.h>
    7.33 +
    7.34 +typedef struct {
    7.35 +	int playing;
    7.36 +	int volume;
    7.37 +	OggVorbis_File vf;
    7.38 +	int section;
    7.39 +	SDL_AudioCVT cvt;
    7.40 +	int len_available;
    7.41 +	Uint8 *snd_available;
    7.42 +} OGG_music;
    7.43 +
    7.44 +/* Initialize the Ogg Vorbis player, with the given mixer settings
    7.45 +   This function returns 0, or -1 if there was an error.
    7.46 + */
    7.47 +extern int OGG_init(SDL_AudioSpec *mixer);
    7.48 +
    7.49 +/* Set the volume for an OGG stream */
    7.50 +extern void OGG_setvolume(OGG_music *music, int volume);
    7.51 +
    7.52 +/* Load an OGG stream from the given file */
    7.53 +extern OGG_music *OGG_new(const char *file);
    7.54 +
    7.55 +/* Start playback of a given OGG stream */
    7.56 +extern void OGG_play(OGG_music *music);
    7.57 +
    7.58 +/* Return non-zero if a stream is currently playing */
    7.59 +extern int OGG_playing(OGG_music *music);
    7.60 +
    7.61 +/* Play some of a stream previously started with OGG_play() */
    7.62 +extern void OGG_playAudio(OGG_music *music, Uint8 *stream, int len);
    7.63 +
    7.64 +/* Stop playback of a stream previously started with OGG_play() */
    7.65 +extern void OGG_stop(OGG_music *music);
    7.66 +
    7.67 +/* Close the given OGG stream */
    7.68 +extern void OGG_delete(OGG_music *music);
    7.69 +
    7.70 +#endif /* OGG_MUSIC */
     8.1 --- a/wavestream.c	Wed Jun 28 19:02:06 2000 +0000
     8.2 +++ b/wavestream.c	Mon Jul 03 00:25:20 2000 +0000
     8.3 @@ -35,12 +35,6 @@
     8.4  #include "wave.h"
     8.5  #include "wavestream.h"
     8.6  
     8.7 -/* Currently we only support a single stream at a time */
     8.8 -static WAVStream *theWave = NULL;
     8.9 -
    8.10 -/* This is initialized by the music mixer */
    8.11 -static SDL_mutex *music_lock = NULL;
    8.12 -
    8.13  /* This is the format of the audio mixer data */
    8.14  static SDL_AudioSpec mixer;
    8.15  
    8.16 @@ -55,13 +49,6 @@
    8.17   */
    8.18  int WAVStream_Init(SDL_AudioSpec *mixerfmt)
    8.19  {
    8.20 -	/* FIXME: clean up the mutex, or move it into music.c */
    8.21 -	music_lock = SDL_CreateMutex();
    8.22 -#ifndef macintosh /* Hmm.. */
    8.23 -	if ( music_lock == NULL ) {
    8.24 -		return(-1);
    8.25 -	}
    8.26 -#endif
    8.27  	mixer = *mixerfmt;
    8.28  	return(0);
    8.29  }
    8.30 @@ -106,75 +93,58 @@
    8.31  /* Start playback of a given WAV stream */
    8.32  extern void WAVStream_Start(WAVStream *wave)
    8.33  {
    8.34 -	SDL_mutexP(music_lock);
    8.35  	clearerr(wave->wavefp);
    8.36  	fseek(wave->wavefp, wave->start, SEEK_SET);
    8.37 -	theWave = wave;
    8.38 -	SDL_mutexV(music_lock);
    8.39  }
    8.40  
    8.41  /* Play some of a stream previously started with WAVStream_Start()
    8.42 -   The music_lock is held while this function is called.
    8.43   */
    8.44 -extern void WAVStream_PlaySome(Uint8 *stream, int len)
    8.45 +extern void WAVStream_PlaySome(WAVStream *wave, Uint8 *stream, int len)
    8.46  {
    8.47  	long pos;
    8.48  
    8.49 -	SDL_mutexP(music_lock);
    8.50 -	if ( theWave && ((pos=ftell(theWave->wavefp)) < theWave->stop) ) {
    8.51 -		if ( theWave->cvt.needed ) {
    8.52 +	if ( (pos=ftell(wave->wavefp)) < wave->stop ) {
    8.53 +		if ( wave->cvt.needed ) {
    8.54  			int original_len;
    8.55  
    8.56 -			original_len=(int)((double)len/theWave->cvt.len_ratio);
    8.57 -			if ( theWave->cvt.len != original_len ) {
    8.58 +			original_len=(int)((double)len/wave->cvt.len_ratio);
    8.59 +			if ( wave->cvt.len != original_len ) {
    8.60  				int worksize;
    8.61 -				if ( theWave->cvt.buf != NULL ) {
    8.62 -					free(theWave->cvt.buf);
    8.63 +				if ( wave->cvt.buf != NULL ) {
    8.64 +					free(wave->cvt.buf);
    8.65  				}
    8.66 -				worksize = original_len*theWave->cvt.len_mult;
    8.67 -				theWave->cvt.buf=(Uint8 *)malloc(worksize);
    8.68 -				if ( theWave->cvt.buf == NULL ) {
    8.69 -					SDL_mutexV(music_lock);
    8.70 +				worksize = original_len*wave->cvt.len_mult;
    8.71 +				wave->cvt.buf=(Uint8 *)malloc(worksize);
    8.72 +				if ( wave->cvt.buf == NULL ) {
    8.73  					return;
    8.74  				}
    8.75 -				theWave->cvt.len = original_len;
    8.76 +				wave->cvt.len = original_len;
    8.77  			}
    8.78 -			if ( (theWave->stop - pos) < original_len ) {
    8.79 -				original_len = (theWave->stop - pos);
    8.80 +			if ( (wave->stop - pos) < original_len ) {
    8.81 +				original_len = (wave->stop - pos);
    8.82  			}
    8.83 -			theWave->cvt.len = original_len;
    8.84 -			fread(theWave->cvt.buf,original_len,1,theWave->wavefp);
    8.85 -			SDL_ConvertAudio(&theWave->cvt);
    8.86 -			memcpy(stream, theWave->cvt.buf, theWave->cvt.len_cvt);
    8.87 +			wave->cvt.len = original_len;
    8.88 +			fread(wave->cvt.buf,original_len,1,wave->wavefp);
    8.89 +			SDL_ConvertAudio(&wave->cvt);
    8.90 +			memcpy(stream, wave->cvt.buf, wave->cvt.len_cvt);
    8.91  		} else {
    8.92 -			if ( (theWave->stop - pos) < len ) {
    8.93 -				len = (theWave->stop - pos);
    8.94 +			if ( (wave->stop - pos) < len ) {
    8.95 +				len = (wave->stop - pos);
    8.96  			}
    8.97 -			fread(stream, len, 1, theWave->wavefp);
    8.98 +			fread(stream, len, 1, wave->wavefp);
    8.99  		}
   8.100  	}
   8.101 -	SDL_mutexV(music_lock);
   8.102  }
   8.103  
   8.104  /* Stop playback of a stream previously started with WAVStream_Start() */
   8.105  extern void WAVStream_Stop(void)
   8.106  {
   8.107 -	SDL_mutexP(music_lock);
   8.108 -	theWave = NULL;
   8.109 -	SDL_mutexV(music_lock);
   8.110  }
   8.111  
   8.112  /* Close the given WAV stream */
   8.113  extern void WAVStream_FreeSong(WAVStream *wave)
   8.114  {
   8.115  	if ( wave ) {
   8.116 -		/* Remove song from the currently playing list */
   8.117 -		SDL_mutexP(music_lock);
   8.118 -		if ( wave == theWave ) {
   8.119 -			theWave = NULL;
   8.120 -		}
   8.121 -		SDL_mutexV(music_lock);
   8.122 -
   8.123  		/* Clean up associated data */
   8.124  		if ( wave->wavefp ) {
   8.125  			fclose(wave->wavefp);
   8.126 @@ -187,16 +157,16 @@
   8.127  }
   8.128  
   8.129  /* Return non-zero if a stream is currently playing */
   8.130 -extern int WAVStream_Active(void)
   8.131 +extern int WAVStream_Active(WAVStream *wave)
   8.132  {
   8.133  	int active;
   8.134  
   8.135 -	SDL_mutexP(music_lock);
   8.136 +	SDL_LockAudio();
   8.137  	active = 0;
   8.138 -	if ( theWave && (ftell(theWave->wavefp) < theWave->stop) ) {
   8.139 +	if ( ftell(wave->wavefp) < wave->stop ) {
   8.140  		active = 1;
   8.141  	}
   8.142 -	SDL_mutexV(music_lock);
   8.143 +	SDL_UnlockAudio();
   8.144  
   8.145  	return(active);
   8.146  }
     9.1 --- a/wavestream.h	Wed Jun 28 19:02:06 2000 +0000
     9.2 +++ b/wavestream.h	Mon Jul 03 00:25:20 2000 +0000
     9.3 @@ -48,7 +48,7 @@
     9.4  extern void WAVStream_Start(WAVStream *wave);
     9.5  
     9.6  /* Play some of a stream previously started with WAVStream_Start() */
     9.7 -extern void WAVStream_PlaySome(Uint8 *stream, int len);
     9.8 +extern void WAVStream_PlaySome(WAVStream *wave, Uint8 *stream, int len);
     9.9  
    9.10  /* Stop playback of a stream previously started with WAVStream_Start() */
    9.11  extern void WAVStream_Stop(void);
    9.12 @@ -57,4 +57,4 @@
    9.13  extern void WAVStream_FreeSong(WAVStream *wave);
    9.14  
    9.15  /* Return non-zero if a stream is currently playing */
    9.16 -extern int WAVStream_Active(void);
    9.17 +extern int WAVStream_Active(WAVStream *wave);