LCOV - code coverage report
Current view: top level - dom/media/webaudio/blink - HRTFDatabase.cpp (source / functions) Hit Total Coverage
Test: output.info Lines: 0 41 0.0 %
Date: 2017-07-14 16:53:18 Functions: 0 5 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :  * Copyright (C) 2010 Google Inc. All rights reserved.
       3             :  *
       4             :  * Redistribution and use in source and binary forms, with or without
       5             :  * modification, are permitted provided that the following conditions
       6             :  * are met:
       7             :  *
       8             :  * 1.  Redistributions of source code must retain the above copyright
       9             :  *     notice, this list of conditions and the following disclaimer.
      10             :  * 2.  Redistributions in binary form must reproduce the above copyright
      11             :  *     notice, this list of conditions and the following disclaimer in the
      12             :  *     documentation and/or other materials provided with the distribution.
      13             :  * 3.  Neither the name of Apple Computer, Inc. ("Apple") nor the names of
      14             :  *     its contributors may be used to endorse or promote products derived
      15             :  *     from this software without specific prior written permission.
      16             :  *
      17             :  * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
      18             :  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
      19             :  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
      20             :  * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
      21             :  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
      22             :  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
      23             :  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
      24             :  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
      25             :  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
      26             :  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
      27             :  */
      28             : 
      29             : #include "HRTFDatabase.h"
      30             : 
      31             : #include "HRTFElevation.h"
      32             : 
      33             : using namespace std;
      34             : 
      35             : namespace WebCore {
      36             : 
      37             : const int HRTFDatabase::MinElevation = -45;
      38             : const int HRTFDatabase::MaxElevation = 90;
      39             : const unsigned HRTFDatabase::RawElevationAngleSpacing = 15;
      40             : const unsigned HRTFDatabase::NumberOfRawElevations = 10; // -45 -> +90 (each 15 degrees)
      41             : const unsigned HRTFDatabase::InterpolationFactor = 1;
      42             : const unsigned HRTFDatabase::NumberOfTotalElevations = NumberOfRawElevations * InterpolationFactor;
      43             : 
      44           0 : nsReturnRef<HRTFDatabase> HRTFDatabase::create(float sampleRate)
      45             : {
      46           0 :     return nsReturnRef<HRTFDatabase>(new HRTFDatabase(sampleRate));
      47             : }
      48             : 
      49           0 : HRTFDatabase::HRTFDatabase(float sampleRate)
      50           0 :     : m_sampleRate(sampleRate)
      51             : {
      52           0 :     m_elevations.SetLength(NumberOfTotalElevations);
      53             : 
      54           0 :     unsigned elevationIndex = 0;
      55           0 :     for (int elevation = MinElevation; elevation <= MaxElevation; elevation += RawElevationAngleSpacing) {
      56           0 :         nsAutoRef<HRTFElevation> hrtfElevation(HRTFElevation::createBuiltin(elevation, sampleRate));
      57           0 :         MOZ_ASSERT(hrtfElevation.get());
      58           0 :         if (!hrtfElevation.get())
      59           0 :             return;
      60             : 
      61           0 :         m_elevations[elevationIndex] = hrtfElevation.out();
      62           0 :         elevationIndex += InterpolationFactor;
      63             :     }
      64             : 
      65             :     // Now, go back and interpolate elevations.
      66             :     if (InterpolationFactor > 1) {
      67             :         for (unsigned i = 0; i < NumberOfTotalElevations; i += InterpolationFactor) {
      68             :             unsigned j = (i + InterpolationFactor);
      69             :             if (j >= NumberOfTotalElevations)
      70             :                 j = i; // for last elevation interpolate with itself
      71             : 
      72             :             // Create the interpolated convolution kernels and delays.
      73             :             for (unsigned jj = 1; jj < InterpolationFactor; ++jj) {
      74             :                 float x = static_cast<float>(jj) / static_cast<float>(InterpolationFactor);
      75             :                 m_elevations[i + jj] = HRTFElevation::createByInterpolatingSlices(m_elevations[i].get(), m_elevations[j].get(), x, sampleRate);
      76             :                 MOZ_ASSERT(m_elevations[i + jj].get());
      77             :             }
      78             :         }
      79             :     }
      80             : }
      81             : 
      82           0 : size_t HRTFDatabase::sizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
      83             : {
      84           0 :     size_t amount = aMallocSizeOf(this);
      85           0 :     amount += m_elevations.ShallowSizeOfExcludingThis(aMallocSizeOf);
      86           0 :     for (size_t i = 0; i < m_elevations.Length(); i++) {
      87           0 :       amount += m_elevations[i]->sizeOfIncludingThis(aMallocSizeOf);
      88             :     }
      89             : 
      90           0 :     return amount;
      91             : }
      92             : 
      93           0 : void HRTFDatabase::getKernelsFromAzimuthElevation(double azimuthBlend, unsigned azimuthIndex, double elevationAngle, HRTFKernel* &kernelL, HRTFKernel* &kernelR,
      94             :                                                   double& frameDelayL, double& frameDelayR)
      95             : {
      96           0 :     unsigned elevationIndex = indexFromElevationAngle(elevationAngle);
      97           0 :     MOZ_ASSERT(elevationIndex < m_elevations.Length() && m_elevations.Length() > 0);
      98             : 
      99           0 :     if (!m_elevations.Length()) {
     100           0 :         kernelL = 0;
     101           0 :         kernelR = 0;
     102           0 :         return;
     103             :     }
     104             : 
     105           0 :     if (elevationIndex > m_elevations.Length() - 1)
     106           0 :         elevationIndex = m_elevations.Length() - 1;
     107             : 
     108           0 :     HRTFElevation* hrtfElevation = m_elevations[elevationIndex].get();
     109           0 :     MOZ_ASSERT(hrtfElevation);
     110           0 :     if (!hrtfElevation) {
     111           0 :         kernelL = 0;
     112           0 :         kernelR = 0;
     113           0 :         return;
     114             :     }
     115             : 
     116           0 :     hrtfElevation->getKernelsFromAzimuth(azimuthBlend, azimuthIndex, kernelL, kernelR, frameDelayL, frameDelayR);
     117             : }
     118             : 
     119           0 : unsigned HRTFDatabase::indexFromElevationAngle(double elevationAngle)
     120             : {
     121             :     // Clamp to allowed range.
     122           0 :     elevationAngle = mozilla::clamped(elevationAngle,
     123           0 :                                       static_cast<double>(MinElevation),
     124           0 :                                       static_cast<double>(MaxElevation));
     125             : 
     126           0 :     unsigned elevationIndex = static_cast<int>(InterpolationFactor * (elevationAngle - MinElevation) / RawElevationAngleSpacing);
     127           0 :     return elevationIndex;
     128             : }
     129             : 
     130             : } // namespace WebCore

Generated by: LCOV version 1.13