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 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 return; | 97 return; |
98 } | 98 } |
99 | 99 |
100 AudioBus* source = input(0)->bus(); | 100 AudioBus* source = input(0)->bus(); |
101 | 101 |
102 if (!source) { | 102 if (!source) { |
103 destination->zero(); | 103 destination->zero(); |
104 return; | 104 return; |
105 } | 105 } |
106 | 106 |
107 // Apply the panning effect. | 107 // The audio thread can't block on this lock, so we call tryLock() instead. |
108 double azimuth; | 108 MutexTryLocker tryLocker(m_pannerLock); |
109 double elevation; | 109 if (tryLocker.locked()) { |
110 getAzimuthElevation(&azimuth, &elevation); | 110 // Apply the panning effect. |
111 m_panner->pan(azimuth, elevation, source, destination, framesToProcess); | 111 double azimuth; |
| 112 double elevation; |
| 113 getAzimuthElevation(&azimuth, &elevation); |
| 114 m_panner->pan(azimuth, elevation, source, destination, framesToProcess); |
112 | 115 |
113 // Get the distance and cone gain. | 116 // Get the distance and cone gain. |
114 double totalGain = distanceConeGain(); | 117 double totalGain = distanceConeGain(); |
115 | 118 |
116 // Snap to desired gain at the beginning. | 119 // Snap to desired gain at the beginning. |
117 if (m_lastGain == -1.0) | 120 if (m_lastGain == -1.0) |
118 m_lastGain = totalGain; | 121 m_lastGain = totalGain; |
119 | 122 |
120 // Apply gain in-place with de-zippering. | 123 // Apply gain in-place with de-zippering. |
121 destination->copyWithGainFrom(*destination, &m_lastGain, totalGain); | 124 destination->copyWithGainFrom(*destination, &m_lastGain, totalGain); |
| 125 } else { |
| 126 // Too bad - The tryLock() failed. We must be in the middle of changing
the panner. |
| 127 destination->zero(); |
| 128 } |
122 } | 129 } |
123 | 130 |
124 void PannerNode::reset() | 131 void PannerNode::reset() |
125 { | 132 { |
126 m_lastGain = -1.0; // force to snap to initial gain | 133 m_lastGain = -1.0; // force to snap to initial gain |
127 if (m_panner.get()) | 134 if (m_panner.get()) |
128 m_panner->reset(); | 135 m_panner->reset(); |
129 } | 136 } |
130 | 137 |
131 void PannerNode::initialize() | 138 void PannerNode::initialize() |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 else | 185 else |
179 ASSERT_NOT_REACHED(); | 186 ASSERT_NOT_REACHED(); |
180 } | 187 } |
181 | 188 |
182 bool PannerNode::setPanningModel(unsigned model) | 189 bool PannerNode::setPanningModel(unsigned model) |
183 { | 190 { |
184 switch (model) { | 191 switch (model) { |
185 case EQUALPOWER: | 192 case EQUALPOWER: |
186 case HRTF: | 193 case HRTF: |
187 if (!m_panner.get() || model != m_panningModel) { | 194 if (!m_panner.get() || model != m_panningModel) { |
| 195 // This synchronizes with process(). |
| 196 MutexLocker processLocker(m_pannerLock); |
| 197 |
188 OwnPtr<Panner> newPanner = Panner::create(model, sampleRate()); | 198 OwnPtr<Panner> newPanner = Panner::create(model, sampleRate()); |
189 m_panner = newPanner.release(); | 199 m_panner = newPanner.release(); |
190 m_panningModel = model; | 200 m_panningModel = model; |
191 } | 201 } |
192 break; | 202 break; |
193 case SOUNDFIELD: | 203 case SOUNDFIELD: |
194 // FIXME: Implement sound field model. See // https://bugs.webkit.org/sh
ow_bug.cgi?id=77367. | 204 // FIXME: Implement sound field model. See // https://bugs.webkit.org/sh
ow_bug.cgi?id=77367. |
195 context()->scriptExecutionContext()->addConsoleMessage(JSMessageSource,
WarningMessageLevel, "'soundfield' panning model not implemented."); | 205 context()->scriptExecutionContext()->addConsoleMessage(JSMessageSource,
WarningMessageLevel, "'soundfield' panning model not implemented."); |
196 break; | 206 break; |
197 default: | 207 default: |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
393 AudioNode* connectedNode = connectedOutput->node(); | 403 AudioNode* connectedNode = connectedOutput->node(); |
394 notifyAudioSourcesConnectedToNode(connectedNode); // recurse | 404 notifyAudioSourcesConnectedToNode(connectedNode); // recurse |
395 } | 405 } |
396 } | 406 } |
397 } | 407 } |
398 } | 408 } |
399 | 409 |
400 } // namespace WebCore | 410 } // namespace WebCore |
401 | 411 |
402 #endif // ENABLE(WEB_AUDIO) | 412 #endif // ENABLE(WEB_AUDIO) |
OLD | NEW |