# HG changeset patch # User Chris Cannam # Date 1405962071 -3600 # Node ID 6b732542a34c9dbaf1e9c69c9023008b8035d8aa # Parent e36fe9312ad4a0085c7d8d193b0d9846241ed30d Experiment with permitting some local variation rather than always aiming to flatten diff -r e36fe9312ad4 -r 6b732542a34c flattendynamics-ladspa.cpp --- a/flattendynamics-ladspa.cpp Thu Jul 17 16:41:55 2014 +0100 +++ b/flattendynamics-ladspa.cpp Mon Jul 21 18:01:11 2014 +0100 @@ -8,9 +8,9 @@ using std::cerr; using std::endl; -const float historySeconds = 4.f; -const float catchUpSeconds = 0.5f; -const float targetRMS = 0.03f; +const float historySeconds = 2.f; +const float catchUpSeconds = 0.2f; +const float targetMaxRMS = 0.07f; const float maxGain = 20.f; const char *const @@ -80,8 +80,9 @@ m_histlen(0), m_histwrite(0), m_histread(0), - m_sumOfSquares(0), - m_rms(0), + m_sumOfSquares(0.f), + m_rms(0.f), + m_maxRms(0.f), m_gain(1.f) { reset(); @@ -151,7 +152,8 @@ m_histread = 0; m_sumOfSquares = 0.0; - m_rms = 0.0; + m_rms = 0.f; + m_maxRms = 0.f; m_gain = 1.f; } @@ -186,6 +188,16 @@ return f; } + if (m_rms > m_maxRms) { + m_maxRms = m_rms; + } + + float frac = m_rms / m_maxRms; + + // push up toward top of 0,1 range + frac = pow(frac, 0.2); + + float targetRMS = targetMaxRMS * frac; float targetGain = targetRMS / m_rms; if (targetGain > maxGain) { targetGain = maxGain; diff -r e36fe9312ad4 -r 6b732542a34c flattendynamics-ladspa.h --- a/flattendynamics-ladspa.h Thu Jul 17 16:41:55 2014 +0100 +++ b/flattendynamics-ladspa.h Mon Jul 21 18:01:11 2014 +0100 @@ -52,6 +52,7 @@ double m_sumOfSquares; float m_rms; + float m_maxRms; float m_gain; };