Removed redundant conversion to float when playing back stereo.
This commit is contained in:
parent
75af792070
commit
9eb209c214
|
@ -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<float>(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]);
|
||||
|
|
|
@ -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<short> m_realtime_buffer;
|
||||
std::vector<float> m_sample_buffer;
|
||||
std::array<ALuint, OAL_BUFFERS> m_buffers;
|
||||
ALuint m_source;
|
||||
ALfloat m_volume;
|
||||
|
|
Loading…
Reference in New Issue