aboutsummaryrefslogtreecommitdiffstats
path: root/Alc
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2019-06-30 12:00:10 -0700
committerChris Robinson <[email protected]>2019-06-30 16:40:08 -0700
commit51f53afe12719513b3736a1c73e7de98d7e301ca (patch)
tree00cb8385163adde88f41b21a322813e5cffec7db /Alc
parent689f70ce6d6b27ea2ccf7463e79dfefe5ce35899 (diff)
Use an optional for ConfigValueInt
Diffstat (limited to 'Alc')
-rw-r--r--Alc/alc.cpp33
-rw-r--r--Alc/alconfig.cpp7
-rw-r--r--Alc/alconfig.h3
-rw-r--r--Alc/backends/portaudio.cpp12
-rw-r--r--Alc/panning.cpp22
5 files changed, 38 insertions, 39 deletions
diff --git a/Alc/alc.cpp b/Alc/alc.cpp
index fb6e15e4..2863b4c7 100644
--- a/Alc/alc.cpp
+++ b/Alc/alc.cpp
@@ -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;
diff --git a/Alc/alconfig.cpp b/Alc/alconfig.cpp
index 710c790c..00643043 100644
--- a/Alc/alconfig.cpp
+++ b/Alc/alconfig.cpp
@@ -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)
diff --git a/Alc/alconfig.h b/Alc/alconfig.h
index 290172a8..e6977101 100644
--- a/Alc/alconfig.h
+++ b/Alc/alconfig.h
@@ -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);
diff --git a/Alc/backends/portaudio.cpp b/Alc/backends/portaudio.cpp
index 990fcbf6..5277f36b 100644
--- a/Alc/backends/portaudio.cpp
+++ b/Alc/backends/portaudio.cpp
@@ -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;
diff --git a/Alc/panning.cpp b/Alc/panning.cpp
index 41e827ef..864d7f28 100644
--- a/Alc/panning.cpp
+++ b/Alc/panning.cpp
@@ -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;