From 50342891aff127eecc1b5fadb94fab974ac7511d Mon Sep 17 00:00:00 2001 From: Christopher Snowhill Date: Mon, 30 May 2022 01:39:12 -0700 Subject: [PATCH] [Convolver] Normalize HRTF impulse when resampling When resampling the impulse according to the playback rate, it becomes necessary to normalize the resulting impulse by the inverse of the sample ratio, as resampling adds more or less loudness by virtue of interpolating samples. Signed-off-by: Christopher Snowhill --- Audio/Chain/HeadphoneFilter.mm | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Audio/Chain/HeadphoneFilter.mm b/Audio/Chain/HeadphoneFilter.mm index 62c4df685..c7e57e701 100644 --- a/Audio/Chain/HeadphoneFilter.mm +++ b/Audio/Chain/HeadphoneFilter.mm @@ -256,6 +256,10 @@ static const int8_t speakers_to_hesuvi_14[11][2] = { free(impulseBuffer); impulseBuffer = resampledImpulse; sampleCount = (int)outputDone; + + // Normalize resampled impulse by sample ratio + float fSampleRatio = (float)sampleRatio; + vDSP_vsdiv(impulseBuffer, 1, &fSampleRatio, impulseBuffer, 1, sampleCount * impulseChannels); } channelCount = channels;