Handle inability of OpenAL implementation to return number of available sources

OpenAL specification doesn't require alcGetIntegerv() to return meaningful values for ALC_MONO_SOURCES and ALC_MONO_SOURCES.
At least Apple's OpenAL implementation returns zeroes, although it can generate reasonable number of sources.
This commit is contained in:
alexey.lysiuk 2016-02-13 11:09:37 +02:00
parent 01bed05275
commit ce8b2974a3
1 changed files with 14 additions and 1 deletions

View File

@ -781,7 +781,20 @@ OpenALSoundRenderer::OpenALSoundRenderer()
alcGetIntegerv(Device, ALC_MONO_SOURCES, 1, &numMono);
alcGetIntegerv(Device, ALC_STEREO_SOURCES, 1, &numStereo);
Sources.Resize(MIN<int>(MAX<int>(*snd_channels, 2), numMono+numStereo));
// OpenAL specification doesn't require alcGetIntegerv() to return
// meaningful values for ALC_MONO_SOURCES and ALC_MONO_SOURCES.
// At least Apple's OpenAL implementation returns zeroes,
// although it can generate reasonable number of sources.
const int numChannels = MAX<int>(*snd_channels, 2);
int numSources = numMono + numStereo;
if (0 == numSources)
{
numSources = numChannels;
}
Sources.Resize(MIN<int>(numChannels, numSources));
for(size_t i = 0;i < Sources.Size();i++)
{
alGenSources(1, &Sources[i]);