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 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
11 * documentation and/or other materials provided with the distribution. | 11 * documentation and/or other materials provided with the distribution. |
12 * | 12 * |
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND AN
Y | 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND AN
Y |
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
15 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | 15 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
16 * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR AN
Y | 16 * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR AN
Y |
17 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | 17 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
18 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | 18 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
19 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND O
N | 19 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND O
N |
20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | 21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
22 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 22 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
23 */ | 23 */ |
24 | 24 |
25 #ifndef HRTFPanner_h | 25 #ifndef HRTFPanner_h |
26 #define HRTFPanner_h | 26 #define HRTFPanner_h |
27 | 27 |
28 #include "core/platform/audio/FFTConvolver.h" | 28 #include "core/platform/audio/FFTConvolver.h" |
| 29 #include "core/platform/audio/HRTFDatabaseLoader.h" |
29 #include "core/platform/audio/Panner.h" | 30 #include "core/platform/audio/Panner.h" |
30 #include "modules/webaudio/DelayDSPKernel.h" | 31 #include "modules/webaudio/DelayDSPKernel.h" |
31 | 32 |
32 namespace WebCore { | 33 namespace WebCore { |
33 | 34 |
34 class HRTFPanner : public Panner { | 35 class HRTFPanner : public Panner { |
35 public: | 36 public: |
36 explicit HRTFPanner(float sampleRate); | 37 HRTFPanner(float sampleRate, HRTFDatabaseLoader*); |
37 virtual ~HRTFPanner(); | 38 virtual ~HRTFPanner(); |
38 | 39 |
39 // Panner | 40 // Panner |
40 virtual void pan(double azimuth, double elevation, const AudioBus* inputBus,
AudioBus* outputBus, size_t framesToProcess); | 41 virtual void pan(double azimuth, double elevation, const AudioBus* inputBus,
AudioBus* outputBus, size_t framesToProcess); |
41 virtual void reset(); | 42 virtual void reset(); |
42 | 43 |
43 size_t fftSize() const { return fftSizeForSampleRate(m_sampleRate); } | 44 size_t fftSize() const { return fftSizeForSampleRate(m_sampleRate); } |
44 static size_t fftSizeForSampleRate(float sampleRate); | 45 static size_t fftSizeForSampleRate(float sampleRate); |
45 | 46 |
46 float sampleRate() const { return m_sampleRate; } | 47 float sampleRate() const { return m_sampleRate; } |
47 | 48 |
48 virtual double tailTime() const OVERRIDE; | 49 virtual double tailTime() const OVERRIDE; |
49 virtual double latencyTime() const OVERRIDE; | 50 virtual double latencyTime() const OVERRIDE; |
50 | 51 |
51 private: | 52 private: |
52 // Given an azimuth angle in the range -180 -> +180, returns the correspondi
ng azimuth index for the database, | 53 // Given an azimuth angle in the range -180 -> +180, returns the correspondi
ng azimuth index for the database, |
53 // and azimuthBlend which is an interpolation value from 0 -> 1. | 54 // and azimuthBlend which is an interpolation value from 0 -> 1. |
54 int calculateDesiredAzimuthIndexAndBlend(double azimuth, double& azimuthBlen
d); | 55 int calculateDesiredAzimuthIndexAndBlend(double azimuth, double& azimuthBlen
d); |
55 | 56 |
| 57 RefPtr<HRTFDatabaseLoader> m_databaseLoader; |
| 58 |
56 float m_sampleRate; | 59 float m_sampleRate; |
57 | 60 |
58 // We maintain two sets of convolvers for smooth cross-faded interpolations
when | 61 // We maintain two sets of convolvers for smooth cross-faded interpolations
when |
59 // then azimuth and elevation are dynamically changing. | 62 // then azimuth and elevation are dynamically changing. |
60 // When the azimuth and elevation are not changing, we simply process with o
ne of the two sets. | 63 // When the azimuth and elevation are not changing, we simply process with o
ne of the two sets. |
61 // Initially we use CrossfadeSelection1 corresponding to m_convolverL1 and m
_convolverR1. | 64 // Initially we use CrossfadeSelection1 corresponding to m_convolverL1 and m
_convolverR1. |
62 // Whenever the azimuth or elevation changes, a crossfade is initiated to tr
ansition | 65 // Whenever the azimuth or elevation changes, a crossfade is initiated to tr
ansition |
63 // to the new position. So if we're currently processing with CrossfadeSelec
tion1, then | 66 // to the new position. So if we're currently processing with CrossfadeSelec
tion1, then |
64 // we transition to CrossfadeSelection2 (and vice versa). | 67 // we transition to CrossfadeSelection2 (and vice versa). |
65 // If we're in the middle of a transition, then we wait until it is complete
before | 68 // If we're in the middle of a transition, then we wait until it is complete
before |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 | 100 |
98 AudioFloatArray m_tempL1; | 101 AudioFloatArray m_tempL1; |
99 AudioFloatArray m_tempR1; | 102 AudioFloatArray m_tempR1; |
100 AudioFloatArray m_tempL2; | 103 AudioFloatArray m_tempL2; |
101 AudioFloatArray m_tempR2; | 104 AudioFloatArray m_tempR2; |
102 }; | 105 }; |
103 | 106 |
104 } // namespace WebCore | 107 } // namespace WebCore |
105 | 108 |
106 #endif // HRTFPanner_h | 109 #endif // HRTFPanner_h |
OLD | NEW |