diff options
author | Chris Robinson <[email protected]> | 2020-01-25 16:32:01 -0800 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2020-01-25 16:59:07 -0800 |
commit | f63880c2ff6523fd57b0fd5f65493d3e065f3550 (patch) | |
tree | 5041ae42b891df166990e5bda8f6270d8eb8a73f /utils/makemhr/loaddef.cpp | |
parent | 3cd4af1b8e5ebb4848eb3e14cca916006c631c37 (diff) |
Use the peak IR magnitude to get the onset
While maybe not technically correct, we actually only care about the difference
between onsets (any base constant is removed). This should work better since it
determines when the IR is most audible, whereas previously it used a variable
threshold of when it reached 15% of the max amplitude.
An even better method may be to check where the IR amplitude exceeds a fixed
threshold (i.e. the same threshold applied to all IRs), but that would need
tweaking to find a level that doesn't catch random noise and doesn't
potentially miss the more occluded IRs.
Diffstat (limited to 'utils/makemhr/loaddef.cpp')
-rw-r--r-- | utils/makemhr/loaddef.cpp | 16 |
1 files changed, 4 insertions, 12 deletions
diff --git a/utils/makemhr/loaddef.cpp b/utils/makemhr/loaddef.cpp index 63014fe5..c61c6f6b 100644 --- a/utils/makemhr/loaddef.cpp +++ b/utils/makemhr/loaddef.cpp @@ -1715,18 +1715,10 @@ static double AverageHrirOnset(const uint rate, const uint n, const double *hrir rs.process(n, hrir, 10 * n, upsampled.data()); } - double mag{0.0}; - for(uint i{0u};i < 10*n;i++) - mag = std::max(std::abs(upsampled[i]), mag); - - mag *= 0.15; - uint i{0u}; - for(;i < 10*n;i++) - { - if(std::abs(upsampled[i]) >= mag) - break; - } - return Lerp(onset, static_cast<double>(i) / (10*rate), f); + auto abs_lt = [](const double &lhs, const double &rhs) -> bool + { return std::abs(lhs) < std::abs(rhs); }; + auto iter = std::max_element(upsampled.cbegin(), upsampled.cend(), abs_lt); + return Lerp(onset, static_cast<double>(std::distance(upsampled.cbegin(), iter))/(10*rate), f); } // Calculate the magnitude response of an HRIR and average it with any |