Add an option to limit the HRTF's IR size

This commit is contained in:
Chris Robinson
2019-11-28 14:51:45 -08:00
parent 4eb9a0b835
commit 846a997956
4 changed files with 24 additions and 9 deletions
+11 -5
View File
@@ -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)});
+1 -1
View File
@@ -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]);
+5 -3
View File
@@ -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;
+7
View File
@@ -128,6 +128,13 @@
# usage (still less than "full", given some number of active sources).
#hrtf-mode = full
## hrtf-size:
# Specifies the impulse response size, in samples, for the HRTF filter. Larger
# values increase the filter quality, while smaller values reduce processing
# cost. A value of 0 (default) uses the full filter size in the dataset, and
# the default dataset has a filter size of 32 samples at 44.1khz.
#hrtf-size = 0
## default-hrtf:
# Specifies the default HRTF to use. When multiple HRTFs are available, this
# determines the preferred one to use if none are specifically requested. Note