From 9eb209c214a3999547fc572a094e5cd300ed7ace Mon Sep 17 00:00:00 2001 From: LAGonauta Date: Fri, 16 Jun 2017 18:54:19 -0300 Subject: [PATCH] Removed redundant conversion to float when playing back stereo. --- Source/Core/AudioCommon/OpenALStream.cpp | 38 ++---------------------- Source/Core/AudioCommon/OpenALStream.h | 3 -- 2 files changed, 2 insertions(+), 39 deletions(-) diff --git a/Source/Core/AudioCommon/OpenALStream.cpp b/Source/Core/AudioCommon/OpenALStream.cpp index 8d9e9cc1c4..7693e5336f 100644 --- a/Source/Core/AudioCommon/OpenALStream.cpp +++ b/Source/Core/AudioCommon/OpenALStream.cpp @@ -259,7 +259,6 @@ void OpenALStream::SoundLoop() // Should we make these larger just in case the mixer ever sends more samples // than what we request? m_realtime_buffer.resize(frames_per_buffer * STEREO_CHANNELS); - m_sample_buffer.resize(frames_per_buffer * STEREO_CHANNELS); m_source = 0; // Clear error state before querying or else we get false positives. @@ -381,44 +380,11 @@ void OpenALStream::SoundLoop() { u32 rendered_frames = m_mixer->Mix(m_realtime_buffer.data(), min_frames); - // Convert the samples from short to float - for (u32 i = 0; i < rendered_frames * STEREO_CHANNELS; ++i) - m_sample_buffer[i] = static_cast(m_realtime_buffer[i]) / (1 << 15); - if (!rendered_frames) continue; - if (float32_capable) - { - palBufferData(m_buffers[next_buffer], AL_FORMAT_STEREO_FLOAT32, m_sample_buffer.data(), - rendered_frames * FRAME_STEREO_FLOAT, frequency); - - err = CheckALError("buffering float32 data"); - if (err == AL_INVALID_ENUM) - { - float32_capable = false; - } - } - else if (fixed32_capable) - { - // Clamping is not necessary here, samples are always between (-1,1) - int stereo_int32[OAL_MAX_FRAMES * STEREO_CHANNELS]; - for (u32 i = 0; i < rendered_frames * STEREO_CHANNELS; ++i) - stereo_int32[i] = (int)((float)m_sample_buffer[i] * (INT64_C(1) << 31)); - - palBufferData(m_buffers[next_buffer], AL_FORMAT_STEREO32, stereo_int32, - rendered_frames * FRAME_STEREO_INT32, frequency); - } - else - { - // Convert the samples from float to short - short stereo[OAL_MAX_FRAMES * STEREO_CHANNELS]; - for (u32 i = 0; i < rendered_frames * STEREO_CHANNELS; ++i) - stereo[i] = (short)((float)m_sample_buffer[i] * (1 << 15)); - - palBufferData(m_buffers[next_buffer], AL_FORMAT_STEREO16, stereo, - rendered_frames * FRAME_STEREO_SHORT, frequency); - } + palBufferData(m_buffers[next_buffer], AL_FORMAT_STEREO16, m_realtime_buffer.data(), + rendered_frames * FRAME_STEREO_SHORT, frequency); } palSourceQueueBuffers(m_source, 1, &m_buffers[next_buffer]); diff --git a/Source/Core/AudioCommon/OpenALStream.h b/Source/Core/AudioCommon/OpenALStream.h index f16fa2c8a2..3b9364c571 100644 --- a/Source/Core/AudioCommon/OpenALStream.h +++ b/Source/Core/AudioCommon/OpenALStream.h @@ -26,8 +26,6 @@ #define SIZE_INT32 4 #define SIZE_FLOAT 4 // size of a float in bytes #define FRAME_STEREO_SHORT STEREO_CHANNELS* SIZE_SHORT -#define FRAME_STEREO_FLOAT STEREO_CHANNELS* SIZE_FLOAT -#define FRAME_STEREO_INT32 STEREO_CHANNELS* SIZE_INT32 #define FRAME_SURROUND_FLOAT SURROUND_CHANNELS* SIZE_FLOAT #define FRAME_SURROUND_SHORT SURROUND_CHANNELS* SIZE_SHORT #define FRAME_SURROUND_INT32 SURROUND_CHANNELS* SIZE_INT32 @@ -73,7 +71,6 @@ private: Common::Event m_sound_sync_event; std::vector m_realtime_buffer; - std::vector m_sample_buffer; std::array m_buffers; ALuint m_source; ALfloat m_volume;