changeset 5:6b732542a34c

Experiment with permitting some local variation rather than always aiming to flatten
author Chris Cannam
date Mon, 21 Jul 2014 18:01:11 +0100
parents e36fe9312ad4
children 231e20ba3168
files flattendynamics-ladspa.cpp flattendynamics-ladspa.h
diffstat 2 files changed, 19 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- 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;
--- 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;
 };