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 11 matching lines...) Expand all Loading... | |
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 using namespace std; | 40 using namespace std; |
40 | 41 |
41 namespace WebCore { | 42 namespace WebCore { |
(...skipping 16 matching lines...) Expand all Loading... | |
58 , m_isDopplerRateDirty(true) | 59 , m_isDopplerRateDirty(true) |
59 , m_lastGain(-1.0) | 60 , m_lastGain(-1.0) |
60 , m_cachedAzimuth(0) | 61 , m_cachedAzimuth(0) |
61 , m_cachedElevation(0) | 62 , m_cachedElevation(0) |
62 , m_cachedDistanceConeGain(1.0f) | 63 , m_cachedDistanceConeGain(1.0f) |
63 , m_cachedDopplerRate(1) | 64 , m_cachedDopplerRate(1) |
64 , m_connectionCount(0) | 65 , m_connectionCount(0) |
65 { | 66 { |
66 // Load the HRTF database asynchronously so we don't block the Javascript th read while creating the HRTF database. | 67 // Load the HRTF database asynchronously so we don't block the Javascript th read while creating the HRTF database. |
67 // The HRTF panner will return zeroes until the database is loaded. | 68 // The HRTF panner will return zeroes until the database is loaded. |
68 m_hrtfDatabaseLoader = HRTFDatabaseLoader::createAndLoadAsynchronouslyIfNece ssary(context->sampleRate()); | 69 RefPtrWillBeRawPtr<HRTFDatabaseLoader> loader = HRTFDatabaseLoader::createAn dLoadAsynchronouslyIfNecessary(context->sampleRate()); |
tkent
2014/07/16 23:32:25
RefPtrWillBeRawPtr should be RefPtr.
KhNo
2014/07/17 16:23:17
Done.
| |
70 listener()->setHRTFDatabaseLoader(loader.release()); | |
Raymond Toy
2014/07/16 16:35:38
Per the comment above, should we check that listen
KhNo
2014/07/17 16:23:17
Yes, we must. Thanks.
| |
69 | 71 |
70 ScriptWrappable::init(this); | 72 ScriptWrappable::init(this); |
71 addInput(adoptPtr(new AudioNodeInput(this))); | 73 addInput(adoptPtr(new AudioNodeInput(this))); |
72 addOutput(adoptPtr(new AudioNodeOutput(this, 2))); | 74 addOutput(adoptPtr(new AudioNodeOutput(this, 2))); |
73 | 75 |
74 // Node-specific default mixing rules. | 76 // Node-specific default mixing rules. |
75 m_channelCount = 2; | 77 m_channelCount = 2; |
76 m_channelCountMode = ClampedMax; | 78 m_channelCountMode = ClampedMax; |
77 m_channelInterpretation = AudioBus::Speakers; | 79 m_channelInterpretation = AudioBus::Speakers; |
78 | 80 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
118 destination->zero(); | 120 destination->zero(); |
119 return; | 121 return; |
120 } | 122 } |
121 | 123 |
122 // The audio thread can't block on this lock, so we call tryLock() instead. | 124 // The audio thread can't block on this lock, so we call tryLock() instead. |
123 MutexTryLocker tryLocker(m_processLock); | 125 MutexTryLocker tryLocker(m_processLock); |
124 MutexTryLocker tryListenerLocker(listener()->listenerLock()); | 126 MutexTryLocker tryListenerLocker(listener()->listenerLock()); |
125 | 127 |
126 if (tryLocker.locked() && tryListenerLocker.locked()) { | 128 if (tryLocker.locked() && tryListenerLocker.locked()) { |
127 // HRTFDatabase should be loaded before proceeding for offline audio con text when the panning model is HRTF. | 129 // HRTFDatabase should be loaded before proceeding for offline audio con text when the panning model is HRTF. |
128 if (m_panningModel == Panner::PanningModelHRTF && !m_hrtfDatabaseLoader- >isLoaded()) { | 130 if (m_panningModel == Panner::PanningModelHRTF && !hrtfDatabaseLoader()- >isLoaded()) { |
129 if (context()->isOfflineContext()) { | 131 if (context()->isOfflineContext()) { |
130 m_hrtfDatabaseLoader->waitForLoaderThreadCompletion(); | 132 hrtfDatabaseLoader()->waitForLoaderThreadCompletion(); |
131 } else { | 133 } else { |
132 destination->zero(); | 134 destination->zero(); |
133 return; | 135 return; |
134 } | 136 } |
135 } | 137 } |
136 | 138 |
137 // Apply the panning effect. | 139 // Apply the panning effect. |
138 double azimuth; | 140 double azimuth; |
139 double elevation; | 141 double elevation; |
140 azimuthElevation(&azimuth, &elevation); | 142 azimuthElevation(&azimuth, &elevation); |
(...skipping 14 matching lines...) Expand all Loading... | |
155 // We must be in the middle of changing the properties of the panner or the listener. | 157 // We must be in the middle of changing the properties of the panner or the listener. |
156 destination->zero(); | 158 destination->zero(); |
157 } | 159 } |
158 } | 160 } |
159 | 161 |
160 void PannerNode::initialize() | 162 void PannerNode::initialize() |
161 { | 163 { |
162 if (isInitialized()) | 164 if (isInitialized()) |
163 return; | 165 return; |
164 | 166 |
165 m_panner = Panner::create(m_panningModel, sampleRate(), m_hrtfDatabaseLoader .get()); | 167 m_panner = Panner::create(m_panningModel, sampleRate(), hrtfDatabaseLoader() ); |
166 listener()->addPanner(this); | 168 listener()->addPanner(this); |
167 | 169 |
168 AudioNode::initialize(); | 170 AudioNode::initialize(); |
169 } | 171 } |
170 | 172 |
171 void PannerNode::uninitialize() | 173 void PannerNode::uninitialize() |
172 { | 174 { |
173 if (!isInitialized()) | 175 if (!isInitialized()) |
174 return; | 176 return; |
175 | 177 |
(...skipping 30 matching lines...) Expand all Loading... | |
206 } | 208 } |
207 | 209 |
208 bool PannerNode::setPanningModel(unsigned model) | 210 bool PannerNode::setPanningModel(unsigned model) |
209 { | 211 { |
210 switch (model) { | 212 switch (model) { |
211 case Panner::PanningModelEqualPower: | 213 case Panner::PanningModelEqualPower: |
212 case Panner::PanningModelHRTF: | 214 case Panner::PanningModelHRTF: |
213 if (!m_panner.get() || model != m_panningModel) { | 215 if (!m_panner.get() || model != m_panningModel) { |
214 // This synchronizes with process(). | 216 // This synchronizes with process(). |
215 MutexLocker processLocker(m_processLock); | 217 MutexLocker processLocker(m_processLock); |
216 OwnPtr<Panner> newPanner = Panner::create(model, sampleRate(), m_hrt fDatabaseLoader.get()); | 218 OwnPtr<Panner> newPanner = Panner::create(model, sampleRate(), hrtfD atabaseLoader()); |
217 m_panner = newPanner.release(); | 219 m_panner = newPanner.release(); |
218 m_panningModel = model; | 220 m_panningModel = model; |
219 } | 221 } |
220 break; | 222 break; |
221 default: | 223 default: |
222 ASSERT_NOT_REACHED(); | 224 ASSERT_NOT_REACHED(); |
223 return false; | 225 return false; |
224 } | 226 } |
225 | 227 |
226 return true; | 228 return true; |
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
573 notifyAudioSourcesConnectedToNode(connectedNode, visitedNode s); // recurse | 575 notifyAudioSourcesConnectedToNode(connectedNode, visitedNode s); // recurse |
574 } | 576 } |
575 } | 577 } |
576 } | 578 } |
577 } | 579 } |
578 } | 580 } |
579 | 581 |
580 } // namespace WebCore | 582 } // namespace WebCore |
581 | 583 |
582 #endif // ENABLE(WEB_AUDIO) | 584 #endif // ENABLE(WEB_AUDIO) |
OLD | NEW |