Use an optional for ConfigValueInt

This commit is contained in:
Chris Robinson 2019-06-30 12:00:10 -07:00
parent 689f70ce6d
commit 51f53afe12
5 changed files with 38 additions and 39 deletions

View File

@ -1061,11 +1061,12 @@ void alc_initconfig(void)
FillCPUCaps(capfilter);
#ifdef _WIN32
RTPrioLevel = 1;
#define DEF_MIXER_PRIO 1
#else
RTPrioLevel = 0;
#define DEF_MIXER_PRIO 0
#endif
ConfigValueInt(nullptr, nullptr, "rt-prio", &RTPrioLevel);
RTPrioLevel = ConfigValueInt(nullptr, nullptr, "rt-prio").value_or(DEF_MIXER_PRIO);
#undef DEF_MIXER_PRIO
aluInit();
aluInitMixer();
@ -1864,10 +1865,10 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList)
if(numMono > INT_MAX-numStereo)
numMono = INT_MAX-numStereo;
numMono += numStereo;
if(ConfigValueInt(devname, nullptr, "sources", &numMono))
if(auto srcsopt = ConfigValueInt(devname, nullptr, "sources"))
{
if(numMono <= 0)
numMono = 256;
if(*srcsopt <= 0) numMono = 256;
else numMono = *srcsopt;
}
else
numMono = maxi(numMono, 256);
@ -1878,8 +1879,8 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList)
device->NumMonoSources = numMono;
device->NumStereoSources = numStereo;
if(ConfigValueInt(devname, nullptr, "sends", &new_sends))
new_sends = mini(numSends, clampi(new_sends, 0, MAX_SENDS));
if(auto sendsopt = ConfigValueInt(devname, nullptr, "sends"))
new_sends = mini(numSends, clampi(*sendsopt, 0, MAX_SENDS));
else
new_sends = numSends;
}
@ -2075,8 +2076,8 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList)
if(GetConfigValueBool(device->DeviceName.c_str(), nullptr, "dither", 1))
{
ALint depth = 0;
ConfigValueInt(device->DeviceName.c_str(), nullptr, "dither-depth", &depth);
ALint depth{
ConfigValueInt(device->DeviceName.c_str(), nullptr, "dither-depth").value_or(0)};
if(depth <= 0)
{
switch(device->FmtType)
@ -3834,10 +3835,8 @@ START_API_FUNC
if(device->AuxiliaryEffectSlotMax == 0) device->AuxiliaryEffectSlotMax = 64;
else device->AuxiliaryEffectSlotMax = minu(device->AuxiliaryEffectSlotMax, INT_MAX);
if(ConfigValueInt(deviceName, nullptr, "sends", &device->NumAuxSends))
device->NumAuxSends = clampi(
DEFAULT_SENDS, 0, clampi(device->NumAuxSends, 0, MAX_SENDS)
);
if(auto sendsopt = ConfigValueInt(deviceName, nullptr, "sends"))
device->NumAuxSends = clampi(DEFAULT_SENDS, 0, clampi(*sendsopt, 0, MAX_SENDS));
device->NumStereoSources = 1;
device->NumMonoSources = device->SourcesMax - device->NumStereoSources;
@ -4141,10 +4140,8 @@ START_API_FUNC
if(device->AuxiliaryEffectSlotMax == 0) device->AuxiliaryEffectSlotMax = 64;
else device->AuxiliaryEffectSlotMax = minu(device->AuxiliaryEffectSlotMax, INT_MAX);
if(ConfigValueInt(nullptr, nullptr, "sends", &device->NumAuxSends))
device->NumAuxSends = clampi(
DEFAULT_SENDS, 0, clampi(device->NumAuxSends, 0, MAX_SENDS)
);
if(auto sendsopt = ConfigValueInt(nullptr, nullptr, "sends"))
device->NumAuxSends = clampi(DEFAULT_SENDS, 0, clampi(*sendsopt, 0, MAX_SENDS));
device->NumStereoSources = 1;
device->NumMonoSources = device->SourcesMax - device->NumStereoSources;

View File

@ -501,13 +501,12 @@ int ConfigValueStr(const char *devName, const char *blockName, const char *keyNa
return 1;
}
int ConfigValueInt(const char *devName, const char *blockName, const char *keyName, int *ret)
al::optional<int> ConfigValueInt(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::strtol(val, nullptr, 0);
return 1;
return al::optional<int>{al::in_place, static_cast<int>(std::strtol(val, nullptr, 0))};
}
int ConfigValueUInt(const char *devName, const char *blockName, const char *keyName, unsigned int *ret)

View File

@ -1,6 +1,7 @@
#ifndef ALCONFIG_H
#define ALCONFIG_H
#include "aloptional.h"
void ReadALConfig();
@ -9,7 +10,7 @@ const char *GetConfigValue(const char *devName, const char *blockName, const cha
int GetConfigValueBool(const char *devName, const char *blockName, const char *keyName, int def);
int ConfigValueStr(const char *devName, const char *blockName, const char *keyName, const char **ret);
int ConfigValueInt(const char *devName, const char *blockName, const char *keyName, int *ret);
al::optional<int> ConfigValueInt(const char *devName, const char *blockName, const char *keyName);
int ConfigValueUInt(const char *devName, const char *blockName, const char *keyName, unsigned int *ret);
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);

View File

@ -129,9 +129,9 @@ ALCenum PortPlayback::open(const ALCchar *name)
mUpdateSize = mDevice->UpdateSize;
mParams.device = -1;
if(!ConfigValueInt(nullptr, "port", "device", &mParams.device) || mParams.device < 0)
mParams.device = Pa_GetDefaultOutputDevice();
auto devidopt = ConfigValueInt(nullptr, "port", "device");
if(devidopt && *devidopt >= 0) mParams.device = *devidopt;
else mParams.device = Pa_GetDefaultOutputDevice();
mParams.suggestedLatency = mDevice->BufferSize / static_cast<double>(mDevice->Frequency);
mParams.hostApiSpecificStreamInfo = nullptr;
@ -298,9 +298,9 @@ ALCenum PortCapture::open(const ALCchar *name)
mRing = CreateRingBuffer(samples, frame_size, false);
if(!mRing) return ALC_INVALID_VALUE;
mParams.device = -1;
if(!ConfigValueInt(nullptr, "port", "capture", &mParams.device) || mParams.device < 0)
mParams.device = Pa_GetDefaultInputDevice();
auto devidopt = ConfigValueInt(nullptr, "port", "capture");
if(devidopt && *devidopt >= 0) mParams.device = *devidopt;
else mParams.device = Pa_GetDefaultOutputDevice();
mParams.suggestedLatency = 0.0f;
mParams.hostApiSpecificStreamInfo = nullptr;

View File

@ -900,18 +900,20 @@ no_hrtf:
device->mRenderMode = StereoPair;
int bs2blevel{((headphones && hrtf_appreq != Hrtf_Disable) ||
(hrtf_appreq == Hrtf_Enable)) ? 5 : 0};
if(device->Type != Loopback)
ConfigValueInt(device->DeviceName.c_str(), nullptr, "cf_level", &bs2blevel);
if(bs2blevel > 0 && bs2blevel <= 6)
{
device->Bs2b = al::make_unique<bs2b>();
bs2b_set_params(device->Bs2b.get(), bs2blevel, device->Frequency);
TRACE("BS2B enabled\n");
InitPanning(device);
device->PostProcess = ProcessBs2b;
return;
if(auto cflevopt = ConfigValueInt(device->DeviceName.c_str(), nullptr, "cf_level"))
{
if(*cflevopt > 0 && *cflevopt <= 6)
{
device->Bs2b = al::make_unique<bs2b>();
bs2b_set_params(device->Bs2b.get(), *cflevopt, device->Frequency);
TRACE("BS2B enabled\n");
InitPanning(device);
device->PostProcess = ProcessBs2b;
return;
}
}
}
const char *mode;