/* * Copyright (C) 2010 Google Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
amount += m_kernelListL.ShallowSizeOfExcludingThis(aMallocSizeOf); for (size_t i = 0; i < m_kernelListL.Length(); i++) {
amount += m_kernelListL[i]->sizeOfIncludingThis(aMallocSizeOf);
}
return amount;
}
size_t HRTFElevation::fftSizeForSampleRate(float sampleRate) { // The IRCAM HRTF impulse responses were 512 sample-frames @44.1KHz, // but these have been truncated to 256 samples. // An FFT-size of twice impulse response size is used (for convolution). // So for sample rates of 44.1KHz an FFT size of 512 is good. // We double the FFT-size only for sample rates at least double this. // If the FFT size is too large then the impulse response will be padded // with zeros without the fade-out provided by HRTFKernel.
MOZ_ASSERT(sampleRate > 1.0 && sampleRate < 1048576.0);
// This is the size if we were to use all raw response samples. unsigned resampledLength =
floorf(ResponseFrameSize * sampleRate / rawSampleRate); // Keep things semi-sane, with max FFT size of 1024. unsigned size = std::min(resampledLength, 1023U); // Ensure a minimum of 2 * WEBAUDIO_BLOCK_SIZE (with the size++ below) for // FFTConvolver and set the 8 least significant bits for rounding up to // the next power of 2 below.
size |= 2 * WEBAUDIO_BLOCK_SIZE - 1; // Round up to the next power of 2, making the FFT size no more than twice // the impulse response length. This doubles size for values that are // already powers of 2. This works by filling in alls bit to right of the // most significant bit. The most significant bit is no greater than // 1 << 9, and the least significant 8 bits were already set above, so // there is at most one bit to add.
size |= (size >> 1);
size++;
MOZ_ASSERT((size & (size - 1)) == 0);
return size;
}
nsReturnRef<HRTFKernel> HRTFElevation::calculateKernelForAzimuthElevation( int azimuth, int elevation, SpeexResamplerState* resampler, float sampleRate) { int elevationIndex = (elevation - firstElevation) / elevationSpacing;
MOZ_ASSERT(elevationIndex >= 0 && elevationIndex <= numberOfElevations);
int numberOfAzimuths = irc_composite_c_r0195[elevationIndex].count; int azimuthSpacing = 360 / numberOfAzimuths;
MOZ_ASSERT(numberOfAzimuths * azimuthSpacing == 360);
// Note that depending on the fftSize returned by the panner, we may be // truncating the impulse response. const size_t resampledResponseLength = fftSizeForSampleRate(sampleRate) / 2;
// Feed the input buffer into the resampler.
spx_uint32_t in_len = ResponseFrameSize;
spx_uint32_t out_len = resampled.Length();
speex_resampler_process_float(resampler, 0, response, &in_len,
resampled.Elements(), &out_len);
if (out_len < resampled.Length()) { // The input should have all been processed.
MOZ_ASSERT(in_len == ResponseFrameSize); // Feed in zeros get the data remaining in the resampler.
spx_uint32_t out_index = out_len;
in_len = speex_resampler_get_input_latency(resampler);
out_len = resampled.Length() - out_index;
speex_resampler_process_float(resampler, 0, nullptr, &in_len,
resampled.Elements() + out_index, &out_len);
out_index += out_len; // There may be some uninitialized samples remaining for very low // sample rates.
PodZero(resampled.Elements() + out_index, resampled.Length() - out_index);
}
// Spacing, in degrees, between every azimuth loaded from resource. // Some elevations do not have data for all these intervals. // See maxElevations. staticconstunsigned AzimuthSpacing = 15; staticconstunsigned NumberOfRawAzimuths = 360 / AzimuthSpacing;
static_assert(AzimuthSpacing * NumberOfRawAzimuths == 360, "Not a multiple"); staticconstunsigned InterpolationFactor =
NumberOfTotalAzimuths / NumberOfRawAzimuths;
static_assert(
NumberOfTotalAzimuths == NumberOfRawAzimuths * InterpolationFactor, "Not a multiple");
// Load convolution kernels from HRTF files. int interpolatedIndex = 0; for (unsigned rawIndex = 0; rawIndex < NumberOfRawAzimuths; ++rawIndex) { // Don't let elevation exceed maximum for this azimuth. int maxElevation = maxElevations[rawIndex]; int actualElevation = std::min(elevation, maxElevation);
if (resampler) speex_resampler_destroy(resampler);
// Now go back and interpolate intermediate azimuth values. for (unsigned i = 0; i < NumberOfTotalAzimuths; i += InterpolationFactor) { int j = (i + InterpolationFactor) % NumberOfTotalAzimuths;
// Create the interpolated convolution kernels and delays. for (unsigned jj = 1; jj < InterpolationFactor; ++jj) { float x = float(jj) / float(InterpolationFactor); // interpolate from 0 -> 1
// Interpolate kernels of corresponding azimuths of the two elevations. for (unsigned i = 0; i < NumberOfTotalAzimuths; ++i) {
kernelListL[i] = HRTFKernel::createInterpolatedKernel(kernelListL1[i],
kernelListL2[i], x);
}
// Return the left and right kernels, // using symmetry to produce the right kernel.
kernelL = m_kernelListL[azimuthIndex]; int azimuthIndexR = (numKernels - azimuthIndex) % numKernels;
kernelR = m_kernelListL[azimuthIndexR];
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.