From 8e885d15ac479c37f236b8de51b8e2256b326cec Mon Sep 17 00:00:00 2001 From: Benau Date: Fri, 14 May 2021 23:58:59 +0800 Subject: [PATCH] Calculate duration from the original buffer size MojoAL use SDL_AudioCVT internally which doubles the size --- src/audio/sfx_buffer.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/audio/sfx_buffer.cpp b/src/audio/sfx_buffer.cpp index 636718d2f..35a2a8075 100644 --- a/src/audio/sfx_buffer.cpp +++ b/src/audio/sfx_buffer.cpp @@ -204,6 +204,13 @@ bool SFXBuffer::loadVorbisBuffer(const std::string &name, ALuint buffer) data.get(), len, info->rate); success = true; + int buffer_size, frequency, bits_per_sample, channels; + buffer_size = len; + frequency = info->rate; + // We use AL_FORMAT_MONO16 or AL_FORMAT_STEREO16 so it's always 16 + bits_per_sample = 16; + channels = info->channels; + ov_clear(&oggFile); fclose(file); @@ -211,11 +218,6 @@ bool SFXBuffer::loadVorbisBuffer(const std::string &name, ALuint buffer) // duration (which is the norm), compute it: if(m_duration < 0) { - ALint buffer_size, frequency, bits_per_sample, channels; - alGetBufferi(buffer, AL_SIZE, &buffer_size ); - alGetBufferi(buffer, AL_FREQUENCY, &frequency ); - alGetBufferi(buffer, AL_CHANNELS, &channels ); - alGetBufferi(buffer, AL_BITS, &bits_per_sample); m_duration = float(buffer_size) / (frequency*channels*(bits_per_sample / 8)); }