changeset 113:c4eae816bdb3 bqvec-openmp

Simplify slightly, make HQ mode the default
author Chris Cannam
date Wed, 07 May 2014 09:08:52 +0100
parents 2169e7a448c5
children b2f0967cb8d1 36f58a539125
files src/EM.cpp src/EM.h src/Silvet.cpp
diffstat 3 files changed, 27 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/src/EM.cpp	Wed May 07 09:01:32 2014 +0100
+++ b/src/EM.cpp	Wed May 07 09:08:52 2014 +0100
@@ -34,7 +34,6 @@
 static double epsilon = 1e-16;
 
 EM::EM(bool useShifts) :
-    m_useShifts(useShifts),
     m_noteCount(SILVET_TEMPLATE_NOTE_COUNT),
     m_shiftCount(useShifts ? SILVET_TEMPLATE_MAX_SHIFT * 2 + 1 : 1),
     m_binCount(SILVET_TEMPLATE_HEIGHT),
@@ -50,16 +49,17 @@
         m_pitches[n] = drand48();
     }
 
-    m_shifts = allocate_channels<double>(m_shiftCount, m_noteCount);
-    m_updateShifts = allocate_channels<double>(m_shiftCount, m_noteCount);
-    for (int f = 0; f < m_shiftCount; ++f) {
-        for (int n = 0; n < m_noteCount; ++n) {
-            if (m_useShifts) {
+    if (useShifts) {
+        m_shifts = allocate_channels<double>(m_shiftCount, m_noteCount);
+        m_updateShifts = allocate_channels<double>(m_shiftCount, m_noteCount);
+        for (int f = 0; f < m_shiftCount; ++f) {
+            for (int n = 0; n < m_noteCount; ++n) {
                 m_shifts[f][n] = drand48();
-            } else {
-                m_shifts[f][n] = 1.0;
             }
         }
+    } else {
+        m_shifts = 0;
+        m_updateShifts = 0;
     }
     
     m_sources = allocate_channels<double>(m_sourceCount, m_noteCount);
@@ -140,7 +140,7 @@
 const double *
 EM::templateFor(int instrument, int note, int shift)
 {
-    if (m_useShifts) {
+    if (m_shifts) {
         return silvet_templates[instrument].data[note] + shift;
     } else {
         return silvet_templates[instrument].data[note] + 
@@ -161,7 +161,7 @@
             const double source = m_sources[i][n];
             for (int f = 0; f < m_shiftCount; ++f) {
                 const double *w = templateFor(i, n, f);
-                const double shift = m_shifts[f][n];
+                const double shift = m_shifts ? m_shifts[f][n] : 1.0;
                 const double factor = pitch * source * shift;
                 v_add_with_gain(m_estimate, w, factor, m_binCount);
             }
@@ -177,13 +177,17 @@
 EM::maximisation(const double *column)
 {
     v_set(m_updatePitches, epsilon, m_noteCount);
-    for (int i = 0; i < m_shiftCount; ++i) {
-        v_set(m_updateShifts[i], epsilon, m_noteCount);
-    }
+
     for (int i = 0; i < m_sourceCount; ++i) {
         v_set(m_updateSources[i], epsilon, m_noteCount);
     }
 
+    if (m_shifts) {
+        for (int i = 0; i < m_shiftCount; ++i) {
+            v_set(m_updateShifts[i], epsilon, m_noteCount);
+        }
+    }
+
     double *contributions = allocate<double>(m_binCount);
 
     for (int n = 0; n < m_noteCount; ++n) {
@@ -192,7 +196,7 @@
 
         for (int f = 0; f < m_shiftCount; ++f) {
 
-            const double shift = m_shifts[f][n];
+            const double shift = m_shifts ? m_shifts[f][n] : 1.0;
 
             for (int i = 0; i < m_sourceCount; ++i) {
 
@@ -215,7 +219,9 @@
                     }
                 }
 
-                m_updateShifts[f][n] += total;
+                if (m_shifts) {
+                    m_updateShifts[f][n] += total;
+                }
             }
         }
     }
@@ -239,13 +245,13 @@
     normaliseColumn(m_updatePitches, m_noteCount);
     std::swap(m_pitches, m_updatePitches);
 
-    if (m_useShifts) {
+    normaliseGrid(m_updateSources, m_sourceCount, m_noteCount);
+    std::swap(m_sources, m_updateSources);
+
+    if (m_shifts) {
         normaliseGrid(m_updateShifts, m_shiftCount, m_noteCount);
         std::swap(m_shifts, m_updateShifts);
     }
-
-    normaliseGrid(m_updateSources, m_sourceCount, m_noteCount);
-    std::swap(m_sources, m_updateSources);
 }
 
 
--- a/src/EM.h	Wed May 07 09:01:32 2014 +0100
+++ b/src/EM.h	Wed May 07 09:08:52 2014 +0100
@@ -49,8 +49,6 @@
     double **m_updateShifts;
     double **m_updateSources;
 
-    bool m_useShifts;
-
     double *m_estimate;
     double *m_q;
     
--- a/src/Silvet.cpp	Wed May 07 09:01:32 2014 +0100
+++ b/src/Silvet.cpp	Wed May 07 09:08:52 2014 +0100
@@ -41,7 +41,7 @@
     Plugin(inputSampleRate),
     m_resampler(0),
     m_cq(0),
-    m_hqMode(false)
+    m_hqMode(true)
 {
 }
 
@@ -138,7 +138,7 @@
     desc.description = "Determines the tradeoff of processing speed against transcription quality";
     desc.minValue = 0;
     desc.maxValue = 1;
-    desc.defaultValue = 0;
+    desc.defaultValue = 1;
     desc.isQuantized = true;
     desc.quantizeStep = 1;
     desc.valueNames.push_back("Draft (faster)");