Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8)

Side by Side Diff: third_party/WebKit/Source/modules/webaudio/PannerNode.h

Issue 1820403002: Implement Automations for PannerNode and AutioListener (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update test because CL for min/maxValue AudioParam landed Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 PannerNode_h 25 #ifndef PannerNode_h
26 #define PannerNode_h 26 #define PannerNode_h
27 27
28 #include "modules/webaudio/AudioListener.h" 28 #include "modules/webaudio/AudioListener.h"
29 #include "modules/webaudio/AudioNode.h" 29 #include "modules/webaudio/AudioNode.h"
30 #include "modules/webaudio/AudioParam.h"
30 #include "platform/audio/AudioBus.h" 31 #include "platform/audio/AudioBus.h"
31 #include "platform/audio/Cone.h" 32 #include "platform/audio/Cone.h"
32 #include "platform/audio/Distance.h" 33 #include "platform/audio/Distance.h"
33 #include "platform/audio/Panner.h" 34 #include "platform/audio/Panner.h"
34 #include "platform/geometry/FloatPoint3D.h" 35 #include "platform/geometry/FloatPoint3D.h"
35 #include "wtf/HashMap.h" 36 #include "wtf/HashMap.h"
36 37
37 namespace blink { 38 namespace blink {
38 39
39 class AbstractAudioContext; 40 class AbstractAudioContext;
40 41
41 // PannerNode is an AudioNode with one input and one output. 42 // PannerNode is an AudioNode with one input and one output.
42 // It positions a sound in 3D space, with the exact effect dependent on the pann ing model. 43 // It positions a sound in 3D space, with the exact effect dependent on the pann ing model.
43 // It has a position and an orientation in 3D space which is relative to the pos ition and orientation of the context's AudioListener. 44 // It has a position and an orientation in 3D space which is relative to the pos ition and orientation of the context's AudioListener.
44 // A distance effect will attenuate the gain as the position moves away from the listener. 45 // A distance effect will attenuate the gain as the position moves away from the listener.
45 // A cone effect will attenuate the gain as the orientation moves away from the listener. 46 // A cone effect will attenuate the gain as the orientation moves away from the listener.
46 // All of these effects follow the OpenAL specification very closely. 47 // All of these effects follow the OpenAL specification very closely.
47 48
48 class PannerHandler final : public AudioHandler { 49 class PannerHandler final : public AudioHandler {
49 public: 50 public:
50 // These enums are used to distinguish what cached values of panner are dirt y. 51 // These enums are used to distinguish what cached values of panner are dirt y.
51 enum { 52 enum {
52 AzimuthElevationDirty = 0x1, 53 AzimuthElevationDirty = 0x1,
53 DistanceConeGainDirty = 0x2, 54 DistanceConeGainDirty = 0x2,
54 }; 55 };
55 56
56 static PassRefPtr<PannerHandler> create(AudioNode&, float sampleRate); 57 static PassRefPtr<PannerHandler> create(
58 AudioNode&,
59 float sampleRate,
60 AudioParamHandler& positionX,
61 AudioParamHandler& positionY,
62 AudioParamHandler& positionZ,
63 AudioParamHandler& orientationX,
64 AudioParamHandler& orientationY,
65 AudioParamHandler& orientationZ);
66
57 ~PannerHandler() override; 67 ~PannerHandler() override;
58 68
59 // AudioHandler 69 // AudioHandler
60 void process(size_t framesToProcess) override; 70 void process(size_t framesToProcess) override;
71 void processSampleAccurateValues(AudioBus* destination, const AudioBus* sour ce, size_t framesToProcess);
61 void initialize() override; 72 void initialize() override;
62 void uninitialize() override; 73 void uninitialize() override;
63 74
64 // Panning model 75 // Panning model
65 String panningModel() const; 76 String panningModel() const;
66 void setPanningModel(const String&); 77 void setPanningModel(const String&);
67 78
68 // Position and orientation 79 // Position and orientation
69 void setPosition(float x, float y, float z); 80 void setPosition(float x, float y, float z);
70 void setOrientation(float x, float y, float z); 81 void setOrientation(float x, float y, float z);
(...skipping 15 matching lines...) Expand all
86 double coneInnerAngle() const { return m_coneEffect.innerAngle(); } 97 double coneInnerAngle() const { return m_coneEffect.innerAngle(); }
87 void setConeInnerAngle(double); 98 void setConeInnerAngle(double);
88 99
89 double coneOuterAngle() const { return m_coneEffect.outerAngle(); } 100 double coneOuterAngle() const { return m_coneEffect.outerAngle(); }
90 void setConeOuterAngle(double); 101 void setConeOuterAngle(double);
91 102
92 double coneOuterGain() const { return m_coneEffect.outerGain(); } 103 double coneOuterGain() const { return m_coneEffect.outerGain(); }
93 void setConeOuterGain(double); 104 void setConeOuterGain(double);
94 105
95 void markPannerAsDirty(unsigned); 106 void markPannerAsDirty(unsigned);
107 void updateDirtyState();
96 108
97 double tailTime() const override { return m_panner ? m_panner->tailTime() : 0; } 109 double tailTime() const override { return m_panner ? m_panner->tailTime() : 0; }
98 double latencyTime() const override { return m_panner ? m_panner->latencyTim e() : 0; } 110 double latencyTime() const override { return m_panner ? m_panner->latencyTim e() : 0; }
99 111
100 void setChannelCount(unsigned long, ExceptionState&) final; 112 void setChannelCount(unsigned long, ExceptionState&) final;
101 void setChannelCountMode(const String&, ExceptionState&) final; 113 void setChannelCountMode(const String&, ExceptionState&) final;
102 114
103 private: 115 private:
104 PannerHandler(AudioNode&, float sampleRate); 116 PannerHandler(
117 AudioNode&,
118 float sampleRate,
119 AudioParamHandler& positionX,
120 AudioParamHandler& positionY,
121 AudioParamHandler& positionZ,
122 AudioParamHandler& orientationX,
123 AudioParamHandler& orientationY,
124 AudioParamHandler& orientationZ);
125
105 // AbstractAudioContext's listener 126 // AbstractAudioContext's listener
106 AudioListener* listener(); 127 AudioListener* listener();
107 128
108 bool setPanningModel(unsigned); // Returns true on success. 129 bool setPanningModel(unsigned); // Returns true on success.
109 bool setDistanceModel(unsigned); // Returns true on success. 130 bool setDistanceModel(unsigned); // Returns true on success.
110 131
111 void calculateAzimuthElevation(double* outAzimuth, double* outElevation); 132 void calculateAzimuthElevation(
112 float calculateDistanceConeGain(); // Returns the combined distance and cone gain attenuation. 133 double* outAzimuth,
134 double* outElevation,
135 const FloatPoint3D& position,
136 const FloatPoint3D& listenerPosition,
137 const FloatPoint3D& listenerForward,
138 const FloatPoint3D& listenerUp);
139
140 // Returns the combined distance and cone gain attenuation.
141 float calculateDistanceConeGain(
142 const FloatPoint3D& position,
143 const FloatPoint3D& orientation,
144 const FloatPoint3D& listenerPosition);
113 145
114 void azimuthElevation(double* outAzimuth, double* outElevation); 146 void azimuthElevation(double* outAzimuth, double* outElevation);
115 float distanceConeGain(); 147 float distanceConeGain();
116 148
117 bool isAzimuthElevationDirty() const { return m_isAzimuthElevationDirty; } 149 bool isAzimuthElevationDirty() const { return m_isAzimuthElevationDirty; }
118 bool isDistanceConeGainDirty() const { return m_isDistanceConeGainDirty; } 150 bool isDistanceConeGainDirty() const { return m_isDistanceConeGainDirty; }
119 151
120 // This Persistent doesn't make a reference cycle including the owner 152 // This Persistent doesn't make a reference cycle including the owner
121 // PannerNode. 153 // PannerNode.
122 Persistent<AudioListener> m_listener; 154 Persistent<AudioListener> m_listener;
123 OwnPtr<Panner> m_panner; 155 OwnPtr<Panner> m_panner;
124 unsigned m_panningModel; 156 unsigned m_panningModel;
125 unsigned m_distanceModel; 157 unsigned m_distanceModel;
126 158
127 // Current source location information
128 FloatPoint3D m_position;
129 FloatPoint3D m_orientation;
130
131 bool m_isAzimuthElevationDirty; 159 bool m_isAzimuthElevationDirty;
132 bool m_isDistanceConeGainDirty; 160 bool m_isDistanceConeGainDirty;
133 161
134 // Gain 162 // Gain
135 DistanceEffect m_distanceEffect; 163 DistanceEffect m_distanceEffect;
136 ConeEffect m_coneEffect; 164 ConeEffect m_coneEffect;
137 float m_lastGain; 165 float m_lastGain;
138 166
139 // Cached values 167 // Cached values
140 double m_cachedAzimuth; 168 double m_cachedAzimuth;
141 double m_cachedElevation; 169 double m_cachedElevation;
142 float m_cachedDistanceConeGain; 170 float m_cachedDistanceConeGain;
143 171
172 const FloatPoint3D position() const
173 {
174 return FloatPoint3D(
175 m_positionX->value(),
176 m_positionY->value(),
177 m_positionZ->value());
178 }
179
180 const FloatPoint3D orientation() const
181 {
182 return FloatPoint3D(
183 m_orientationX->value(),
184 m_orientationY->value(),
185 m_orientationZ->value());
186 }
187
188 // True if any of this panner's AudioParams have automations.
189 bool hasSampleAccurateValues() const;
190
191 RefPtr<AudioParamHandler> m_positionX;
192 RefPtr<AudioParamHandler> m_positionY;
193 RefPtr<AudioParamHandler> m_positionZ;
194
195 RefPtr<AudioParamHandler> m_orientationX;
196 RefPtr<AudioParamHandler> m_orientationY;
197 RefPtr<AudioParamHandler> m_orientationZ;
198
199 FloatPoint3D m_lastPosition;
200 FloatPoint3D m_lastOrientation;
201
144 // Synchronize process() with setting of the panning model, source's locatio n information, listener, distance parameters and sound cones. 202 // Synchronize process() with setting of the panning model, source's locatio n information, listener, distance parameters and sound cones.
145 mutable Mutex m_processLock; 203 mutable Mutex m_processLock;
146 }; 204 };
147 205
148 class PannerNode final : public AudioNode { 206 class PannerNode final : public AudioNode {
149 DEFINE_WRAPPERTYPEINFO(); 207 DEFINE_WRAPPERTYPEINFO();
150 public: 208 public:
151 static PannerNode* create(AbstractAudioContext&, float sampleRate); 209 static PannerNode* create(AbstractAudioContext&, float sampleRate);
152 PannerHandler& pannerHandler() const; 210 PannerHandler& pannerHandler() const;
153 211
212 DECLARE_VIRTUAL_TRACE();
213
214 // Uses a 3D cartesian coordinate system
215 AudioParam* positionX() const { return m_positionX; };
216 AudioParam* positionY() const { return m_positionY; };
217 AudioParam* positionZ() const { return m_positionZ; };
218
219 AudioParam* orientationX() const { return m_orientationX; };
220 AudioParam* orientationY() const { return m_orientationY; };
221 AudioParam* orientationZ() const { return m_orientationZ; };
222
154 String panningModel() const; 223 String panningModel() const;
155 void setPanningModel(const String&); 224 void setPanningModel(const String&);
156 void setPosition(float x, float y, float z); 225 void setPosition(float x, float y, float z);
157 void setOrientation(float x, float y, float z); 226 void setOrientation(float x, float y, float z);
158 void setVelocity(float x, float y, float z); 227 void setVelocity(float x, float y, float z);
159 String distanceModel() const; 228 String distanceModel() const;
160 void setDistanceModel(const String&); 229 void setDistanceModel(const String&);
161 double refDistance() const; 230 double refDistance() const;
162 void setRefDistance(double); 231 void setRefDistance(double);
163 double maxDistance() const; 232 double maxDistance() const;
164 void setMaxDistance(double); 233 void setMaxDistance(double);
165 double rolloffFactor() const; 234 double rolloffFactor() const;
166 void setRolloffFactor(double); 235 void setRolloffFactor(double);
167 double coneInnerAngle() const; 236 double coneInnerAngle() const;
168 void setConeInnerAngle(double); 237 void setConeInnerAngle(double);
169 double coneOuterAngle() const; 238 double coneOuterAngle() const;
170 void setConeOuterAngle(double); 239 void setConeOuterAngle(double);
171 double coneOuterGain() const; 240 double coneOuterGain() const;
172 void setConeOuterGain(double); 241 void setConeOuterGain(double);
173 242
174 private: 243 private:
175 PannerNode(AbstractAudioContext&, float sampleRate); 244 PannerNode(AbstractAudioContext&, float sampleRate);
245
246 Member<AudioParam> m_positionX;
247 Member<AudioParam> m_positionY;
248 Member<AudioParam> m_positionZ;
249
250 Member<AudioParam> m_orientationX;
251 Member<AudioParam> m_orientationY;
252 Member<AudioParam> m_orientationZ;
176 }; 253 };
177 254
178 } // namespace blink 255 } // namespace blink
179 256
180 #endif // PannerNode_h 257 #endif // PannerNode_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698