traverso-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Traverso-commit] traverso/src/plugins/native CorrelationMeter.cp...


From: Nicola Doebelin
Subject: [Traverso-commit] traverso/src/plugins/native CorrelationMeter.cp...
Date: Thu, 07 Feb 2008 11:46:09 +0000

CVSROOT:        /sources/traverso
Module name:    traverso
Changes by:     Nicola Doebelin <n_doebelin>    08/02/07 11:46:09

Modified files:
        src/plugins/native: CorrelationMeter.cpp CorrelationMeter.h 

Log message:
        fixes bug #21952: "Correlation meter and FFT spectrometer 'falloff'" 
for the correlation meter

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/traverso/src/plugins/native/CorrelationMeter.cpp?cvsroot=traverso&r1=1.3&r2=1.4
http://cvs.savannah.gnu.org/viewcvs/traverso/src/plugins/native/CorrelationMeter.h?cvsroot=traverso&r1=1.1&r2=1.2

Patches:
Index: CorrelationMeter.cpp
===================================================================
RCS file: /sources/traverso/traverso/src/plugins/native/CorrelationMeter.cpp,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- CorrelationMeter.cpp        21 Jan 2008 16:22:16 -0000      1.3
+++ CorrelationMeter.cpp        7 Feb 2008 11:46:09 -0000       1.4
@@ -16,7 +16,7 @@
 along with this program; if not, write to the Free Software
 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA.
 
-$Id: CorrelationMeter.cpp,v 1.3 2008/01/21 16:22:16 r_sijrier Exp $
+$Id: CorrelationMeter.cpp,v 1.4 2008/02/07 11:46:09 n_doebelin Exp $
 
 */
 
@@ -25,7 +25,7 @@
 #include <AudioBus.h>
 #include <AudioDevice.h>
 #include <Debugger.h>
-
+#include <QDebug>
 #include <math.h>
 
 // Always put me below _all_ includes, this is needed
@@ -33,6 +33,8 @@
 #include "Debugger.h"
                
 #define SMOOTH_FACTOR  1
+#define BUFFER_READOUT_TOLERANCE 2  // recommended: 1-10
+#define METER_COLLAPSE_SPEED 4       // recommended: 1-10
 
 
 CorrelationMeter::CorrelationMeter()
@@ -43,10 +45,13 @@
        
        // Initialize member variables, that need to be initialized
        calculate_fract();
-       // With memset, we're able to very efficiently set all bytes of an array
+       // With memset, we're able to very efficIf there is no new data in the 
ringbuffer, fill it with default values,
+       // otherwise the meter will stop working between clipsiently set all 
bytes of an array
        // or struct to zero
        memset(&m_history, 0, sizeof(CorrelationMeterData));
        
+       m_bufferreadouts = 0;
+
        connect(&audiodevice(), SIGNAL(driverParamsChanged()), this, 
SLOT(calculate_fract()));
 }
 
@@ -172,11 +177,45 @@
        // to the buffer since last time we checked.
        int readcount = m_databuffer->read_space();
        
-       // If there is no new data in the ringbuffer, leave it alone and return 
zero
+       // If there is no new data in the buffer, this may have 2 reasons:
+       // 
+       // 1) too fast readout, buffer is not ready again
+       // 2) no data available because no data is played back (e.g. between 
clips)
+       // 
+       // We want to distinguish the two cases, because the behavour of the 
meter
+       // should be different. In case 1) we just ignore the update and do 
nothing, 
+       // the next cycle will probably have data available again. In case 2) we
+       // want to use dummy values instead, because that's what the meter 
should
+       // display if silence is played. The trick to achieve this is to ignore 
a 
+       // certain number of buffer readouts (defined in 
BUFFER_READOUT_TOLERANCE).
+       // If more readouts occur in a row, we assume that silence is played 
back,
+       // and start collapsing the meter to r = 1.0 in the center.
+
        if (readcount == 0) {
+               // add another 'if' to avoid unlimited growth of the variable
+               if (m_bufferreadouts <= BUFFER_READOUT_TOLERANCE) {
+                       m_bufferreadouts++;
+               }
+
+               // check if dummy values should be stored in the buffer, or
+               // if the readout should be ignored
+               if (m_bufferreadouts >= BUFFER_READOUT_TOLERANCE) {
+                       CorrelationMeterData dummydata;
+                       dummydata.r = 1.0;
+                       dummydata.levelLeft = 0.0;
+                       dummydata.levelRight = 0.0;
+                       for (int i = 0; i < METER_COLLAPSE_SPEED; ++i) {
+                               m_databuffer->write(&dummydata, 1);
+                       }
+               } else {
                return 0;
        }
        
+       } else {
+               m_bufferreadouts = 0;
+       }
+
+       
        // We need to know the 'history' of these variables to get a smooth
        // and consistent (independend of buffersizes) stereometer behaviour.
        // So we get it from our history struct.

Index: CorrelationMeter.h
===================================================================
RCS file: /sources/traverso/traverso/src/plugins/native/CorrelationMeter.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- CorrelationMeter.h  27 Nov 2006 21:53:42 -0000      1.1
+++ CorrelationMeter.h  7 Feb 2008 11:46:09 -0000       1.2
@@ -17,7 +17,7 @@
 along with this program; if not, write to the Free Software
 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA.
 
-$Id: CorrelationMeter.h,v 1.1 2006/11/27 21:53:42 r_sijrier Exp $
+$Id: CorrelationMeter.h,v 1.2 2008/02/07 11:46:09 n_doebelin Exp $
 */
 
 
@@ -58,6 +58,7 @@
        RingBufferNPT<CorrelationMeterData>*    m_databuffer;
        CorrelationMeterData                    m_history;
        float                           m_fract;
+       int                                     m_bufferreadouts;
        
 private slots:
        void calculate_fract();




reply via email to

[Prev in Thread] Current Thread [Next in Thread]