changeset 17:67d54627efd3

* Fix phase calculation for percussive frames, and some tweaks -- we can do better fairly easily though
author Chris Cannam
date Wed, 13 Sep 2006 18:58:17 +0000
parents 3715efc38f95
children c1aee08c60b1
files audioio/PhaseVocoderTimeStretcher.cpp audioio/PhaseVocoderTimeStretcher.h main/MainWindow.cpp
diffstat 3 files changed, 13 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/audioio/PhaseVocoderTimeStretcher.cpp	Wed Sep 13 17:17:42 2006 +0000
+++ b/audioio/PhaseVocoderTimeStretcher.cpp	Wed Sep 13 18:58:17 2006 +0000
@@ -40,7 +40,7 @@
             m_n1 = 256;
         }
         if (m_sharpen) {
-            m_n1 /= 2;
+//            m_n1 /= 2;
             m_wlen = 2048;
         }
         m_n2 = m_n1 * ratio;
@@ -55,7 +55,7 @@
             m_n2 = 256;
         }
         if (m_sharpen) {
-            m_n2 /= 2;
+//            m_n2 /= 2;
             if (m_wlen < 2048) m_wlen = 2048;
         }
         m_n1 = m_n2 / ratio;
@@ -68,6 +68,7 @@
     if (m_sharpen) m_prevMag = new float *[m_channels];
     else m_prevMag = 0;
     m_prevPercussiveCount = new int[m_channels];
+    m_prevPercussive = false;
 
     m_dbuf = (float *)fftwf_malloc(sizeof(float) * m_wlen);
     m_time = (fftwf_complex *)fftwf_malloc(sizeof(fftwf_complex) * m_wlen);
@@ -231,7 +232,7 @@
                 bool thisChannelPercussive =
                     processBlock(c, m_dbuf, m_mashbuf[c],
                                  c == 0 ? m_modulationbuf : 0,
-                                 isPercussive);
+                                 m_prevPercussive);
 
                 if (thisChannelPercussive && c == 0) {
                     isPercussive = true;
@@ -263,6 +264,8 @@
                 }
             }
 
+            m_prevPercussive = isPercussive;
+
             for (size_t i = 0; i < m_wlen - n2; ++i) {
                 m_modulationbuf[i] = m_modulationbuf[i + n2];
 	    }
@@ -319,10 +322,10 @@
 PhaseVocoderTimeStretcher::processBlock(size_t c,
                                         float *buf, float *out,
                                         float *modulation,
-                                        bool knownPercussive)
+                                        bool lastPercussive)
 {
     size_t i;
-    bool isPercussive = knownPercussive;
+    bool isPercussive = false;
 
     // buf contains m_wlen samples; out contains enough space for
     // m_wlen * ratio samples (we mix into out, rather than replacing)
@@ -363,7 +366,7 @@
             m_prevMag[c][i] = mag;
         }
         
-        if (count > m_wlen / 6 &&
+        if (count > m_wlen / 4 && //!!!
             count > m_prevPercussiveCount[c] * 1.2) {
             isPercussive = true;
             std::cerr << "isPercussive (count = " << count << ", prev = " << m_prevPercussiveCount[c] << ")" << std::endl;
@@ -373,7 +376,7 @@
     }
 
     size_t n2 = m_n2;
-    if (isPercussive) n2 = m_n1;
+    if (lastPercussive) n2 = m_n1;
 	
     for (i = 0; i < m_wlen; ++i) {
 
--- a/audioio/PhaseVocoderTimeStretcher.h	Wed Sep 13 17:17:42 2006 +0000
+++ b/audioio/PhaseVocoderTimeStretcher.h	Wed Sep 13 18:58:17 2006 +0000
@@ -125,7 +125,7 @@
     bool processBlock(size_t channel,
                       float *in, float *out,
                       float *modulation,
-                      bool knownPercussive);
+                      bool lastPercussive);
 
     size_t m_channels;
     float m_ratio;
@@ -139,6 +139,7 @@
     float **m_prevAdjustedPhase;
     float **m_prevMag;
     int *m_prevPercussiveCount;
+    bool m_prevPercussive;
 
     float *m_dbuf;
     fftwf_complex *m_time;
--- a/main/MainWindow.cpp	Wed Sep 13 17:17:42 2006 +0000
+++ b/main/MainWindow.cpp	Wed Sep 13 18:58:17 2006 +0000
@@ -167,7 +167,7 @@
 	    this, SLOT(playSpeedChanged(int)));
 
     m_playSharpen = new QCheckBox(frame);
-    m_playSharpen->setToolTip(tr("Sharpen"));
+    m_playSharpen->setToolTip(tr("Sharpen percussive transients"));
     m_playSharpen->setEnabled(false);
     m_playSharpen->setChecked(false);
     connect(m_playSharpen, SIGNAL(clicked()),