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 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 return; | 96 return; |
97 } | 97 } |
98 | 98 |
99 AudioBus* source = input(0)->bus(); | 99 AudioBus* source = input(0)->bus(); |
100 | 100 |
101 if (!source) { | 101 if (!source) { |
102 destination->zero(); | 102 destination->zero(); |
103 return; | 103 return; |
104 } | 104 } |
105 | 105 |
106 // Apply the panning effect. | 106 // The audio thread can't block on this lock, so we call tryLock() instead. |
107 double azimuth; | 107 MutexTryLocker tryLocker(m_pannerLock); |
108 double elevation; | 108 if (tryLocker.locked()) { |
109 getAzimuthElevation(&azimuth, &elevation); | 109 // Apply the panning effect. |
110 m_panner->pan(azimuth, elevation, source, destination, framesToProcess); | 110 double azimuth; |
| 111 double elevation; |
| 112 getAzimuthElevation(&azimuth, &elevation); |
| 113 m_panner->pan(azimuth, elevation, source, destination, framesToProcess); |
111 | 114 |
112 // Get the distance and cone gain. | 115 // Get the distance and cone gain. |
113 double totalGain = distanceConeGain(); | 116 double totalGain = distanceConeGain(); |
114 | 117 |
115 // Snap to desired gain at the beginning. | 118 // Snap to desired gain at the beginning. |
116 if (m_lastGain == -1.0) | 119 if (m_lastGain == -1.0) |
117 m_lastGain = totalGain; | 120 m_lastGain = totalGain; |
118 | 121 |
119 // Apply gain in-place with de-zippering. | 122 // Apply gain in-place with de-zippering. |
120 destination->copyWithGainFrom(*destination, &m_lastGain, totalGain); | 123 destination->copyWithGainFrom(*destination, &m_lastGain, totalGain); |
| 124 } else { |
| 125 // Too bad - The tryLock() failed. We must be in the middle of changing
the panner. |
| 126 destination->zero(); |
| 127 } |
121 } | 128 } |
122 | 129 |
123 void PannerNode::reset() | 130 void PannerNode::reset() |
124 { | 131 { |
125 m_lastGain = -1.0; // force to snap to initial gain | 132 m_lastGain = -1.0; // force to snap to initial gain |
126 if (m_panner.get()) | 133 if (m_panner.get()) |
127 m_panner->reset(); | 134 m_panner->reset(); |
128 } | 135 } |
129 | 136 |
130 void PannerNode::initialize() | 137 void PannerNode::initialize() |
(...skipping 19 matching lines...) Expand all Loading... |
150 { | 157 { |
151 return context()->listener(); | 158 return context()->listener(); |
152 } | 159 } |
153 | 160 |
154 void PannerNode::setPanningModel(unsigned short model, ExceptionCode& ec) | 161 void PannerNode::setPanningModel(unsigned short model, ExceptionCode& ec) |
155 { | 162 { |
156 switch (model) { | 163 switch (model) { |
157 case EQUALPOWER: | 164 case EQUALPOWER: |
158 case HRTF: | 165 case HRTF: |
159 if (!m_panner.get() || model != m_panningModel) { | 166 if (!m_panner.get() || model != m_panningModel) { |
| 167 // This synchronizes with process(). |
| 168 MutexLocker processLocker(m_pannerLock); |
| 169 |
160 OwnPtr<Panner> newPanner = Panner::create(model, sampleRate()); | 170 OwnPtr<Panner> newPanner = Panner::create(model, sampleRate()); |
161 m_panner = newPanner.release(); | 171 m_panner = newPanner.release(); |
162 m_panningModel = model; | 172 m_panningModel = model; |
163 } | 173 } |
164 break; | 174 break; |
165 case SOUNDFIELD: | 175 case SOUNDFIELD: |
166 // FIXME: Implement sound field model. See // https://bugs.webkit.org/sh
ow_bug.cgi?id=77367. | 176 // FIXME: Implement sound field model. See // https://bugs.webkit.org/sh
ow_bug.cgi?id=77367. |
167 // For now, fall through to throw an exception. | 177 // For now, fall through to throw an exception. |
168 default: | 178 default: |
169 ec = NOT_SUPPORTED_ERR; | 179 ec = NOT_SUPPORTED_ERR; |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
335 AudioNode* connectedNode = connectedOutput->node(); | 345 AudioNode* connectedNode = connectedOutput->node(); |
336 notifyAudioSourcesConnectedToNode(connectedNode); // recurse | 346 notifyAudioSourcesConnectedToNode(connectedNode); // recurse |
337 } | 347 } |
338 } | 348 } |
339 } | 349 } |
340 } | 350 } |
341 | 351 |
342 } // namespace WebCore | 352 } // namespace WebCore |
343 | 353 |
344 #endif // ENABLE(WEB_AUDIO) | 354 #endif // ENABLE(WEB_AUDIO) |
OLD | NEW |