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 HRTFKernel_h | 29 #ifndef HRTFKernel_h |
30 #define HRTFKernel_h | 30 #define HRTFKernel_h |
31 | 31 |
32 #include "platform/audio/FFTFrame.h" | 32 #include "platform/audio/FFTFrame.h" |
33 #include "wtf/Allocator.h" | 33 #include "wtf/Allocator.h" |
34 #include "wtf/Noncopyable.h" | 34 #include "wtf/Noncopyable.h" |
35 #include "wtf/PtrUtil.h" | 35 #include "wtf/OwnPtr.h" |
| 36 #include "wtf/PassOwnPtr.h" |
36 #include "wtf/Vector.h" | 37 #include "wtf/Vector.h" |
37 #include <memory> | |
38 | 38 |
39 namespace blink { | 39 namespace blink { |
40 | 40 |
41 class AudioChannel; | 41 class AudioChannel; |
42 | 42 |
43 // HRTF stands for Head-Related Transfer Function. | 43 // HRTF stands for Head-Related Transfer Function. |
44 // HRTFKernel is a frequency-domain representation of an impulse-response used a
s part of the spatialized panning system. | 44 // HRTFKernel is a frequency-domain representation of an impulse-response used a
s part of the spatialized panning system. |
45 // For a given azimuth / elevation angle there will be one HRTFKernel for the le
ft ear transfer function, and one for the right ear. | 45 // For a given azimuth / elevation angle there will be one HRTFKernel for the le
ft ear transfer function, and one for the right ear. |
46 // The leading delay (average group delay) for each impulse response is extracte
d: | 46 // The leading delay (average group delay) for each impulse response is extracte
d: |
47 // m_fftFrame is the frequency-domain representation of the impulse respons
e with the delay removed | 47 // m_fftFrame is the frequency-domain representation of the impulse respons
e with the delay removed |
48 // m_frameDelay is the leading delay of the original impulse response. | 48 // m_frameDelay is the leading delay of the original impulse response. |
49 class PLATFORM_EXPORT HRTFKernel { | 49 class PLATFORM_EXPORT HRTFKernel { |
50 USING_FAST_MALLOC(HRTFKernel); | 50 USING_FAST_MALLOC(HRTFKernel); |
51 WTF_MAKE_NONCOPYABLE(HRTFKernel); | 51 WTF_MAKE_NONCOPYABLE(HRTFKernel); |
52 public: | 52 public: |
53 // Note: this is destructive on the passed in AudioChannel. | 53 // Note: this is destructive on the passed in AudioChannel. |
54 // The length of channel must be a power of two. | 54 // The length of channel must be a power of two. |
55 static std::unique_ptr<HRTFKernel> create(AudioChannel* channel, size_t fftS
ize, float sampleRate) | 55 static PassOwnPtr<HRTFKernel> create(AudioChannel* channel, size_t fftSize,
float sampleRate) |
56 { | 56 { |
57 return wrapUnique(new HRTFKernel(channel, fftSize, sampleRate)); | 57 return adoptPtr(new HRTFKernel(channel, fftSize, sampleRate)); |
58 } | 58 } |
59 | 59 |
60 static std::unique_ptr<HRTFKernel> create(std::unique_ptr<FFTFrame> fftFrame
, float frameDelay, float sampleRate) | 60 static PassOwnPtr<HRTFKernel> create(PassOwnPtr<FFTFrame> fftFrame, float fr
ameDelay, float sampleRate) |
61 { | 61 { |
62 return wrapUnique(new HRTFKernel(std::move(fftFrame), frameDelay, sample
Rate)); | 62 return adoptPtr(new HRTFKernel(std::move(fftFrame), frameDelay, sampleRa
te)); |
63 } | 63 } |
64 | 64 |
65 // Given two HRTFKernels, and an interpolation factor x: 0 -> 1, returns an
interpolated HRTFKernel. | 65 // Given two HRTFKernels, and an interpolation factor x: 0 -> 1, returns an
interpolated HRTFKernel. |
66 static std::unique_ptr<HRTFKernel> createInterpolatedKernel(HRTFKernel* kern
el1, HRTFKernel* kernel2, float x); | 66 static PassOwnPtr<HRTFKernel> createInterpolatedKernel(HRTFKernel* kernel1,
HRTFKernel* kernel2, float x); |
67 | 67 |
68 FFTFrame* fftFrame() { return m_fftFrame.get(); } | 68 FFTFrame* fftFrame() { return m_fftFrame.get(); } |
69 | 69 |
70 size_t fftSize() const { return m_fftFrame->fftSize(); } | 70 size_t fftSize() const { return m_fftFrame->fftSize(); } |
71 float frameDelay() const { return m_frameDelay; } | 71 float frameDelay() const { return m_frameDelay; } |
72 | 72 |
73 float sampleRate() const { return m_sampleRate; } | 73 float sampleRate() const { return m_sampleRate; } |
74 double nyquist() const { return 0.5 * sampleRate(); } | 74 double nyquist() const { return 0.5 * sampleRate(); } |
75 | 75 |
76 // Converts back into impulse-response form. | 76 // Converts back into impulse-response form. |
77 std::unique_ptr<AudioChannel> createImpulseResponse(); | 77 PassOwnPtr<AudioChannel> createImpulseResponse(); |
78 | 78 |
79 private: | 79 private: |
80 // Note: this is destructive on the passed in AudioChannel. | 80 // Note: this is destructive on the passed in AudioChannel. |
81 HRTFKernel(AudioChannel*, size_t fftSize, float sampleRate); | 81 HRTFKernel(AudioChannel*, size_t fftSize, float sampleRate); |
82 | 82 |
83 HRTFKernel(std::unique_ptr<FFTFrame> fftFrame, float frameDelay, float sampl
eRate) | 83 HRTFKernel(PassOwnPtr<FFTFrame> fftFrame, float frameDelay, float sampleRate
) |
84 : m_fftFrame(std::move(fftFrame)) | 84 : m_fftFrame(std::move(fftFrame)) |
85 , m_frameDelay(frameDelay) | 85 , m_frameDelay(frameDelay) |
86 , m_sampleRate(sampleRate) | 86 , m_sampleRate(sampleRate) |
87 { | 87 { |
88 } | 88 } |
89 | 89 |
90 std::unique_ptr<FFTFrame> m_fftFrame; | 90 OwnPtr<FFTFrame> m_fftFrame; |
91 float m_frameDelay; | 91 float m_frameDelay; |
92 float m_sampleRate; | 92 float m_sampleRate; |
93 }; | 93 }; |
94 | 94 |
95 typedef Vector<std::unique_ptr<HRTFKernel>> HRTFKernelList; | 95 typedef Vector<OwnPtr<HRTFKernel>> HRTFKernelList; |
96 | 96 |
97 } // namespace blink | 97 } // namespace blink |
98 | 98 |
99 #endif // HRTFKernel_h | 99 #endif // HRTFKernel_h |
OLD | NEW |