aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Alc/alc.cpp51
-rw-r--r--Alc/alconfig.cpp8
-rw-r--r--Alc/alconfig.h2
-rw-r--r--Alc/backends/jack.cpp12
4 files changed, 39 insertions, 34 deletions
diff --git a/Alc/alc.cpp b/Alc/alc.cpp
index 2863b4c7..ec9953fe 100644
--- a/Alc/alc.cpp
+++ b/Alc/alc.cpp
@@ -1824,7 +1824,7 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList)
device->UpdateSize = DEFAULT_UPDATE_SIZE;
device->Frequency = DEFAULT_OUTPUT_RATE;
- ConfigValueUInt(devname, nullptr, "frequency", &freq);
+ freq = ConfigValueUInt(devname, nullptr, "frequency").value_or(freq);
if(freq < 1)
device->Flags.unset<FrequencyRequest>();
else
@@ -1840,12 +1840,11 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList)
device->Flags.set<FrequencyRequest>();
}
- ConfigValueUInt(devname, nullptr, "period_size", &device->UpdateSize);
- device->UpdateSize = clampu(device->UpdateSize, 64, 8192);
+ if(auto persizeopt = ConfigValueUInt(devname, nullptr, "period_size"))
+ device->UpdateSize = clampu(*persizeopt, 64, 8192);
- ALuint periods{};
- if(ConfigValueUInt(devname, nullptr, "periods", &periods))
- device->BufferSize = device->UpdateSize * clampu(periods, 2, 16);
+ if(auto peropt = ConfigValueUInt(devname, nullptr, "periods"))
+ device->BufferSize = device->UpdateSize * clampu(*peropt, 2, 16);
else
device->BufferSize = maxu(device->BufferSize, device->UpdateSize*2);
}
@@ -3805,8 +3804,7 @@ START_API_FUNC
}
}
- ALuint freq{};
- if(ConfigValueUInt(deviceName, nullptr, "frequency", &freq) && freq > 0)
+ if(ALuint freq{ConfigValueUInt(deviceName, nullptr, "frequency").value_or(0)})
{
if(freq < MIN_OUTPUT_RATE)
{
@@ -3819,21 +3817,24 @@ START_API_FUNC
device->Flags.set<FrequencyRequest>();
}
- ConfigValueUInt(deviceName, nullptr, "period_size", &device->UpdateSize);
- device->UpdateSize = clampu(device->UpdateSize, 64, 8192);
+ if(auto persizeopt = ConfigValueUInt(deviceName, nullptr, "period_size"))
+ device->UpdateSize = clampu(*persizeopt, 64, 8192);
- ALuint periods{};
- if(ConfigValueUInt(deviceName, nullptr, "periods", &periods))
- device->BufferSize = device->UpdateSize * clampu(periods, 2, 16);
+ if(auto peropt = ConfigValueUInt(deviceName, nullptr, "periods"))
+ device->BufferSize = device->UpdateSize * clampu(*peropt, 2, 16);
else
device->BufferSize = maxu(device->BufferSize, device->UpdateSize*2);
- ConfigValueUInt(deviceName, nullptr, "sources", &device->SourcesMax);
- if(device->SourcesMax == 0) device->SourcesMax = 256;
+ if(auto srcsopt = ConfigValueUInt(deviceName, nullptr, "sources"))
+ {
+ if(*srcsopt > 0) device->SourcesMax = *srcsopt;
+ }
- ConfigValueUInt(deviceName, nullptr, "slots", &device->AuxiliaryEffectSlotMax);
- if(device->AuxiliaryEffectSlotMax == 0) device->AuxiliaryEffectSlotMax = 64;
- else device->AuxiliaryEffectSlotMax = minu(device->AuxiliaryEffectSlotMax, INT_MAX);
+ if(auto slotsopt = ConfigValueUInt(deviceName, nullptr, "slots"))
+ {
+ if(*slotsopt > 0)
+ device->AuxiliaryEffectSlotMax = minu(*slotsopt, INT_MAX);
+ }
if(auto sendsopt = ConfigValueInt(deviceName, nullptr, "sends"))
device->NumAuxSends = clampi(DEFAULT_SENDS, 0, clampi(*sendsopt, 0, MAX_SENDS));
@@ -4133,12 +4134,16 @@ START_API_FUNC
device->FmtChans = DevFmtChannelsDefault;
device->FmtType = DevFmtTypeDefault;
- ConfigValueUInt(nullptr, nullptr, "sources", &device->SourcesMax);
- if(device->SourcesMax == 0) device->SourcesMax = 256;
+ if(auto srcsopt = ConfigValueUInt(nullptr, nullptr, "sources"))
+ {
+ if(*srcsopt > 0) device->SourcesMax = *srcsopt;
+ }
- ConfigValueUInt(nullptr, nullptr, "slots", &device->AuxiliaryEffectSlotMax);
- if(device->AuxiliaryEffectSlotMax == 0) device->AuxiliaryEffectSlotMax = 64;
- else device->AuxiliaryEffectSlotMax = minu(device->AuxiliaryEffectSlotMax, INT_MAX);
+ if(auto slotsopt = ConfigValueUInt(nullptr, nullptr, "slots"))
+ {
+ if(*slotsopt > 0)
+ device->AuxiliaryEffectSlotMax = minu(*slotsopt, INT_MAX);
+ }
if(auto sendsopt = ConfigValueInt(nullptr, nullptr, "sends"))
device->NumAuxSends = clampi(DEFAULT_SENDS, 0, clampi(*sendsopt, 0, MAX_SENDS));
diff --git a/Alc/alconfig.cpp b/Alc/alconfig.cpp
index 00643043..8b299afc 100644
--- a/Alc/alconfig.cpp
+++ b/Alc/alconfig.cpp
@@ -509,13 +509,13 @@ al::optional<int> ConfigValueInt(const char *devName, const char *blockName, con
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)
+al::optional<unsigned int> ConfigValueUInt(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::strtoul(val, nullptr, 0);
- return 1;
+ return al::optional<unsigned int>{al::in_place,
+ static_cast<unsigned int>(std::strtoul(val, nullptr, 0))};
}
int ConfigValueFloat(const char *devName, const char *blockName, const char *keyName, float *ret)
diff --git a/Alc/alconfig.h b/Alc/alconfig.h
index e6977101..275fed75 100644
--- a/Alc/alconfig.h
+++ b/Alc/alconfig.h
@@ -11,7 +11,7 @@ int GetConfigValueBool(const char *devName, const char *blockName, const char *k
int ConfigValueStr(const char *devName, const char *blockName, const char *keyName, const char **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);
+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);
diff --git a/Alc/backends/jack.cpp b/Alc/backends/jack.cpp
index c58f73bc..99e9019b 100644
--- a/Alc/backends/jack.cpp
+++ b/Alc/backends/jack.cpp
@@ -203,9 +203,9 @@ int JackPlayback::bufferSizeNotify(jack_nframes_t numframes)
mDevice->UpdateSize = numframes;
mDevice->BufferSize = numframes*2;
- ALuint bufsize{mDevice->UpdateSize};
- if(ConfigValueUInt(mDevice->DeviceName.c_str(), "jack", "buffer-size", &bufsize))
- bufsize = maxu(NextPowerOf2(bufsize), mDevice->UpdateSize);
+ const char *devname{mDevice->DeviceName.c_str()};
+ ALuint bufsize{ConfigValueUInt(devname, "jack", "buffer-size").value_or(mDevice->UpdateSize)};
+ bufsize = maxu(NextPowerOf2(bufsize), mDevice->UpdateSize);
mDevice->BufferSize = bufsize + mDevice->UpdateSize;
TRACE("%u / %u buffer\n", mDevice->UpdateSize, mDevice->BufferSize);
@@ -374,9 +374,9 @@ ALCboolean JackPlayback::reset()
mDevice->UpdateSize = jack_get_buffer_size(mClient);
mDevice->BufferSize = mDevice->UpdateSize * 2;
- ALuint bufsize{mDevice->UpdateSize};
- if(ConfigValueUInt(mDevice->DeviceName.c_str(), "jack", "buffer-size", &bufsize))
- bufsize = maxu(NextPowerOf2(bufsize), mDevice->UpdateSize);
+ const char *devname{mDevice->DeviceName.c_str()};
+ ALuint bufsize{ConfigValueUInt(devname, "jack", "buffer-size").value_or(mDevice->UpdateSize)};
+ bufsize = maxu(NextPowerOf2(bufsize), mDevice->UpdateSize);
mDevice->BufferSize = bufsize + mDevice->UpdateSize;
/* Force 32-bit float output. */