changeset 11:e662e661ae65

Simpler decay
author Chris Cannam
date Tue, 22 Jul 2014 13:32:55 +0100
parents 46ed42184699
children e54f4293614b
files flattendynamics-ladspa.cpp
diffstat 1 files changed, 10 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/flattendynamics-ladspa.cpp	Tue Jul 22 13:28:05 2014 +0100
+++ b/flattendynamics-ladspa.cpp	Tue Jul 22 13:32:55 2014 +0100
@@ -12,6 +12,7 @@
 const float shortTermSeconds = 1.f;
 const float catchUpSeconds = 0.2f;
 const float targetMaxRMS = 0.07f;
+const float rmsMaxDecay = 0.999f;
 const float maxGain = 20.f;
 
 const char *const
@@ -200,9 +201,8 @@
 
     if (m_rmsLongTerm >= m_maxRmsLongTerm) {
         m_maxRmsLongTerm = m_rmsLongTerm;
-    } else {
-        float decay = 0.999;
-        m_maxRmsLongTerm = m_rmsLongTerm + (m_maxRmsLongTerm - m_rmsLongTerm) * decay;
+    } else if (m_rmsLongTerm < m_maxRmsLongTerm * rmsMaxDecay) {
+        m_maxRmsLongTerm *= rmsMaxDecay;
     }
 
     if (m_rmsShortTerm > m_maxRmsShortTerm) {
@@ -243,6 +243,13 @@
 void
 FlattenDynamics::updateRMS(float f)
 {
+    // We update the RMS values by maintaining a sum-of-last-n-squares
+    // total (which the RMS is the square root of 1/n of) and
+    // recording the last n samples of history in a circular
+    // buffer. When a sample drops off the start of the history, we
+    // remove the square of it from the sum-of-squares total; then we
+    // add the square of the new sample.
+
     int nextWrite = (m_histwrite + 1) % m_histlen;
 
     float loseLongTerm = 0.f;