* 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
master
Giel van Schijndel 2007-05-01 00:04:37 +00:00
parent bfad55739b
commit 8a5c7d9f6d
2 changed files with 2 additions and 35 deletions

View File

@ -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, &section);
@ -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;

View File

@ -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;