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

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

Issue 232453003: Add logic to cache elements of panner node from calculation with own attributes and AudioListener (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Unrelated fix has been separated. Created 6 years, 8 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
« no previous file with comments | « Source/modules/webaudio/AudioListener.cpp ('k') | Source/modules/webaudio/PannerNode.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 LINEAR_DISTANCE = 0,
60 INVERSE_DISTANCE = 1, 60 INVERSE_DISTANCE = 1,
61 EXPONENTIAL_DISTANCE = 2, 61 EXPONENTIAL_DISTANCE = 2,
62 }; 62 };
63 63
64 // These enums are used to distinguish what cached values of panner are dirt y.
65 enum {
66 AzimuthElevationDirty = 0x1,
67 DistanceConeGainDirty = 0x2,
68 DopplerRateDirty = 0x4,
69 };
70
64 static PassRefPtr<PannerNode> create(AudioContext* context, float sampleRate ) 71 static PassRefPtr<PannerNode> create(AudioContext* context, float sampleRate )
65 { 72 {
66 return adoptRef(new PannerNode(context, sampleRate)); 73 return adoptRef(new PannerNode(context, sampleRate));
67 } 74 }
68 75
69 virtual ~PannerNode(); 76 virtual ~PannerNode();
70 77
71 // AudioNode 78 // AudioNode
72 virtual void process(size_t framesToProcess) OVERRIDE; 79 virtual void process(size_t framesToProcess) OVERRIDE;
73 virtual void pullInputs(size_t framesToProcess) OVERRIDE; 80 virtual void pullInputs(size_t framesToProcess) OVERRIDE;
74 virtual void initialize() OVERRIDE; 81 virtual void initialize() OVERRIDE;
75 virtual void uninitialize() OVERRIDE; 82 virtual void uninitialize() OVERRIDE;
76 83
77 // AudioContext's listener
78 AudioListener* listener();
79
80 // Panning model 84 // Panning model
81 String panningModel() const; 85 String panningModel() const;
82 void setPanningModel(const String&); 86 void setPanningModel(const String&);
83 87
84 // Position 88 // Position, orientation and velocity
85 void setPosition(float x, float y, float z); 89 void setPosition(float x, float y, float z);
86
87 // Orientation
88 void setOrientation(float x, float y, float z); 90 void setOrientation(float x, float y, float z);
89
90 // Velocity
91 void setVelocity(float x, float y, float z); 91 void setVelocity(float x, float y, float z);
92 92
93 // Distance parameters 93 // Distance parameters
94 String distanceModel() const; 94 String distanceModel() const;
95 void setDistanceModel(const String&); 95 void setDistanceModel(const String&);
96 96
97 double refDistance() { return m_distanceEffect.refDistance(); } 97 double refDistance() { return m_distanceEffect.refDistance(); }
98 void setRefDistance(double refDistance) { m_distanceEffect.setRefDistance(re fDistance); } 98 void setRefDistance(double);
99 99
100 double maxDistance() { return m_distanceEffect.maxDistance(); } 100 double maxDistance() { return m_distanceEffect.maxDistance(); }
101 void setMaxDistance(double maxDistance) { m_distanceEffect.setMaxDistance(ma xDistance); } 101 void setMaxDistance(double);
102 102
103 double rolloffFactor() { return m_distanceEffect.rolloffFactor(); } 103 double rolloffFactor() { return m_distanceEffect.rolloffFactor(); }
104 void setRolloffFactor(double rolloffFactor) { m_distanceEffect.setRolloffFac tor(rolloffFactor); } 104 void setRolloffFactor(double);
105 105
106 // Sound cones - angles in degrees 106 // Sound cones - angles in degrees
107 double coneInnerAngle() const { return m_coneEffect.innerAngle(); } 107 double coneInnerAngle() const { return m_coneEffect.innerAngle(); }
108 void setConeInnerAngle(double angle) { m_coneEffect.setInnerAngle(angle); } 108 void setConeInnerAngle(double);
109 109
110 double coneOuterAngle() const { return m_coneEffect.outerAngle(); } 110 double coneOuterAngle() const { return m_coneEffect.outerAngle(); }
111 void setConeOuterAngle(double angle) { m_coneEffect.setOuterAngle(angle); } 111 void setConeOuterAngle(double);
112 112
113 double coneOuterGain() const { return m_coneEffect.outerGain(); } 113 double coneOuterGain() const { return m_coneEffect.outerGain(); }
114 void setConeOuterGain(double angle) { m_coneEffect.setOuterGain(angle); } 114 void setConeOuterGain(double);
115
116 void markPannerAsDirty(unsigned);
115 117
116 // It must be called on audio thread, currently called only process() in Aud ioBufferSourceNode. 118 // It must be called on audio thread, currently called only process() in Aud ioBufferSourceNode.
117 double dopplerRate(); 119 double dopplerRate();
118 120
119 virtual double tailTime() const OVERRIDE { return m_panner ? m_panner->tailT ime() : 0; } 121 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; } 122 virtual double latencyTime() const OVERRIDE { return m_panner ? m_panner->la tencyTime() : 0; }
121 123
122 private: 124 private:
123 PannerNode(AudioContext*, float sampleRate); 125 PannerNode(AudioContext*, float sampleRate);
124 126
127 // AudioContext's listener
128 AudioListener* listener();
129
125 bool setPanningModel(unsigned); // Returns true on success. 130 bool setPanningModel(unsigned); // Returns true on success.
126 bool setDistanceModel(unsigned); // Returns true on success. 131 bool setDistanceModel(unsigned); // Returns true on success.
132
127 void calculateAzimuthElevation(double* outAzimuth, double* outElevation); 133 void calculateAzimuthElevation(double* outAzimuth, double* outElevation);
128 // Returns the combined distance and cone gain attenuation. 134 float calculateDistanceConeGain(); // Returns the combined distance and cone gain attenuation.
129 float calculateDistanceConeGain();
130 double calculateDopplerRate(); 135 double calculateDopplerRate();
131 136
132 void azimuthElevation(double* outAzimuth, double* outElevation); 137 void azimuthElevation(double* outAzimuth, double* outElevation);
133 float distanceConeGain(); 138 float distanceConeGain();
134 139
135 bool isAzimuthElevationDirty(); 140 bool isAzimuthElevationDirty() const { return m_isAzimuthElevationDirty; }
136 bool isDistanceConeGainDirty(); 141 bool isDistanceConeGainDirty() const { return m_isDistanceConeGainDirty; }
137 bool isDopplerRateDirty(); 142 bool isDopplerRateDirty() const { return m_isDopplerRateDirty; }
138 143
139 // Notifies any AudioBufferSourceNodes connected to us either directly or in directly about our existence. 144 // 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. 145 // This is in order to handle the pitch change necessary for the doppler shi ft.
141 void notifyAudioSourcesConnectedToNode(AudioNode*, HashMap<AudioNode*, bool> &visitedNodes); 146 void notifyAudioSourcesConnectedToNode(AudioNode*, HashMap<AudioNode*, bool> &visitedNodes);
142 147
143 void updateCachedListener();
144 void updateCachedSourceLocationInfo();
145
146 OwnPtr<Panner> m_panner; 148 OwnPtr<Panner> m_panner;
147 unsigned m_panningModel; 149 unsigned m_panningModel;
148 unsigned m_distanceModel; 150 unsigned m_distanceModel;
149 151
150 // Current source location information 152 // Current source location information
151 FloatPoint3D m_position; 153 FloatPoint3D m_position;
152 FloatPoint3D m_orientation; 154 FloatPoint3D m_orientation;
153 FloatPoint3D m_velocity; 155 FloatPoint3D m_velocity;
154 156
155 // Cached source location information 157 bool m_isAzimuthElevationDirty;
156 FloatPoint3D m_cachedPosition; 158 bool m_isDistanceConeGainDirty;
157 FloatPoint3D m_cachedOrientation; 159 bool m_isDopplerRateDirty;
158 FloatPoint3D m_cachedVelocity;
159 160
160 // Gain 161 // Gain
161 DistanceEffect m_distanceEffect; 162 DistanceEffect m_distanceEffect;
162 ConeEffect m_coneEffect; 163 ConeEffect m_coneEffect;
163 float m_lastGain; 164 float m_lastGain;
164 165
166 // Cached values
165 double m_cachedAzimuth; 167 double m_cachedAzimuth;
166 double m_cachedElevation; 168 double m_cachedElevation;
167 float m_cachedDistanceConeGain; 169 float m_cachedDistanceConeGain;
168 double m_cachedDopplerRate; 170 double m_cachedDopplerRate;
169 171
170 // Cached listener parameters after processing.
171 RefPtr<AudioListener> m_cachedListener;
172
173 RefPtr<HRTFDatabaseLoader> m_hrtfDatabaseLoader; 172 RefPtr<HRTFDatabaseLoader> m_hrtfDatabaseLoader;
174 173
175 // AudioContext's connection count 174 // AudioContext's connection count
176 unsigned m_connectionCount; 175 unsigned m_connectionCount;
177 176
178 // Synchronize process() with setting of the panning model, distance model a nd caching of the source location/orientation info. 177 // Synchronize process() with setting of the panning model, source's locatio n information, listener, distance parameters and sound cones.
179 mutable Mutex m_processLock; 178 mutable Mutex m_processLock;
180 }; 179 };
181 180
182 } // namespace WebCore 181 } // namespace WebCore
183 182
184 #endif // PannerNode_h 183 #endif // PannerNode_h
OLDNEW
« no previous file with comments | « Source/modules/webaudio/AudioListener.cpp ('k') | Source/modules/webaudio/PannerNode.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698