comparison 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
comparison
equal deleted inserted replaced
1264:a99641535e02 1265:e2e66bfd4a88
17 #define COLUMN_OP_H 17 #define COLUMN_OP_H
18 18
19 #include "BaseTypes.h" 19 #include "BaseTypes.h"
20 20
21 #include <cmath> 21 #include <cmath>
22 #include <vector>
23 #include <algorithm>
24 #include <iostream>
22 25
23 /** 26 /**
24 * Display normalization types for columns in e.g. grid plots. 27 * Display normalization types for columns in e.g. grid plots.
25 * 28 *
26 * Max1 means to normalize to max value = 1.0. 29 * Max1 means to normalize to max value = 1.0.
66 } 69 }
67 return out; 70 return out;
68 } 71 }
69 72
70 /** 73 /**
71 * Scale an FFT output by half the FFT size. 74 * Scale an FFT output downward by half the FFT size.
72 */ 75 */
73 static Column fftScale(const Column &in, int fftSize) { 76 static Column fftScale(const Column &in, int fftSize) {
74 return applyGain(in, 2.0 / fftSize); 77 return applyGain(in, 2.0 / fftSize);
75 } 78 }
76 79
77 /** 80 /**
78 * Determine whether an index points to a local peak. 81 * Determine whether an index points to a local peak.
79 */ 82 */
80 static bool isPeak(const Column &in, int ix) { 83 static bool isPeak(const Column &in, int ix) {
81 84 if (!in_range_for(in, ix)) {
82 if (!in_range_for(in, ix-1)) return false; 85 return false;
83 if (!in_range_for(in, ix+1)) return false; 86 }
84 if (in[ix] < in[ix+1]) return false; 87 if (ix == 0) {
85 if (in[ix] < in[ix-1]) return false; 88 return in[0] >= in[1];
86 89 }
90 if (!in_range_for(in, ix+1)) {
91 return in[ix] > in[ix-1];
92 }
93 if (in[ix] < in[ix+1]) {
94 return false;
95 }
96 if (in[ix] <= in[ix-1]) {
97 return false;
98 }
87 return true; 99 return true;
88 } 100 }
89 101
90 /** 102 /**
91 * Return a column containing only the local peak values (all 103 * Return a column containing only the local peak values (all
107 * Return a column normalized from the input column according to 119 * Return a column normalized from the input column according to
108 * the given normalization scheme. 120 * the given normalization scheme.
109 */ 121 */
110 static Column normalize(const Column &in, ColumnNormalization n) { 122 static Column normalize(const Column &in, ColumnNormalization n) {
111 123
112 if (n == ColumnNormalization::None) { 124 if (n == ColumnNormalization::None || in.empty()) {
113 return in; 125 return in;
114 } 126 }
115 127
116 float scale = 1.f; 128 float scale = 1.f;
117 129
146 158
147 /** 159 /**
148 * Distribute the given column into a target vector of a different 160 * Distribute the given column into a target vector of a different
149 * size, optionally using linear interpolation. The binfory vector 161 * size, optionally using linear interpolation. The binfory vector
150 * contains a mapping from y coordinate (i.e. index into the 162 * contains a mapping from y coordinate (i.e. index into the
151 * target vector) to bin (i.e. index into the source column). 163 * target vector) to bin (i.e. index into the source column). The
164 * source column ("in") may be a partial column; it's assumed to
165 * contain enough bins to span the destination range, starting
166 * with the bin of index minbin.
152 */ 167 */
153 static Column distribute(const Column &in, 168 static Column distribute(const Column &in,
154 int h, 169 int h,
155 const std::vector<double> &binfory, 170 const std::vector<double> &binfory,
156 int minbin, 171 int minbin,
164 double sy0 = binfory[y] - minbin; 179 double sy0 = binfory[y] - minbin;
165 double sy1 = sy0 + 1; 180 double sy1 = sy0 + 1;
166 if (y+1 < h) { 181 if (y+1 < h) {
167 sy1 = binfory[y+1] - minbin; 182 sy1 = binfory[y+1] - minbin;
168 } 183 }
184
185 std::cerr << "y = " << y << " of " << h << ", sy0 = " << sy0 << ", sy1 = " << sy1 << std::endl;
169 186
170 if (interpolate && fabs(sy1 - sy0) < 1.0) { 187 if (interpolate && fabs(sy1 - sy0) < 1.0) {
171 188
172 double centre = (sy0 + sy1) / 2; 189 double centre = (sy0 + sy1) / 2;
173 double dist = (centre - 0.5) - rint(centre - 0.5); 190 double dist = (centre - 0.5) - rint(centre - 0.5);