diff options
author | Chris Robinson <[email protected]> | 2019-06-30 16:38:25 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2019-06-30 16:40:08 -0700 |
commit | 49ceae681b4889ed9500fa9c15b21cca7eb08fc3 (patch) | |
tree | eaa687c2c2bfa116c25b220512adbcc8da324f93 | |
parent | 3658dafdcbbd114caaf81cb27cf6ccc07045b0aa (diff) |
Return optionals from the remaining ConfigValue* methods
-rw-r--r-- | Alc/alc.cpp | 17 | ||||
-rw-r--r-- | Alc/alconfig.cpp | 17 | ||||
-rw-r--r-- | Alc/alconfig.h | 4 | ||||
-rw-r--r-- | Alc/panning.cpp | 8 |
4 files changed, 23 insertions, 23 deletions
diff --git a/Alc/alc.cpp b/Alc/alc.cpp index 7cf28ed3..014998bc 100644 --- a/Alc/alc.cpp +++ b/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); diff --git a/Alc/alconfig.cpp b/Alc/alconfig.cpp index c5abd6ab..36aac48d 100644 --- a/Alc/alconfig.cpp +++ b/Alc/alconfig.cpp @@ -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) diff --git a/Alc/alconfig.h b/Alc/alconfig.h index 9b1c09aa..ffc7adad 100644 --- a/Alc/alconfig.h +++ b/Alc/alconfig.h @@ -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 */ diff --git a/Alc/panning.cpp b/Alc/panning.cpp index aa290821..0a3e89fc 100644 --- a/Alc/panning.cpp +++ b/Alc/panning.cpp @@ -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; |