Return optionals from the remaining ConfigValue* methods
This commit is contained in:
parent
3658dafdcb
commit
49ceae681b
17
Alc/alc.cpp
17
Alc/alc.cpp
@ -1091,9 +1091,11 @@ void alc_initconfig(void)
|
||||
TrapALCError = !!GetConfigValueBool(nullptr, nullptr, "trap-alc-error", TrapALCError);
|
||||
}
|
||||
|
||||
float valf{};
|
||||
if(ConfigValueFloat(nullptr, "reverb", "boost", &valf))
|
||||
if(auto boostopt = ConfigValueFloat(nullptr, "reverb", "boost"))
|
||||
{
|
||||
const float valf{std::isfinite(*boostopt) ? clampf(*boostopt, -24.0f, 24.0f) : 0.0f};
|
||||
ReverbBoost *= std::pow(10.0f, valf / 20.0f);
|
||||
}
|
||||
|
||||
auto devopt = ConfigValueStr(nullptr, nullptr, "drivers");
|
||||
if(const char *devs{getenv("ALSOFT_DRIVERS")})
|
||||
@ -1675,7 +1677,6 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList)
|
||||
ALboolean update_failed;
|
||||
ALCsizei hrtf_id = -1;
|
||||
ALCuint oldFreq;
|
||||
int val;
|
||||
|
||||
if((!attrList || !attrList[0]) && device->Type == Loopback)
|
||||
{
|
||||
@ -2116,8 +2117,8 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList)
|
||||
device->DitherDepth);
|
||||
|
||||
device->LimiterState = gainLimiter;
|
||||
if(ConfigValueBool(device->DeviceName.c_str(), nullptr, "output-limiter", &val))
|
||||
gainLimiter = val ? ALC_TRUE : ALC_FALSE;
|
||||
if(auto limopt = ConfigValueBool(device->DeviceName.c_str(), nullptr, "output-limiter"))
|
||||
gainLimiter = *limopt ? ALC_TRUE : ALC_FALSE;
|
||||
|
||||
/* Valid values for gainLimiter are ALC_DONT_CARE_SOFT, ALC_TRUE, and
|
||||
* ALC_FALSE. For ALC_DONT_CARE_SOFT, use the limiter for integer-based
|
||||
@ -3487,14 +3488,14 @@ START_API_FUNC
|
||||
|
||||
InitContext(context.get());
|
||||
|
||||
ALfloat valf{};
|
||||
if(ConfigValueFloat(dev->DeviceName.c_str(), nullptr, "volume-adjust", &valf))
|
||||
if(auto volopt = ConfigValueFloat(dev->DeviceName.c_str(), nullptr, "volume-adjust"))
|
||||
{
|
||||
const ALfloat valf{*volopt};
|
||||
if(!std::isfinite(valf))
|
||||
ERR("volume-adjust must be finite: %f\n", valf);
|
||||
else
|
||||
{
|
||||
ALfloat db = clampf(valf, -24.0f, 24.0f);
|
||||
const ALfloat db{clampf(valf, -24.0f, 24.0f)};
|
||||
if(db != valf)
|
||||
WARN("volume-adjust clamped: %f, range: +/-%f\n", valf, 24.0f);
|
||||
context->GainBoost = std::pow(10.0f, db/20.0f);
|
||||
|
@ -517,23 +517,22 @@ al::optional<unsigned int> ConfigValueUInt(const char *devName, const char *bloc
|
||||
static_cast<unsigned int>(std::strtoul(val, nullptr, 0))};
|
||||
}
|
||||
|
||||
int ConfigValueFloat(const char *devName, const char *blockName, const char *keyName, float *ret)
|
||||
al::optional<float> ConfigValueFloat(const char *devName, const char *blockName, const char *keyName)
|
||||
{
|
||||
const char *val = GetConfigValue(devName, blockName, keyName, "");
|
||||
if(!val[0]) return 0;
|
||||
if(!val[0]) return al::nullopt;
|
||||
|
||||
*ret = std::strtof(val, nullptr);
|
||||
return 1;
|
||||
return al::optional<float>{al::in_place, std::strtof(val, nullptr)};
|
||||
}
|
||||
|
||||
int ConfigValueBool(const char *devName, const char *blockName, const char *keyName, int *ret)
|
||||
al::optional<bool> ConfigValueBool(const char *devName, const char *blockName, const char *keyName)
|
||||
{
|
||||
const char *val = GetConfigValue(devName, blockName, keyName, "");
|
||||
if(!val[0]) return 0;
|
||||
if(!val[0]) return al::nullopt;
|
||||
|
||||
*ret = (strcasecmp(val, "true") == 0 || strcasecmp(val, "yes") == 0 ||
|
||||
strcasecmp(val, "on") == 0 || atoi(val) != 0);
|
||||
return 1;
|
||||
return al::optional<bool>{al::in_place,
|
||||
strcasecmp(val, "true") == 0 || strcasecmp(val, "yes") == 0 ||
|
||||
strcasecmp(val, "on") == 0 || atoi(val) != 0};
|
||||
}
|
||||
|
||||
int GetConfigValueBool(const char *devName, const char *blockName, const char *keyName, int def)
|
||||
|
@ -14,7 +14,7 @@ int GetConfigValueBool(const char *devName, const char *blockName, const char *k
|
||||
al::optional<std::string> ConfigValueStr(const char *devName, const char *blockName, const char *keyName);
|
||||
al::optional<int> ConfigValueInt(const char *devName, const char *blockName, const char *keyName);
|
||||
al::optional<unsigned int> ConfigValueUInt(const char *devName, const char *blockName, const char *keyName);
|
||||
int ConfigValueFloat(const char *devName, const char *blockName, const char *keyName, float *ret);
|
||||
int ConfigValueBool(const char *devName, const char *blockName, const char *keyName, int *ret);
|
||||
al::optional<float> ConfigValueFloat(const char *devName, const char *blockName, const char *keyName);
|
||||
al::optional<bool> ConfigValueBool(const char *devName, const char *blockName, const char *keyName);
|
||||
|
||||
#endif /* ALCONFIG_H */
|
||||
|
@ -382,13 +382,13 @@ void InitPanning(ALCdevice *device)
|
||||
);
|
||||
device->Dry.NumChannels = static_cast<ALuint>(count);
|
||||
|
||||
ALfloat nfc_delay{0.0f};
|
||||
if(ConfigValueFloat(devname, "decoder", "nfc-ref-delay", &nfc_delay) && nfc_delay > 0.0f)
|
||||
ALfloat nfc_delay{ConfigValueFloat(devname, "decoder", "nfc-ref-delay").value_or(0.0f)};
|
||||
if(nfc_delay > 0.0f)
|
||||
{
|
||||
static constexpr ALuint chans_per_order[MAX_AMBI_ORDER+1]{ 1, 3, 5, 7 };
|
||||
nfc_delay = clampf(nfc_delay, 0.001f, 1000.0f);
|
||||
InitNearFieldCtrl(device, nfc_delay * SPEEDOFSOUNDMETRESPERSEC,
|
||||
device->mAmbiOrder, chans_per_order);
|
||||
InitNearFieldCtrl(device, nfc_delay * SPEEDOFSOUNDMETRESPERSEC, device->mAmbiOrder,
|
||||
chans_per_order);
|
||||
}
|
||||
|
||||
device->RealOut.NumChannels = 0;
|
||||
|
Loading…
x
Reference in New Issue
Block a user