aboutsummaryrefslogtreecommitdiffstats
path: root/utils/makemhr
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2020-01-25 16:32:01 -0800
committerChris Robinson <[email protected]>2020-01-25 16:59:07 -0800
commitf63880c2ff6523fd57b0fd5f65493d3e065f3550 (patch)
tree5041ae42b891df166990e5bda8f6270d8eb8a73f /utils/makemhr
parent3cd4af1b8e5ebb4848eb3e14cca916006c631c37 (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')
-rw-r--r--utils/makemhr/loaddef.cpp16
-rw-r--r--utils/makemhr/loadsofa.cpp10
2 files changed, 7 insertions, 19 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
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<double> &
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<double>(std::distance(upsampled.cbegin(), iter)) / (10.0*rate);
}