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 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
42 // It positions a sound in 3D space, with the exact effect dependent on the pann ing model. | 42 // 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. | 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 // A distance effect will attenuate the gain as the position moves away from the listener. | 44 // 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. | 45 // 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. | 46 // All of these effects follow the OpenAL specification very closely. |
47 | 47 |
48 class PannerNode FINAL : public AudioNode { | 48 class PannerNode FINAL : public AudioNode { |
49 public: | 49 public: |
50 // These must be defined as in the .idl file and must match those in the Pan ner class. | 50 // These must be defined as in the .idl file and must match those in the Pan ner class. |
51 enum { | 51 enum { |
52 EQUALPOWER = 0, | 52 EqualPower = 0, |
Raymond Toy
2014/04/16 17:36:15
Why is the case changed for this enum and the enum
KhNo
2014/04/17 13:41:03
When I added dirty enums, webkit style checker of
| |
53 HRTF = 1, | 53 HRTF = 1, |
54 }; | 54 }; |
55 | 55 |
56 // These must be defined as in the .idl file and must match those | 56 // These must be defined as in the .idl file and must match those |
57 // in the DistanceEffect class. | 57 // in the DistanceEffect class. |
58 enum { | 58 enum { |
59 LINEAR_DISTANCE = 0, | 59 LinearDistance = 0, |
60 INVERSE_DISTANCE = 1, | 60 InverseDistance = 1, |
61 EXPONENTIAL_DISTANCE = 2, | 61 ExponentialDistance = 2, |
62 }; | |
63 | |
64 enum { | |
Raymond Toy
2014/04/16 17:36:15
Add comment on what these flags are for.
KhNo
2014/04/17 13:41:03
Done.
| |
65 AzimuthElevationDirty = 0x00000001, | |
66 DistanceConeGainDirty = 0x00000002, | |
67 DopplerRateDirty = 0x00000004, | |
62 }; | 68 }; |
63 | 69 |
64 static PassRefPtr<PannerNode> create(AudioContext* context, float sampleRate ) | 70 static PassRefPtr<PannerNode> create(AudioContext* context, float sampleRate ) |
65 { | 71 { |
66 return adoptRef(new PannerNode(context, sampleRate)); | 72 return adoptRef(new PannerNode(context, sampleRate)); |
67 } | 73 } |
68 | 74 |
69 virtual ~PannerNode(); | 75 virtual ~PannerNode(); |
70 | 76 |
71 // AudioNode | 77 // AudioNode |
72 virtual void process(size_t framesToProcess) OVERRIDE; | 78 virtual void process(size_t framesToProcess) OVERRIDE; |
73 virtual void pullInputs(size_t framesToProcess) OVERRIDE; | 79 virtual void pullInputs(size_t framesToProcess) OVERRIDE; |
74 virtual void initialize() OVERRIDE; | 80 virtual void initialize() OVERRIDE; |
75 virtual void uninitialize() OVERRIDE; | 81 virtual void uninitialize() OVERRIDE; |
76 | 82 |
77 // AudioContext's listener | |
78 AudioListener* listener(); | |
79 | |
80 // Panning model | 83 // Panning model |
81 String panningModel() const; | 84 String panningModel() const; |
82 void setPanningModel(const String&); | 85 void setPanningModel(const String&); |
83 | 86 |
84 // Position | 87 // Position, orientation and velocity |
85 void setPosition(float x, float y, float z); | 88 void setPosition(float x, float y, float z); |
86 | |
87 // Orientation | |
88 void setOrientation(float x, float y, float z); | 89 void setOrientation(float x, float y, float z); |
89 | |
90 // Velocity | |
91 void setVelocity(float x, float y, float z); | 90 void setVelocity(float x, float y, float z); |
92 | 91 |
93 // Distance parameters | 92 // Distance parameters |
94 String distanceModel() const; | 93 String distanceModel() const; |
95 void setDistanceModel(const String&); | 94 void setDistanceModel(const String&); |
96 | 95 |
97 double refDistance() { return m_distanceEffect.refDistance(); } | 96 double refDistance() { return m_distanceEffect.refDistance(); } |
98 void setRefDistance(double refDistance) { m_distanceEffect.setRefDistance(re fDistance); } | 97 void setRefDistance(double); |
99 | 98 |
100 double maxDistance() { return m_distanceEffect.maxDistance(); } | 99 double maxDistance() { return m_distanceEffect.maxDistance(); } |
101 void setMaxDistance(double maxDistance) { m_distanceEffect.setMaxDistance(ma xDistance); } | 100 void setMaxDistance(double); |
102 | 101 |
103 double rolloffFactor() { return m_distanceEffect.rolloffFactor(); } | 102 double rolloffFactor() { return m_distanceEffect.rolloffFactor(); } |
104 void setRolloffFactor(double rolloffFactor) { m_distanceEffect.setRolloffFac tor(rolloffFactor); } | 103 void setRolloffFactor(double); |
105 | 104 |
106 // Sound cones - angles in degrees | 105 // Sound cones - angles in degrees |
107 double coneInnerAngle() const { return m_coneEffect.innerAngle(); } | 106 double coneInnerAngle() const { return m_coneEffect.innerAngle(); } |
108 void setConeInnerAngle(double angle) { m_coneEffect.setInnerAngle(angle); } | 107 void setConeInnerAngle(double); |
109 | 108 |
110 double coneOuterAngle() const { return m_coneEffect.outerAngle(); } | 109 double coneOuterAngle() const { return m_coneEffect.outerAngle(); } |
111 void setConeOuterAngle(double angle) { m_coneEffect.setOuterAngle(angle); } | 110 void setConeOuterAngle(double); |
112 | 111 |
113 double coneOuterGain() const { return m_coneEffect.outerGain(); } | 112 double coneOuterGain() const { return m_coneEffect.outerGain(); } |
114 void setConeOuterGain(double angle) { m_coneEffect.setOuterGain(angle); } | 113 void setConeOuterGain(double); |
114 | |
115 void updatePannerDirty(unsigned); | |
115 | 116 |
116 // It must be called on audio thread, currently called only process() in Aud ioBufferSourceNode. | 117 // It must be called on audio thread, currently called only process() in Aud ioBufferSourceNode. |
117 double dopplerRate(); | 118 double dopplerRate(); |
118 | 119 |
119 virtual double tailTime() const OVERRIDE { return m_panner ? m_panner->tailT ime() : 0; } | 120 virtual double tailTime() const OVERRIDE { return m_panner ? m_panner->tailT ime() : 0; } |
120 virtual double latencyTime() const OVERRIDE { return m_panner ? m_panner->la tencyTime() : 0; } | 121 virtual double latencyTime() const OVERRIDE { return m_panner ? m_panner->la tencyTime() : 0; } |
121 | 122 |
122 private: | 123 private: |
123 PannerNode(AudioContext*, float sampleRate); | 124 PannerNode(AudioContext*, float sampleRate); |
124 | 125 |
126 // AudioContext's listener | |
127 AudioListener* listener(); | |
128 | |
125 bool setPanningModel(unsigned); // Returns true on success. | 129 bool setPanningModel(unsigned); // Returns true on success. |
126 bool setDistanceModel(unsigned); // Returns true on success. | 130 bool setDistanceModel(unsigned); // Returns true on success. |
131 | |
127 void calculateAzimuthElevation(double* outAzimuth, double* outElevation); | 132 void calculateAzimuthElevation(double* outAzimuth, double* outElevation); |
128 // Returns the combined distance and cone gain attenuation. | 133 float calculateDistanceConeGain(); // Returns the combined distance and cone gain attenuation. |
129 float calculateDistanceConeGain(); | |
130 double calculateDopplerRate(); | 134 double calculateDopplerRate(); |
131 | 135 |
132 void azimuthElevation(double* outAzimuth, double* outElevation); | 136 void azimuthElevation(double* outAzimuth, double* outElevation); |
133 float distanceConeGain(); | 137 float distanceConeGain(); |
134 | 138 |
135 bool isAzimuthElevationDirty(); | 139 bool isAzimuthElevationDirty() const { return m_isAzimuthElevationDirty; } |
136 bool isDistanceConeGainDirty(); | 140 bool isDistanceConeGainDirty() const { return m_isDistanceConeGainDirty; } |
137 bool isDopplerRateDirty(); | 141 bool isDopplerRateDirty() const { return m_isDopplerRateDirty; } |
138 | 142 |
139 // Notifies any AudioBufferSourceNodes connected to us either directly or in directly about our existence. | 143 // Notifies any AudioBufferSourceNodes connected to us either directly or in directly about our existence. |
140 // This is in order to handle the pitch change necessary for the doppler shi ft. | 144 // This is in order to handle the pitch change necessary for the doppler shi ft. |
141 void notifyAudioSourcesConnectedToNode(AudioNode*, HashMap<AudioNode*, bool> &visitedNodes); | 145 void notifyAudioSourcesConnectedToNode(AudioNode*, HashMap<AudioNode*, bool> &visitedNodes); |
142 | 146 |
143 void updateCachedListener(); | |
144 void updateCachedSourceLocationInfo(); | |
145 | |
146 OwnPtr<Panner> m_panner; | 147 OwnPtr<Panner> m_panner; |
147 unsigned m_panningModel; | 148 unsigned m_panningModel; |
148 unsigned m_distanceModel; | 149 unsigned m_distanceModel; |
149 | 150 |
150 // Current source location information | 151 // Current source location information |
151 FloatPoint3D m_position; | 152 FloatPoint3D m_position; |
152 FloatPoint3D m_orientation; | 153 FloatPoint3D m_orientation; |
153 FloatPoint3D m_velocity; | 154 FloatPoint3D m_velocity; |
154 | 155 |
155 // Cached source location information | 156 bool m_isAzimuthElevationDirty; |
156 FloatPoint3D m_cachedPosition; | 157 bool m_isDistanceConeGainDirty; |
157 FloatPoint3D m_cachedOrientation; | 158 bool m_isDopplerRateDirty; |
158 FloatPoint3D m_cachedVelocity; | |
159 | 159 |
160 // Gain | 160 // Gain |
161 DistanceEffect m_distanceEffect; | 161 DistanceEffect m_distanceEffect; |
162 ConeEffect m_coneEffect; | 162 ConeEffect m_coneEffect; |
163 float m_lastGain; | 163 float m_lastGain; |
164 | 164 |
165 double m_cachedAzimuth; | 165 double m_cachedAzimuth; |
166 double m_cachedElevation; | 166 double m_cachedElevation; |
167 float m_cachedDistanceConeGain; | 167 float m_cachedDistanceConeGain; |
168 double m_cachedDopplerRate; | 168 double m_cachedDopplerRate; |
169 | 169 |
170 // Cached listener parameters after processing. | |
171 RefPtr<AudioListener> m_cachedListener; | |
172 | |
173 RefPtr<HRTFDatabaseLoader> m_hrtfDatabaseLoader; | 170 RefPtr<HRTFDatabaseLoader> m_hrtfDatabaseLoader; |
174 | 171 |
175 // AudioContext's connection count | 172 // AudioContext's connection count |
176 unsigned m_connectionCount; | 173 unsigned m_connectionCount; |
177 | 174 |
178 // Synchronize process() with setting of the panning model, distance model a nd caching of the source location/orientation info. | 175 // Synchronize process() with setting of the panning model, source's locatio n information, listener, distance parameters and sound cones. |
179 mutable Mutex m_processLock; | 176 mutable Mutex m_processLock; |
180 }; | 177 }; |
181 | 178 |
182 } // namespace WebCore | 179 } // namespace WebCore |
183 | 180 |
184 #endif // PannerNode_h | 181 #endif // PannerNode_h |
OLD | NEW |