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.cpp


From: Nicola Doebelin
Subject: [Traverso-commit] traverso/src/plugins/native CorrelationMeter.cpp
Date: Sun, 10 Feb 2008 23:47:07 +0000

CVSROOT:        /sources/traverso
Module name:    traverso
Changes by:     Nicola Doebelin <n_doebelin>    08/02/10 23:47:07

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

Log message:
        * fixes wrong behaviour of correlation meter when playing silence
        * code cleanup

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/traverso/src/plugins/native/CorrelationMeter.cpp?cvsroot=traverso&r1=1.5&r2=1.6

Patches:
Index: CorrelationMeter.cpp
===================================================================
RCS file: /sources/traverso/traverso/src/plugins/native/CorrelationMeter.cpp,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -b -r1.5 -r1.6
--- CorrelationMeter.cpp        7 Feb 2008 15:33:17 -0000       1.5
+++ CorrelationMeter.cpp        10 Feb 2008 23:47:06 -0000      1.6
@@ -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.5 2008/02/07 15:33:17 n_doebelin Exp $
+$Id: CorrelationMeter.cpp,v 1.6 2008/02/10 23:47:06 n_doebelin Exp $
 
 */
 
@@ -177,6 +177,16 @@
        // to the buffer since last time we checked.
        int readcount = m_databuffer->read_space();
 
+       // Create an empty CorrelationMeterData struct data,
+       CorrelationMeterData data;
+
+       // 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.
+       r = m_history.r;
+       float levelLeft = m_history.levelLeft;
+       float levelRight = m_history.levelRight;
+       
        // If there is no new data in the buffer, this may have 2 reasons:
        // 
        // 1) too fast readout, buffer is not ready again
@@ -191,7 +201,7 @@
        // 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) {
+       if (readcount <= 0) {
                // add another 'if' to avoid unlimited growth of the variable
                if (m_bufferreadouts < RINGBUFFER_SIZE) {
                        m_bufferreadouts++;
@@ -200,31 +210,29 @@
                // 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 < int(METER_COLLAPSE_SPEED / 
m_fract); ++i) {
-                               m_databuffer->write(&dummydata, 1);
+                       // set the return value to > 0 to trigger widget update
+                       readcount = 1;
+
+                       data.r = 1.0;
+
+                       // must be != 0, otherwise the direction does not drift 
to the center
+                       data.levelLeft = METER_COLLAPSE_SPEED;
+                       data.levelRight = METER_COLLAPSE_SPEED;
+
+                       // This is ugly, there shouldn't be a loop here. Maybe 
it is possible without.
+                       // The loop makes sure that the collapse speed is 
independent of the buffer size
+                       for (int i = 0; i < METER_COLLAPSE_SPEED / m_fract; 
++i) {
+                               r = data.r * m_fract + r * (1.0 - m_fract);
+                               levelLeft = data.levelLeft * m_fract + 
levelLeft * (1.0 - m_fract);
+                               levelRight = data.levelRight * m_fract + 
levelRight * (1.0 - m_fract);
                        }
                } else {
+                       // no new data, return 0 to suppress widget update
                        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.
-       r = m_history.r;
-       float levelLeft = m_history.levelLeft;
-       float levelRight = m_history.levelRight;
-       
-       // Create an empty CorrelationMeterData struct data,
-       CorrelationMeterData data;
        
        for (int i=0; i<readcount; ++i) {
                // which we fill by reading from the databuffer.
@@ -238,17 +246,17 @@
                levelLeft = data.levelLeft * m_fract + levelLeft * (1.0 - 
m_fract);
                levelRight = data.levelRight * m_fract + levelRight * (1.0 - 
m_fract);
        }
+       }
        
        // Now that we truely have taken into account all the levelLeft/Right 
data
        // for all buffers that have been processed since last call to 
get_data()
        // we now can calculate the direction variable.
-       if ( ! ((levelLeft + levelRight) == 0.0) ) {
+       if (levelLeft + levelRight == 0.0) {
+               direction = 0.0;
+       } else {
                float vl = levelLeft / (levelLeft + levelRight);
                float vr = levelRight / (levelLeft + levelRight);
-       
                direction = vr - vl;
-       } else {
-               direction = 0;
        }
 
        // Store the calculated variables in the history struct, to be used on




reply via email to

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