diff base/ColumnOp.h @ 1265:e2e66bfd4a88 3.0-integration

Start tests for ColumnOp (+ some resulting fixes)
author Chris Cannam
date Thu, 17 Nov 2016 11:56:54 +0000
parents 303039dd9e05
children dd190086db73
line wrap: on
line diff
--- a/base/ColumnOp.h	Wed Nov 16 16:12:42 2016 +0000
+++ b/base/ColumnOp.h	Thu Nov 17 11:56:54 2016 +0000
@@ -19,6 +19,9 @@
 #include "BaseTypes.h"
 
 #include <cmath>
+#include <vector>
+#include <algorithm>
+#include <iostream>
 
 /**
  * Display normalization types for columns in e.g. grid plots.
@@ -68,7 +71,7 @@
     }
 
     /**
-     * Scale an FFT output by half the FFT size.
+     * Scale an FFT output downward by half the FFT size.
      */
     static Column fftScale(const Column &in, int fftSize) {
         return applyGain(in, 2.0 / fftSize);
@@ -78,12 +81,21 @@
      * Determine whether an index points to a local peak.
      */
     static bool isPeak(const Column &in, int ix) {
-	
-	if (!in_range_for(in, ix-1)) return false;
-	if (!in_range_for(in, ix+1)) return false;
-	if (in[ix] < in[ix+1]) return false;
-	if (in[ix] < in[ix-1]) return false;
-	
+        if (!in_range_for(in, ix)) {
+            return false;
+        }
+        if (ix == 0) {
+            return in[0] >= in[1];
+        }
+        if (!in_range_for(in, ix+1)) {
+            return in[ix] > in[ix-1];
+        }
+	if (in[ix] < in[ix+1]) {
+            return false;
+        }
+	if (in[ix] <= in[ix-1]) {
+            return false;
+        }
 	return true;
     }
 
@@ -109,7 +121,7 @@
      */
     static Column normalize(const Column &in, ColumnNormalization n) {
 
-	if (n == ColumnNormalization::None) {
+	if (n == ColumnNormalization::None || in.empty()) {
 	    return in;
 	}
 
@@ -148,7 +160,10 @@
      * Distribute the given column into a target vector of a different
      * size, optionally using linear interpolation. The binfory vector
      * contains a mapping from y coordinate (i.e. index into the
-     * target vector) to bin (i.e. index into the source column).
+     * target vector) to bin (i.e. index into the source column). The
+     * source column ("in") may be a partial column; it's assumed to
+     * contain enough bins to span the destination range, starting
+     * with the bin of index minbin.
      */
     static Column distribute(const Column &in,
 			     int h,
@@ -166,6 +181,8 @@
 	    if (y+1 < h) {
 		sy1 = binfory[y+1] - minbin;
 	    }
+
+            std::cerr << "y = " << y << " of " << h << ", sy0 = " << sy0 << ", sy1 = " << sy1 << std::endl;
         
 	    if (interpolate && fabs(sy1 - sy0) < 1.0) {