Mercurial > hg > svcore
comparison base/ColumnOp.h @ 1195:c118d2022ffa spectrogram-minor-refactor
Scale range matching
author | Chris Cannam |
---|---|
date | Mon, 01 Aug 2016 15:06:16 +0100 |
parents | 927d329252bf |
children | fbe0fd84cb50 |
comparison
equal
deleted
inserted
replaced
1194:238780e92f86 | 1195:c118d2022ffa |
---|---|
50 * Column type. | 50 * Column type. |
51 */ | 51 */ |
52 typedef std::vector<float> Column; | 52 typedef std::vector<float> Column; |
53 | 53 |
54 /** | 54 /** |
55 * Scale an FFT output by half the FFT size. | 55 * Scale the given column using the given gain multiplier. |
56 */ | 56 */ |
57 static Column fftScale(const Column &in, int fftSize) { | 57 static Column applyGain(const Column &in, float gain) { |
58 | 58 |
59 if (gain == 1.f) { | |
60 return in; | |
61 } | |
59 Column out; | 62 Column out; |
60 out.reserve(in.size()); | 63 out.reserve(in.size()); |
61 float scale = 2.f / float(fftSize); | |
62 for (auto v: in) { | 64 for (auto v: in) { |
63 out.push_back(v * scale); | 65 out.push_back(v * gain); |
64 } | 66 } |
65 | 67 return out; |
66 return out; | 68 } |
69 | |
70 /** | |
71 * Scale an FFT output by half the FFT size. | |
72 */ | |
73 static Column fftScale(const Column &in, int fftSize) { | |
74 return applyGain(in, 2.f / float(fftSize)); | |
67 } | 75 } |
68 | 76 |
69 /** | 77 /** |
70 * Determine whether an index points to a local peak. | 78 * Determine whether an index points to a local peak. |
71 */ | 79 */ |
142 | 150 |
143 return out; | 151 return out; |
144 } | 152 } |
145 | 153 |
146 /** | 154 /** |
147 * Scale the given column using the given gain multiplier. | |
148 */ | |
149 static Column applyGain(const Column &in, float gain) { | |
150 | |
151 if (gain == 1.f) { | |
152 return in; | |
153 } | |
154 Column out; | |
155 out.reserve(in.size()); | |
156 for (auto v: in) { | |
157 out.push_back(v * gain); | |
158 } | |
159 return out; | |
160 } | |
161 | |
162 /** | |
163 * Distribute the given column into a target vector of a different | 155 * Distribute the given column into a target vector of a different |
164 * size, optionally using linear interpolation. The binfory vector | 156 * size, optionally using linear interpolation. The binfory vector |
165 * contains a mapping from y coordinate (i.e. index into the | 157 * contains a mapping from y coordinate (i.e. index into the |
166 * target vector) to bin (i.e. index into the source column). | 158 * target vector) to bin (i.e. index into the source column). |
167 */ | 159 */ |