From 8a5c7d9f6d619afec2494f29c04b2fa408893e70 Mon Sep 17 00:00:00 2001 From: Giel van Schijndel Date: Tue, 1 May 2007 00:04:37 +0000 Subject: [PATCH] * remove ability to resize external buffer (realloc) because this made the code overly complex while providing only little gain * instead we now just calculate the precise amount of memory needed ahead of time and just malloc for decoding of each track (decoding only occurs while loading so these extra malloc calls shouldn't go at the expense of performance) git-svn-id: svn+ssh://svn.gna.org/svn/warzone/trunk@1572 4a71c877-e1ca-e34f-864e-861f7616d084 --- lib/sound/oggvorbis.c | 19 +------------------ lib/sound/openal_track.c | 18 +----------------- 2 files changed, 2 insertions(+), 35 deletions(-) diff --git a/lib/sound/oggvorbis.c b/lib/sound/oggvorbis.c index 8c65af184..7e8dba1a4 100644 --- a/lib/sound/oggvorbis.c +++ b/lib/sound/oggvorbis.c @@ -224,23 +224,6 @@ soundDataBuffer* sound_DecodeOggVorbis(OggVorbisDecoderState* decoder, size_t bu // Decode PCM data into the buffer until there is nothing to decode left do { - // If the PCM buffer has become to small increase it by reallocating double its previous size - if (size == bufferSize && targetBuffer != NULL) - { - void* newBuffer; - bufferSize *= 2; - newBuffer = realloc(buffer, bufferSize + sizeof(soundDataBuffer)); - if (newBuffer == NULL) - { - debug(LOG_ERROR, "sound_DecodeOggVorbis: realloc failed, bailing out\n"); - return buffer; - } - - buffer = newBuffer; - buffer->data = (char*)(buffer + 1); - buffer->bufferSize = bufferSize + sizeof(soundDataBuffer); - } - // Decode int section; result = ov_read(&decoder->oggVorbis_stream, &buffer->data[size], bufferSize - size, OGG_ENDIAN, 2, 1, §ion); @@ -256,7 +239,7 @@ soundDataBuffer* sound_DecodeOggVorbis(OggVorbisDecoderState* decoder, size_t bu size += result; } - } while ((result != 0 && size < bufferSize) || (size == bufferSize && targetBuffer != NULL)); + } while ((result != 0 && size < bufferSize)); buffer->size = size; diff --git a/lib/sound/openal_track.c b/lib/sound/openal_track.c index 8c3d92536..984a39d36 100644 --- a/lib/sound/openal_track.c +++ b/lib/sound/openal_track.c @@ -60,9 +60,6 @@ static ALfloat sfx3d_volume = 1.0; static ALCdevice* device = 0; static ALCcontext* context = 0; -static char* DataBuffer = NULL; // Needed for sound_DecodeOggVorbisTrack, must be global, so it can be free'd on shutdown -static size_t DataBuffer_size = 16 * 1024; - BOOL openal_initialized = FALSE; BOOL cdAudio_Update( void ); @@ -153,9 +150,6 @@ void sound_ShutdownLibrary( void ) device = 0; } - free(DataBuffer); - DataBuffer = NULL; - while( aSample ) { tmpSample = aSample->next; @@ -262,25 +256,15 @@ static inline TRACK* sound_DecodeOggVorbisTrack(TRACK *psTrack, PHYSFS_file* PHY OggVorbisDecoderState* decoder = sound_CreateOggVorbisDecoder(PHYSFS_fileHandle, TRUE); soundDataBuffer* soundBuffer; - // Allocate an initial buffer to contain the decoded PCM data - if (DataBuffer == NULL) - { - DataBuffer = malloc(DataBuffer_size); - } - - soundBuffer = sound_DecodeOggVorbis(decoder, DataBuffer_size, DataBuffer); + soundBuffer = sound_DecodeOggVorbis(decoder, 0, NULL); sound_DestroyOggVorbisDecoder(decoder); - DataBuffer = (char*)soundBuffer; - if (soundBuffer == NULL) { free(psTrack); return NULL; } - DataBuffer_size = soundBuffer->bufferSize; - // Determine PCM data format format = (soundBuffer->channelCount == 1) ? AL_FORMAT_MONO16 : AL_FORMAT_STEREO16;