aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--alc/alc.cpp42
-rw-r--r--alc/device.cpp4
-rw-r--r--alc/device.h23
-rw-r--r--alc/panning.cpp27
4 files changed, 55 insertions, 41 deletions
diff --git a/alc/alc.cpp b/alc/alc.cpp
index 16346801..7cc35617 100644
--- a/alc/alc.cpp
+++ b/alc/alc.cpp
@@ -1663,7 +1663,6 @@ ALCenum UpdateDeviceParams(ALCdevice *device, const int *attrList)
UpdateClockBase(device);
- const char *devname{nullptr};
if(loopback)
{
device->Frequency = freq;
@@ -1678,13 +1677,11 @@ ALCenum UpdateDeviceParams(ALCdevice *device, const int *attrList)
}
else
{
- devname = device->DeviceName.c_str();
-
device->BufferSize = DEFAULT_UPDATE_SIZE * DEFAULT_NUM_UPDATES;
device->UpdateSize = DEFAULT_UPDATE_SIZE;
device->Frequency = DEFAULT_OUTPUT_RATE;
- freq = ConfigValueUInt(devname, nullptr, "frequency").value_or(freq);
+ freq = device->configValue<uint>(nullptr, "frequency").value_or(freq);
if(freq < 1)
device->Flags.reset(FrequencyRequest);
else
@@ -1699,10 +1696,10 @@ ALCenum UpdateDeviceParams(ALCdevice *device, const int *attrList)
device->Flags.set(FrequencyRequest);
}
- if(auto persizeopt = ConfigValueUInt(devname, nullptr, "period_size"))
+ if(auto persizeopt = device->configValue<uint>(nullptr, "period_size"))
device->UpdateSize = clampu(*persizeopt, 64, 8192);
- if(auto peropt = ConfigValueUInt(devname, nullptr, "periods"))
+ if(auto peropt = device->configValue<uint>(nullptr, "periods"))
device->BufferSize = device->UpdateSize * clampu(*peropt, 2, 16);
else
device->BufferSize = maxu(device->BufferSize, device->UpdateSize*2);
@@ -1711,7 +1708,7 @@ ALCenum UpdateDeviceParams(ALCdevice *device, const int *attrList)
if(numMono > INT_MAX-numStereo)
numMono = INT_MAX-numStereo;
numMono += numStereo;
- if(auto srcsopt = ConfigValueUInt(devname, nullptr, "sources"))
+ if(auto srcsopt = device->configValue<uint>(nullptr, "sources"))
{
if(*srcsopt <= 0) numMono = 256;
else numMono = *srcsopt;
@@ -1725,7 +1722,7 @@ ALCenum UpdateDeviceParams(ALCdevice *device, const int *attrList)
device->NumMonoSources = numMono;
device->NumStereoSources = numStereo;
- if(auto sendsopt = ConfigValueInt(devname, nullptr, "sends"))
+ if(auto sendsopt = device->configValue<int>(nullptr, "sends"))
new_sends = minu(numSends, static_cast<uint>(clampi(*sendsopt, 0, MAX_SENDS)));
else
new_sends = numSends;
@@ -1766,7 +1763,7 @@ ALCenum UpdateDeviceParams(ALCdevice *device, const int *attrList)
device->mHrtfStatus = ALC_HRTF_DISABLED_SOFT;
if(device->Type != DeviceType::Loopback)
{
- if(auto hrtfopt = ConfigValueStr(device->DeviceName.c_str(), nullptr, "hrtf"))
+ if(auto hrtfopt = device->configValue<std::string>(nullptr, "hrtf"))
{
const char *hrtf{hrtfopt->c_str()};
if(al::strcasecmp(hrtf, "true") == 0)
@@ -1857,9 +1854,9 @@ ALCenum UpdateDeviceParams(ALCdevice *device, const int *attrList)
sample_delay += FrontStablizer::DelayLength;
}
- if(GetConfigValueBool(device->DeviceName.c_str(), nullptr, "dither", 1))
+ if(device->getConfigValueBool(nullptr, "dither", 1))
{
- int depth{ConfigValueInt(device->DeviceName.c_str(), nullptr, "dither-depth").value_or(0)};
+ int depth{device->configValue<int>(nullptr, "dither-depth").value_or(0)};
if(depth <= 0)
{
switch(device->FmtType)
@@ -1892,7 +1889,7 @@ ALCenum UpdateDeviceParams(ALCdevice *device, const int *attrList)
device->DitherDepth);
device->LimiterState = gainLimiter;
- if(auto limopt = ConfigValueBool(device->DeviceName.c_str(), nullptr, "output-limiter"))
+ if(auto limopt = device->configValue<bool>(nullptr, "output-limiter"))
gainLimiter = *limopt ? ALC_TRUE : ALC_FALSE;
/* Valid values for gainLimiter are ALC_DONT_CARE_SOFT, ALC_TRUE, and
@@ -2935,7 +2932,7 @@ START_API_FUNC
ContextRef context{new ALCcontext{dev}};
context->init();
- if(auto volopt = ConfigValueFloat(dev->DeviceName.c_str(), nullptr, "volume-adjust"))
+ if(auto volopt = dev->configValue<float>(nullptr, "volume-adjust"))
{
const float valf{*volopt};
if(!std::isfinite(valf))
@@ -3170,8 +3167,7 @@ START_API_FUNC
return nullptr;
}
- deviceName = device->DeviceName.c_str();
- if(auto chanopt = ConfigValueStr(deviceName, nullptr, "channels"))
+ if(auto chanopt = device->configValue<std::string>(nullptr, "channels"))
{
static const struct ChannelMap {
const char name[16];
@@ -3204,7 +3200,7 @@ START_API_FUNC
device->Flags.set(ChannelsRequest);
}
}
- if(auto typeopt = ConfigValueStr(deviceName, nullptr, "sample-type"))
+ if(auto typeopt = device->configValue<std::string>(nullptr, "sample-type"))
{
static const struct TypeMap {
const char name[16];
@@ -3233,7 +3229,7 @@ START_API_FUNC
}
}
- if(uint freq{ConfigValueUInt(deviceName, nullptr, "frequency").value_or(0u)})
+ if(uint freq{device->configValue<uint>(nullptr, "frequency").value_or(0u)})
{
if(freq < MIN_OUTPUT_RATE || freq > MAX_OUTPUT_RATE)
{
@@ -3248,28 +3244,28 @@ START_API_FUNC
device->Flags.set(FrequencyRequest);
}
- if(auto persizeopt = ConfigValueUInt(deviceName, nullptr, "period_size"))
+ if(auto persizeopt = device->configValue<uint>(nullptr, "period_size"))
device->UpdateSize = clampu(*persizeopt, 64, 8192);
- if(auto peropt = ConfigValueUInt(deviceName, nullptr, "periods"))
+ if(auto peropt = device->configValue<uint>(nullptr, "periods"))
device->BufferSize = device->UpdateSize * clampu(*peropt, 2, 16);
else
device->BufferSize = maxu(device->BufferSize, device->UpdateSize*2);
- if(auto srcsmax = ConfigValueUInt(deviceName, nullptr, "sources").value_or(0))
+ if(auto srcsmax = device->configValue<uint>(nullptr, "sources").value_or(0))
device->SourcesMax = srcsmax;
- if(auto slotsmax = ConfigValueUInt(deviceName, nullptr, "slots").value_or(0))
+ if(auto slotsmax = device->configValue<uint>(nullptr, "slots").value_or(0))
device->AuxiliaryEffectSlotMax = minu(slotsmax, INT_MAX);
- if(auto sendsopt = ConfigValueInt(deviceName, nullptr, "sends"))
+ if(auto sendsopt = device->configValue<int>(nullptr, "sends"))
device->NumAuxSends = minu(DEFAULT_SENDS,
static_cast<uint>(clampi(*sendsopt, 0, MAX_SENDS)));
device->NumStereoSources = 1;
device->NumMonoSources = device->SourcesMax - device->NumStereoSources;
- if(auto ambiopt = ConfigValueStr(deviceName, nullptr, "ambi-format"))
+ if(auto ambiopt = device->configValue<std::string>(nullptr, "ambi-format"))
{
const ALCchar *fmt{ambiopt->c_str()};
if(al::strcasecmp(fmt, "fuma") == 0)
diff --git a/alc/device.cpp b/alc/device.cpp
index 0f7d2b57..41ef6d44 100644
--- a/alc/device.cpp
+++ b/alc/device.cpp
@@ -64,8 +64,8 @@ ALCdevice::~ALCdevice()
void ALCdevice::enumerateHrtfs()
{
- mHrtfList = EnumerateHrtf(ConfigValueStr(DeviceName.c_str(), nullptr, "hrtf-paths"));
- if(auto defhrtfopt = ConfigValueStr(DeviceName.c_str(), nullptr, "default-hrtf"))
+ mHrtfList = EnumerateHrtf(configValue<std::string>(nullptr, "hrtf-paths"));
+ if(auto defhrtfopt = configValue<std::string>(nullptr, "default-hrtf"))
{
auto iter = std::find(mHrtfList.begin(), mHrtfList.end(), *defhrtfopt);
if(iter == mHrtfList.end())
diff --git a/alc/device.h b/alc/device.h
index 2f465b16..5fba0eb5 100644
--- a/alc/device.h
+++ b/alc/device.h
@@ -10,6 +10,7 @@
#include "AL/alc.h"
#include "AL/alext.h"
+#include "alconfig.h"
#include "almalloc.h"
#include "alnumeric.h"
#include "core/device.h"
@@ -104,7 +105,29 @@ struct ALCdevice : public al::intrusive_ref<ALCdevice>, DeviceBase {
void enumerateHrtfs();
+ bool getConfigValueBool(const char *block, const char *key, int def)
+ { return GetConfigValueBool(DeviceName.c_str(), block, key, def); }
+
+ template<typename T>
+ al::optional<T> configValue(const char *block, const char *key) = delete;
+
DEF_NEWDEL(ALCdevice)
};
+template<>
+inline al::optional<std::string> ALCdevice::configValue(const char *block, const char *key)
+{ return ConfigValueStr(DeviceName.c_str(), block, key); }
+template<>
+inline al::optional<int> ALCdevice::configValue(const char *block, const char *key)
+{ return ConfigValueInt(DeviceName.c_str(), block, key); }
+template<>
+inline al::optional<uint> ALCdevice::configValue(const char *block, const char *key)
+{ return ConfigValueUInt(DeviceName.c_str(), block, key); }
+template<>
+inline al::optional<float> ALCdevice::configValue(const char *block, const char *key)
+{ return ConfigValueFloat(DeviceName.c_str(), block, key); }
+template<>
+inline al::optional<bool> ALCdevice::configValue(const char *block, const char *key)
+{ return ConfigValueBool(DeviceName.c_str(), block, key); }
+
#endif
diff --git a/alc/panning.cpp b/alc/panning.cpp
index f2869681..083dd400 100644
--- a/alc/panning.cpp
+++ b/alc/panning.cpp
@@ -207,8 +207,7 @@ void InitNearFieldCtrl(ALCdevice *device, float ctrl_dist, uint order, bool is3d
static const uint chans_per_order3d[MaxAmbiOrder+1]{ 1, 3, 5, 7 };
/* NFC is only used when AvgSpeakerDist is greater than 0. */
- const char *devname{device->DeviceName.c_str()};
- if(!GetConfigValueBool(devname, "decoder", "nfc", 0) || !(ctrl_dist > 0.0f))
+ if(!device->getConfigValueBool("decoder", "nfc", 0) || !(ctrl_dist > 0.0f))
return;
device->AvgSpeakerDist = clampf(ctrl_dist, 0.1f, 10.0f);
@@ -224,8 +223,7 @@ void InitDistanceComp(ALCdevice *device, DecoderView decoder,
{
const float maxdist{std::accumulate(std::begin(dists), std::end(dists), 0.0f, maxf)};
- const char *devname{device->DeviceName.c_str()};
- if(!GetConfigValueBool(devname, "decoder", "distance-comp", 1) || !(maxdist > 0.0f))
+ if(!device->getConfigValueBool("decoder", "distance-comp", 1) || !(maxdist > 0.0f))
return;
const auto distSampleScale = static_cast<float>(device->Frequency) / SpeedOfSoundMetersPerSec;
@@ -547,7 +545,6 @@ void InitPanning(ALCdevice *device, const bool hqdec=false, const bool stablize=
case DevFmtX61: decoder = X61Config; break;
case DevFmtX71: decoder = X71Config; break;
case DevFmtAmbi3D:
- const char *devname{device->DeviceName.c_str()};
auto&& acnmap = GetAmbiLayout(device->mAmbiLayout);
auto&& n3dscale = GetAmbiScales(device->mAmbiScale);
@@ -558,7 +555,7 @@ void InitPanning(ALCdevice *device, const bool hqdec=false, const bool stablize=
{ return BFChannelConfig{1.0f/n3dscale[acn], acn}; });
AllocChannels(device, count, 0);
- float nfc_delay{ConfigValueFloat(devname, "decoder", "nfc-ref-delay").value_or(0.0f)};
+ float nfc_delay{device->configValue<float>("decoder", "nfc-ref-delay").value_or(0.0f)};
if(nfc_delay > 0.0f)
InitNearFieldCtrl(device, nfc_delay * SpeedOfSoundMetersPerSec, device->mAmbiOrder,
true);
@@ -738,7 +735,7 @@ void InitHrtfPanning(ALCdevice *device)
*/
device->mRenderMode = RenderMode::Hrtf;
uint ambi_order{1};
- if(auto modeopt = ConfigValueStr(device->DeviceName.c_str(), nullptr, "hrtf-mode"))
+ if(auto modeopt = device->configValue<std::string>(nullptr, "hrtf-mode"))
{
struct HrtfModeEntry {
char name[8];
@@ -823,8 +820,6 @@ void InitUhjPanning(ALCdevice *device)
void aluInitRenderer(ALCdevice *device, int hrtf_id, HrtfRequestMode hrtf_appreq,
HrtfRequestMode hrtf_userreq)
{
- const char *devname{device->DeviceName.c_str()};
-
/* Hold the HRTF the device last used, in case it's used again. */
HrtfStorePtr old_hrtf{std::move(device->mHrtf)};
@@ -885,7 +880,7 @@ void aluInitRenderer(ALCdevice *device, int hrtf_id, HrtfRequestMode hrtf_appreq
};
if(layout)
{
- if(auto decopt = ConfigValueStr(devname, "decoder", layout))
+ if(auto decopt = device->configValue<std::string>("decoder", layout))
load_config(decopt->c_str());
}
@@ -895,8 +890,8 @@ void aluInitRenderer(ALCdevice *device, int hrtf_id, HrtfRequestMode hrtf_appreq
const bool stablize{device->RealOut.ChannelIndex[FrontCenter] != INVALID_CHANNEL_INDEX
&& device->RealOut.ChannelIndex[FrontLeft] != INVALID_CHANNEL_INDEX
&& device->RealOut.ChannelIndex[FrontRight] != INVALID_CHANNEL_INDEX
- && GetConfigValueBool(devname, nullptr, "front-stablizer", 0) != 0};
- const bool hqdec{GetConfigValueBool(devname, "decoder", "hq-mode", 1) != 0};
+ && device->getConfigValueBool(nullptr, "front-stablizer", 0) != 0};
+ const bool hqdec{device->getConfigValueBool("decoder", "hq-mode", 1) != 0};
InitPanning(device, hqdec, stablize, decoder);
if(decoder.mOrder > 0)
{
@@ -926,7 +921,7 @@ void aluInitRenderer(ALCdevice *device, int hrtf_id, HrtfRequestMode hrtf_appreq
bool headphones{device->IsHeadphones};
if(device->Type != DeviceType::Loopback)
{
- if(auto modeopt = ConfigValueStr(device->DeviceName.c_str(), nullptr, "stereo-mode"))
+ if(auto modeopt = device->configValue<std::string>(nullptr, "stereo-mode"))
{
const char *mode{modeopt->c_str()};
if(al::strcasecmp(mode, "headphones") == 0)
@@ -991,7 +986,7 @@ void aluInitRenderer(ALCdevice *device, int hrtf_id, HrtfRequestMode hrtf_appreq
HrtfStore *hrtf{device->mHrtf.get()};
device->mIrSize = hrtf->irSize;
- if(auto hrtfsizeopt = ConfigValueUInt(devname, nullptr, "hrtf-size"))
+ if(auto hrtfsizeopt = device->configValue<uint>(nullptr, "hrtf-size"))
{
if(*hrtfsizeopt > 0 && *hrtfsizeopt < device->mIrSize)
device->mIrSize = maxu(*hrtfsizeopt, MinIrLength);
@@ -1010,7 +1005,7 @@ no_hrtf:
if(device->Type != DeviceType::Loopback)
{
- if(auto cflevopt = ConfigValueInt(device->DeviceName.c_str(), nullptr, "cf_level"))
+ if(auto cflevopt = device->configValue<int>(nullptr, "cf_level"))
{
if(*cflevopt > 0 && *cflevopt <= 6)
{
@@ -1025,7 +1020,7 @@ no_hrtf:
}
}
- if(auto encopt = ConfigValueStr(device->DeviceName.c_str(), nullptr, "stereo-encoding"))
+ if(auto encopt = device->configValue<std::string>(nullptr, "stereo-encoding"))
{
const char *mode{encopt->c_str()};
if(al::strcasecmp(mode, "uhj") == 0)