Avoid reinitializing the resampler with each HRIR
This commit is contained in:
parent
cd6bb65d49
commit
4cfd63a1c7
@ -230,19 +230,17 @@ bool CheckIrData(MYSOFA_HRTF *sofaHrtf)
|
|||||||
|
|
||||||
|
|
||||||
/* Calculate the onset time of a HRIR. */
|
/* Calculate the onset time of a HRIR. */
|
||||||
static double CalcHrirOnset(const uint rate, const uint n, std::vector<double> &upsampled,
|
static constexpr int OnsetRateMultiple{10};
|
||||||
const double *hrir)
|
static double CalcHrirOnset(PPhaseResampler &rs, const uint rate, const uint n,
|
||||||
|
std::vector<double> &upsampled, const double *hrir)
|
||||||
{
|
{
|
||||||
{
|
rs.process(n, hrir, static_cast<uint>(upsampled.size()), upsampled.data());
|
||||||
PPhaseResampler rs;
|
|
||||||
rs.init(rate, 10 * rate);
|
|
||||||
rs.process(n, hrir, 10 * n, upsampled.data());
|
|
||||||
}
|
|
||||||
|
|
||||||
auto abs_lt = [](const double &lhs, const double &rhs) -> bool
|
auto abs_lt = [](const double &lhs, const double &rhs) -> bool
|
||||||
{ return std::abs(lhs) < std::abs(rhs); };
|
{ return std::abs(lhs) < std::abs(rhs); };
|
||||||
auto iter = std::max_element(upsampled.cbegin(), upsampled.cend(), abs_lt);
|
auto iter = std::max_element(upsampled.cbegin(), upsampled.cend(), abs_lt);
|
||||||
return static_cast<double>(std::distance(upsampled.cbegin(), iter)) / (10.0*rate);
|
return static_cast<double>(std::distance(upsampled.cbegin(), iter)) /
|
||||||
|
(double{OnsetRateMultiple}*rate);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Calculate the magnitude response of a HRIR. */
|
/* Calculate the magnitude response of a HRIR. */
|
||||||
@ -269,9 +267,12 @@ static bool LoadResponses(MYSOFA_HRTF *sofaHrtf, HrirDataT *hData)
|
|||||||
/* Temporary buffers used to calculate the IR's onset and frequency
|
/* Temporary buffers used to calculate the IR's onset and frequency
|
||||||
* magnitudes.
|
* magnitudes.
|
||||||
*/
|
*/
|
||||||
auto upsampled = std::vector<double>(10 * hData->mIrPoints);
|
auto upsampled = std::vector<double>(OnsetRateMultiple * hData->mIrPoints);
|
||||||
auto htemp = std::vector<complex_d>(hData->mFftSize);
|
auto htemp = std::vector<complex_d>(hData->mFftSize);
|
||||||
auto hrir = std::vector<double>(hData->mFftSize);
|
auto hrir = std::vector<double>(hData->mFftSize);
|
||||||
|
/* This resampler is used to help detect the response onset. */
|
||||||
|
PPhaseResampler rs;
|
||||||
|
rs.init(hData->mIrRate, OnsetRateMultiple*hData->mIrRate);
|
||||||
|
|
||||||
for(uint si{0u};si < sofaHrtf->M;++si)
|
for(uint si{0u};si < sofaHrtf->M;++si)
|
||||||
{
|
{
|
||||||
@ -322,7 +323,7 @@ static bool LoadResponses(MYSOFA_HRTF *sofaHrtf, HrirDataT *hData)
|
|||||||
std::copy_n(&sofaHrtf->DataIR.values[(si*sofaHrtf->R + ti)*sofaHrtf->N],
|
std::copy_n(&sofaHrtf->DataIR.values[(si*sofaHrtf->R + ti)*sofaHrtf->N],
|
||||||
hData->mIrPoints, hrir.begin());
|
hData->mIrPoints, hrir.begin());
|
||||||
azd->mIrs[ti] = &hrirs[hData->mIrSize * (hData->mIrCount*ti + azd->mIndex)];
|
azd->mIrs[ti] = &hrirs[hData->mIrSize * (hData->mIrCount*ti + azd->mIndex)];
|
||||||
azd->mDelays[ti] = CalcHrirOnset(hData->mIrRate, hData->mIrPoints, upsampled,
|
azd->mDelays[ti] = CalcHrirOnset(rs, hData->mIrRate, hData->mIrPoints, upsampled,
|
||||||
hrir.data());
|
hrir.data());
|
||||||
CalcHrirMagnitude(hData->mIrPoints, hData->mFftSize, htemp, hrir.data(),
|
CalcHrirMagnitude(hData->mIrPoints, hData->mFftSize, htemp, hrir.data(),
|
||||||
azd->mIrs[ti]);
|
azd->mIrs[ti]);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user