Skip to content

Commit

Permalink
Removed redundant conversion to float when playing back stereo.
Browse files Browse the repository at this point in the history
  • Loading branch information
LAGonauta committed Jun 18, 2017
1 parent 02127c9 commit 881ec9b
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 39 deletions.
38 changes: 2 additions & 36 deletions Source/Core/AudioCommon/OpenALStream.cpp
Expand Up @@ -203,7 +203,6 @@ void OpenALStream::SoundLoop()
// Should we make these larger just in case the mixer ever sends more samples
// than what we request?
realtime_buffer.resize(frames_per_buffer * STEREO_CHANNELS);
sample_buffer.resize(frames_per_buffer * STEREO_CHANNELS);
source = 0;

// Clear error state before querying or else we get false positives.
Expand Down Expand Up @@ -325,44 +324,11 @@ void OpenALStream::SoundLoop()
{
u32 rendered_frames = m_mixer->Mix(realtime_buffer.data(), min_frames);

// Convert the samples from short to float
for (u32 i = 0; i < rendered_frames * STEREO_CHANNELS; ++i)
sample_buffer[i] = static_cast<float>(realtime_buffer[i]) / (1 << 15);

if (!rendered_frames)
continue;

if (float32_capable)
{
alBufferData(buffers[next_buffer], AL_FORMAT_STEREO_FLOAT32, 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)sample_buffer[i] * (INT64_C(1) << 31));

alBufferData(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)sample_buffer[i] * (1 << 15));

alBufferData(buffers[next_buffer], AL_FORMAT_STEREO16, stereo,
rendered_frames * FRAME_STEREO_SHORT, frequency);
}
alBufferData(buffers[next_buffer], AL_FORMAT_STEREO16, realtime_buffer.data(),
rendered_frames * FRAME_STEREO_SHORT, frequency);
}

alSourceQueueBuffers(source, 1, &buffers[next_buffer]);
Expand Down
3 changes: 0 additions & 3 deletions Source/Core/AudioCommon/OpenALStream.h
Expand Up @@ -35,8 +35,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
Expand Down Expand Up @@ -81,7 +79,6 @@ class OpenALStream final : public SoundStream
Common::Event sound_sync_event;

std::vector<short> realtime_buffer;
std::vector<float> sample_buffer;
std::array<ALuint, OAL_BUFFERS> buffers;
ALuint source;
ALfloat m_volume;
Expand Down

0 comments on commit 881ec9b

Please sign in to comment.