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 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 if (!source) { | 124 if (!source) { |
125 destination->zero(); | 125 destination->zero(); |
126 return; | 126 return; |
127 } | 127 } |
128 | 128 |
129 // The audio thread can't block on this lock, so we call tryLock() instead. | 129 // The audio thread can't block on this lock, so we call tryLock() instead. |
130 MutexTryLocker tryLocker(m_processLock); | 130 MutexTryLocker tryLocker(m_processLock); |
131 MutexTryLocker tryListenerLocker(listener()->listenerLock()); | 131 MutexTryLocker tryListenerLocker(listener()->listenerLock()); |
132 | 132 |
133 if (tryLocker.locked() && tryListenerLocker.locked()) { | 133 if (tryLocker.locked() && tryListenerLocker.locked()) { |
134 // HRTFDatabase should be loaded before proceeding when the panning mode
l is HRTF. | 134 if (!context()->hasRealtimeConstraint() && m_panningModel == Panner::Pan
ningModelHRTF) { |
135 if (m_panningModel == Panner::PanningModelHRTF && !listener()->isHRTFDat
abaseLoaded()) { | 135 // For an OfflineAudioContext, we need to make sure the HRTFDatabase |
136 if (context()->hasRealtimeConstraint()) { | 136 // is loaded before proceeding. For realtime contexts, we don't |
137 // Realtime AudioContext's cannot block on the HRTFDatabase | 137 // have to wait. The HRTF panner handles that case itself. |
138 // loader. Instead, copy the input to the output so we can at | |
139 // least hear something until the database is ready. | |
140 destination->copyFrom(*source, m_channelInterpretation); | |
141 return; | |
142 } | |
143 | |
144 listener()->waitForHRTFDatabaseLoaderThreadCompletion(); | 138 listener()->waitForHRTFDatabaseLoaderThreadCompletion(); |
145 } | 139 } |
146 | 140 |
147 if (hasSampleAccurateValues() || listener()->hasSampleAccurateValues())
{ | 141 if (hasSampleAccurateValues() || listener()->hasSampleAccurateValues())
{ |
148 // It's tempting to skip sample-accurate processing if isAzimuthElev
ationDirty() and | 142 // It's tempting to skip sample-accurate processing if isAzimuthElev
ationDirty() and |
149 // isDistanceConeGain() both return false. But in general we can't
because something | 143 // isDistanceConeGain() both return false. But in general we can't
because something |
150 // may scheduled to start in the middle of the rendering quantum. O
n the other hand, | 144 // may scheduled to start in the middle of the rendering quantum. O
n the other hand, |
151 // the audible effect may be small enough that we can afford to do t
his optimization. | 145 // the audible effect may be small enough that we can afford to do t
his optimization. |
152 processSampleAccurateValues(destination, source, framesToProcess); | 146 processSampleAccurateValues(destination, source, framesToProcess); |
153 } else { | 147 } else { |
154 // Apply the panning effect. | 148 // Apply the panning effect. |
155 double azimuth; | 149 double azimuth; |
156 double elevation; | 150 double elevation; |
157 | 151 |
158 // Update dirty state in case something has moved; this can happen i
f the AudioParam for | 152 // Update dirty state in case something has moved; this can happen i
f the AudioParam for |
159 // the position or orientation component is set directly. | 153 // the position or orientation component is set directly. |
160 updateDirtyState(); | 154 updateDirtyState(); |
161 | 155 |
162 azimuthElevation(&azimuth, &elevation); | 156 azimuthElevation(&azimuth, &elevation); |
163 | 157 |
164 m_panner->pan(azimuth, elevation, source, destination, framesToProce
ss); | 158 m_panner->pan(azimuth, elevation, source, destination, framesToProce
ss, internalChannelInterpretation()); |
165 | 159 |
166 // Get the distance and cone gain. | 160 // Get the distance and cone gain. |
167 float totalGain = distanceConeGain(); | 161 float totalGain = distanceConeGain(); |
168 | 162 |
169 m_lastGain = totalGain; | 163 m_lastGain = totalGain; |
170 | 164 |
171 // Apply gain in-place with de-zippering. | 165 // Apply gain in-place with de-zippering. |
172 destination->copyWithGainFrom(*destination, &m_lastGain, totalGain); | 166 destination->copyWithGainFrom(*destination, &m_lastGain, totalGain); |
173 } | 167 } |
174 } else { | 168 } else { |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 FloatPoint3D listenerForward(forwardX[k], forwardY[k], forwardZ[k]); | 218 FloatPoint3D listenerForward(forwardX[k], forwardY[k], forwardZ[k]); |
225 FloatPoint3D listenerUp(upX[k], upY[k], upZ[k]); | 219 FloatPoint3D listenerUp(upX[k], upY[k], upZ[k]); |
226 | 220 |
227 calculateAzimuthElevation(&azimuth[k], &elevation[k], | 221 calculateAzimuthElevation(&azimuth[k], &elevation[k], |
228 pannerPosition, listenerPosition, listenerForward, listenerUp); | 222 pannerPosition, listenerPosition, listenerForward, listenerUp); |
229 | 223 |
230 // Get distance and cone gain | 224 // Get distance and cone gain |
231 totalGain[k] = calculateDistanceConeGain(pannerPosition, orientation, li
stenerPosition); | 225 totalGain[k] = calculateDistanceConeGain(pannerPosition, orientation, li
stenerPosition); |
232 } | 226 } |
233 | 227 |
234 m_panner->panWithSampleAccurateValues(azimuth, elevation, source, destinatio
n, framesToProcess); | 228 m_panner->panWithSampleAccurateValues(azimuth, elevation, source, destinatio
n, framesToProcess, internalChannelInterpretation()); |
235 destination->copyWithSampleAccurateGainValuesFrom(*destination, totalGain, f
ramesToProcess); | 229 destination->copyWithSampleAccurateGainValuesFrom(*destination, totalGain, f
ramesToProcess); |
236 } | 230 } |
237 | 231 |
238 void PannerHandler::initialize() | 232 void PannerHandler::initialize() |
239 { | 233 { |
240 if (isInitialized()) | 234 if (isInitialized()) |
241 return; | 235 return; |
242 | 236 |
243 m_panner = Panner::create(m_panningModel, sampleRate(), listener()->hrtfData
baseLoader()); | 237 m_panner = Panner::create(m_panningModel, sampleRate(), listener()->hrtfData
baseLoader()); |
244 listener()->addPanner(*this); | 238 listener()->addPanner(*this); |
(...skipping 537 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
782 visitor->trace(m_positionZ); | 776 visitor->trace(m_positionZ); |
783 | 777 |
784 visitor->trace(m_orientationX); | 778 visitor->trace(m_orientationX); |
785 visitor->trace(m_orientationY); | 779 visitor->trace(m_orientationY); |
786 visitor->trace(m_orientationZ); | 780 visitor->trace(m_orientationZ); |
787 | 781 |
788 AudioNode::trace(visitor); | 782 AudioNode::trace(visitor); |
789 } | 783 } |
790 | 784 |
791 } // namespace blink | 785 } // namespace blink |
OLD | NEW |