From ce99f41240e00d85f2b89da7885a016631af617a Mon Sep 17 00:00:00 2001 From: LAGonauta Date: Fri, 11 Sep 2015 10:46:32 -0300 Subject: [PATCH 1/2] Added X-Fi check and now Surround FLOAT is converted to SHORT --- Source/Core/AudioCommon/OpenALStream.cpp | 43 +++++++++++++++++++++++++++++--- Source/Core/AudioCommon/OpenALStream.h | 2 ++ 2 files changed, 41 insertions(+), 4 deletions(-) diff --git a/Source/Core/AudioCommon/OpenALStream.cpp b/Source/Core/AudioCommon/OpenALStream.cpp index 66c7caf..add041b 100644 --- a/Source/Core/AudioCommon/OpenALStream.cpp +++ b/Source/Core/AudioCommon/OpenALStream.cpp @@ -146,18 +146,39 @@ void OpenALStream::SoundLoop() memset(uiBuffers, 0, numBuffers * sizeof(ALuint)); uiSource = 0; + // Checks if a X-Fi is being used. If it is, disable FLOAT32 support. + if (strstr(alGetString(AL_RENDERER), "X-Fi") != NULL) + { + float32_capable = false; + } + // Generate some AL Buffers for streaming alGenBuffers(numBuffers, (ALuint *)uiBuffers); // Generate a Source to playback the Buffers alGenSources(1, &uiSource); // Short Silence - memset(sampleBuffer, 0, OAL_MAX_SAMPLES * numBuffers * FRAME_SURROUND_FLOAT); + if (float32_capable) + { + memset(sampleBuffer, 0, OAL_MAX_SAMPLES * numBuffers * FRAME_SURROUND_FLOAT); + } + else + { + memset(sampleBuffer, 0, OAL_MAX_SAMPLES * numBuffers * FRAME_SURROUND_SHORT); + } memset(realtimeBuffer, 0, OAL_MAX_SAMPLES * FRAME_STEREO_SHORT); + for (int i = 0; i < numBuffers; i++) { if (surround_capable) - alBufferData(uiBuffers[i], AL_FORMAT_51CHN32, sampleBuffer, 4 * FRAME_SURROUND_FLOAT, ulFrequency); + if (float32_capable) + { + alBufferData(uiBuffers[i], AL_FORMAT_51CHN32, sampleBuffer, 4 * FRAME_SURROUND_FLOAT, ulFrequency); + } + else + { + alBufferData(uiBuffers[i], AL_FORMAT_51CHN16, sampleBuffer, 4 * FRAME_SURROUND_SHORT, ulFrequency); + } else alBufferData(uiBuffers[i], AL_FORMAT_STEREO16, realtimeBuffer, 4 * FRAME_STEREO_SHORT, ulFrequency); } @@ -252,15 +273,29 @@ void OpenALStream::SoundLoop() { float dpl2[OAL_MAX_SAMPLES * OAL_MAX_BUFFERS * SURROUND_CHANNELS]; DPL2Decode(sampleBuffer, nSamples, dpl2); + // zero-out the subwoofer channel - DPL2Decode generates a pretty // good 5.0 but not a good 5.1 output. Sadly there is not a 5.0 // AL_FORMAT_50CHN32 to make this super-explicit. // DPL2Decode output: LEFTFRONT, RIGHTFRONT, CENTREFRONT, (sub), LEFTREAR, RIGHTREAR for (u32 i = 0; i < nSamples; ++i) { - dpl2[i*SURROUND_CHANNELS + 3 /*sub/lfe*/] = 0.0f; + dpl2[i*SURROUND_CHANNELS + 3 /*sub/lfe*/] = 0.0; + } + + if (float32_capable) + { + alBufferData(uiBufferTemp[iBuffersFilled], AL_FORMAT_51CHN32, dpl2, nSamples * FRAME_SURROUND_FLOAT, ulFrequency); + } + else + { + short surround_short[OAL_MAX_SAMPLES * SURROUND_CHANNELS * OAL_MAX_BUFFERS]; + for (u32 i = 0; i < nSamples * SURROUND_CHANNELS; ++i) + surround_short[i] = (short)((float)dpl2[i] * (1 << 15)); + + alBufferData(uiBufferTemp[iBuffersFilled], AL_FORMAT_51CHN16, surround_short, nSamples * FRAME_SURROUND_SHORT, ulFrequency); } - alBufferData(uiBufferTemp[iBuffersFilled], AL_FORMAT_51CHN32, dpl2, nSamples * FRAME_SURROUND_FLOAT, ulFrequency); + ALenum err = alGetError(); if (err == AL_INVALID_ENUM) { diff --git a/Source/Core/AudioCommon/OpenALStream.h b/Source/Core/AudioCommon/OpenALStream.h index e961900..17302b8 100644 --- a/Source/Core/AudioCommon/OpenALStream.h +++ b/Source/Core/AudioCommon/OpenALStream.h @@ -47,9 +47,11 @@ #define SURROUND_CHANNELS 6 // number of channels in surround mode #define SIZE_SHORT 2 #define SIZE_FLOAT 4 // size of a float in bytes +#define SIZE_INT 4 #define FRAME_STEREO_SHORT STEREO_CHANNELS * SIZE_SHORT #define FRAME_STEREO_FLOAT STEREO_CHANNELS * SIZE_FLOAT #define FRAME_SURROUND_FLOAT SURROUND_CHANNELS * SIZE_FLOAT +#define FRAME_SURROUND_SHORT SURROUND_CHANNELS * SIZE_SHORT #endif class OpenALStream final : public SoundStream -- 2.5.2.windows.1