Commit 6e00639d authored by Raymond Toy's avatar Raymond Toy Committed by Commit Bot

Zero-pad HRTF response if needed

The HRTF response size can some times be smaller than the FFT size.
This can happen if the FFT size has a lower limit, such as for PFFFT
which clamps the size to the lower bound.  To account for this, create
a new HRTF response that is zero-padded to the FFT size.

Manually tested against repro cases from the bugs; ASAN issue no
longer reproduces.

Bug: 1032000, 1041411
Change-Id: Ic2136a92a6e1bf4f2f78f434b065c21dc1b72b5d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2003571Reviewed-by: default avatarHongchan Choi <hongchan@chromium.org>
Commit-Queue: Raymond Toy <rtoy@chromium.org>
Cr-Commit-Position: refs/heads/master@{#732837}
parent b8283fe6
......@@ -154,14 +154,32 @@ bool HRTFElevation::CalculateKernelsForAzimuthElevation(
AudioBus::CreateBufferFromRange(bus.get(), start_frame, stop_frame));
scoped_refptr<AudioBus> response(AudioBus::CreateBySampleRateConverting(
pre_sample_rate_converted_response.get(), false, sample_rate));
// Note that depending on the fftSize returned by the panner, we may be
// truncating the impulse response we just loaded in, or we might zero-pad it.
const size_t fft_size = HRTFPanner::FftSizeForSampleRate(sample_rate);
if (2 * response->length() < fft_size) {
// Need to resize the response buffer length so that it fis the fft size.
// Create a new response of the right length and copy over the current
// response.
scoped_refptr<AudioBus> padded_response(
AudioBus::Create(response->NumberOfChannels(), fft_size / 2));
for (unsigned channel = 0; channel < response->NumberOfChannels();
++channel) {
memcpy(padded_response->Channel(channel)->MutableData(),
response->Channel(channel)->Data(),
response->length() * sizeof(float));
}
response = padded_response;
}
DCHECK_GE(2 * response->length(), fft_size);
AudioChannel* left_ear_impulse_response =
response->Channel(AudioBus::kChannelLeft);
AudioChannel* right_ear_impulse_response =
response->Channel(AudioBus::kChannelRight);
// Note that depending on the fftSize returned by the panner, we may be
// truncating the impulse response we just loaded in.
const size_t fft_size = HRTFPanner::FftSizeForSampleRate(sample_rate);
kernel_l = std::make_unique<HRTFKernel>(left_ear_impulse_response, fft_size,
sample_rate);
kernel_r = std::make_unique<HRTFKernel>(right_ear_impulse_response, fft_size,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment