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

Side by Side Diff: third_party/WebKit/Source/platform/audio/EqualPowerPanner.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/EqualPowerPanner.h" 29 #include "platform/audio/EqualPowerPanner.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 "wtf/MathExtras.h" 33 #include "wtf/MathExtras.h"
34 #include <algorithm>
35 #include <cmath>
35 36
36 // Use a 50ms smoothing / de-zippering time-constant. 37 // Use a 50ms smoothing / de-zippering time-constant.
37 const float SmoothingTimeConstant = 0.050f; 38 const float SmoothingTimeConstant = 0.050f;
38 39
39 namespace blink { 40 namespace blink {
40 41
41 EqualPowerPanner::EqualPowerPanner(float sampleRate) 42 EqualPowerPanner::EqualPowerPanner(float sampleRate)
42 : Panner(PanningModelEqualPower) 43 : Panner(PanningModelEqualPower)
43 , m_isFirstRender(true) 44 , m_isFirstRender(true)
44 , m_gainL(0.0) 45 , m_gainL(0.0)
(...skipping 18 matching lines...) Expand all
63 64
64 const float* sourceL = inputBus->channel(0)->data(); 65 const float* sourceL = inputBus->channel(0)->data();
65 const float* sourceR = numberOfInputChannels > 1 ? inputBus->channel(1)->dat a() : sourceL; 66 const float* sourceR = numberOfInputChannels > 1 ? inputBus->channel(1)->dat a() : sourceL;
66 float* destinationL = outputBus->channelByType(AudioBus::ChannelLeft)->mutab leData(); 67 float* destinationL = outputBus->channelByType(AudioBus::ChannelLeft)->mutab leData();
67 float* destinationR = outputBus->channelByType(AudioBus::ChannelRight)->muta bleData(); 68 float* destinationR = outputBus->channelByType(AudioBus::ChannelRight)->muta bleData();
68 69
69 if (!sourceL || !sourceR || !destinationL || !destinationR) 70 if (!sourceL || !sourceR || !destinationL || !destinationR)
70 return; 71 return;
71 72
72 // Clamp azimuth to allowed range of -180 -> +180. 73 // Clamp azimuth to allowed range of -180 -> +180.
73 azimuth = std::max(-180.0, azimuth); 74 azimuth = clampTo(azimuth, -180.0, 180.0);
74 azimuth = std::min(180.0, azimuth);
75 75
76 // Alias the azimuth ranges behind us to in front of us: 76 // Alias the azimuth ranges behind us to in front of us:
77 // -90 -> -180 to -90 -> 0 and 90 -> 180 to 90 -> 0 77 // -90 -> -180 to -90 -> 0 and 90 -> 180 to 90 -> 0
78 if (azimuth < -90) 78 if (azimuth < -90)
79 azimuth = -180 - azimuth; 79 azimuth = -180 - azimuth;
80 else if (azimuth > 90) 80 else if (azimuth > 90)
81 azimuth = 180 - azimuth; 81 azimuth = 180 - azimuth;
82 82
83 double desiredPanPosition; 83 double desiredPanPosition;
84 double desiredGainL; 84 double desiredGainL;
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 } 148 }
149 } 149 }
150 150
151 m_gainL = gainL; 151 m_gainL = gainL;
152 m_gainR = gainR; 152 m_gainR = gainR;
153 } 153 }
154 154
155 } // namespace blink 155 } // namespace blink
156 156
157 #endif // ENABLE(WEB_AUDIO) 157 #endif // ENABLE(WEB_AUDIO)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698