Skip to content

Commit

Permalink
Added backwards compatibility with old OpenAL drivers.
Browse files Browse the repository at this point in the history
  • Loading branch information
skidau committed Jan 15, 2013
1 parent e75a7b4 commit a9388ce
Showing 1 changed file with 30 additions and 10 deletions.
40 changes: 30 additions & 10 deletions Source/Core/AudioCommon/Src/OpenALStream.cpp
Expand Up @@ -184,6 +184,11 @@ void OpenALStream::SoundLoop()
soundTouch.setSetting(SETTING_OVERLAP_MS, 12);

bool surround_capable = Core::g_CoreStartupParameter.bDPL2Decoder;
#if defined(__APPLE__)
bool float32_capable = false;
#else
bool float32_capable = true;
#endif

while (!threadData)
{
Expand Down Expand Up @@ -270,18 +275,33 @@ void OpenALStream::SoundLoop()
#endif
if (!surround_capable)
{
#if defined(__APPLE__)
// Convert the samples from float to short
short stereo[OAL_MAX_SAMPLES * 2 * 2 * OAL_MAX_BUFFERS];
for (u32 i = 0; i < nSamples; ++i)
if (float32_capable)
{
stereo[i * 2 + 0] = (short)((float)sampleBuffer[i * 2 + 0] * (1 << 16));
stereo[i * 2 + 1] = (short)((float)sampleBuffer[i * 2 + 1] * (1 << 16));
alBufferData(uiBufferTemp[iBuffersFilled], AL_FORMAT_STEREO_FLOAT32, sampleBuffer, nSamples * 4 * 2, ulFrequency);
ALenum err = alGetError();
if (err == AL_INVALID_ENUM)
{
float32_capable = false;
}
else if (err != 0)
{
ERROR_LOG(AUDIO, "Error occurred while buffering float32 data: %08x", err);
}

}

if (!float32_capable)
{
// Convert the samples from float to short
short stereo[OAL_MAX_SAMPLES * 2 * 2 * OAL_MAX_BUFFERS];
for (u32 i = 0; i < nSamples; ++i)
{
stereo[i * 2 + 0] = (short)((float)sampleBuffer[i * 2 + 0] * (1 << 16));
stereo[i * 2 + 1] = (short)((float)sampleBuffer[i * 2 + 1] * (1 << 16));
}
alBufferData(uiBufferTemp[iBuffersFilled], AL_FORMAT_STEREO16, stereo, nSamples * 2 * 2, ulFrequency);

}
alBufferData(uiBufferTemp[iBuffersFilled], AL_FORMAT_STEREO16, stereo, nSamples * 2 * 2, ulFrequency);
#else
alBufferData(uiBufferTemp[iBuffersFilled], AL_FORMAT_STEREO_FLOAT32, sampleBuffer, nSamples * 4 * 2, ulFrequency);
#endif
}

alSourceQueueBuffers(uiSource, 1, &uiBufferTemp[iBuffersFilled]);
Expand Down

0 comments on commit a9388ce

Please sign in to comment.