Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 14 matching lines...) Expand all Loading... | |
| 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 "config.h" | 29 #include "config.h" |
| 30 | 30 |
| 31 #if ENABLE(WEB_AUDIO) | 31 #if ENABLE(WEB_AUDIO) |
| 32 | 32 |
| 33 #include "platform/audio/DynamicsCompressorKernel.h" | 33 #include "platform/audio/DynamicsCompressorKernel.h" |
| 34 | 34 |
| 35 #include <algorithm> | |
| 36 #include "platform/audio/AudioUtilities.h" | 35 #include "platform/audio/AudioUtilities.h" |
| 37 #include "platform/audio/DenormalDisabler.h" | 36 #include "platform/audio/DenormalDisabler.h" |
| 38 #include "wtf/MathExtras.h" | 37 #include "wtf/MathExtras.h" |
| 38 #include <algorithm> | |
| 39 #include <cmath> | |
|
Raymond Toy
2015/12/17 19:45:55
Are both of these needed? Previously, you replace
Daniel Bratell
2015/12/17 22:56:16
DynamicsCompressorKernel::process uses std::max()
| |
| 39 | 40 |
| 40 namespace blink { | 41 namespace blink { |
| 41 | 42 |
| 42 using namespace AudioUtilities; | 43 using namespace AudioUtilities; |
| 43 | 44 |
| 44 // Metering hits peaks instantly, but releases this fast (in seconds). | 45 // Metering hits peaks instantly, but releases this fast (in seconds). |
| 45 const float meteringReleaseTimeConstant = 0.325f; | 46 const float meteringReleaseTimeConstant = 0.325f; |
| 46 | 47 |
| 47 const float uninitializedValue = -1; | 48 const float uninitializedValue = -1; |
| 48 | 49 |
| (...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 314 // Fix gremlins. | 315 // Fix gremlins. |
| 315 if (std::isnan(compressionDiffDb)) | 316 if (std::isnan(compressionDiffDb)) |
| 316 compressionDiffDb = -1; | 317 compressionDiffDb = -1; |
| 317 if (std::isinf(compressionDiffDb)) | 318 if (std::isinf(compressionDiffDb)) |
| 318 compressionDiffDb = -1; | 319 compressionDiffDb = -1; |
| 319 | 320 |
| 320 // Adaptive release - higher compression (lower compressionDiffDb) releases faster. | 321 // Adaptive release - higher compression (lower compressionDiffDb) releases faster. |
| 321 | 322 |
| 322 // Contain within range: -12 -> 0 then scale to go from 0 -> 3 | 323 // Contain within range: -12 -> 0 then scale to go from 0 -> 3 |
| 323 float x = compressionDiffDb; | 324 float x = compressionDiffDb; |
| 324 x = std::max(-12.0f, x); | 325 x = clampTo(x, -12.0f, 0.0f); |
| 325 x = std::min(0.0f, x); | |
| 326 x = 0.25f * (x + 12); | 326 x = 0.25f * (x + 12); |
| 327 | 327 |
| 328 // Compute adaptive release curve using 4th order polynomial. | 328 // Compute adaptive release curve using 4th order polynomial. |
| 329 // Normal values for the polynomial coefficients would create a mono tonically increasing function. | 329 // Normal values for the polynomial coefficients would create a mono tonically increasing function. |
| 330 float x2 = x * x; | 330 float x2 = x * x; |
| 331 float x3 = x2 * x; | 331 float x3 = x2 * x; |
| 332 float x4 = x2 * x2; | 332 float x4 = x2 * x2; |
| 333 float releaseFrames = kA + kB * x + kC * x2 + kD * x3 + kE * x4; | 333 float releaseFrames = kA + kB * x + kC * x2 + kD * x3 + kE * x4; |
| 334 | 334 |
| 335 #define kSpacingDb 5 | 335 #define kSpacingDb 5 |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 468 | 468 |
| 469 m_preDelayReadIndex = 0; | 469 m_preDelayReadIndex = 0; |
| 470 m_preDelayWriteIndex = DefaultPreDelayFrames; | 470 m_preDelayWriteIndex = DefaultPreDelayFrames; |
| 471 | 471 |
| 472 m_maxAttackCompressionDiffDb = -1; // uninitialized state | 472 m_maxAttackCompressionDiffDb = -1; // uninitialized state |
| 473 } | 473 } |
| 474 | 474 |
| 475 } // namespace blink | 475 } // namespace blink |
| 476 | 476 |
| 477 #endif // ENABLE(WEB_AUDIO) | 477 #endif // ENABLE(WEB_AUDIO) |
| OLD | NEW |