From f63880c2ff6523fd57b0fd5f65493d3e065f3550 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Sat, 25 Jan 2020 16:32:01 -0800 Subject: 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. --- utils/makemhr/loaddef.cpp | 16 ++++------------ utils/makemhr/loadsofa.cpp | 10 +++------- 2 files changed, 7 insertions(+), 19 deletions(-) (limited to 'utils/makemhr') 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(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(std::distance(upsampled.cbegin(), iter))/(10*rate), f); } // Calculate the magnitude response of an HRIR and average it with any diff --git a/utils/makemhr/loadsofa.cpp b/utils/makemhr/loadsofa.cpp index 81df8aa4..af816529 100644 --- a/utils/makemhr/loadsofa.cpp +++ b/utils/makemhr/loadsofa.cpp @@ -239,13 +239,9 @@ static double CalcHrirOnset(const uint rate, const uint n, std::vector & rs.process(n, hrir, 10 * n, upsampled.data()); } - double mag{std::accumulate(upsampled.cbegin(), upsampled.cend(), double{0.0}, - [](const double magnitude, const double sample) -> double - { return std::max(magnitude, std::abs(sample)); })}; - - mag *= 0.15; - auto iter = std::find_if(upsampled.cbegin(), upsampled.cend(), - [mag](const double sample) -> bool { return (std::abs(sample) >= mag); }); + 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 static_cast(std::distance(upsampled.cbegin(), iter)) / (10.0*rate); } -- cgit v1.2.3