Use an optional for ConfigValueInt
This commit is contained in:
parent
689f70ce6d
commit
51f53afe12
33
Alc/alc.cpp
33
Alc/alc.cpp
@ -1061,11 +1061,12 @@ void alc_initconfig(void)
|
|||||||
FillCPUCaps(capfilter);
|
FillCPUCaps(capfilter);
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
RTPrioLevel = 1;
|
#define DEF_MIXER_PRIO 1
|
||||||
#else
|
#else
|
||||||
RTPrioLevel = 0;
|
#define DEF_MIXER_PRIO 0
|
||||||
#endif
|
#endif
|
||||||
ConfigValueInt(nullptr, nullptr, "rt-prio", &RTPrioLevel);
|
RTPrioLevel = ConfigValueInt(nullptr, nullptr, "rt-prio").value_or(DEF_MIXER_PRIO);
|
||||||
|
#undef DEF_MIXER_PRIO
|
||||||
|
|
||||||
aluInit();
|
aluInit();
|
||||||
aluInitMixer();
|
aluInitMixer();
|
||||||
@ -1864,10 +1865,10 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList)
|
|||||||
if(numMono > INT_MAX-numStereo)
|
if(numMono > INT_MAX-numStereo)
|
||||||
numMono = INT_MAX-numStereo;
|
numMono = INT_MAX-numStereo;
|
||||||
numMono += numStereo;
|
numMono += numStereo;
|
||||||
if(ConfigValueInt(devname, nullptr, "sources", &numMono))
|
if(auto srcsopt = ConfigValueInt(devname, nullptr, "sources"))
|
||||||
{
|
{
|
||||||
if(numMono <= 0)
|
if(*srcsopt <= 0) numMono = 256;
|
||||||
numMono = 256;
|
else numMono = *srcsopt;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
numMono = maxi(numMono, 256);
|
numMono = maxi(numMono, 256);
|
||||||
@ -1878,8 +1879,8 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList)
|
|||||||
device->NumMonoSources = numMono;
|
device->NumMonoSources = numMono;
|
||||||
device->NumStereoSources = numStereo;
|
device->NumStereoSources = numStereo;
|
||||||
|
|
||||||
if(ConfigValueInt(devname, nullptr, "sends", &new_sends))
|
if(auto sendsopt = ConfigValueInt(devname, nullptr, "sends"))
|
||||||
new_sends = mini(numSends, clampi(new_sends, 0, MAX_SENDS));
|
new_sends = mini(numSends, clampi(*sendsopt, 0, MAX_SENDS));
|
||||||
else
|
else
|
||||||
new_sends = numSends;
|
new_sends = numSends;
|
||||||
}
|
}
|
||||||
@ -2075,8 +2076,8 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList)
|
|||||||
|
|
||||||
if(GetConfigValueBool(device->DeviceName.c_str(), nullptr, "dither", 1))
|
if(GetConfigValueBool(device->DeviceName.c_str(), nullptr, "dither", 1))
|
||||||
{
|
{
|
||||||
ALint depth = 0;
|
ALint depth{
|
||||||
ConfigValueInt(device->DeviceName.c_str(), nullptr, "dither-depth", &depth);
|
ConfigValueInt(device->DeviceName.c_str(), nullptr, "dither-depth").value_or(0)};
|
||||||
if(depth <= 0)
|
if(depth <= 0)
|
||||||
{
|
{
|
||||||
switch(device->FmtType)
|
switch(device->FmtType)
|
||||||
@ -3834,10 +3835,8 @@ START_API_FUNC
|
|||||||
if(device->AuxiliaryEffectSlotMax == 0) device->AuxiliaryEffectSlotMax = 64;
|
if(device->AuxiliaryEffectSlotMax == 0) device->AuxiliaryEffectSlotMax = 64;
|
||||||
else device->AuxiliaryEffectSlotMax = minu(device->AuxiliaryEffectSlotMax, INT_MAX);
|
else device->AuxiliaryEffectSlotMax = minu(device->AuxiliaryEffectSlotMax, INT_MAX);
|
||||||
|
|
||||||
if(ConfigValueInt(deviceName, nullptr, "sends", &device->NumAuxSends))
|
if(auto sendsopt = ConfigValueInt(deviceName, nullptr, "sends"))
|
||||||
device->NumAuxSends = clampi(
|
device->NumAuxSends = clampi(DEFAULT_SENDS, 0, clampi(*sendsopt, 0, MAX_SENDS));
|
||||||
DEFAULT_SENDS, 0, clampi(device->NumAuxSends, 0, MAX_SENDS)
|
|
||||||
);
|
|
||||||
|
|
||||||
device->NumStereoSources = 1;
|
device->NumStereoSources = 1;
|
||||||
device->NumMonoSources = device->SourcesMax - device->NumStereoSources;
|
device->NumMonoSources = device->SourcesMax - device->NumStereoSources;
|
||||||
@ -4141,10 +4140,8 @@ START_API_FUNC
|
|||||||
if(device->AuxiliaryEffectSlotMax == 0) device->AuxiliaryEffectSlotMax = 64;
|
if(device->AuxiliaryEffectSlotMax == 0) device->AuxiliaryEffectSlotMax = 64;
|
||||||
else device->AuxiliaryEffectSlotMax = minu(device->AuxiliaryEffectSlotMax, INT_MAX);
|
else device->AuxiliaryEffectSlotMax = minu(device->AuxiliaryEffectSlotMax, INT_MAX);
|
||||||
|
|
||||||
if(ConfigValueInt(nullptr, nullptr, "sends", &device->NumAuxSends))
|
if(auto sendsopt = ConfigValueInt(nullptr, nullptr, "sends"))
|
||||||
device->NumAuxSends = clampi(
|
device->NumAuxSends = clampi(DEFAULT_SENDS, 0, clampi(*sendsopt, 0, MAX_SENDS));
|
||||||
DEFAULT_SENDS, 0, clampi(device->NumAuxSends, 0, MAX_SENDS)
|
|
||||||
);
|
|
||||||
|
|
||||||
device->NumStereoSources = 1;
|
device->NumStereoSources = 1;
|
||||||
device->NumMonoSources = device->SourcesMax - device->NumStereoSources;
|
device->NumMonoSources = device->SourcesMax - device->NumStereoSources;
|
||||||
|
@ -501,13 +501,12 @@ int ConfigValueStr(const char *devName, const char *blockName, const char *keyNa
|
|||||||
return 1;
|
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, "");
|
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 al::optional<int>{al::in_place, static_cast<int>(std::strtol(val, nullptr, 0))};
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int ConfigValueUInt(const char *devName, const char *blockName, const char *keyName, unsigned int *ret)
|
int ConfigValueUInt(const char *devName, const char *blockName, const char *keyName, unsigned int *ret)
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#ifndef ALCONFIG_H
|
#ifndef ALCONFIG_H
|
||||||
#define ALCONFIG_H
|
#define ALCONFIG_H
|
||||||
|
|
||||||
|
#include "aloptional.h"
|
||||||
|
|
||||||
void ReadALConfig();
|
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 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 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 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 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);
|
int ConfigValueBool(const char *devName, const char *blockName, const char *keyName, int *ret);
|
||||||
|
@ -129,9 +129,9 @@ ALCenum PortPlayback::open(const ALCchar *name)
|
|||||||
|
|
||||||
mUpdateSize = mDevice->UpdateSize;
|
mUpdateSize = mDevice->UpdateSize;
|
||||||
|
|
||||||
mParams.device = -1;
|
auto devidopt = ConfigValueInt(nullptr, "port", "device");
|
||||||
if(!ConfigValueInt(nullptr, "port", "device", &mParams.device) || mParams.device < 0)
|
if(devidopt && *devidopt >= 0) mParams.device = *devidopt;
|
||||||
mParams.device = Pa_GetDefaultOutputDevice();
|
else mParams.device = Pa_GetDefaultOutputDevice();
|
||||||
mParams.suggestedLatency = mDevice->BufferSize / static_cast<double>(mDevice->Frequency);
|
mParams.suggestedLatency = mDevice->BufferSize / static_cast<double>(mDevice->Frequency);
|
||||||
mParams.hostApiSpecificStreamInfo = nullptr;
|
mParams.hostApiSpecificStreamInfo = nullptr;
|
||||||
|
|
||||||
@ -298,9 +298,9 @@ ALCenum PortCapture::open(const ALCchar *name)
|
|||||||
mRing = CreateRingBuffer(samples, frame_size, false);
|
mRing = CreateRingBuffer(samples, frame_size, false);
|
||||||
if(!mRing) return ALC_INVALID_VALUE;
|
if(!mRing) return ALC_INVALID_VALUE;
|
||||||
|
|
||||||
mParams.device = -1;
|
auto devidopt = ConfigValueInt(nullptr, "port", "capture");
|
||||||
if(!ConfigValueInt(nullptr, "port", "capture", &mParams.device) || mParams.device < 0)
|
if(devidopt && *devidopt >= 0) mParams.device = *devidopt;
|
||||||
mParams.device = Pa_GetDefaultInputDevice();
|
else mParams.device = Pa_GetDefaultOutputDevice();
|
||||||
mParams.suggestedLatency = 0.0f;
|
mParams.suggestedLatency = 0.0f;
|
||||||
mParams.hostApiSpecificStreamInfo = nullptr;
|
mParams.hostApiSpecificStreamInfo = nullptr;
|
||||||
|
|
||||||
|
@ -900,18 +900,20 @@ no_hrtf:
|
|||||||
|
|
||||||
device->mRenderMode = StereoPair;
|
device->mRenderMode = StereoPair;
|
||||||
|
|
||||||
int bs2blevel{((headphones && hrtf_appreq != Hrtf_Disable) ||
|
|
||||||
(hrtf_appreq == Hrtf_Enable)) ? 5 : 0};
|
|
||||||
if(device->Type != Loopback)
|
if(device->Type != Loopback)
|
||||||
ConfigValueInt(device->DeviceName.c_str(), nullptr, "cf_level", &bs2blevel);
|
|
||||||
if(bs2blevel > 0 && bs2blevel <= 6)
|
|
||||||
{
|
{
|
||||||
device->Bs2b = al::make_unique<bs2b>();
|
if(auto cflevopt = ConfigValueInt(device->DeviceName.c_str(), nullptr, "cf_level"))
|
||||||
bs2b_set_params(device->Bs2b.get(), bs2blevel, device->Frequency);
|
{
|
||||||
TRACE("BS2B enabled\n");
|
if(*cflevopt > 0 && *cflevopt <= 6)
|
||||||
InitPanning(device);
|
{
|
||||||
device->PostProcess = ProcessBs2b;
|
device->Bs2b = al::make_unique<bs2b>();
|
||||||
return;
|
bs2b_set_params(device->Bs2b.get(), *cflevopt, device->Frequency);
|
||||||
|
TRACE("BS2B enabled\n");
|
||||||
|
InitPanning(device);
|
||||||
|
device->PostProcess = ProcessBs2b;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *mode;
|
const char *mode;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user