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

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: More rebase 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
11 * documentation and/or other materials provided with the distribution. 11 * documentation and/or other materials provided with the distribution.
12 * 12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND AN Y 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND AN Y
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 15 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
16 * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR AN Y 16 * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR AN Y
17 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 17 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
18 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 18 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
19 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND O N 19 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND O N
20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
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 "platform/audio/EqualPowerPanner.h" 25 #include "platform/audio/EqualPowerPanner.h"
26 26
27 #if ENABLE(WEB_AUDIO) 27 #if ENABLE(WEB_AUDIO)
28 #include <algorithm>
29 #include "platform/audio/AudioBus.h" 28 #include "platform/audio/AudioBus.h"
30 #include "platform/audio/AudioUtilities.h" 29 #include "platform/audio/AudioUtilities.h"
31 #include "wtf/MathExtras.h" 30 #include "wtf/MathExtras.h"
31 #include <algorithm>
32 #include <cmath>
32 33
33 // Use a 50ms smoothing / de-zippering time-constant. 34 // Use a 50ms smoothing / de-zippering time-constant.
34 const float SmoothingTimeConstant = 0.050f; 35 const float SmoothingTimeConstant = 0.050f;
35 36
36 namespace blink { 37 namespace blink {
37 38
38 EqualPowerPanner::EqualPowerPanner(float sampleRate) 39 EqualPowerPanner::EqualPowerPanner(float sampleRate)
39 : Panner(PanningModelEqualPower) 40 : Panner(PanningModelEqualPower)
40 , m_isFirstRender(true) 41 , m_isFirstRender(true)
41 , m_gainL(0.0) 42 , m_gainL(0.0)
(...skipping 18 matching lines...) Expand all
60 61
61 const float* sourceL = inputBus->channel(0)->data(); 62 const float* sourceL = inputBus->channel(0)->data();
62 const float* sourceR = numberOfInputChannels > 1 ? inputBus->channel(1)->dat a() : sourceL; 63 const float* sourceR = numberOfInputChannels > 1 ? inputBus->channel(1)->dat a() : sourceL;
63 float* destinationL = outputBus->channelByType(AudioBus::ChannelLeft)->mutab leData(); 64 float* destinationL = outputBus->channelByType(AudioBus::ChannelLeft)->mutab leData();
64 float* destinationR = outputBus->channelByType(AudioBus::ChannelRight)->muta bleData(); 65 float* destinationR = outputBus->channelByType(AudioBus::ChannelRight)->muta bleData();
65 66
66 if (!sourceL || !sourceR || !destinationL || !destinationR) 67 if (!sourceL || !sourceR || !destinationL || !destinationR)
67 return; 68 return;
68 69
69 // Clamp azimuth to allowed range of -180 -> +180. 70 // Clamp azimuth to allowed range of -180 -> +180.
70 azimuth = std::max(-180.0, azimuth); 71 azimuth = clampTo(azimuth, -180.0, 180.0);
71 azimuth = std::min(180.0, azimuth);
72 72
73 // Alias the azimuth ranges behind us to in front of us: 73 // Alias the azimuth ranges behind us to in front of us:
74 // -90 -> -180 to -90 -> 0 and 90 -> 180 to 90 -> 0 74 // -90 -> -180 to -90 -> 0 and 90 -> 180 to 90 -> 0
75 if (azimuth < -90) 75 if (azimuth < -90)
76 azimuth = -180 - azimuth; 76 azimuth = -180 - azimuth;
77 else if (azimuth > 90) 77 else if (azimuth > 90)
78 azimuth = 180 - azimuth; 78 azimuth = 180 - azimuth;
79 79
80 double desiredPanPosition; 80 double desiredPanPosition;
81 double desiredGainL; 81 double desiredGainL;
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 } 145 }
146 } 146 }
147 147
148 m_gainL = gainL; 148 m_gainL = gainL;
149 m_gainR = gainR; 149 m_gainR = gainR;
150 } 150 }
151 151
152 } // namespace blink 152 } // namespace blink
153 153
154 #endif // ENABLE(WEB_AUDIO) 154 #endif // ENABLE(WEB_AUDIO)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698