aboutsummaryrefslogtreecommitdiffstats
path: root/alc
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2019-11-28 14:51:45 -0800
committerChris Robinson <[email protected]>2019-11-28 14:51:45 -0800
commit846a9979567ac9033ccb5ca96f683b21555b2708 (patch)
tree6d856139e396aa2714ff75336ac495225a76d811 /alc
parent4eb9a0b835dda89a833d9f9d00ed94f46b471e9f (diff)
Add an option to limit the HRTF's IR size
Diffstat (limited to 'alc')
-rw-r--r--alc/hrtf.cpp16
-rw-r--r--alc/hrtf.h2
-rw-r--r--alc/panning.cpp8
3 files changed, 17 insertions, 9 deletions
diff --git a/alc/hrtf.cpp b/alc/hrtf.cpp
index f8df522b..1b3c47e3 100644
--- a/alc/hrtf.cpp
+++ b/alc/hrtf.cpp
@@ -342,9 +342,6 @@ void BuildBFormatHrtf(const HrtfStore *Hrtf, DirectHrtfState *state,
Hrtf->delays[idx[0]][1]*blend[0] + Hrtf->delays[idx[1]][1]*blend[1] +
Hrtf->delays[idx[2]][1]*blend[2] + Hrtf->delays[idx[3]][1]*blend[3]);
- const size_t irSize{Hrtf->irSize};
- ASSUME(irSize >= MIN_IR_SIZE);
-
/* Calculate the blended HRIR coefficients. */
double *coeffout{al::assume_aligned<16>(&res.hrir[0][0])};
std::fill(coeffout, coeffout + HRIR_LENGTH*2, 0.0);
@@ -1264,7 +1261,7 @@ al::vector<std::string> EnumerateHrtf(const char *devname)
return list;
}
-HrtfStore *GetLoadedHrtf(const std::string &name, ALuint devrate)
+HrtfStore *GetLoadedHrtf(const std::string &name, const char *devname, const ALuint devrate)
{
std::lock_guard<std::mutex> _{EnumeratedHrtfLock};
auto entry_iter = std::find_if(EnumeratedHrtfs.cbegin(), EnumeratedHrtfs.cend(),
@@ -1362,9 +1359,9 @@ HrtfStore *GetLoadedHrtf(const std::string &name, ALuint devrate)
rs.init(hrtf->sampleRate, devrate);
for(size_t i{0};i < irCount;++i)
{
+ HrirArray &coeffs = const_cast<HrirArray&>(hrtf->coeffs[i]);
for(size_t j{0};j < 2;++j)
{
- HrirArray &coeffs = const_cast<HrirArray&>(hrtf->coeffs[i]);
std::transform(coeffs.cbegin(), coeffs.cend(), inout[0].begin(),
[j](const float2 &in) noexcept -> double { return in[j]; });
rs.process(HRIR_LENGTH, inout[0].data(), HRIR_LENGTH, inout[1].data());
@@ -1383,6 +1380,15 @@ HrtfStore *GetLoadedHrtf(const std::string &name, ALuint devrate)
hrtf->sampleRate = devrate;
}
+ if(auto hrtfsizeopt = ConfigValueUInt(devname, nullptr, "hrtf-size"))
+ {
+ if(*hrtfsizeopt > 0 && *hrtfsizeopt < hrtf->irSize)
+ {
+ hrtf->irSize = maxu(*hrtfsizeopt, MIN_IR_SIZE);
+ hrtf->irSize -= hrtf->irSize % MOD_IR_SIZE;
+ }
+ }
+
TRACE("Loaded HRTF %s for sample rate %uhz, %u-sample filter\n", name.c_str(),
hrtf->sampleRate, hrtf->irSize);
LoadedHrtfs.emplace_back(LoadedHrtf{fname, std::move(hrtf)});
diff --git a/alc/hrtf.h b/alc/hrtf.h
index 46160409..7a69fcb1 100644
--- a/alc/hrtf.h
+++ b/alc/hrtf.h
@@ -89,7 +89,7 @@ struct AngularPoint {
al::vector<std::string> EnumerateHrtf(const char *devname);
-HrtfStore *GetLoadedHrtf(const std::string &name, ALuint devrate);
+HrtfStore *GetLoadedHrtf(const std::string &name, const char *devname, const ALuint devrate);
void GetHrtfCoeffs(const HrtfStore *Hrtf, ALfloat elevation, ALfloat azimuth, ALfloat distance,
ALfloat spread, HrirArray &coeffs, ALsizei (&delays)[2]);
diff --git a/alc/panning.cpp b/alc/panning.cpp
index 0cf91ac1..38674f5e 100644
--- a/alc/panning.cpp
+++ b/alc/panning.cpp
@@ -812,8 +812,9 @@ void aluInitRenderer(ALCdevice *device, ALint hrtf_id, HrtfRequestMode hrtf_appr
if(hrtf_id >= 0 && static_cast<ALuint>(hrtf_id) < device->HrtfList.size())
{
+ const char *devname{device->DeviceName.c_str()};
const std::string &hrtfname = device->HrtfList[static_cast<ALuint>(hrtf_id)];
- if(HrtfStore *hrtf{GetLoadedHrtf(hrtfname, device->Frequency)})
+ if(HrtfStore *hrtf{GetLoadedHrtf(hrtfname, devname, device->Frequency)})
{
device->mHrtf = hrtf;
device->HrtfName = hrtfname;
@@ -822,9 +823,10 @@ void aluInitRenderer(ALCdevice *device, ALint hrtf_id, HrtfRequestMode hrtf_appr
if(!device->mHrtf)
{
- auto find_hrtf = [device](const std::string &hrtfname) -> bool
+ const char *devname{device->DeviceName.c_str()};
+ auto find_hrtf = [device,devname](const std::string &hrtfname) -> bool
{
- HrtfStore *hrtf{GetLoadedHrtf(hrtfname, device->Frequency)};
+ HrtfStore *hrtf{GetLoadedHrtf(hrtfname, devname, device->Frequency)};
if(!hrtf) return false;
device->mHrtf = hrtf;
device->HrtfName = hrtfname;