aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2023-12-21 21:26:36 -0800
committerChris Robinson <[email protected]>2023-12-21 21:26:36 -0800
commit863c48a3e78e8a2f1e9217eaf6cda02cbe44e366 (patch)
treef08e2a3a5e63a142824c526d8b3caaa8301d4f5f
parentec2ffbfa6ddda5cb6fc37074e7f9e37f8315da39 (diff)
Use string_views for querying config parameters
-rw-r--r--al/error.cpp2
-rw-r--r--alc/alc.cpp62
-rw-r--r--alc/alconfig.cpp35
-rw-r--r--alc/alconfig.h19
-rw-r--r--alc/backends/alsa.cpp29
-rw-r--r--alc/backends/jack.cpp10
-rw-r--r--alc/backends/oss.cpp4
-rw-r--r--alc/backends/pipewire.cpp4
-rw-r--r--alc/backends/portaudio.cpp4
-rw-r--r--alc/backends/pulseaudio.cpp12
-rw-r--r--alc/backends/solaris.cpp2
-rw-r--r--alc/backends/wasapi.cpp6
-rw-r--r--alc/backends/wave.cpp4
-rw-r--r--alc/device.cpp4
-rw-r--r--alc/device.h26
-rw-r--r--alc/panning.cpp8
16 files changed, 122 insertions, 109 deletions
diff --git a/al/error.cpp b/al/error.cpp
index b8692118..26dc522f 100644
--- a/al/error.cpp
+++ b/al/error.cpp
@@ -108,7 +108,7 @@ AL_API auto AL_APIENTRY alGetError() noexcept -> ALenum
{
auto optstr = al::getenv(envname);
if(!optstr)
- optstr = ConfigValueStr(nullptr, "game_compat", optname);
+ optstr = ConfigValueStr({}, "game_compat", optname);
if(optstr)
{
diff --git a/alc/alc.cpp b/alc/alc.cpp
index a0fbdb0f..3ad07aaa 100644
--- a/alc/alc.cpp
+++ b/alc/alc.cpp
@@ -427,7 +427,7 @@ void alc_initconfig()
#ifdef HAVE_NEON
capfilter |= CPU_CAP_NEON;
#endif
- if(auto cpuopt = ConfigValueStr(nullptr, nullptr, "disable-cpu-exts"))
+ if(auto cpuopt = ConfigValueStr({}, {}, "disable-cpu-exts"))
{
const char *str{cpuopt->c_str()};
if(al::strcasecmp(str, "all") == 0)
@@ -480,9 +480,9 @@ void alc_initconfig()
CPUCapFlags = caps & capfilter;
}
- if(auto priopt = ConfigValueInt(nullptr, nullptr, "rt-prio"))
+ if(auto priopt = ConfigValueInt({}, {}, "rt-prio"))
RTPrioLevel = *priopt;
- if(auto limopt = ConfigValueBool(nullptr, nullptr, "rt-time-limit"))
+ if(auto limopt = ConfigValueBool({}, {}, "rt-time-limit"))
AllowRTTimeLimit = *limopt;
{
@@ -496,18 +496,18 @@ void alc_initconfig()
return true;
return false;
}
- return GetConfigValueBool(nullptr, "game_compat", optname, false);
+ return GetConfigValueBool({}, "game_compat", optname, false);
};
sBufferSubDataCompat = checkflag("__ALSOFT_ENABLE_SUB_DATA_EXT", "enable-sub-data-ext");
compatflags.set(CompatFlags::ReverseX, checkflag("__ALSOFT_REVERSE_X", "reverse-x"));
compatflags.set(CompatFlags::ReverseY, checkflag("__ALSOFT_REVERSE_Y", "reverse-y"));
compatflags.set(CompatFlags::ReverseZ, checkflag("__ALSOFT_REVERSE_Z", "reverse-z"));
- aluInit(compatflags, ConfigValueFloat(nullptr, "game_compat", "nfc-scale").value_or(1.0f));
+ aluInit(compatflags, ConfigValueFloat({}, "game_compat", "nfc-scale").value_or(1.0f));
}
- Voice::InitMixer(ConfigValueStr(nullptr, nullptr, "resampler"));
+ Voice::InitMixer(ConfigValueStr({}, {}, "resampler"));
- if(auto uhjfiltopt = ConfigValueStr(nullptr, "uhj", "decode-filter"))
+ if(auto uhjfiltopt = ConfigValueStr({}, "uhj", "decode-filter"))
{
if(al::strcasecmp(uhjfiltopt->c_str(), "fir256") == 0)
UhjDecodeQuality = UhjQualityType::FIR256;
@@ -518,7 +518,7 @@ void alc_initconfig()
else
WARN("Unsupported uhj/decode-filter: %s\n", uhjfiltopt->c_str());
}
- if(auto uhjfiltopt = ConfigValueStr(nullptr, "uhj", "encode-filter"))
+ if(auto uhjfiltopt = ConfigValueStr({}, "uhj", "encode-filter"))
{
if(al::strcasecmp(uhjfiltopt->c_str(), "fir256") == 0)
UhjEncodeQuality = UhjQualityType::FIR256;
@@ -544,17 +544,17 @@ void alc_initconfig()
TrapALError = al::strcasecmp(traperr->c_str(), "true") == 0
|| strtol(traperr->c_str(), nullptr, 0) == 1;
else
- TrapALError = !!GetConfigValueBool(nullptr, nullptr, "trap-al-error", false);
+ TrapALError = GetConfigValueBool({}, {}, "trap-al-error", false);
traperr = al::getenv("ALSOFT_TRAP_ALC_ERROR");
if(traperr)
TrapALCError = al::strcasecmp(traperr->c_str(), "true") == 0
|| strtol(traperr->c_str(), nullptr, 0) == 1;
else
- TrapALCError = !!GetConfigValueBool(nullptr, nullptr, "trap-alc-error", false);
+ TrapALCError = GetConfigValueBool({}, {}, "trap-alc-error", false);
}
- if(auto boostopt = ConfigValueFloat(nullptr, "reverb", "boost"))
+ if(auto boostopt = ConfigValueFloat({}, "reverb", "boost"))
{
const float valf{std::isfinite(*boostopt) ? clampf(*boostopt, -24.0f, 24.0f) : 0.0f};
ReverbBoost *= std::pow(10.0f, valf / 20.0f);
@@ -562,7 +562,7 @@ void alc_initconfig()
auto BackendListEnd = std::end(BackendList);
auto devopt = al::getenv("ALSOFT_DRIVERS");
- if(devopt || (devopt=ConfigValueStr(nullptr, nullptr, "drivers")))
+ if(devopt || (devopt=ConfigValueStr({}, {}, "drivers")))
{
auto backendlist_cur = std::begin(BackendList);
@@ -648,7 +648,7 @@ void alc_initconfig()
if(!CaptureFactory)
WARN("No capture backend available!\n");
- if(auto exclopt = ConfigValueStr(nullptr, nullptr, "excludefx"))
+ if(auto exclopt = ConfigValueStr({}, {}, "excludefx"))
{
const char *next{exclopt->c_str()};
do {
@@ -670,14 +670,12 @@ void alc_initconfig()
InitEffect(&ALCcontext::sDefaultEffect);
auto defrevopt = al::getenv("ALSOFT_DEFAULT_REVERB");
- if(defrevopt || (defrevopt=ConfigValueStr(nullptr, nullptr, "default-reverb")))
+ if(defrevopt || (defrevopt=ConfigValueStr({}, {}, "default-reverb")))
LoadReverbPreset(defrevopt->c_str(), &ALCcontext::sDefaultEffect);
#ifdef ALSOFT_EAX
{
- const char *eax_block_name{"eax"};
-
- if(const auto eax_enable_opt = ConfigValueBool(nullptr, eax_block_name, "enable"))
+ if(const auto eax_enable_opt = ConfigValueBool({}, "eax", "enable"))
{
eax_g_is_enabled = *eax_enable_opt;
if(!eax_g_is_enabled)
@@ -1021,7 +1019,7 @@ ALCenum UpdateDeviceParams(ALCdevice *device, const int *attrList)
{
/* Get default settings from the user configuration */
- if(auto freqopt = device->configValue<uint>(nullptr, "frequency"))
+ if(auto freqopt = device->configValue<uint>({}, "frequency"))
{
optsrate = clampu(*freqopt, MinOutputRate, MaxOutputRate);
@@ -1029,14 +1027,14 @@ ALCenum UpdateDeviceParams(ALCdevice *device, const int *attrList)
period_size = static_cast<uint>(period_size*scale + 0.5);
}
- if(auto persizeopt = device->configValue<uint>(nullptr, "period_size"))
+ if(auto persizeopt = device->configValue<uint>({}, "period_size"))
period_size = clampu(*persizeopt, 64, 8192);
- if(auto numperopt = device->configValue<uint>(nullptr, "periods"))
+ if(auto numperopt = device->configValue<uint>({}, "periods"))
buffer_size = clampu(*numperopt, 2, 16) * period_size;
else
buffer_size = period_size * uint{DefaultNumUpdates};
- if(auto typeopt = device->configValue<std::string>(nullptr, "sample-type"))
+ if(auto typeopt = device->configValue<std::string>({}, "sample-type"))
{
struct TypeMap {
const char name[8]; /* NOLINT(*-avoid-c-arrays) */
@@ -1061,7 +1059,7 @@ ALCenum UpdateDeviceParams(ALCdevice *device, const int *attrList)
else
opttype = iter->type;
}
- if(auto chanopt = device->configValue<std::string>(nullptr, "channels"))
+ if(auto chanopt = device->configValue<std::string>({}, "channels"))
{
struct ChannelMap {
const char name[16]; /* NOLINT(*-avoid-c-arrays) */
@@ -1095,7 +1093,7 @@ ALCenum UpdateDeviceParams(ALCdevice *device, const int *attrList)
aorder = iter->order;
}
}
- if(auto ambiopt = device->configValue<std::string>(nullptr, "ambi-format"))
+ if(auto ambiopt = device->configValue<std::string>({}, "ambi-format"))
{
const ALCchar *fmt{ambiopt->c_str()};
if(al::strcasecmp(fmt, "fuma") == 0)
@@ -1122,7 +1120,7 @@ ALCenum UpdateDeviceParams(ALCdevice *device, const int *attrList)
ERR("Unsupported ambi-format: %s\n", fmt);
}
- if(auto hrtfopt = device->configValue<std::string>(nullptr, "hrtf"))
+ if(auto hrtfopt = device->configValue<std::string>({}, "hrtf"))
{
WARN("general/hrtf is deprecated, please use stereo-encoding instead\n");
@@ -1139,7 +1137,7 @@ ALCenum UpdateDeviceParams(ALCdevice *device, const int *attrList)
}
}
- if(auto encopt = device->configValue<std::string>(nullptr, "stereo-encoding"))
+ if(auto encopt = device->configValue<std::string>({}, "stereo-encoding"))
{
const char *mode{encopt->c_str()};
if(al::strcasecmp(mode, "basic") == 0 || al::strcasecmp(mode, "panpot") == 0)
@@ -1475,7 +1473,7 @@ ALCenum UpdateDeviceParams(ALCdevice *device, const int *attrList)
if(device->Type != DeviceType::Loopback)
{
- if(auto modeopt = device->configValue<std::string>(nullptr, "stereo-mode"))
+ if(auto modeopt = device->configValue<std::string>({}, "stereo-mode"))
{
const char *mode{modeopt->c_str()};
if(al::strcasecmp(mode, "headphones") == 0)
@@ -1492,7 +1490,7 @@ ALCenum UpdateDeviceParams(ALCdevice *device, const int *attrList)
/* Calculate the max number of sources, and split them between the mono and
* stereo count given the requested number of stereo sources.
*/
- if(auto srcsopt = device->configValue<uint>(nullptr, "sources"))
+ if(auto srcsopt = device->configValue<uint>({}, "sources"))
{
if(*srcsopt <= 0) numMono = 256;
else numMono = maxu(*srcsopt, 16);
@@ -1508,7 +1506,7 @@ ALCenum UpdateDeviceParams(ALCdevice *device, const int *attrList)
device->NumMonoSources = numMono;
device->NumStereoSources = numStereo;
- if(auto sendsopt = device->configValue<int>(nullptr, "sends"))
+ if(auto sendsopt = device->configValue<int>({}, "sends"))
numSends = minu(numSends, static_cast<uint>(clampi(*sendsopt, 0, MaxSendCount)));
device->NumAuxSends = numSends;
@@ -1536,9 +1534,9 @@ ALCenum UpdateDeviceParams(ALCdevice *device, const int *attrList)
if(auto *encoder{device->mUhjEncoder.get()})
sample_delay += encoder->getDelay();
- if(device->getConfigValueBool(nullptr, "dither", true))
+ if(device->getConfigValueBool({}, "dither", true))
{
- int depth{device->configValue<int>(nullptr, "dither-depth").value_or(0)};
+ int depth{device->configValue<int>({}, "dither-depth").value_or(0)};
if(depth <= 0)
{
switch(device->FmtType)
@@ -1571,7 +1569,7 @@ ALCenum UpdateDeviceParams(ALCdevice *device, const int *attrList)
device->DitherDepth);
if(!optlimit)
- optlimit = device->configValue<bool>(nullptr, "output-limiter");
+ optlimit = device->configValue<bool>({}, "output-limiter");
/* If the gain limiter is unset, use the limiter for integer-based output
* (where samples must be clamped), and don't for floating-point (which can
@@ -2696,7 +2694,7 @@ ALC_API ALCcontext* ALC_APIENTRY alcCreateContext(ALCdevice *device, const ALCin
}
context->init();
- if(auto volopt = dev->configValue<float>(nullptr, "volume-adjust"))
+ if(auto volopt = dev->configValue<float>({}, "volume-adjust"))
{
const float valf{*volopt};
if(!std::isfinite(valf))
diff --git a/alc/alconfig.cpp b/alc/alconfig.cpp
index c9936725..d9e97e09 100644
--- a/alc/alconfig.cpp
+++ b/alc/alconfig.cpp
@@ -277,16 +277,19 @@ void LoadConfigFromFile(std::istream &f)
ConfOpts.shrink_to_fit();
}
-const char *GetConfigValue(const char *devName, const char *blockName, const char *keyName)
+const char *GetConfigValue(const std::string_view devName, const std::string_view blockName,
+ const std::string_view keyName)
{
- if(!keyName)
+ if(keyName.empty())
return nullptr;
+ auto generalName = std::string_view{"general"};
std::string key;
- if(blockName && al::strcasecmp(blockName, "general") != 0)
+ if(!blockName.empty() && (blockName.size() != generalName.size() ||
+ al::strncasecmp(blockName.data(), generalName.data(), blockName.size()) != 0))
{
key = blockName;
- if(devName)
+ if(!devName.empty())
{
key += '/';
key += devName;
@@ -296,7 +299,7 @@ const char *GetConfigValue(const char *devName, const char *blockName, const cha
}
else
{
- if(devName)
+ if(!devName.empty())
{
key = devName;
key += '/';
@@ -315,9 +318,9 @@ const char *GetConfigValue(const char *devName, const char *blockName, const cha
return nullptr;
}
- if(!devName)
+ if(devName.empty())
return nullptr;
- return GetConfigValue(nullptr, blockName, keyName);
+ return GetConfigValue({}, blockName, keyName);
}
} // namespace
@@ -489,35 +492,40 @@ void ReadALConfig()
}
#endif
-std::optional<std::string> ConfigValueStr(const char *devName, const char *blockName, const char *keyName)
+std::optional<std::string> ConfigValueStr(const std::string_view devName,
+ const std::string_view blockName, const std::string_view keyName)
{
if(const char *val{GetConfigValue(devName, blockName, keyName)})
return val;
return std::nullopt;
}
-std::optional<int> ConfigValueInt(const char *devName, const char *blockName, const char *keyName)
+std::optional<int> ConfigValueInt(const std::string_view devName, const std::string_view blockName,
+ const std::string_view keyName)
{
if(const char *val{GetConfigValue(devName, blockName, keyName)})
return static_cast<int>(std::strtol(val, nullptr, 0));
return std::nullopt;
}
-std::optional<unsigned int> ConfigValueUInt(const char *devName, const char *blockName, const char *keyName)
+std::optional<unsigned int> ConfigValueUInt(const std::string_view devName,
+ const std::string_view blockName, const std::string_view keyName)
{
if(const char *val{GetConfigValue(devName, blockName, keyName)})
return static_cast<unsigned int>(std::strtoul(val, nullptr, 0));
return std::nullopt;
}
-std::optional<float> ConfigValueFloat(const char *devName, const char *blockName, const char *keyName)
+std::optional<float> ConfigValueFloat(const std::string_view devName,
+ const std::string_view blockName, const std::string_view keyName)
{
if(const char *val{GetConfigValue(devName, blockName, keyName)})
return std::strtof(val, nullptr);
return std::nullopt;
}
-std::optional<bool> ConfigValueBool(const char *devName, const char *blockName, const char *keyName)
+std::optional<bool> ConfigValueBool(const std::string_view devName,
+ const std::string_view blockName, const std::string_view keyName)
{
if(const char *val{GetConfigValue(devName, blockName, keyName)})
return al::strcasecmp(val, "on") == 0 || al::strcasecmp(val, "yes") == 0
@@ -525,7 +533,8 @@ std::optional<bool> ConfigValueBool(const char *devName, const char *blockName,
return std::nullopt;
}
-bool GetConfigValueBool(const char *devName, const char *blockName, const char *keyName, bool def)
+bool GetConfigValueBool(const std::string_view devName, const std::string_view blockName,
+ const std::string_view keyName, bool def)
{
if(const char *val{GetConfigValue(devName, blockName, keyName)})
return (al::strcasecmp(val, "on") == 0 || al::strcasecmp(val, "yes") == 0
diff --git a/alc/alconfig.h b/alc/alconfig.h
index 1eb44405..e7daac28 100644
--- a/alc/alconfig.h
+++ b/alc/alconfig.h
@@ -3,16 +3,23 @@
#include <optional>
#include <string>
+#include <string_view>
void ReadALConfig();
-bool GetConfigValueBool(const char *devName, const char *blockName, const char *keyName, bool def);
+bool GetConfigValueBool(const std::string_view devName, const std::string_view blockName,
+ const std::string_view keyName, bool def);
-std::optional<std::string> ConfigValueStr(const char *devName, const char *blockName, const char *keyName);
-std::optional<int> ConfigValueInt(const char *devName, const char *blockName, const char *keyName);
-std::optional<unsigned int> ConfigValueUInt(const char *devName, const char *blockName, const char *keyName);
-std::optional<float> ConfigValueFloat(const char *devName, const char *blockName, const char *keyName);
-std::optional<bool> ConfigValueBool(const char *devName, const char *blockName, const char *keyName);
+std::optional<std::string> ConfigValueStr(const std::string_view devName,
+ const std::string_view blockName, const std::string_view keyName);
+std::optional<int> ConfigValueInt(const std::string_view devName, const std::string_view blockName,
+ const std::string_view keyName);
+std::optional<unsigned int> ConfigValueUInt(const std::string_view devName,
+ const std::string_view blockName, const std::string_view keyName);
+std::optional<float> ConfigValueFloat(const std::string_view devName,
+ const std::string_view blockName, const std::string_view keyName);
+std::optional<bool> ConfigValueBool(const std::string_view devName,
+ const std::string_view blockName, const std::string_view keyName);
#endif /* ALCONFIG_H */
diff --git a/alc/backends/alsa.cpp b/alc/backends/alsa.cpp
index 344c440c..9bbcb241 100644
--- a/alc/backends/alsa.cpp
+++ b/alc/backends/alsa.cpp
@@ -253,10 +253,11 @@ std::vector<DevMap> PlaybackDevices;
std::vector<DevMap> CaptureDevices;
-const char *prefix_name(snd_pcm_stream_t stream)
+const std::string_view prefix_name(snd_pcm_stream_t stream)
{
- assert(stream == SND_PCM_STREAM_PLAYBACK || stream == SND_PCM_STREAM_CAPTURE);
- return (stream==SND_PCM_STREAM_PLAYBACK) ? "device-prefix" : "capture-prefix";
+ if(stream == SND_PCM_STREAM_PLAYBACK)
+ return "device-prefix";
+ return "capture-prefix";
}
std::vector<DevMap> probe_devices(snd_pcm_stream_t stream)
@@ -268,11 +269,11 @@ std::vector<DevMap> probe_devices(snd_pcm_stream_t stream)
snd_pcm_info_t *pcminfo;
snd_pcm_info_malloc(&pcminfo);
- auto defname = ConfigValueStr(nullptr, "alsa",
+ auto defname = ConfigValueStr({}, "alsa",
(stream == SND_PCM_STREAM_PLAYBACK) ? "device" : "capture");
devlist.emplace_back(alsaDevice, defname ? defname->c_str() : "default");
- if(auto customdevs = ConfigValueStr(nullptr, "alsa",
+ if(auto customdevs = ConfigValueStr({}, "alsa",
(stream == SND_PCM_STREAM_PLAYBACK) ? "custom-devices" : "custom-captures"))
{
size_t nextpos{customdevs->find_first_not_of(';')};
@@ -300,8 +301,8 @@ std::vector<DevMap> probe_devices(snd_pcm_stream_t stream)
}
}
- const std::string main_prefix{
- ConfigValueStr(nullptr, "alsa", prefix_name(stream)).value_or("plughw:")};
+ const std::string main_prefix{ConfigValueStr({}, "alsa", prefix_name(stream))
+ .value_or("plughw:")};
int card{-1};
int err{snd_card_next(&card)};
@@ -327,8 +328,7 @@ std::vector<DevMap> probe_devices(snd_pcm_stream_t stream)
name = prefix_name(stream);
name += '-';
name += cardid;
- const std::string card_prefix{
- ConfigValueStr(nullptr, "alsa", name.c_str()).value_or(main_prefix)};
+ const std::string card_prefix{ConfigValueStr({}, "alsa", name).value_or(main_prefix)};
int dev{-1};
while(true)
@@ -353,8 +353,7 @@ std::vector<DevMap> probe_devices(snd_pcm_stream_t stream)
name += cardid;
name += '-';
name += std::to_string(dev);
- const std::string device_prefix{
- ConfigValueStr(nullptr, "alsa", name.c_str()).value_or(card_prefix)};
+ const std::string device_prefix{ConfigValueStr({},"alsa", name).value_or(card_prefix)};
/* "CardName, PcmName (CARD=cardid,DEV=dev)" */
name = cardname;
@@ -643,7 +642,7 @@ void AlsaPlayback::open(std::string_view name)
else
{
name = alsaDevice;
- if(auto driveropt = ConfigValueStr(nullptr, "alsa", "device"))
+ if(auto driveropt = ConfigValueStr({}, "alsa", "device"))
driver = std::move(driveropt).value();
}
TRACE("Opening device \"%s\"\n", driver.c_str());
@@ -691,7 +690,7 @@ bool AlsaPlayback::reset()
break;
}
- bool allowmmap{!!GetConfigValueBool(mDevice->DeviceName.c_str(), "alsa", "mmap", true)};
+ bool allowmmap{GetConfigValueBool(mDevice->DeviceName, "alsa", "mmap", true)};
uint periodLen{static_cast<uint>(mDevice->UpdateSize * 1000000_u64 / mDevice->Frequency)};
uint bufferLen{static_cast<uint>(mDevice->BufferSize * 1000000_u64 / mDevice->Frequency)};
uint rate{mDevice->Frequency};
@@ -750,7 +749,7 @@ bool AlsaPlayback::reset()
else mDevice->FmtChans = DevFmtStereo;
}
/* set rate (implicitly constrains period/buffer parameters) */
- if(!GetConfigValueBool(mDevice->DeviceName.c_str(), "alsa", "allow-resampler", false)
+ if(!GetConfigValueBool(mDevice->DeviceName, "alsa", "allow-resampler", false)
|| !mDevice->Flags.test(FrequencyRequest))
{
if(snd_pcm_hw_params_set_rate_resample(mPcmHandle, hp.get(), 0) < 0)
@@ -914,7 +913,7 @@ void AlsaCapture::open(std::string_view name)
else
{
name = alsaDevice;
- if(auto driveropt = ConfigValueStr(nullptr, "alsa", "capture"))
+ if(auto driveropt = ConfigValueStr({}, "alsa", "capture"))
driver = std::move(driveropt).value();
}
diff --git a/alc/backends/jack.cpp b/alc/backends/jack.cpp
index eb87b0a7..922873b8 100644
--- a/alc/backends/jack.cpp
+++ b/alc/backends/jack.cpp
@@ -210,7 +210,7 @@ void EnumerateDevices(jack_client_t *client, std::vector<DeviceEntry> &list)
}
}
- if(auto listopt = ConfigValueStr(nullptr, "jack", "custom-devices"))
+ if(auto listopt = ConfigValueStr({}, "jack", "custom-devices"))
{
for(size_t strpos{0};strpos < listopt->size();)
{
@@ -509,7 +509,7 @@ bool JackPlayback::reset()
std::for_each(mPort.begin(), mPort.end(), unregister_port);
mPort.fill(nullptr);
- mRTMixing = GetConfigValueBool(mDevice->DeviceName.c_str(), "jack", "rt-mix", true);
+ mRTMixing = GetConfigValueBool(mDevice->DeviceName, "jack", "rt-mix", true);
jack_set_process_callback(mClient,
mRTMixing ? &JackPlayback::processRtC : &JackPlayback::processC, this);
@@ -527,7 +527,7 @@ bool JackPlayback::reset()
}
else
{
- const char *devname{mDevice->DeviceName.c_str()};
+ const std::string_view devname{mDevice->DeviceName};
uint bufsize{ConfigValueUInt(devname, "jack", "buffer-size").value_or(mDevice->UpdateSize)};
bufsize = maxu(NextPowerOf2(bufsize), mDevice->UpdateSize);
mDevice->BufferSize = bufsize + mDevice->UpdateSize;
@@ -577,7 +577,7 @@ void JackPlayback::start()
if(jack_activate(mClient))
throw al::backend_exception{al::backend_error::DeviceError, "Failed to activate client"};
- const char *devname{mDevice->DeviceName.c_str()};
+ const std::string_view devname{mDevice->DeviceName};
if(ConfigValueBool(devname, "jack", "connect-ports").value_or(true))
{
JackPortsPtr pnames{jack_get_ports(mClient, mPortPattern.c_str(), JackDefaultAudioType,
@@ -676,7 +676,7 @@ bool JackBackendFactory::init()
if(!jack_load())
return false;
- if(!GetConfigValueBool(nullptr, "jack", "spawn-server", false))
+ if(!GetConfigValueBool({}, "jack", "spawn-server", false))
ClientOptions = static_cast<jack_options_t>(ClientOptions | JackNoStartServer);
const PathNamePair &binname = GetProcBinary();
diff --git a/alc/backends/oss.cpp b/alc/backends/oss.cpp
index 8e547497..9a4aa9a8 100644
--- a/alc/backends/oss.cpp
+++ b/alc/backends/oss.cpp
@@ -631,9 +631,9 @@ BackendFactory &OSSBackendFactory::getFactory()
bool OSSBackendFactory::init()
{
- if(auto devopt = ConfigValueStr(nullptr, "oss", "device"))
+ if(auto devopt = ConfigValueStr({}, "oss", "device"))
DefaultPlayback = std::move(*devopt);
- if(auto capopt = ConfigValueStr(nullptr, "oss", "capture"))
+ if(auto capopt = ConfigValueStr({}, "oss", "capture"))
DefaultCapture = std::move(*capopt);
return true;
diff --git a/alc/backends/pipewire.cpp b/alc/backends/pipewire.cpp
index d3ab8984..7b206d2d 100644
--- a/alc/backends/pipewire.cpp
+++ b/alc/backends/pipewire.cpp
@@ -1688,7 +1688,7 @@ bool PipeWirePlayback::reset()
pw_stream_flags flags{PW_STREAM_FLAG_AUTOCONNECT | PW_STREAM_FLAG_INACTIVE
| PW_STREAM_FLAG_MAP_BUFFERS};
- if(GetConfigValueBool(mDevice->DeviceName.c_str(), "pipewire", "rt-mix", false))
+ if(GetConfigValueBool(mDevice->DeviceName, "pipewire", "rt-mix", false))
flags |= PW_STREAM_FLAG_RT_PROCESS;
if(int res{pw_stream_connect(mStream.get(), PW_DIRECTION_OUTPUT, PwIdAny, flags, &params, 1)})
throw al::backend_exception{al::backend_error::DeviceError,
@@ -2191,7 +2191,7 @@ bool PipeWireBackendFactory::init()
if(!gEventHandler.init())
return false;
- if(!GetConfigValueBool(nullptr, "pipewire", "assume-audio", false)
+ if(!GetConfigValueBool({}, "pipewire", "assume-audio", false)
&& !gEventHandler.waitForAudio())
{
gEventHandler.kill();
diff --git a/alc/backends/portaudio.cpp b/alc/backends/portaudio.cpp
index b6013dcc..15a0f3ac 100644
--- a/alc/backends/portaudio.cpp
+++ b/alc/backends/portaudio.cpp
@@ -117,7 +117,7 @@ void PortPlayback::open(std::string_view name)
static_cast<int>(name.length()), name.data()};
PaStreamParameters params{};
- auto devidopt = ConfigValueInt(nullptr, "port", "device");
+ auto devidopt = ConfigValueInt({}, "port", "device");
if(devidopt && *devidopt >= 0) params.device = *devidopt;
else params.device = Pa_GetDefaultOutputDevice();
params.suggestedLatency = mDevice->BufferSize / static_cast<double>(mDevice->Frequency);
@@ -280,7 +280,7 @@ void PortCapture::open(std::string_view name)
mRing = RingBuffer::Create(samples, frame_size, false);
- auto devidopt = ConfigValueInt(nullptr, "port", "capture");
+ auto devidopt = ConfigValueInt({}, "port", "capture");
if(devidopt && *devidopt >= 0) mParams.device = *devidopt;
else mParams.device = Pa_GetDefaultOutputDevice();
mParams.suggestedLatency = 0.0f;
diff --git a/alc/backends/pulseaudio.cpp b/alc/backends/pulseaudio.cpp
index aec91229..6d842475 100644
--- a/alc/backends/pulseaudio.cpp
+++ b/alc/backends/pulseaudio.cpp
@@ -808,7 +808,7 @@ void PulsePlayback::open(std::string_view name)
pa_stream_flags_t flags{PA_STREAM_START_CORKED | PA_STREAM_FIX_FORMAT | PA_STREAM_FIX_RATE |
PA_STREAM_FIX_CHANNELS};
- if(!GetConfigValueBool(nullptr, "pulse", "allow-moves", true))
+ if(!GetConfigValueBool({}, "pulse", "allow-moves", true))
flags |= PA_STREAM_DONT_MOVE;
pa_sample_spec spec{};
@@ -867,9 +867,9 @@ bool PulsePlayback::reset()
pa_stream_flags_t flags{PA_STREAM_START_CORKED | PA_STREAM_INTERPOLATE_TIMING |
PA_STREAM_AUTO_TIMING_UPDATE | PA_STREAM_EARLY_REQUESTS};
- if(!GetConfigValueBool(nullptr, "pulse", "allow-moves", true))
+ if(!GetConfigValueBool({}, "pulse", "allow-moves", true))
flags |= PA_STREAM_DONT_MOVE;
- if(GetConfigValueBool(mDevice->DeviceName.c_str(), "pulse", "adjust-latency", false))
+ if(GetConfigValueBool(mDevice->DeviceName, "pulse", "adjust-latency", false))
{
/* ADJUST_LATENCY can't be specified with EARLY_REQUESTS, for some
* reason. So if the user wants to adjust the overall device latency,
@@ -878,7 +878,7 @@ bool PulsePlayback::reset()
flags &= ~PA_STREAM_EARLY_REQUESTS;
flags |= PA_STREAM_ADJUST_LATENCY;
}
- if(GetConfigValueBool(mDevice->DeviceName.c_str(), "pulse", "fix-rate", false)
+ if(GetConfigValueBool(mDevice->DeviceName, "pulse", "fix-rate", false)
|| !mDevice->Flags.test(FrequencyRequest))
flags |= PA_STREAM_FIX_RATE;
@@ -1215,7 +1215,7 @@ void PulseCapture::open(std::string_view name)
mAttr.fragsize = minu(samples, 50*mDevice->Frequency/1000) * frame_size;
pa_stream_flags_t flags{PA_STREAM_START_CORKED | PA_STREAM_ADJUST_LATENCY};
- if(!GetConfigValueBool(nullptr, "pulse", "allow-moves", true))
+ if(!GetConfigValueBool({}, "pulse", "allow-moves", true))
flags |= PA_STREAM_DONT_MOVE;
TRACE("Connecting to \"%s\"\n", pulse_name ? pulse_name : "(default)");
@@ -1426,7 +1426,7 @@ bool PulseBackendFactory::init()
#endif /* HAVE_DYNLOAD */
pulse_ctx_flags = PA_CONTEXT_NOFLAGS;
- if(!GetConfigValueBool(nullptr, "pulse", "spawn-server", false))
+ if(!GetConfigValueBool({}, "pulse", "spawn-server", false))
pulse_ctx_flags |= PA_CONTEXT_NOAUTOSPAWN;
try {
diff --git a/alc/backends/solaris.cpp b/alc/backends/solaris.cpp
index b29a8cea..c7387284 100644
--- a/alc/backends/solaris.cpp
+++ b/alc/backends/solaris.cpp
@@ -265,7 +265,7 @@ BackendFactory &SolarisBackendFactory::getFactory()
bool SolarisBackendFactory::init()
{
- if(auto devopt = ConfigValueStr(nullptr, "solaris", "device"))
+ if(auto devopt = ConfigValueStr({}, "solaris", "device"))
solaris_driver = std::move(*devopt);
return true;
}
diff --git a/alc/backends/wasapi.cpp b/alc/backends/wasapi.cpp
index a164ed24..4fcae59c 100644
--- a/alc/backends/wasapi.cpp
+++ b/alc/backends/wasapi.cpp
@@ -1498,7 +1498,7 @@ void WasapiPlayback::prepareFormat(WAVEFORMATEXTENSIBLE &OutputType)
void WasapiPlayback::finalizeFormat(WAVEFORMATEXTENSIBLE &OutputType)
{
- if(!GetConfigValueBool(mDevice->DeviceName.c_str(), "wasapi", "allow-resampler", true))
+ if(!GetConfigValueBool(mDevice->DeviceName, "wasapi", "allow-resampler", true))
mDevice->Frequency = OutputType.Format.nSamplesPerSec;
else
mDevice->Frequency = minu(mDevice->Frequency, OutputType.Format.nSamplesPerSec);
@@ -1612,7 +1612,7 @@ bool WasapiPlayback::reset()
HRESULT WasapiPlayback::resetProxy()
{
- if(GetConfigValueBool(mDevice->DeviceName.c_str(), "wasapi", "spatial-api", false))
+ if(GetConfigValueBool(mDevice->DeviceName, "wasapi", "spatial-api", false))
{
auto &audio = mAudio.emplace<SpatialDevice>();
HRESULT hr{sDeviceHelper->activateAudioClient(mMMDev, __uuidof(ISpatialAudioClient),
@@ -1777,7 +1777,7 @@ HRESULT WasapiPlayback::resetProxy()
mDevice->Flags.reset(DirectEar).set(Virtualization);
if(streamParams.StaticObjectTypeMask == ChannelMask_Stereo)
mDevice->FmtChans = DevFmtStereo;
- if(!GetConfigValueBool(mDevice->DeviceName.c_str(), "wasapi", "allow-resampler", true))
+ if(!GetConfigValueBool(mDevice->DeviceName, "wasapi", "allow-resampler", true))
mDevice->Frequency = OutputType.Format.nSamplesPerSec;
else
mDevice->Frequency = minu(mDevice->Frequency, OutputType.Format.nSamplesPerSec);
diff --git a/alc/backends/wave.cpp b/alc/backends/wave.cpp
index 11794608..95064906 100644
--- a/alc/backends/wave.cpp
+++ b/alc/backends/wave.cpp
@@ -195,7 +195,7 @@ int WaveBackend::mixerProc()
void WaveBackend::open(std::string_view name)
{
- auto fname = ConfigValueStr(nullptr, "wave", "file");
+ auto fname = ConfigValueStr({}, "wave", "file");
if(!fname) throw al::backend_exception{al::backend_error::NoDevice,
"No wave output filename"};
@@ -231,7 +231,7 @@ bool WaveBackend::reset()
fseek(mFile, 0, SEEK_SET);
clearerr(mFile);
- if(GetConfigValueBool(nullptr, "wave", "bformat", false))
+ if(GetConfigValueBool({}, "wave", "bformat", false))
{
mDevice->FmtChans = DevFmtAmbi3D;
mDevice->mAmbiOrder = 1;
diff --git a/alc/device.cpp b/alc/device.cpp
index 5a34ad64..f13e6071 100644
--- a/alc/device.cpp
+++ b/alc/device.cpp
@@ -55,8 +55,8 @@ ALCdevice::~ALCdevice()
void ALCdevice::enumerateHrtfs()
{
- mHrtfList = EnumerateHrtf(configValue<std::string>(nullptr, "hrtf-paths"));
- if(auto defhrtfopt = configValue<std::string>(nullptr, "default-hrtf"))
+ mHrtfList = EnumerateHrtf(configValue<std::string>({}, "hrtf-paths"));
+ if(auto defhrtfopt = configValue<std::string>({}, "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 0f36304b..4eb693ff 100644
--- a/alc/device.h
+++ b/alc/device.h
@@ -143,28 +143,28 @@ struct ALCdevice : public al::intrusive_ref<ALCdevice>, DeviceBase {
void enumerateHrtfs();
- bool getConfigValueBool(const char *block, const char *key, bool def)
- { return GetConfigValueBool(DeviceName.c_str(), block, key, def); }
+ bool getConfigValueBool(const std::string_view block, const std::string_view key, bool def)
+ { return GetConfigValueBool(DeviceName, block, key, def); }
template<typename T>
- inline std::optional<T> configValue(const char *block, const char *key) = delete;
+ inline std::optional<T> configValue(const std::string_view block, const std::string_view key) = delete;
};
template<>
-inline std::optional<std::string> ALCdevice::configValue(const char *block, const char *key)
-{ return ConfigValueStr(DeviceName.c_str(), block, key); }
+inline std::optional<std::string> ALCdevice::configValue(const std::string_view block, const std::string_view key)
+{ return ConfigValueStr(DeviceName, block, key); }
template<>
-inline std::optional<int> ALCdevice::configValue(const char *block, const char *key)
-{ return ConfigValueInt(DeviceName.c_str(), block, key); }
+inline std::optional<int> ALCdevice::configValue(const std::string_view block, const std::string_view key)
+{ return ConfigValueInt(DeviceName, block, key); }
template<>
-inline std::optional<uint> ALCdevice::configValue(const char *block, const char *key)
-{ return ConfigValueUInt(DeviceName.c_str(), block, key); }
+inline std::optional<uint> ALCdevice::configValue(const std::string_view block, const std::string_view key)
+{ return ConfigValueUInt(DeviceName, block, key); }
template<>
-inline std::optional<float> ALCdevice::configValue(const char *block, const char *key)
-{ return ConfigValueFloat(DeviceName.c_str(), block, key); }
+inline std::optional<float> ALCdevice::configValue(const std::string_view block, const std::string_view key)
+{ return ConfigValueFloat(DeviceName, block, key); }
template<>
-inline std::optional<bool> ALCdevice::configValue(const char *block, const char *key)
-{ return ConfigValueBool(DeviceName.c_str(), block, key); }
+inline std::optional<bool> ALCdevice::configValue(const std::string_view block, const std::string_view key)
+{ return ConfigValueBool(DeviceName, block, key); }
/** Stores the latest ALC device error. */
void alcSetError(ALCdevice *device, ALCenum errorCode);
diff --git a/alc/panning.cpp b/alc/panning.cpp
index c0fe83ee..3b40687e 100644
--- a/alc/panning.cpp
+++ b/alc/panning.cpp
@@ -846,7 +846,7 @@ void InitHrtfPanning(ALCdevice *device)
*/
device->mRenderMode = RenderMode::Hrtf;
uint ambi_order{1};
- if(auto modeopt = device->configValue<std::string>(nullptr, "hrtf-mode"))
+ if(auto modeopt = device->configValue<std::string>({}, "hrtf-mode"))
{
struct HrtfModeEntry {
char name[7]; /* NOLINT(*-avoid-c-arrays) */
@@ -1024,7 +1024,7 @@ void aluInitRenderer(ALCdevice *device, int hrtf_id, std::optional<StereoEncodin
const bool stablize{device->RealOut.ChannelIndex[FrontCenter] != InvalidChannelIndex
&& device->RealOut.ChannelIndex[FrontLeft] != InvalidChannelIndex
&& device->RealOut.ChannelIndex[FrontRight] != InvalidChannelIndex
- && device->getConfigValueBool(nullptr, "front-stablizer", false) != 0};
+ && device->getConfigValueBool({}, "front-stablizer", false) != 0};
const bool hqdec{device->getConfigValueBool("decoder", "hq-mode", true) != 0};
InitPanning(device, hqdec, stablize, decoder);
if(decoder)
@@ -1093,7 +1093,7 @@ void aluInitRenderer(ALCdevice *device, int hrtf_id, std::optional<StereoEncodin
HrtfStore *hrtf{device->mHrtf.get()};
device->mIrSize = hrtf->mIrSize;
- if(auto hrtfsizeopt = device->configValue<uint>(nullptr, "hrtf-size"))
+ if(auto hrtfsizeopt = device->configValue<uint>({}, "hrtf-size"))
{
if(*hrtfsizeopt > 0 && *hrtfsizeopt < device->mIrSize)
device->mIrSize = maxu(*hrtfsizeopt, MinIrLength);
@@ -1132,7 +1132,7 @@ void aluInitRenderer(ALCdevice *device, int hrtf_id, std::optional<StereoEncodin
device->mRenderMode = RenderMode::Pairwise;
if(device->Type != DeviceType::Loopback)
{
- if(auto cflevopt = device->configValue<int>(nullptr, "cf_level"))
+ if(auto cflevopt = device->configValue<int>({}, "cf_level"))
{
if(*cflevopt > 0 && *cflevopt <= 6)
{