From 00d80497d8b3653448a01f82c87fe5c59d157e67 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Sun, 12 Jan 2020 11:24:30 -0800 Subject: [PATCH] Warn when resampled HRIR delays get clamped --- alc/hrtf.cpp | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/alc/hrtf.cpp b/alc/hrtf.cpp index 2ac4c539..05222c7a 100644 --- a/alc/hrtf.cpp +++ b/alc/hrtf.cpp @@ -1337,13 +1337,27 @@ HrtfStore *GetLoadedHrtf(const std::string &name, const char *devname, const ALu } rs = {}; + size_t max_clipped{0}; + uint64_t max_delay{0}; const ALuint srate{hrtf->sampleRate}; for(size_t i{0};i < irCount;++i) { for(ALubyte &delay : const_cast(hrtf->delays[i])) - delay = static_cast(minu64(MAX_HRIR_DELAY*HRIR_DELAY_FRACONE, - (uint64_t{delay}*devrate + srate/2) / srate)); + { + const uint64_t new_delay{(uint64_t{delay}*devrate + srate/2) / srate}; + max_delay = maxu64(max_delay, new_delay); + if(new_delay <= MAX_HRIR_DELAY*HRIR_DELAY_FRACONE) + delay = static_cast(new_delay); + else + { + ++max_clipped; + delay = MAX_HRIR_DELAY*HRIR_DELAY_FRACONE; + } + } } + if(max_clipped > 0) + WARN("%zu delay%s clamped (max: %.2f)\n", max_clipped, (max_clipped==1)?"":"s", + static_cast(max_delay) / double{HRIR_DELAY_FRACONE}); /* Scale the IR size for the new sample rate and update the stored * sample rate.