aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Robinson <chris.kcat@gmail.com>2021-07-31 14:24:49 -0700
committerChris Robinson <chris.kcat@gmail.com>2021-07-31 14:24:49 -0700
commit0a0849db997df2015223bfd43cb7490fc8cd601e (patch)
treed5ea8c1e3bf0d905e9ec36d43ab0ad5a96fb68f4
parent440b59704c82684786bf7e251b4882f2a12c4c06 (diff)
Use an optional bool instead of two tri-state enums
-rw-r--r--alc/alc.cpp18
-rw-r--r--alc/alu.h11
-rw-r--r--alc/panning.cpp93
3 files changed, 49 insertions, 73 deletions
diff --git a/alc/alc.cpp b/alc/alc.cpp
index 21c95cbd..8c09e474 100644
--- a/alc/alc.cpp
+++ b/alc/alc.cpp
@@ -1514,10 +1514,9 @@ static inline void UpdateClockBase(ALCdevice *device)
*/
ALCenum UpdateDeviceParams(ALCdevice *device, const int *attrList)
{
- HrtfRequestMode hrtf_userreq{Hrtf_Default};
- HrtfRequestMode hrtf_appreq{Hrtf_Default};
ALCenum gainLimiter{device->LimiterState};
uint new_sends{device->NumAuxSends};
+ al::optional<bool> hrtfreq{};
DevFmtChannels oldChans;
DevFmtType oldType;
int hrtf_id{-1};
@@ -1602,11 +1601,11 @@ ALCenum UpdateDeviceParams(ALCdevice *device, const int *attrList)
case ALC_HRTF_SOFT:
TRACE_ATTR(ALC_HRTF_SOFT, attrList[attrIdx + 1]);
if(attrList[attrIdx + 1] == ALC_FALSE)
- hrtf_appreq = Hrtf_Disable;
+ hrtfreq = al::make_optional(false);
else if(attrList[attrIdx + 1] == ALC_TRUE)
- hrtf_appreq = Hrtf_Enable;
+ hrtfreq = al::make_optional(true);
else
- hrtf_appreq = Hrtf_Default;
+ hrtfreq = al::nullopt;
break;
case ALC_HRTF_ID_SOFT:
@@ -1761,14 +1760,15 @@ ALCenum UpdateDeviceParams(ALCdevice *device, const int *attrList)
{
const char *hrtf{hrtfopt->c_str()};
if(al::strcasecmp(hrtf, "true") == 0)
- hrtf_userreq = Hrtf_Enable;
+ hrtfreq = al::make_optional(true);
else if(al::strcasecmp(hrtf, "false") == 0)
- hrtf_userreq = Hrtf_Disable;
+ hrtfreq = al::make_optional(false);
else if(al::strcasecmp(hrtf, "auto") != 0)
ERR("Unexpected hrtf value: %s\n", hrtf);
}
- if(hrtf_userreq == Hrtf_Enable || (hrtf_userreq != Hrtf_Disable && hrtf_appreq == Hrtf_Enable))
+ /* If the app or user wants HRTF, try to set stereo playback. */
+ if(hrtfreq && hrtfreq.value())
{
device->FmtChans = DevFmtStereo;
device->Flags.set(ChannelsRequest);
@@ -1829,7 +1829,7 @@ ALCenum UpdateDeviceParams(ALCdevice *device, const int *attrList)
case DevFmtAmbi3D: break;
}
- aluInitRenderer(device, hrtf_id, hrtf_appreq, hrtf_userreq);
+ aluInitRenderer(device, hrtf_id, hrtfreq);
device->NumAuxSends = new_sends;
TRACE("Max sources: %d (%d + %d), effect slots: %d, sends: %d\n",
diff --git a/alc/alu.h b/alc/alu.h
index 67c7c410..05d3b92c 100644
--- a/alc/alu.h
+++ b/alc/alu.h
@@ -1,6 +1,8 @@
#ifndef ALU_H
#define ALU_H
+#include "aloptional.h"
+
struct ALCcontext;
struct ALCdevice;
struct EffectSlot;
@@ -11,12 +13,6 @@ constexpr float GainMixMax{1000.0f}; /* +60dB */
constexpr float AirAbsorbGainHF{0.99426f}; /* -0.05dB */
-enum HrtfRequestMode {
- Hrtf_Default = 0,
- Hrtf_Enable = 1,
- Hrtf_Disable = 2,
-};
-
void aluInit(void);
/* aluInitRenderer
@@ -24,8 +20,7 @@ void aluInit(void);
* Set up the appropriate panning method and mixing method given the device
* properties.
*/
-void aluInitRenderer(ALCdevice *device, int hrtf_id, HrtfRequestMode hrtf_appreq,
- HrtfRequestMode hrtf_userreq);
+void aluInitRenderer(ALCdevice *device, int hrtf_id, al::optional<bool> hrtfreq);
void aluInitEffectPanning(EffectSlot *slot, ALCcontext *context);
diff --git a/alc/panning.cpp b/alc/panning.cpp
index be7f13e1..45794454 100644
--- a/alc/panning.cpp
+++ b/alc/panning.cpp
@@ -827,8 +827,7 @@ void InitUhjPanning(ALCdevice *device)
} // namespace
-void aluInitRenderer(ALCdevice *device, int hrtf_id, HrtfRequestMode hrtf_appreq,
- HrtfRequestMode hrtf_userreq)
+void aluInitRenderer(ALCdevice *device, int hrtf_id, al::optional<bool> hrtfreq)
{
/* Hold the HRTF the device last used, in case it's used again. */
HrtfStorePtr old_hrtf{std::move(device->mHrtf)};
@@ -843,7 +842,7 @@ void aluInitRenderer(ALCdevice *device, int hrtf_id, HrtfRequestMode hrtf_appreq
if(device->FmtChans != DevFmtStereo)
{
old_hrtf = nullptr;
- if(hrtf_appreq == Hrtf_Enable)
+ if(hrtfreq && hrtfreq.value())
device->mHrtfStatus = ALC_HRTF_UNSUPPORTED_FORMAT_SOFT;
const char *layout{nullptr};
@@ -942,76 +941,58 @@ void aluInitRenderer(ALCdevice *device, int hrtf_id, HrtfRequestMode hrtf_appreq
}
}
- if(hrtf_userreq == Hrtf_Default)
- {
- bool usehrtf = (headphones && hrtf_appreq != Hrtf_Disable) ||
- (hrtf_appreq == Hrtf_Enable);
- if(!usehrtf) goto no_hrtf;
-
- device->mHrtfStatus = ALC_HRTF_ENABLED_SOFT;
- if(headphones && hrtf_appreq != Hrtf_Disable)
- device->mHrtfStatus = ALC_HRTF_HEADPHONES_DETECTED_SOFT;
- }
- else
- {
- if(hrtf_userreq != Hrtf_Enable)
- {
- if(hrtf_appreq == Hrtf_Enable)
- device->mHrtfStatus = ALC_HRTF_DENIED_SOFT;
- goto no_hrtf;
- }
- device->mHrtfStatus = ALC_HRTF_REQUIRED_SOFT;
- }
-
- if(device->mHrtfList.empty())
- device->enumerateHrtfs();
-
- if(hrtf_id >= 0 && static_cast<uint>(hrtf_id) < device->mHrtfList.size())
+ /* If there's no request for HRTF and the device is headphones, or if HRTF
+ * is explicitly requested, try to enable it.
+ */
+ if((!hrtfreq && headphones) || (hrtfreq && hrtfreq.value()))
{
- const std::string &hrtfname = device->mHrtfList[static_cast<uint>(hrtf_id)];
- if(HrtfStorePtr hrtf{GetLoadedHrtf(hrtfname, device->Frequency)})
- {
- device->mHrtf = std::move(hrtf);
- device->mHrtfName = hrtfname;
- }
- }
+ if(device->mHrtfList.empty())
+ device->enumerateHrtfs();
- if(!device->mHrtf)
- {
- for(const auto &hrtfname : device->mHrtfList)
+ if(hrtf_id >= 0 && static_cast<uint>(hrtf_id) < device->mHrtfList.size())
{
+ const std::string &hrtfname = device->mHrtfList[static_cast<uint>(hrtf_id)];
if(HrtfStorePtr hrtf{GetLoadedHrtf(hrtfname, device->Frequency)})
{
device->mHrtf = std::move(hrtf);
device->mHrtfName = hrtfname;
- break;
}
}
- }
- if(device->mHrtf)
- {
- old_hrtf = nullptr;
-
- HrtfStore *hrtf{device->mHrtf.get()};
- device->mIrSize = hrtf->irSize;
- if(auto hrtfsizeopt = device->configValue<uint>(nullptr, "hrtf-size"))
+ if(!device->mHrtf)
{
- if(*hrtfsizeopt > 0 && *hrtfsizeopt < device->mIrSize)
- device->mIrSize = maxu(*hrtfsizeopt, MinIrLength);
+ for(const auto &hrtfname : device->mHrtfList)
+ {
+ if(HrtfStorePtr hrtf{GetLoadedHrtf(hrtfname, device->Frequency)})
+ {
+ device->mHrtf = std::move(hrtf);
+ device->mHrtfName = hrtfname;
+ break;
+ }
+ }
}
- InitHrtfPanning(device);
- device->PostProcess = &ALCdevice::ProcessHrtf;
- return;
- }
- device->mHrtfStatus = ALC_HRTF_UNSUPPORTED_FORMAT_SOFT;
+ if(device->mHrtf)
+ {
+ old_hrtf = nullptr;
+
+ HrtfStore *hrtf{device->mHrtf.get()};
+ device->mIrSize = hrtf->irSize;
+ if(auto hrtfsizeopt = device->configValue<uint>(nullptr, "hrtf-size"))
+ {
+ if(*hrtfsizeopt > 0 && *hrtfsizeopt < device->mIrSize)
+ device->mIrSize = maxu(*hrtfsizeopt, MinIrLength);
+ }
-no_hrtf:
+ InitHrtfPanning(device);
+ device->PostProcess = &ALCdevice::ProcessHrtf;
+ device->mHrtfStatus = ALC_HRTF_ENABLED_SOFT;
+ return;
+ }
+ }
old_hrtf = nullptr;
device->mRenderMode = RenderMode::Pairwise;
-
if(device->Type != DeviceType::Loopback)
{
if(auto cflevopt = device->configValue<int>(nullptr, "cf_level"))