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

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

Issue 393363002: Move handle of HRTFDatabaseLoader to AudioListener. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Update as review. Created 6 years, 5 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
(...skipping 11 matching lines...) Expand all
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 #include "config.h" 25 #include "config.h"
26 26
27 #if ENABLE(WEB_AUDIO) 27 #if ENABLE(WEB_AUDIO)
28 28
29 #include "modules/webaudio/PannerNode.h" 29 #include "modules/webaudio/PannerNode.h"
30 30
31 #include "core/dom/ExecutionContext.h" 31 #include "core/dom/ExecutionContext.h"
32 #include "platform/audio/HRTFDatabaseLoader.h"
32 #include "platform/audio/HRTFPanner.h" 33 #include "platform/audio/HRTFPanner.h"
33 #include "modules/webaudio/AudioBufferSourceNode.h" 34 #include "modules/webaudio/AudioBufferSourceNode.h"
34 #include "modules/webaudio/AudioContext.h" 35 #include "modules/webaudio/AudioContext.h"
35 #include "modules/webaudio/AudioNodeInput.h" 36 #include "modules/webaudio/AudioNodeInput.h"
36 #include "modules/webaudio/AudioNodeOutput.h" 37 #include "modules/webaudio/AudioNodeOutput.h"
37 #include "wtf/MathExtras.h" 38 #include "wtf/MathExtras.h"
38 39
39 namespace WebCore { 40 namespace WebCore {
40 41
41 static void fixNANs(double &x) 42 static void fixNANs(double &x)
(...skipping 14 matching lines...) Expand all
56 , m_isDopplerRateDirty(true) 57 , m_isDopplerRateDirty(true)
57 , m_lastGain(-1.0) 58 , m_lastGain(-1.0)
58 , m_cachedAzimuth(0) 59 , m_cachedAzimuth(0)
59 , m_cachedElevation(0) 60 , m_cachedElevation(0)
60 , m_cachedDistanceConeGain(1.0f) 61 , m_cachedDistanceConeGain(1.0f)
61 , m_cachedDopplerRate(1) 62 , m_cachedDopplerRate(1)
62 , m_connectionCount(0) 63 , m_connectionCount(0)
63 { 64 {
64 // Load the HRTF database asynchronously so we don't block the Javascript th read while creating the HRTF database. 65 // Load the HRTF database asynchronously so we don't block the Javascript th read while creating the HRTF database.
65 // The HRTF panner will return zeroes until the database is loaded. 66 // The HRTF panner will return zeroes until the database is loaded.
66 m_hrtfDatabaseLoader = HRTFDatabaseLoader::createAndLoadAsynchronouslyIfNece ssary(context->sampleRate()); 67 listener()->createAndLoadHRTFDatabaseLoader(context->sampleRate());
67 68
68 ScriptWrappable::init(this); 69 ScriptWrappable::init(this);
69 addInput(); 70 addInput();
70 addOutput(AudioNodeOutput::create(this, 2)); 71 addOutput(AudioNodeOutput::create(this, 2));
71 72
72 // Node-specific default mixing rules. 73 // Node-specific default mixing rules.
73 m_channelCount = 2; 74 m_channelCount = 2;
74 m_channelCountMode = ClampedMax; 75 m_channelCountMode = ClampedMax;
75 m_channelInterpretation = AudioBus::Speakers; 76 m_channelInterpretation = AudioBus::Speakers;
76 77
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 destination->zero(); 117 destination->zero();
117 return; 118 return;
118 } 119 }
119 120
120 // The audio thread can't block on this lock, so we call tryLock() instead. 121 // The audio thread can't block on this lock, so we call tryLock() instead.
121 MutexTryLocker tryLocker(m_processLock); 122 MutexTryLocker tryLocker(m_processLock);
122 MutexTryLocker tryListenerLocker(listener()->listenerLock()); 123 MutexTryLocker tryListenerLocker(listener()->listenerLock());
123 124
124 if (tryLocker.locked() && tryListenerLocker.locked()) { 125 if (tryLocker.locked() && tryListenerLocker.locked()) {
125 // HRTFDatabase should be loaded before proceeding for offline audio con text when the panning model is HRTF. 126 // HRTFDatabase should be loaded before proceeding for offline audio con text when the panning model is HRTF.
126 if (m_panningModel == Panner::PanningModelHRTF && !m_hrtfDatabaseLoader- >isLoaded()) { 127 if (m_panningModel == Panner::PanningModelHRTF && !hrtfDatabaseLoader()- >isLoaded()) {
Raymond Toy 2014/07/17 17:25:45 Since the HRTF database is loaded in the listener,
127 if (context()->isOfflineContext()) { 128 if (context()->isOfflineContext()) {
128 m_hrtfDatabaseLoader->waitForLoaderThreadCompletion(); 129 hrtfDatabaseLoader()->waitForLoaderThreadCompletion();
Raymond Toy 2014/07/17 17:25:46 Same as above. Maybe use listener()->waitForHRTFL
129 } else { 130 } else {
130 destination->zero(); 131 destination->zero();
131 return; 132 return;
132 } 133 }
133 } 134 }
134 135
135 // Apply the panning effect. 136 // Apply the panning effect.
136 double azimuth; 137 double azimuth;
137 double elevation; 138 double elevation;
138 azimuthElevation(&azimuth, &elevation); 139 azimuthElevation(&azimuth, &elevation);
(...skipping 14 matching lines...) Expand all
153 // We must be in the middle of changing the properties of the panner or the listener. 154 // We must be in the middle of changing the properties of the panner or the listener.
154 destination->zero(); 155 destination->zero();
155 } 156 }
156 } 157 }
157 158
158 void PannerNode::initialize() 159 void PannerNode::initialize()
159 { 160 {
160 if (isInitialized()) 161 if (isInitialized())
161 return; 162 return;
162 163
163 m_panner = Panner::create(m_panningModel, sampleRate(), m_hrtfDatabaseLoader .get()); 164 m_panner = Panner::create(m_panningModel, sampleRate(), hrtfDatabaseLoader() );
164 listener()->addPanner(this); 165 listener()->addPanner(this);
165 166
166 AudioNode::initialize(); 167 AudioNode::initialize();
167 } 168 }
168 169
169 void PannerNode::uninitialize() 170 void PannerNode::uninitialize()
170 { 171 {
171 if (!isInitialized()) 172 if (!isInitialized())
172 return; 173 return;
173 174
(...skipping 30 matching lines...) Expand all
204 } 205 }
205 206
206 bool PannerNode::setPanningModel(unsigned model) 207 bool PannerNode::setPanningModel(unsigned model)
207 { 208 {
208 switch (model) { 209 switch (model) {
209 case Panner::PanningModelEqualPower: 210 case Panner::PanningModelEqualPower:
210 case Panner::PanningModelHRTF: 211 case Panner::PanningModelHRTF:
211 if (!m_panner.get() || model != m_panningModel) { 212 if (!m_panner.get() || model != m_panningModel) {
212 // This synchronizes with process(). 213 // This synchronizes with process().
213 MutexLocker processLocker(m_processLock); 214 MutexLocker processLocker(m_processLock);
214 OwnPtr<Panner> newPanner = Panner::create(model, sampleRate(), m_hrt fDatabaseLoader.get()); 215 OwnPtr<Panner> newPanner = Panner::create(model, sampleRate(), hrtfD atabaseLoader());
215 m_panner = newPanner.release(); 216 m_panner = newPanner.release();
216 m_panningModel = model; 217 m_panningModel = model;
217 } 218 }
218 break; 219 break;
219 default: 220 default:
220 ASSERT_NOT_REACHED(); 221 ASSERT_NOT_REACHED();
221 return false; 222 return false;
222 } 223 }
223 224
224 return true; 225 return true;
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after
571 notifyAudioSourcesConnectedToNode(connectedNode, visitedNode s); // recurse 572 notifyAudioSourcesConnectedToNode(connectedNode, visitedNode s); // recurse
572 } 573 }
573 } 574 }
574 } 575 }
575 } 576 }
576 } 577 }
577 578
578 } // namespace WebCore 579 } // namespace WebCore
579 580
580 #endif // ENABLE(WEB_AUDIO) 581 #endif // ENABLE(WEB_AUDIO)
OLDNEW
« Source/modules/webaudio/AudioListener.h ('K') | « Source/modules/webaudio/PannerNode.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698