comparison base/ColumnOp.h @ 1197:fbe0fd84cb50 spectrogram-minor-refactor

Float/double conversion fixes
author Chris Cannam
date Mon, 01 Aug 2016 16:25:06 +0100
parents c118d2022ffa
children b494439a301c
comparison
equal deleted inserted replaced
1196:c7b9c902642f 1197:fbe0fd84cb50
52 typedef std::vector<float> Column; 52 typedef std::vector<float> Column;
53 53
54 /** 54 /**
55 * Scale the given column using the given gain multiplier. 55 * Scale the given column using the given gain multiplier.
56 */ 56 */
57 static Column applyGain(const Column &in, float gain) { 57 static Column applyGain(const Column &in, double gain) {
58 58
59 if (gain == 1.f) { 59 if (gain == 1.0) {
60 return in; 60 return in;
61 } 61 }
62 Column out; 62 Column out;
63 out.reserve(in.size()); 63 out.reserve(in.size());
64 for (auto v: in) { 64 for (auto v: in) {
65 out.push_back(v * gain); 65 out.push_back(float(v * gain));
66 } 66 }
67 return out; 67 return out;
68 } 68 }
69 69
70 /** 70 /**
71 * Scale an FFT output by half the FFT size. 71 * Scale an FFT output by half the FFT size.
72 */ 72 */
73 static Column fftScale(const Column &in, int fftSize) { 73 static Column fftScale(const Column &in, int fftSize) {
74 return applyGain(in, 2.f / float(fftSize)); 74 return applyGain(in, 2.0 / fftSize);
75 } 75 }
76 76
77 /** 77 /**
78 * Determine whether an index points to a local peak. 78 * Determine whether an index points to a local peak.
79 */ 79 */
138 if (max > 0.f) { 138 if (max > 0.f) {
139 scale = log10f(max + 1.f) / max; 139 scale = log10f(max + 1.f) / max;
140 } 140 }
141 } 141 }
142 } 142 }
143 143
144 std::vector<float> out; 144 return applyGain(in, scale);
145 out.reserve(in.size());
146
147 for (auto v: in) {
148 out.push_back(v * scale);
149 }
150
151 return out;
152 } 145 }
153 146
154 /** 147 /**
155 * Distribute the given column into a target vector of a different 148 * Distribute the given column into a target vector of a different
156 * size, optionally using linear interpolation. The binfory vector 149 * size, optionally using linear interpolation. The binfory vector