Avoid using config methods in hrtf.cpp
This commit is contained in:
parent
6ae12d0b85
commit
d6d6fd7378
31
alc/alc.cpp
31
alc/alc.cpp
@ -1927,7 +1927,7 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const int *attrList)
|
||||
/*************************************************************************
|
||||
* Update device format request if HRTF is requested
|
||||
*/
|
||||
device->HrtfStatus = ALC_HRTF_DISABLED_SOFT;
|
||||
device->mHrtfStatus = ALC_HRTF_DISABLED_SOFT;
|
||||
if(device->Type != DeviceType::Loopback)
|
||||
{
|
||||
if(auto hrtfopt = ConfigValueStr(device->DeviceName.c_str(), nullptr, "hrtf"))
|
||||
@ -2331,6 +2331,19 @@ ALCdevice::~ALCdevice()
|
||||
if(oldarray != &EmptyContextArray) delete oldarray;
|
||||
}
|
||||
|
||||
void ALCdevice::enumerateHrtfs()
|
||||
{
|
||||
mHrtfList = EnumerateHrtf(ConfigValueStr(DeviceName.c_str(), nullptr, "hrtf-paths"));
|
||||
if(auto defhrtfopt = ConfigValueStr(DeviceName.c_str(), nullptr, "default-hrtf"))
|
||||
{
|
||||
auto iter = std::find(mHrtfList.begin(), mHrtfList.end(), *defhrtfopt);
|
||||
if(iter == mHrtfList.end())
|
||||
WARN("Failed to find default HRTF \"%s\"\n", defhrtfopt->c_str());
|
||||
else if(iter != mHrtfList.begin())
|
||||
std::rotate(mHrtfList.begin(), iter, iter+1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/** Checks if the device handle is valid, and returns a new reference if so. */
|
||||
static DeviceRef VerifyDevice(ALCdevice *device)
|
||||
@ -2732,7 +2745,7 @@ START_API_FUNC
|
||||
if(DeviceRef dev{VerifyDevice(Device)})
|
||||
{
|
||||
std::lock_guard<std::mutex> _{dev->StateLock};
|
||||
value = (dev->mHrtf ? dev->HrtfName.c_str() : "");
|
||||
value = (dev->mHrtf ? dev->mHrtfName.c_str() : "");
|
||||
}
|
||||
else
|
||||
alcSetError(nullptr, ALC_INVALID_DEVICE);
|
||||
@ -2930,7 +2943,7 @@ static size_t GetIntegerv(ALCdevice *device, ALCenum param, const al::span<int>
|
||||
values[i++] = (device->mHrtf ? ALC_TRUE : ALC_FALSE);
|
||||
|
||||
values[i++] = ALC_HRTF_STATUS_SOFT;
|
||||
values[i++] = device->HrtfStatus;
|
||||
values[i++] = device->mHrtfStatus;
|
||||
|
||||
values[i++] = ALC_OUTPUT_LIMITER_SOFT;
|
||||
values[i++] = device->Limiter ? ALC_TRUE : ALC_FALSE;
|
||||
@ -3052,14 +3065,14 @@ static size_t GetIntegerv(ALCdevice *device, ALCenum param, const al::span<int>
|
||||
return 1;
|
||||
|
||||
case ALC_HRTF_STATUS_SOFT:
|
||||
values[0] = device->HrtfStatus;
|
||||
values[0] = device->mHrtfStatus;
|
||||
return 1;
|
||||
|
||||
case ALC_NUM_HRTF_SPECIFIERS_SOFT:
|
||||
{
|
||||
std::lock_guard<std::mutex> _{device->StateLock};
|
||||
device->HrtfList = EnumerateHrtf(device->DeviceName.c_str());
|
||||
values[0] = static_cast<int>(minz(device->HrtfList.size(),
|
||||
device->enumerateHrtfs();
|
||||
values[0] = static_cast<int>(minz(device->mHrtfList.size(),
|
||||
std::numeric_limits<int>::max()));
|
||||
}
|
||||
return 1;
|
||||
@ -3170,7 +3183,7 @@ START_API_FUNC
|
||||
values[i++] = (dev->mHrtf ? ALC_TRUE : ALC_FALSE);
|
||||
|
||||
values[i++] = ALC_HRTF_STATUS_SOFT;
|
||||
values[i++] = dev->HrtfStatus;
|
||||
values[i++] = dev->mHrtfStatus;
|
||||
|
||||
values[i++] = ALC_OUTPUT_LIMITER_SOFT;
|
||||
values[i++] = dev->Limiter ? ALC_TRUE : ALC_FALSE;
|
||||
@ -4115,8 +4128,8 @@ START_API_FUNC
|
||||
else switch(paramName)
|
||||
{
|
||||
case ALC_HRTF_SPECIFIER_SOFT:
|
||||
if(index >= 0 && static_cast<uint>(index) < dev->HrtfList.size())
|
||||
return dev->HrtfList[static_cast<uint>(index)].c_str();
|
||||
if(index >= 0 && static_cast<uint>(index) < dev->mHrtfList.size())
|
||||
return dev->mHrtfList[static_cast<uint>(index)].c_str();
|
||||
alcSetError(dev.get(), ALC_INVALID_VALUE);
|
||||
break;
|
||||
|
||||
|
@ -291,9 +291,9 @@ struct ALCdevice : public al::intrusive_ref<ALCdevice> {
|
||||
ALCuint NumStereoSources{};
|
||||
ALCuint NumAuxSends{};
|
||||
|
||||
std::string HrtfName;
|
||||
al::vector<std::string> HrtfList;
|
||||
ALCenum HrtfStatus{ALC_FALSE};
|
||||
std::string mHrtfName;
|
||||
al::vector<std::string> mHrtfList;
|
||||
ALCenum mHrtfStatus{ALC_FALSE};
|
||||
|
||||
ALCenum LimiterState{ALC_DONT_CARE_SOFT};
|
||||
|
||||
@ -317,6 +317,8 @@ struct ALCdevice : public al::intrusive_ref<ALCdevice> {
|
||||
ALCdevice& operator=(const ALCdevice&) = delete;
|
||||
~ALCdevice();
|
||||
|
||||
void enumerateHrtfs();
|
||||
|
||||
uint bytesFromFmt() const noexcept { return BytesFromDevFmt(FmtType); }
|
||||
uint channelsFromFmt() const noexcept { return ChannelsFromDevFmt(FmtChans, mAmbiOrder); }
|
||||
uint frameSizeFromFmt() const noexcept { return bytesFromFmt() * channelsFromFmt(); }
|
||||
|
14
alc/hrtf.cpp
14
alc/hrtf.cpp
@ -42,7 +42,6 @@
|
||||
|
||||
#include "albit.h"
|
||||
#include "albyte.h"
|
||||
#include "alconfig.h"
|
||||
#include "alfstream.h"
|
||||
#include "almalloc.h"
|
||||
#include "alnumeric.h"
|
||||
@ -1217,13 +1216,13 @@ al::span<const char> GetResource(int name)
|
||||
} // namespace
|
||||
|
||||
|
||||
al::vector<std::string> EnumerateHrtf(const char *devname)
|
||||
al::vector<std::string> EnumerateHrtf(al::optional<std::string> pathopt)
|
||||
{
|
||||
std::lock_guard<std::mutex> _{EnumeratedHrtfLock};
|
||||
EnumeratedHrtfs.clear();
|
||||
|
||||
bool usedefaults{true};
|
||||
if(auto pathopt = ConfigValueStr(devname, nullptr, "hrtf-paths"))
|
||||
if(pathopt)
|
||||
{
|
||||
const char *pathlist{pathopt->c_str()};
|
||||
while(pathlist && *pathlist)
|
||||
@ -1271,15 +1270,6 @@ al::vector<std::string> EnumerateHrtf(const char *devname)
|
||||
for(auto &entry : EnumeratedHrtfs)
|
||||
list.emplace_back(entry.mDispName);
|
||||
|
||||
if(auto defhrtfopt = ConfigValueStr(devname, nullptr, "default-hrtf"))
|
||||
{
|
||||
auto iter = std::find(list.begin(), list.end(), *defhrtfopt);
|
||||
if(iter == list.end())
|
||||
WARN("Failed to find default HRTF \"%s\"\n", defhrtfopt->c_str());
|
||||
else if(iter != list.begin())
|
||||
std::rotate(list.begin(), iter, iter+1);
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
|
@ -7,6 +7,7 @@
|
||||
#include <string>
|
||||
|
||||
#include "almalloc.h"
|
||||
#include "aloptional.h"
|
||||
#include "alspan.h"
|
||||
#include "atomic.h"
|
||||
#include "core/ambidefs.h"
|
||||
@ -81,7 +82,7 @@ struct DirectHrtfState {
|
||||
};
|
||||
|
||||
|
||||
al::vector<std::string> EnumerateHrtf(const char *devname);
|
||||
al::vector<std::string> EnumerateHrtf(al::optional<std::string> pathopt);
|
||||
HrtfStorePtr GetLoadedHrtf(const std::string &name, const uint devrate);
|
||||
|
||||
void GetHrtfCoeffs(const HrtfStore *Hrtf, float elevation, float azimuth, float distance,
|
||||
|
@ -788,7 +788,7 @@ void InitHrtfPanning(ALCdevice *device)
|
||||
((ambi_order%10) == 2) ? "nd" :
|
||||
((ambi_order%10) == 3) ? "rd" : "th",
|
||||
(device->mRenderMode == RenderMode::Hrtf) ? "+ Full " : "",
|
||||
device->HrtfName.c_str());
|
||||
device->mHrtfName.c_str());
|
||||
|
||||
al::span<const AngularPoint> AmbiPoints{AmbiPoints1O};
|
||||
const float (*AmbiMatrix)[MaxAmbiChannels]{AmbiMatrix1O};
|
||||
@ -844,7 +844,7 @@ void aluInitRenderer(ALCdevice *device, int hrtf_id, HrtfRequestMode hrtf_appreq
|
||||
device->mHrtfState = nullptr;
|
||||
device->mHrtf = nullptr;
|
||||
device->mIrSize = 0;
|
||||
device->HrtfName.clear();
|
||||
device->mHrtfName.clear();
|
||||
device->mXOverFreq = 400.0f;
|
||||
device->mRenderMode = RenderMode::Normal;
|
||||
|
||||
@ -852,7 +852,7 @@ void aluInitRenderer(ALCdevice *device, int hrtf_id, HrtfRequestMode hrtf_appreq
|
||||
{
|
||||
old_hrtf = nullptr;
|
||||
if(hrtf_appreq == Hrtf_Enable)
|
||||
device->HrtfStatus = ALC_HRTF_UNSUPPORTED_FORMAT_SOFT;
|
||||
device->mHrtfStatus = ALC_HRTF_UNSUPPORTED_FORMAT_SOFT;
|
||||
|
||||
const char *layout{nullptr};
|
||||
switch(device->FmtChans)
|
||||
@ -933,42 +933,42 @@ void aluInitRenderer(ALCdevice *device, int hrtf_id, HrtfRequestMode hrtf_appreq
|
||||
(hrtf_appreq == Hrtf_Enable);
|
||||
if(!usehrtf) goto no_hrtf;
|
||||
|
||||
device->HrtfStatus = ALC_HRTF_ENABLED_SOFT;
|
||||
device->mHrtfStatus = ALC_HRTF_ENABLED_SOFT;
|
||||
if(headphones && hrtf_appreq != Hrtf_Disable)
|
||||
device->HrtfStatus = ALC_HRTF_HEADPHONES_DETECTED_SOFT;
|
||||
device->mHrtfStatus = ALC_HRTF_HEADPHONES_DETECTED_SOFT;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(hrtf_userreq != Hrtf_Enable)
|
||||
{
|
||||
if(hrtf_appreq == Hrtf_Enable)
|
||||
device->HrtfStatus = ALC_HRTF_DENIED_SOFT;
|
||||
device->mHrtfStatus = ALC_HRTF_DENIED_SOFT;
|
||||
goto no_hrtf;
|
||||
}
|
||||
device->HrtfStatus = ALC_HRTF_REQUIRED_SOFT;
|
||||
device->mHrtfStatus = ALC_HRTF_REQUIRED_SOFT;
|
||||
}
|
||||
|
||||
if(device->HrtfList.empty())
|
||||
device->HrtfList = EnumerateHrtf(device->DeviceName.c_str());
|
||||
if(device->mHrtfList.empty())
|
||||
device->enumerateHrtfs();
|
||||
|
||||
if(hrtf_id >= 0 && static_cast<uint>(hrtf_id) < device->HrtfList.size())
|
||||
if(hrtf_id >= 0 && static_cast<uint>(hrtf_id) < device->mHrtfList.size())
|
||||
{
|
||||
const std::string &hrtfname = device->HrtfList[static_cast<uint>(hrtf_id)];
|
||||
const std::string &hrtfname = device->mHrtfList[static_cast<uint>(hrtf_id)];
|
||||
if(HrtfStorePtr hrtf{GetLoadedHrtf(hrtfname, device->Frequency)})
|
||||
{
|
||||
device->mHrtf = std::move(hrtf);
|
||||
device->HrtfName = hrtfname;
|
||||
device->mHrtfName = hrtfname;
|
||||
}
|
||||
}
|
||||
|
||||
if(!device->mHrtf)
|
||||
{
|
||||
for(const auto &hrtfname : device->HrtfList)
|
||||
for(const auto &hrtfname : device->mHrtfList)
|
||||
{
|
||||
if(HrtfStorePtr hrtf{GetLoadedHrtf(hrtfname, device->Frequency)})
|
||||
{
|
||||
device->mHrtf = std::move(hrtf);
|
||||
device->HrtfName = hrtfname;
|
||||
device->mHrtfName = hrtfname;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -990,7 +990,7 @@ void aluInitRenderer(ALCdevice *device, int hrtf_id, HrtfRequestMode hrtf_appreq
|
||||
device->PostProcess = &ALCdevice::ProcessHrtf;
|
||||
return;
|
||||
}
|
||||
device->HrtfStatus = ALC_HRTF_UNSUPPORTED_FORMAT_SOFT;
|
||||
device->mHrtfStatus = ALC_HRTF_UNSUPPORTED_FORMAT_SOFT;
|
||||
|
||||
no_hrtf:
|
||||
old_hrtf = nullptr;
|
||||
|
Loading…
x
Reference in New Issue
Block a user