Mercurial > hg > match-vamp
comparison src/FeatureExtractor.cpp @ 180:d1bc89794cd4 tuning-rescale
Build with -Wconversion
author | Chris Cannam |
---|---|
date | Thu, 19 Feb 2015 16:14:33 +0000 |
parents | 1440773da492 |
children | 24ddab06aace |
comparison
equal
deleted
inserted
replaced
179:9ab52cb6baa3 | 180:d1bc89794cd4 |
---|---|
86 // referenceFrequency when creating the map -- setting it up for | 86 // referenceFrequency when creating the map -- setting it up for |
87 // 440Hz -- and then use it to scale the individual | 87 // 440Hz -- and then use it to scale the individual |
88 // frequency-domain audio frames before applying the map to them. | 88 // frequency-domain audio frames before applying the map to them. |
89 | 89 |
90 double refFreq = 440.; // See above -- *not* the parameter! | 90 double refFreq = 440.; // See above -- *not* the parameter! |
91 double binWidth = m_params.sampleRate / m_params.fftSize; | 91 double binWidth = double(m_params.sampleRate) / m_params.fftSize; |
92 int crossoverBin = (int)(2 / (pow(2, 1/12.0) - 1)); | 92 int crossoverBin = (int)(2 / (pow(2, 1/12.0) - 1)); |
93 int crossoverMidi = lrint(log(crossoverBin * binWidth / refFreq)/ | 93 int crossoverMidi = int(log(crossoverBin * binWidth / refFreq)/ |
94 log(2.0) * 12 + 69); | 94 log(2.0) * 12 + 69 + 0.5); |
95 | 95 |
96 int i = 0; | 96 int i = 0; |
97 while (i <= crossoverBin) { | 97 while (i <= crossoverBin) { |
98 double freq = i * binWidth; | 98 double freq = i * binWidth; |
99 if (freq < m_params.minFrequency || freq > m_params.maxFrequency) { | 99 if (freq < m_params.minFrequency || freq > m_params.maxFrequency) { |
109 if (freq < m_params.minFrequency || freq > m_params.maxFrequency) { | 109 if (freq < m_params.minFrequency || freq > m_params.maxFrequency) { |
110 m_freqMap[i++] = -1; | 110 m_freqMap[i++] = -1; |
111 } else { | 111 } else { |
112 double midi = log(freq / refFreq) / log(2.0) * 12 + 69; | 112 double midi = log(freq / refFreq) / log(2.0) * 12 + 69; |
113 if (midi > 127) midi = 127; | 113 if (midi > 127) midi = 127; |
114 int target = crossoverBin + lrint(midi) - crossoverMidi; | 114 int target = crossoverBin + int(midi + 0.5) - crossoverMidi; |
115 if (target >= m_featureSize) target = m_featureSize - 1; | 115 if (target >= m_featureSize) target = m_featureSize - 1; |
116 m_freqMap[i++] = target; | 116 m_freqMap[i++] = target; |
117 } | 117 } |
118 } | 118 } |
119 | 119 |
130 | 130 |
131 void | 131 void |
132 FeatureExtractor::makeChromaFrequencyMap() | 132 FeatureExtractor::makeChromaFrequencyMap() |
133 { | 133 { |
134 double refFreq = m_params.referenceFrequency; | 134 double refFreq = m_params.referenceFrequency; |
135 double binWidth = m_params.sampleRate / m_params.fftSize; | 135 double binWidth = double(m_params.sampleRate) / m_params.fftSize; |
136 int crossoverBin = (int)(1 / (pow(2, 1/12.0) - 1)); | 136 int crossoverBin = (int)(1 / (pow(2, 1/12.0) - 1)); |
137 int i = 0; | 137 int i = 0; |
138 while (i <= crossoverBin) { | 138 while (i <= crossoverBin) { |
139 double freq = i * binWidth; | 139 double freq = i * binWidth; |
140 if (freq < m_params.minFrequency || freq > m_params.maxFrequency) { | 140 if (freq < m_params.minFrequency || freq > m_params.maxFrequency) { |
147 double freq = i * binWidth; | 147 double freq = i * binWidth; |
148 if (freq < m_params.minFrequency || freq > m_params.maxFrequency) { | 148 if (freq < m_params.minFrequency || freq > m_params.maxFrequency) { |
149 m_freqMap[i++] = -1; | 149 m_freqMap[i++] = -1; |
150 } else { | 150 } else { |
151 double midi = log(freq / refFreq) / log(2.0) * 12 + 69; | 151 double midi = log(freq / refFreq) / log(2.0) * 12 + 69; |
152 m_freqMap[i++] = (lrint(midi)) % 12 + 1; | 152 m_freqMap[i++] = (int(midi + 0.5)) % 12 + 1; |
153 } | 153 } |
154 } | 154 } |
155 } | 155 } |
156 | 156 |
157 vector<double> | 157 vector<double> |
219 | 219 |
220 if (m_params.useChromaFrequencyMap) return mags; | 220 if (m_params.useChromaFrequencyMap) return mags; |
221 | 221 |
222 double ratio = 440. / m_params.referenceFrequency; | 222 double ratio = 440. / m_params.referenceFrequency; |
223 | 223 |
224 int n = mags.size(); | 224 int n = static_cast<int>(mags.size()); |
225 | 225 |
226 vector<double> scaled(n, 0.0); | 226 vector<double> scaled(n, 0.0); |
227 | 227 |
228 for (int target = 0; target < n; ++target) { | 228 for (int target = 0; target < n; ++target) { |
229 | 229 |