Merge pull request #5187 from ligfx/fixopenalmac

Fix OpenAL backend on macOS
This commit is contained in:
shuffle2 2017-06-06 15:33:56 -07:00 committed by GitHub
commit 8c59775772
2 changed files with 28 additions and 27 deletions

View File

@ -155,17 +155,23 @@ static ALenum CheckALError(const char* desc)
return err; return err;
} }
static bool IsCreativeXFi()
{
return strstr(alGetString(AL_RENDERER), "X-Fi") != nullptr;
}
void OpenALStream::SoundLoop() void OpenALStream::SoundLoop()
{ {
Common::SetCurrentThreadName("Audio thread - openal"); Common::SetCurrentThreadName("Audio thread - openal");
bool surround_capable = SConfig::GetInstance().bDPL2Decoder; bool float32_capable = alIsExtensionPresent("AL_EXT_float32") != 0;
bool float32_capable = false; bool surround_capable = alIsExtensionPresent("AL_EXT_MCFORMATS") || IsCreativeXFi();
bool fixed32_capable = false; bool use_surround = SConfig::GetInstance().bDPL2Decoder && surround_capable;
#if defined(__APPLE__) // As there is no extension to check for 32-bit fixed point support
surround_capable = false; // and we know that only a X-Fi with hardware OpenAL supports it,
#endif // we just check if one is being used.
bool fixed32_capable = IsCreativeXFi();
u32 ulFrequency = m_mixer->GetSampleRate(); u32 ulFrequency = m_mixer->GetSampleRate();
numBuffers = SConfig::GetInstance().iLatency + 2; // OpenAL requires a minimum of two buffers numBuffers = SConfig::GetInstance().iLatency + 2; // OpenAL requires a minimum of two buffers
@ -173,15 +179,6 @@ void OpenALStream::SoundLoop()
memset(uiBuffers, 0, numBuffers * sizeof(ALuint)); memset(uiBuffers, 0, numBuffers * sizeof(ALuint));
uiSource = 0; uiSource = 0;
if (alIsExtensionPresent("AL_EXT_float32"))
float32_capable = true;
// As there is no extension to check for 32-bit fixed point support
// and we know that only a X-Fi with hardware OpenAL supports it,
// we just check if one is being used.
if (strstr(alGetString(AL_RENDERER), "X-Fi"))
fixed32_capable = true;
// Clear error state before querying or else we get false positives. // Clear error state before querying or else we get false positives.
ALenum err = alGetError(); ALenum err = alGetError();
@ -226,7 +223,7 @@ void OpenALStream::SoundLoop()
unsigned int numSamples = OAL_MAX_SAMPLES; unsigned int numSamples = OAL_MAX_SAMPLES;
if (surround_capable) if (use_surround)
{ {
// DPL2 accepts 240 samples minimum (FWRDURATION) // DPL2 accepts 240 samples minimum (FWRDURATION)
unsigned int minSamples = 240; unsigned int minSamples = 240;
@ -297,7 +294,7 @@ void OpenALStream::SoundLoop()
// 5.1 is not supported by the host, fallback to stereo // 5.1 is not supported by the host, fallback to stereo
WARN_LOG(AUDIO, WARN_LOG(AUDIO,
"Unable to set 5.1 surround mode. Updating OpenAL Soft might fix this issue."); "Unable to set 5.1 surround mode. Updating OpenAL Soft might fix this issue.");
surround_capable = false; use_surround = false;
} }
} }
else else

View File

@ -42,19 +42,23 @@
#define FRAME_SURROUND_INT32 SURROUND_CHANNELS* SIZE_INT32 #define FRAME_SURROUND_INT32 SURROUND_CHANNELS* SIZE_INT32
#endif #endif
#if defined(__APPLE__) // From AL_EXT_float32
// OS X does not have the alext AL_FORMAT_STEREO_FLOAT32, AL_FORMAT_STEREO32, #ifndef AL_FORMAT_STEREO_FLOAT32
// AL_FORMAT_51CHN32 and AL_FORMAT_51CHN16 yet. #define AL_FORMAT_STEREO_FLOAT32 0x10011
#define AL_FORMAT_STEREO_FLOAT32 0 #endif
#define AL_FORMAT_STEREO32 0
#define AL_FORMAT_51CHN32 0 // From AL_EXT_MCFORMATS
#define AL_FORMAT_51CHN16 0 #ifndef AL_FORMAT_51CHN16
#elif defined(_WIN32) #define AL_FORMAT_51CHN16 0x120B
#endif
#ifndef AL_FORMAT_51CHN32
#define AL_FORMAT_51CHN32 0x120C
#endif
// Only X-Fi on Windows supports the alext AL_FORMAT_STEREO32 alext for now, // Only X-Fi on Windows supports the alext AL_FORMAT_STEREO32 alext for now,
// but it is not documented or in "OpenAL/include/al.h". // but it is not documented or in "OpenAL/include/al.h".
#ifndef AL_FORMAT_STEREO32
#define AL_FORMAT_STEREO32 0x1203 #define AL_FORMAT_STEREO32 0x1203
#else
#define AL_FORMAT_STEREO32 0
#endif #endif
class OpenALStream final : public SoundStream class OpenALStream final : public SoundStream