diff --git a/src/client/sound/header/local.h b/src/client/sound/header/local.h index 74e9700b..8e7f95e6 100644 --- a/src/client/sound/header/local.h +++ b/src/client/sound/header/local.h @@ -171,6 +171,9 @@ void S_BuildSoundList( int *sounds ); #define SOUND_FULLVOLUME 80 #define SOUND_LOOPATTENUATE 0.003 +// number of buffers in flight (needed for ogg) +extern int active_buffers; + // for snd_al.c - copied from Q2Pro and adapted void AL_SoundInfo( void ); qboolean AL_Init( void ); diff --git a/src/client/sound/snd_al.c b/src/client/sound/snd_al.c index 8629c224..75875833 100644 --- a/src/client/sound/snd_al.c +++ b/src/client/sound/snd_al.c @@ -37,6 +37,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #define MIN_CHANNELS 16 qboolean streamPlaying; +int active_buffers; + static ALuint streamSource; static ALuint s_srcnums[MAX_CHANNELS-1]; @@ -142,6 +144,7 @@ sfxcache_t *AL_UploadSfx( sfx_t *s, wavinfo_t *s_info, byte *data ) { qalGetError(); qalGenBuffers( 1, &name ); qalBufferData( name, format, data, size, s_info->rate ); + active_buffers++; if( qalGetError() != AL_NO_ERROR ) { // s->error = Q_ERR_LIBRARY_ERROR; FIXME: do I want this info? return NULL; @@ -169,6 +172,7 @@ void AL_DeleteSfx( sfx_t *s ) { name = sc->bufnum; qalDeleteBuffers( 1, &name ); + active_buffers--; } void AL_StopChannel( channel_t *ch ) { @@ -444,6 +448,7 @@ static void S_AL_StreamDie( void ) ALuint buffer; qalSourceUnqueueBuffers(streamSource, 1, &buffer); qalDeleteBuffers(1, &buffer); + active_buffers--; } // S_AL_FreeStreamChannel(stream); @@ -461,6 +466,7 @@ static void S_AL_StreamUpdate( void ) ALuint buffer; qalSourceUnqueueBuffers(streamSource, 1, &buffer); qalDeleteBuffers(1, &buffer); + active_buffers--; } // Start the streamSource playing if necessary @@ -516,6 +522,7 @@ void AL_RawSamples( int samples, int rate, int width, int channels, byte *data, // Create a buffer, and stuff the data into it qalGenBuffers(1, &buffer); qalBufferData(buffer, format, (ALvoid *)data, (samples * width * channels), rate); + active_buffers++; // set volume qalSourcef( streamSource, AL_GAIN, volume ); diff --git a/src/client/sound/snd_vorbis.c b/src/client/sound/snd_vorbis.c index f22af971..6f616224 100644 --- a/src/client/sound/snd_vorbis.c +++ b/src/client/sound/snd_vorbis.c @@ -602,10 +602,38 @@ OGG_Stream ( void ) return; } +#ifdef USE_OPENAL + /* + */ + if ( ogg_status == PLAY ) + { + + /* active_buffers are all active OpenAL buffers, + buffering normal sfx _and_ ogg/vorbis samples. + Empirical testing showed that there are most + likly never more than 256 sfx buffers active. + Read ogg samples into buffers until there are + 384 active buffers. This keeps at least 128 + ogg buffers (128 * 4096 Byte = 512 KByte) in + the memory. That's about 30 second of music + playback, more than enough to rule out buffer + underruns even at very, very, very low frame + rates. */ + while ( active_buffers <= 384 ) + { + OGG_Read(); + } + } +#else + /* Read that number samples into the buffer, that + were played since the last call to this function. + This keeps the buffer at all times at an "optimal" + fill level. */ while ( ogg_status == PLAY && paintedtime + MAX_RAW_SAMPLES - 2048 > s_rawend ) { OGG_Read(); } +#endif } /*