OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * | 7 * |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
(...skipping 14 matching lines...) Expand all Loading... |
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | 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. | 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 */ | 27 */ |
28 | 28 |
29 #ifndef HRTFElevation_h | 29 #ifndef HRTFElevation_h |
30 #define HRTFElevation_h | 30 #define HRTFElevation_h |
31 | 31 |
32 #include "platform/audio/HRTFKernel.h" | 32 #include "platform/audio/HRTFKernel.h" |
33 #include "wtf/Allocator.h" | 33 #include "wtf/Allocator.h" |
34 #include "wtf/Noncopyable.h" | 34 #include "wtf/Noncopyable.h" |
35 #include "wtf/OwnPtr.h" | |
36 #include "wtf/PassOwnPtr.h" | |
37 #include "wtf/PassRefPtr.h" | 35 #include "wtf/PassRefPtr.h" |
38 #include "wtf/RefPtr.h" | 36 #include "wtf/RefPtr.h" |
39 #include "wtf/text/CString.h" | 37 #include "wtf/text/CString.h" |
40 #include "wtf/text/WTFString.h" | 38 #include "wtf/text/WTFString.h" |
| 39 #include <memory> |
41 | 40 |
42 namespace blink { | 41 namespace blink { |
43 | 42 |
44 // HRTFElevation contains all of the HRTFKernels (one left ear and one right ear
per azimuth angle) for a particular elevation. | 43 // HRTFElevation contains all of the HRTFKernels (one left ear and one right ear
per azimuth angle) for a particular elevation. |
45 | 44 |
46 class PLATFORM_EXPORT HRTFElevation { | 45 class PLATFORM_EXPORT HRTFElevation { |
47 USING_FAST_MALLOC(HRTFElevation); | 46 USING_FAST_MALLOC(HRTFElevation); |
48 WTF_MAKE_NONCOPYABLE(HRTFElevation); | 47 WTF_MAKE_NONCOPYABLE(HRTFElevation); |
49 public: | 48 public: |
50 // Loads and returns an HRTFElevation with the given HRTF database subject n
ame and elevation from browser (or WebKit.framework) resources. | 49 // Loads and returns an HRTFElevation with the given HRTF database subject n
ame and elevation from browser (or WebKit.framework) resources. |
51 // Normally, there will only be a single HRTF database set, but this API sup
ports the possibility of multiple ones with different names. | 50 // Normally, there will only be a single HRTF database set, but this API sup
ports the possibility of multiple ones with different names. |
52 // Interpolated azimuths will be generated based on InterpolationFactor. | 51 // Interpolated azimuths will be generated based on InterpolationFactor. |
53 // Valid values for elevation are -45 -> +90 in 15 degree increments. | 52 // Valid values for elevation are -45 -> +90 in 15 degree increments. |
54 static PassOwnPtr<HRTFElevation> createForSubject(const String& subjectName,
int elevation, float sampleRate); | 53 static std::unique_ptr<HRTFElevation> createForSubject(const String& subject
Name, int elevation, float sampleRate); |
55 | 54 |
56 // Given two HRTFElevations, and an interpolation factor x: 0 -> 1, returns
an interpolated HRTFElevation. | 55 // Given two HRTFElevations, and an interpolation factor x: 0 -> 1, returns
an interpolated HRTFElevation. |
57 static PassOwnPtr<HRTFElevation> createByInterpolatingSlices(HRTFElevation*
hrtfElevation1, HRTFElevation* hrtfElevation2, float x, float sampleRate); | 56 static std::unique_ptr<HRTFElevation> createByInterpolatingSlices(HRTFElevat
ion* hrtfElevation1, HRTFElevation* hrtfElevation2, float x, float sampleRate); |
58 | 57 |
59 // Returns the list of left or right ear HRTFKernels for all the azimuths go
ing from 0 to 360 degrees. | 58 // Returns the list of left or right ear HRTFKernels for all the azimuths go
ing from 0 to 360 degrees. |
60 HRTFKernelList* kernelListL() { return m_kernelListL.get(); } | 59 HRTFKernelList* kernelListL() { return m_kernelListL.get(); } |
61 HRTFKernelList* kernelListR() { return m_kernelListR.get(); } | 60 HRTFKernelList* kernelListR() { return m_kernelListR.get(); } |
62 | 61 |
63 double elevationAngle() const { return m_elevationAngle; } | 62 double elevationAngle() const { return m_elevationAngle; } |
64 unsigned numberOfAzimuths() const { return NumberOfTotalAzimuths; } | 63 unsigned numberOfAzimuths() const { return NumberOfTotalAzimuths; } |
65 float sampleRate() const { return m_sampleRate; } | 64 float sampleRate() const { return m_sampleRate; } |
66 | 65 |
67 // Returns the left and right kernels for the given azimuth index. | 66 // Returns the left and right kernels for the given azimuth index. |
68 // The interpolated delays based on azimuthBlend: 0 -> 1 are returned in fra
meDelayL and frameDelayR. | 67 // The interpolated delays based on azimuthBlend: 0 -> 1 are returned in fra
meDelayL and frameDelayR. |
69 void getKernelsFromAzimuth(double azimuthBlend, unsigned azimuthIndex, HRTFK
ernel* &kernelL, HRTFKernel* &kernelR, double& frameDelayL, double& frameDelayR)
; | 68 void getKernelsFromAzimuth(double azimuthBlend, unsigned azimuthIndex, HRTFK
ernel* &kernelL, HRTFKernel* &kernelR, double& frameDelayL, double& frameDelayR)
; |
70 | 69 |
71 // Spacing, in degrees, between every azimuth loaded from resource. | 70 // Spacing, in degrees, between every azimuth loaded from resource. |
72 static const unsigned AzimuthSpacing; | 71 static const unsigned AzimuthSpacing; |
73 | 72 |
74 // Number of azimuths loaded from resource. | 73 // Number of azimuths loaded from resource. |
75 static const unsigned NumberOfRawAzimuths; | 74 static const unsigned NumberOfRawAzimuths; |
76 | 75 |
77 // Interpolates by this factor to get the total number of azimuths from ever
y azimuth loaded from resource. | 76 // Interpolates by this factor to get the total number of azimuths from ever
y azimuth loaded from resource. |
78 static const unsigned InterpolationFactor; | 77 static const unsigned InterpolationFactor; |
79 | 78 |
80 // Total number of azimuths after interpolation. | 79 // Total number of azimuths after interpolation. |
81 static const unsigned NumberOfTotalAzimuths; | 80 static const unsigned NumberOfTotalAzimuths; |
82 | 81 |
83 // Given a specific azimuth and elevation angle, returns the left and right
HRTFKernel. | 82 // Given a specific azimuth and elevation angle, returns the left and right
HRTFKernel. |
84 // Valid values for azimuth are 0 -> 345 in 15 degree increments. | 83 // Valid values for azimuth are 0 -> 345 in 15 degree increments. |
85 // Valid values for elevation are -45 -> +90 in 15 degree increments. | 84 // Valid values for elevation are -45 -> +90 in 15 degree increments. |
86 // Returns true on success. | 85 // Returns true on success. |
87 static bool calculateKernelsForAzimuthElevation(int azimuth, int elevation,
float sampleRate, const String& subjectName, OwnPtr<HRTFKernel>& kernelL, OwnPtr
<HRTFKernel>& kernelR); | 86 static bool calculateKernelsForAzimuthElevation(int azimuth, int elevation,
float sampleRate, const String& subjectName, std::unique_ptr<HRTFKernel>& kernel
L, std::unique_ptr<HRTFKernel>& kernelR); |
88 | 87 |
89 private: | 88 private: |
90 HRTFElevation(PassOwnPtr<HRTFKernelList> kernelListL, PassOwnPtr<HRTFKernelL
ist> kernelListR, int elevation, float sampleRate) | 89 HRTFElevation(std::unique_ptr<HRTFKernelList> kernelListL, std::unique_ptr<H
RTFKernelList> kernelListR, int elevation, float sampleRate) |
91 : m_kernelListL(std::move(kernelListL)) | 90 : m_kernelListL(std::move(kernelListL)) |
92 , m_kernelListR(std::move(kernelListR)) | 91 , m_kernelListR(std::move(kernelListR)) |
93 , m_elevationAngle(elevation) | 92 , m_elevationAngle(elevation) |
94 , m_sampleRate(sampleRate) | 93 , m_sampleRate(sampleRate) |
95 { | 94 { |
96 } | 95 } |
97 | 96 |
98 OwnPtr<HRTFKernelList> m_kernelListL; | 97 std::unique_ptr<HRTFKernelList> m_kernelListL; |
99 OwnPtr<HRTFKernelList> m_kernelListR; | 98 std::unique_ptr<HRTFKernelList> m_kernelListR; |
100 double m_elevationAngle; | 99 double m_elevationAngle; |
101 float m_sampleRate; | 100 float m_sampleRate; |
102 }; | 101 }; |
103 | 102 |
104 } // namespace blink | 103 } // namespace blink |
105 | 104 |
106 #endif // HRTFElevation_h | 105 #endif // HRTFElevation_h |
OLD | NEW |