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

Side by Side Diff: third_party/WebKit/Source/platform/audio/HRTFPanner.cpp

Issue 1530723004: Use clampTo instead of chaining std::max(std::min(...)) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Handling that minimumThumbLength > trackLen. Created 5 years 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 10 matching lines...) Expand all
21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
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 "platform/audio/HRTFPanner.h" 29 #include "platform/audio/HRTFPanner.h"
30 30
31 #include <algorithm>
32 #include "platform/audio/AudioBus.h" 31 #include "platform/audio/AudioBus.h"
33 #include "platform/audio/AudioUtilities.h" 32 #include "platform/audio/AudioUtilities.h"
34 #include "platform/audio/HRTFDatabase.h" 33 #include "platform/audio/HRTFDatabase.h"
35 #include "wtf/MathExtras.h" 34 #include "wtf/MathExtras.h"
36 #include "wtf/RefPtr.h" 35 #include "wtf/RefPtr.h"
37 36
38 namespace blink { 37 namespace blink {
39 38
40 // The value of 2 milliseconds is larger than the largest delay which exists in any HRTFKernel from the default HRTFDatabase (0.0136 seconds). 39 // The value of 2 milliseconds is larger than the largest delay which exists in any HRTFKernel from the default HRTFDatabase (0.0136 seconds).
41 // We ASSERT the delay values used in process() with this value. 40 // We ASSERT the delay values used in process() with this value.
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 int numberOfAzimuths = HRTFDatabase::numberOfAzimuths(); 111 int numberOfAzimuths = HRTFDatabase::numberOfAzimuths();
113 const double angleBetweenAzimuths = 360.0 / numberOfAzimuths; 112 const double angleBetweenAzimuths = 360.0 / numberOfAzimuths;
114 113
115 // Calculate the azimuth index and the blend (0 -> 1) for interpolation. 114 // Calculate the azimuth index and the blend (0 -> 1) for interpolation.
116 double desiredAzimuthIndexFloat = azimuth / angleBetweenAzimuths; 115 double desiredAzimuthIndexFloat = azimuth / angleBetweenAzimuths;
117 int desiredAzimuthIndex = static_cast<int>(desiredAzimuthIndexFloat); 116 int desiredAzimuthIndex = static_cast<int>(desiredAzimuthIndexFloat);
118 azimuthBlend = desiredAzimuthIndexFloat - static_cast<double>(desiredAzimuth Index); 117 azimuthBlend = desiredAzimuthIndexFloat - static_cast<double>(desiredAzimuth Index);
119 118
120 // We don't immediately start using this azimuth index, but instead approach this index from the last index we rendered at. 119 // We don't immediately start using this azimuth index, but instead approach this index from the last index we rendered at.
121 // This minimizes the clicks and graininess for moving sources which occur o therwise. 120 // This minimizes the clicks and graininess for moving sources which occur o therwise.
122 desiredAzimuthIndex = std::max(0, desiredAzimuthIndex); 121 desiredAzimuthIndex = clampTo(desiredAzimuthIndex, 0, numberOfAzimuths - 1);
123 desiredAzimuthIndex = std::min(numberOfAzimuths - 1, desiredAzimuthIndex);
124 return desiredAzimuthIndex; 122 return desiredAzimuthIndex;
125 } 123 }
126 124
127 void HRTFPanner::pan(double desiredAzimuth, double elevation, const AudioBus* in putBus, AudioBus* outputBus, size_t framesToProcess) 125 void HRTFPanner::pan(double desiredAzimuth, double elevation, const AudioBus* in putBus, AudioBus* outputBus, size_t framesToProcess)
128 { 126 {
129 unsigned numInputChannels = inputBus ? inputBus->numberOfChannels() : 0; 127 unsigned numInputChannels = inputBus ? inputBus->numberOfChannels() : 0;
130 128
131 bool isInputGood = inputBus && numInputChannels >= 1 && numInputChannels <= 2; 129 bool isInputGood = inputBus && numInputChannels >= 1 && numInputChannels <= 2;
132 ASSERT(isInputGood); 130 ASSERT(isInputGood);
133 131
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 double HRTFPanner::latencyTime() const 308 double HRTFPanner::latencyTime() const
311 { 309 {
312 // The latency of a FFTConvolver is also fftSize() / 2, and is in addition t o its tailTime of the 310 // The latency of a FFTConvolver is also fftSize() / 2, and is in addition t o its tailTime of the
313 // same value. 311 // same value.
314 return (fftSize() / 2) / static_cast<double>(sampleRate()); 312 return (fftSize() / 2) / static_cast<double>(sampleRate());
315 } 313 }
316 314
317 } // namespace blink 315 } // namespace blink
318 316
319 #endif // ENABLE(WEB_AUDIO) 317 #endif // ENABLE(WEB_AUDIO)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698