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

Side by Side Diff: Source/platform/audio/DynamicsCompressorKernel.cpp

Issue 170453004: Add constant twoPiDouble/twoPiFloat to MathExtras.h (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: add constant values to header Created 6 years, 10 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
« no previous file with comments | « Source/platform/audio/DownSampler.cpp ('k') | Source/platform/audio/EqualPowerPanner.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 287
288 // Fix gremlins. 288 // Fix gremlins.
289 if (std::isnan(m_detectorAverage)) 289 if (std::isnan(m_detectorAverage))
290 m_detectorAverage = 1; 290 m_detectorAverage = 1;
291 if (std::isinf(m_detectorAverage)) 291 if (std::isinf(m_detectorAverage))
292 m_detectorAverage = 1; 292 m_detectorAverage = 1;
293 293
294 float desiredGain = m_detectorAverage; 294 float desiredGain = m_detectorAverage;
295 295
296 // Pre-warp so we get desiredGain after sin() warp below. 296 // Pre-warp so we get desiredGain after sin() warp below.
297 float scaledDesiredGain = asinf(desiredGain) / (0.5f * piFloat); 297 float scaledDesiredGain = asinf(desiredGain) / (piOverTwoFloat);
298 298
299 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~ 299 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~
300 // Deal with envelopes 300 // Deal with envelopes
301 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~ 301 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~
302 302
303 // envelopeRate is the rate we slew from current compressor level to the desired level. 303 // envelopeRate is the rate we slew from current compressor level to the desired level.
304 // The exact rate depends on if we're attacking or releasing and by how much. 304 // The exact rate depends on if we're attacking or releasing and by how much.
305 float envelopeRate; 305 float envelopeRate;
306 306
307 bool isReleasing = scaledDesiredGain > m_compressorGain; 307 bool isReleasing = scaledDesiredGain > m_compressorGain;
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
419 if (envelopeRate < 1) { 419 if (envelopeRate < 1) {
420 // Attack - reduce gain to desired. 420 // Attack - reduce gain to desired.
421 compressorGain += (scaledDesiredGain - compressorGain) * env elopeRate; 421 compressorGain += (scaledDesiredGain - compressorGain) * env elopeRate;
422 } else { 422 } else {
423 // Release - exponentially increase gain to 1.0 423 // Release - exponentially increase gain to 1.0
424 compressorGain *= envelopeRate; 424 compressorGain *= envelopeRate;
425 compressorGain = min(1.0f, compressorGain); 425 compressorGain = min(1.0f, compressorGain);
426 } 426 }
427 427
428 // Warp pre-compression gain to smooth out sharp exponential tra nsition points. 428 // Warp pre-compression gain to smooth out sharp exponential tra nsition points.
429 float postWarpCompressorGain = sinf(0.5f * piFloat * compressorG ain); 429 float postWarpCompressorGain = sinf(piOverTwoFloat * compressorG ain);
430 430
431 // Calculate total gain using master gain and effect blend. 431 // Calculate total gain using master gain and effect blend.
432 float totalGain = dryMix + wetMix * masterLinearGain * postWarpC ompressorGain; 432 float totalGain = dryMix + wetMix * masterLinearGain * postWarpC ompressorGain;
433 433
434 // Calculate metering. 434 // Calculate metering.
435 float dbRealGain = 20 * log10(postWarpCompressorGain); 435 float dbRealGain = 20 * log10(postWarpCompressorGain);
436 if (dbRealGain < m_meteringGain) 436 if (dbRealGain < m_meteringGain)
437 m_meteringGain = dbRealGain; 437 m_meteringGain = dbRealGain;
438 else 438 else
439 m_meteringGain += (dbRealGain - m_meteringGain) * m_metering ReleaseK; 439 m_meteringGain += (dbRealGain - m_meteringGain) * m_metering ReleaseK;
(...skipping 30 matching lines...) Expand all
470 470
471 m_preDelayReadIndex = 0; 471 m_preDelayReadIndex = 0;
472 m_preDelayWriteIndex = DefaultPreDelayFrames; 472 m_preDelayWriteIndex = DefaultPreDelayFrames;
473 473
474 m_maxAttackCompressionDiffDb = -1; // uninitialized state 474 m_maxAttackCompressionDiffDb = -1; // uninitialized state
475 } 475 }
476 476
477 } // namespace WebCore 477 } // namespace WebCore
478 478
479 #endif // ENABLE(WEB_AUDIO) 479 #endif // ENABLE(WEB_AUDIO)
OLDNEW
« no previous file with comments | « Source/platform/audio/DownSampler.cpp ('k') | Source/platform/audio/EqualPowerPanner.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698