1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-26 18:35:20 +00:00

Use a loop to find the OpenAL format from the decoder format

This commit is contained in:
Chris Robinson 2012-03-19 00:49:52 -07:00
parent 6a256d3993
commit e234b90173

View File

@ -25,26 +25,24 @@ static void throwALerror()
static ALenum getALFormat(ChannelConfig chans, SampleType type)
{
if(chans == ChannelConfig_Mono)
static const struct {
ALenum format;
ChannelConfig chans;
SampleType type;
} fmtlist[] = {
{ AL_FORMAT_MONO16, ChannelConfig_Mono, SampleType_Int16 },
{ AL_FORMAT_MONO8, ChannelConfig_Mono, SampleType_UInt8 },
{ AL_FORMAT_STEREO16, ChannelConfig_Stereo, SampleType_Int16 },
{ AL_FORMAT_STEREO8, ChannelConfig_Stereo, SampleType_UInt8 },
};
static const size_t fmtlistsize = sizeof(fmtlist)/sizeof(fmtlist[0]);
for(size_t i = 0;i < fmtlistsize;i++)
{
if(type == SampleType_Int16)
return AL_FORMAT_MONO16;
else if(type == SampleType_UInt8)
return AL_FORMAT_MONO8;
else
fail("Unsupported sample type");
if(fmtlist[i].chans == chans && fmtlist[i].type == type)
return fmtlist[i].format;
}
else if(chans == ChannelConfig_Stereo)
{
if(type == SampleType_Int16)
return AL_FORMAT_STEREO16;
else if(type == SampleType_UInt8)
return AL_FORMAT_STEREO8;
else
fail("Unsupported sample type");
}
else
fail("Unsupported channel config");
fail("Unsupported sound format");
return AL_NONE;
}