• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef HRTFElevation_h
30 #define HRTFElevation_h
31 
32 #include "HRTFKernel.h"
33 #include <wtf/Noncopyable.h>
34 #include <wtf/OwnPtr.h>
35 #include <wtf/PassOwnPtr.h>
36 #include <wtf/PassRefPtr.h>
37 #include <wtf/RefCounted.h>
38 #include <wtf/RefPtr.h>
39 #include <wtf/text/CString.h>
40 #include <wtf/text/WTFString.h>
41 
42 namespace WebCore {
43 
44 // HRTFElevation contains all of the HRTFKernels (one left ear and one right ear per azimuth angle) for a particular elevation.
45 
46 class HRTFElevation {
47     WTF_MAKE_NONCOPYABLE(HRTFElevation);
48 public:
49     // Loads and returns an HRTFElevation with the given HRTF database subject name and elevation from browser (or WebKit.framework) resources.
50     // Normally, there will only be a single HRTF database set, but this API supports the possibility of multiple ones with different names.
51     // Interpolated azimuths will be generated based on InterpolationFactor.
52     // Valid values for elevation are -45 -> +90 in 15 degree increments.
53     static PassOwnPtr<HRTFElevation> createForSubject(const String& subjectName, int elevation, double sampleRate);
54 
55     // Given two HRTFElevations, and an interpolation factor x: 0 -> 1, returns an interpolated HRTFElevation.
56     static PassOwnPtr<HRTFElevation> createByInterpolatingSlices(HRTFElevation* hrtfElevation1, HRTFElevation* hrtfElevation2, double x, double sampleRate);
57 
58     // Returns the list of left or right ear HRTFKernels for all the azimuths going from 0 to 360 degrees.
kernelListL()59     HRTFKernelList* kernelListL() { return m_kernelListL.get(); }
kernelListR()60     HRTFKernelList* kernelListR() { return m_kernelListR.get(); }
61 
elevationAngle()62     double elevationAngle() const { return m_elevationAngle; }
numberOfAzimuths()63     unsigned numberOfAzimuths() { return NumberOfTotalAzimuths; }
sampleRate()64     double sampleRate() const { return m_sampleRate; }
65 
66     // Returns the left and right kernels for the given azimuth index.
67     // The interpolated delays based on azimuthBlend: 0 -> 1 are returned in frameDelayL and frameDelayR.
68     void getKernelsFromAzimuth(double azimuthBlend, unsigned azimuthIndex, HRTFKernel* &kernelL, HRTFKernel* &kernelR, double& frameDelayL, double& frameDelayR);
69 
70     // Spacing, in degrees, between every azimuth loaded from resource.
71     static const unsigned AzimuthSpacing;
72 
73     // Number of azimuths loaded from resource.
74     static const unsigned NumberOfRawAzimuths;
75 
76     // Interpolates by this factor to get the total number of azimuths from every azimuth loaded from resource.
77     static const unsigned InterpolationFactor;
78 
79     // Total number of azimuths after interpolation.
80     static const unsigned NumberOfTotalAzimuths;
81 
82     // Given a specific azimuth and elevation angle, returns the left and right HRTFKernel.
83     // Valid values for azimuth are 0 -> 345 in 15 degree increments.
84     // Valid values for elevation are -45 -> +90 in 15 degree increments.
85     // Returns true on success.
86     static bool calculateKernelsForAzimuthElevation(int azimuth, int elevation, double sampleRate, const String& subjectName,
87                                                     RefPtr<HRTFKernel>& kernelL, RefPtr<HRTFKernel>& kernelR);
88 
89     // Given a specific azimuth and elevation angle, returns the left and right HRTFKernel in kernelL and kernelR.
90     // This method averages the measured response using symmetry of azimuth (for example by averaging the -30.0 and +30.0 azimuth responses).
91     // Returns true on success.
92     static bool calculateSymmetricKernelsForAzimuthElevation(int azimuth, int elevation, double sampleRate, const String& subjectName,
93                                                              RefPtr<HRTFKernel>& kernelL, RefPtr<HRTFKernel>& kernelR);
94 private:
HRTFElevation(PassOwnPtr<HRTFKernelList> kernelListL,PassOwnPtr<HRTFKernelList> kernelListR,int elevation,double sampleRate)95     HRTFElevation(PassOwnPtr<HRTFKernelList> kernelListL, PassOwnPtr<HRTFKernelList> kernelListR, int elevation, double sampleRate)
96         : m_kernelListL(kernelListL)
97         , m_kernelListR(kernelListR)
98         , m_elevationAngle(elevation)
99         , m_sampleRate(sampleRate)
100     {
101     }
102 
103     OwnPtr<HRTFKernelList> m_kernelListL;
104     OwnPtr<HRTFKernelList> m_kernelListR;
105     double m_elevationAngle;
106     double m_sampleRate;
107 };
108 
109 } // namespace WebCore
110 
111 #endif // HRTFElevation_h
112