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

Side by Side Diff: third_party/WebKit/Source/platform/audio/DynamicsCompressorKernel.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 4 years, 12 months 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) 2011 Google Inc. All rights reserved. 2 * Copyright (C) 2011 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 * 7 *
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 11 matching lines...) Expand all
22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */ 27 */
28 28
29 #include "platform/audio/DynamicsCompressorKernel.h" 29 #include "platform/audio/DynamicsCompressorKernel.h"
30 30
31 #if ENABLE(WEB_AUDIO) 31 #if ENABLE(WEB_AUDIO)
32 #include <algorithm>
33 #include "platform/audio/AudioUtilities.h" 32 #include "platform/audio/AudioUtilities.h"
34 #include "platform/audio/DenormalDisabler.h" 33 #include "platform/audio/DenormalDisabler.h"
35 #include "wtf/MathExtras.h" 34 #include "wtf/MathExtras.h"
35 #include <algorithm>
36 #include <cmath>
36 37
37 namespace blink { 38 namespace blink {
38 39
39 using namespace AudioUtilities; 40 using namespace AudioUtilities;
40 41
41 // Metering hits peaks instantly, but releases this fast (in seconds). 42 // Metering hits peaks instantly, but releases this fast (in seconds).
42 const float meteringReleaseTimeConstant = 0.325f; 43 const float meteringReleaseTimeConstant = 0.325f;
43 44
44 const float uninitializedValue = -1; 45 const float uninitializedValue = -1;
45 46
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
311 // Fix gremlins. 312 // Fix gremlins.
312 if (std::isnan(compressionDiffDb)) 313 if (std::isnan(compressionDiffDb))
313 compressionDiffDb = -1; 314 compressionDiffDb = -1;
314 if (std::isinf(compressionDiffDb)) 315 if (std::isinf(compressionDiffDb))
315 compressionDiffDb = -1; 316 compressionDiffDb = -1;
316 317
317 // Adaptive release - higher compression (lower compressionDiffDb) releases faster. 318 // Adaptive release - higher compression (lower compressionDiffDb) releases faster.
318 319
319 // Contain within range: -12 -> 0 then scale to go from 0 -> 3 320 // Contain within range: -12 -> 0 then scale to go from 0 -> 3
320 float x = compressionDiffDb; 321 float x = compressionDiffDb;
321 x = std::max(-12.0f, x); 322 x = clampTo(x, -12.0f, 0.0f);
322 x = std::min(0.0f, x);
323 x = 0.25f * (x + 12); 323 x = 0.25f * (x + 12);
324 324
325 // Compute adaptive release curve using 4th order polynomial. 325 // Compute adaptive release curve using 4th order polynomial.
326 // Normal values for the polynomial coefficients would create a mono tonically increasing function. 326 // Normal values for the polynomial coefficients would create a mono tonically increasing function.
327 float x2 = x * x; 327 float x2 = x * x;
328 float x3 = x2 * x; 328 float x3 = x2 * x;
329 float x4 = x2 * x2; 329 float x4 = x2 * x2;
330 float releaseFrames = kA + kB * x + kC * x2 + kD * x3 + kE * x4; 330 float releaseFrames = kA + kB * x + kC * x2 + kD * x3 + kE * x4;
331 331
332 #define kSpacingDb 5 332 #define kSpacingDb 5
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
465 465
466 m_preDelayReadIndex = 0; 466 m_preDelayReadIndex = 0;
467 m_preDelayWriteIndex = DefaultPreDelayFrames; 467 m_preDelayWriteIndex = DefaultPreDelayFrames;
468 468
469 m_maxAttackCompressionDiffDb = -1; // uninitialized state 469 m_maxAttackCompressionDiffDb = -1; // uninitialized state
470 } 470 }
471 471
472 } // namespace blink 472 } // namespace blink
473 473
474 #endif // ENABLE(WEB_AUDIO) 474 #endif // ENABLE(WEB_AUDIO)
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/platform/audio/Biquad.cpp ('k') | third_party/WebKit/Source/platform/audio/EqualPowerPanner.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698