/* * 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. */ #ifdef UNSAFE_BUFFERS_BUILD // TODO(crbug.com/351564777): Remove this and convert code to safer constructs. #pragma allow_unsafe_buffers #endif #include "third_party/blink/renderer/platform/audio/hrtf_elevation.h" #include <math.h> #include <algorithm> #include <memory> #include <utility> #include "base/memory/ptr_util.h" #include "base/synchronization/lock.h" #include "third_party/blink/renderer/platform/audio/audio_bus.h" #include "third_party/blink/renderer/platform/audio/hrtf_database.h" #include "third_party/blink/renderer/platform/audio/hrtf_panner.h" #include "third_party/blink/renderer/platform/wtf/text/string_hash.h" namespace blink { namespace { // Spacing, in degrees, between every azimuth loaded from resource. constexpr unsigned kAzimuthSpacing = …; // Number of azimuths loaded from resource. constexpr unsigned kNumberOfRawAzimuths = …; // Interpolates by this factor to get the total number of azimuths from every // azimuth loaded from resource. constexpr unsigned kInterpolationFactor = …; // Total number of azimuths after interpolation. constexpr unsigned kNumberOfTotalAzimuths = …; // Total number of components of an HRTF database. constexpr size_t kTotalNumberOfResponses = …; // Number of frames in an individual impulse response. constexpr size_t kResponseFrameSize = …; // Sample-rate of the spatialization impulse responses as stored in the resource // file. The impulse responses may be resampled to a different sample-rate // (depending on the audio hardware) when they are loaded. constexpr float kResponseSampleRate = …; // This table maps the index into the elevation table with the corresponding // angle. See https://bugs.webkit.org/show_bug.cgi?id=98294#c9 for the // elevation angles and their order in the concatenated response. constexpr int kElevationIndexTableSize = …; constexpr int kElevationIndexTable[kElevationIndexTableSize] = …; // The range of elevations for the IRCAM impulse responses varies depending on // azimuth, but the minimum elevation appears to always be -45. // // Here's how it goes: constexpr int kMaxElevations[] = …; // Lazily load a concatenated HRTF database for given subject and store it in a // local hash table to ensure quick efficient future retrievals. scoped_refptr<AudioBus> GetConcatenatedImpulseResponsesForSubject( int subject_resource_id) { … } } // namespace bool HRTFElevation::CalculateKernelsForAzimuthElevation( int azimuth, int elevation, float sample_rate, int subject_resource_id, std::unique_ptr<HRTFKernel>& kernel_l, std::unique_ptr<HRTFKernel>& kernel_r) { … } std::unique_ptr<HRTFElevation> HRTFElevation::CreateForSubject( int subject_resource_id, int elevation, float sample_rate) { … } std::unique_ptr<HRTFElevation> HRTFElevation::CreateByInterpolatingSlices( HRTFElevation* hrtf_elevation1, HRTFElevation* hrtf_elevation2, float x) { … } unsigned HRTFElevation::NumberOfAzimuths() { … } void HRTFElevation::GetKernelsFromAzimuth(double azimuth_blend, unsigned azimuth_index, HRTFKernel*& kernel_l, HRTFKernel*& kernel_r, double& frame_delay_l, double& frame_delay_r) { … } } // namespace blink