mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-02-04 03:40:14 +00:00
Replace a few more explicit loops
This commit is contained in:
parent
1e123a22e1
commit
0c1ad7c74e
@ -1,9 +1,10 @@
|
||||
#include <algorithm>
|
||||
#include <stdexcept>
|
||||
#include <iostream>
|
||||
#include <cstring>
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
#include <cstring>
|
||||
#include <array>
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
@ -174,95 +175,92 @@ namespace MWSound
|
||||
|
||||
static ALenum getALFormat(ChannelConfig chans, SampleType type)
|
||||
{
|
||||
static const struct {
|
||||
struct FormatEntry {
|
||||
ALenum format;
|
||||
ChannelConfig chans;
|
||||
SampleType type;
|
||||
} fmtlist[] = {
|
||||
};
|
||||
struct FormatEntryExt {
|
||||
const char name[32];
|
||||
ChannelConfig chans;
|
||||
SampleType type;
|
||||
};
|
||||
static const std::array<FormatEntry,4> 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(fmtlist[i].chans == chans && fmtlist[i].type == type)
|
||||
return fmtlist[i].format;
|
||||
}
|
||||
auto fmt = std::find_if(fmtlist.cbegin(), fmtlist.cend(),
|
||||
[chans,type](const FormatEntry &fmt) -> bool
|
||||
{ return fmt.chans == chans && fmt.type == type; }
|
||||
);
|
||||
if(fmt != fmtlist.cend())
|
||||
return fmt->format;
|
||||
|
||||
if(alIsExtensionPresent("AL_EXT_MCFORMATS"))
|
||||
{
|
||||
static const struct {
|
||||
char name[32];
|
||||
ChannelConfig chans;
|
||||
SampleType type;
|
||||
} mcfmtlist[] = {
|
||||
static const std::array<FormatEntryExt,6> mcfmtlist{{
|
||||
{ "AL_FORMAT_QUAD16", ChannelConfig_Quad, SampleType_Int16 },
|
||||
{ "AL_FORMAT_QUAD8", ChannelConfig_Quad, SampleType_UInt8 },
|
||||
{ "AL_FORMAT_51CHN16", ChannelConfig_5point1, SampleType_Int16 },
|
||||
{ "AL_FORMAT_51CHN8", ChannelConfig_5point1, SampleType_UInt8 },
|
||||
{ "AL_FORMAT_71CHN16", ChannelConfig_7point1, SampleType_Int16 },
|
||||
{ "AL_FORMAT_71CHN8", ChannelConfig_7point1, SampleType_UInt8 },
|
||||
};
|
||||
static const size_t mcfmtlistsize = sizeof(mcfmtlist)/sizeof(mcfmtlist[0]);
|
||||
}};
|
||||
ALenum format = AL_NONE;
|
||||
|
||||
for(size_t i = 0;i < mcfmtlistsize;i++)
|
||||
std::find_if(mcfmtlist.cbegin(), mcfmtlist.cend(),
|
||||
[&format,chans,type](const FormatEntryExt &fmt) -> bool
|
||||
{
|
||||
if(mcfmtlist[i].chans == chans && mcfmtlist[i].type == type)
|
||||
{
|
||||
ALenum format = alGetEnumValue(mcfmtlist[i].name);
|
||||
if(fmt.chans == chans && fmt.type == type)
|
||||
format = alGetEnumValue(fmt.name);
|
||||
return format != 0 && format != -1;
|
||||
}
|
||||
);
|
||||
if(format != 0 && format != -1)
|
||||
return format;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(alIsExtensionPresent("AL_EXT_FLOAT32"))
|
||||
{
|
||||
static const struct {
|
||||
char name[32];
|
||||
ChannelConfig chans;
|
||||
SampleType type;
|
||||
} fltfmtlist[] = {
|
||||
static const std::array<FormatEntryExt,2> fltfmtlist{{
|
||||
{ "AL_FORMAT_MONO_FLOAT32", ChannelConfig_Mono, SampleType_Float32 },
|
||||
{ "AL_FORMAT_STEREO_FLOAT32", ChannelConfig_Stereo, SampleType_Float32 },
|
||||
};
|
||||
static const size_t fltfmtlistsize = sizeof(fltfmtlist)/sizeof(fltfmtlist[0]);
|
||||
}};
|
||||
ALenum format = AL_NONE;
|
||||
|
||||
for(size_t i = 0;i < fltfmtlistsize;i++)
|
||||
std::find_if(fltfmtlist.cbegin(), fltfmtlist.cend(),
|
||||
[&format,chans,type](const FormatEntryExt &fmt) -> bool
|
||||
{
|
||||
if(fltfmtlist[i].chans == chans && fltfmtlist[i].type == type)
|
||||
{
|
||||
ALenum format = alGetEnumValue(fltfmtlist[i].name);
|
||||
if(fmt.chans == chans && fmt.type == type)
|
||||
format = alGetEnumValue(fmt.name);
|
||||
return format != 0 && format != -1;
|
||||
}
|
||||
);
|
||||
if(format != 0 && format != -1)
|
||||
return format;
|
||||
}
|
||||
}
|
||||
|
||||
if(alIsExtensionPresent("AL_EXT_MCFORMATS"))
|
||||
{
|
||||
static const struct {
|
||||
char name[32];
|
||||
ChannelConfig chans;
|
||||
SampleType type;
|
||||
} fltmcfmtlist[] = {
|
||||
static const std::array<FormatEntryExt,3> fltmcfmtlist{{
|
||||
{ "AL_FORMAT_QUAD32", ChannelConfig_Quad, SampleType_Float32 },
|
||||
{ "AL_FORMAT_51CHN32", ChannelConfig_5point1, SampleType_Float32 },
|
||||
{ "AL_FORMAT_71CHN32", ChannelConfig_7point1, SampleType_Float32 },
|
||||
};
|
||||
static const size_t fltmcfmtlistsize = sizeof(fltmcfmtlist)/sizeof(fltmcfmtlist[0]);
|
||||
}};
|
||||
|
||||
for(size_t i = 0;i < fltmcfmtlistsize;i++)
|
||||
std::find_if(fltmcfmtlist.cbegin(), fltmcfmtlist.cend(),
|
||||
[&format,chans,type](const FormatEntryExt &fmt) -> bool
|
||||
{
|
||||
if(fltmcfmtlist[i].chans == chans && fltmcfmtlist[i].type == type)
|
||||
{
|
||||
ALenum format = alGetEnumValue(fltmcfmtlist[i].name);
|
||||
if(fmt.chans == chans && fmt.type == type)
|
||||
format = alGetEnumValue(fmt.name);
|
||||
return format != 0 && format != -1;
|
||||
}
|
||||
);
|
||||
if(format != 0 && format != -1)
|
||||
return format;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::cerr<< "Unsupported sound format ("<<getChannelConfigName(chans)<<", "<<
|
||||
getSampleTypeName(type)<<")" <<std::endl;
|
||||
|
Loading…
x
Reference in New Issue
Block a user