Mercurial > hg > match-vamp
comparison src/FeatureExtractor.cpp @ 166:d23dad16d6f9 refactors
Simplify freq handling
author | Chris Cannam |
---|---|
date | Thu, 05 Feb 2015 11:53:23 +0000 |
parents | cf1282d1f940 |
children | 001db4c32eb0 ef3c4b451c57 |
comparison
equal
deleted
inserted
replaced
165:31602361fb65 | 166:d23dad16d6f9 |
---|---|
22 #include <cassert> | 22 #include <cassert> |
23 #include <cmath> | 23 #include <cmath> |
24 | 24 |
25 using namespace std; | 25 using namespace std; |
26 | 26 |
27 //#define DEBUG_FEATURE_EXTRACTOR 1 | 27 #define DEBUG_FEATURE_EXTRACTOR 1 |
28 | 28 |
29 FeatureExtractor::FeatureExtractor(Parameters parameters) : | 29 FeatureExtractor::FeatureExtractor(Parameters parameters) : |
30 m_params(parameters) | 30 m_params(parameters) |
31 { | 31 { |
32 m_featureSize = getFeatureSizeFor(parameters); | 32 m_featureSize = getFeatureSizeFor(parameters); |
74 double binWidth = m_params.sampleRate / m_params.fftSize; | 74 double binWidth = m_params.sampleRate / m_params.fftSize; |
75 int crossoverBin = (int)(2 / (pow(2, 1/12.0) - 1)); | 75 int crossoverBin = (int)(2 / (pow(2, 1/12.0) - 1)); |
76 int crossoverMidi = lrint(log(crossoverBin * binWidth / refFreq)/ | 76 int crossoverMidi = lrint(log(crossoverBin * binWidth / refFreq)/ |
77 log(2.0) * 12 + 69); | 77 log(2.0) * 12 + 69); |
78 | 78 |
79 #ifdef DEBUG_FEATURE_EXTRACTOR | |
79 cerr << "FeatureExtractor::makeStandardFrequencyMap: refFreq = " << refFreq << endl; | 80 cerr << "FeatureExtractor::makeStandardFrequencyMap: refFreq = " << refFreq << endl; |
81 #endif | |
80 | 82 |
81 int i = 0; | 83 int i = 0; |
82 while (i <= crossoverBin) { | 84 while (i <= crossoverBin) { |
83 m_freqMap[i] = i; | 85 m_freqMap[i] = i; |
84 ++i; | 86 ++i; |
89 if (midi > 127) midi = 127; | 91 if (midi > 127) midi = 127; |
90 int target = crossoverBin + lrint(midi) - crossoverMidi; | 92 int target = crossoverBin + lrint(midi) - crossoverMidi; |
91 if (target >= m_featureSize) target = m_featureSize - 1; | 93 if (target >= m_featureSize) target = m_featureSize - 1; |
92 m_freqMap[i++] = target; | 94 m_freqMap[i++] = target; |
93 } | 95 } |
96 | |
97 #ifdef DEBUG_FEATURE_EXTRACTOR | |
98 cerr << "FeatureExtractor: crossover bin is " << crossoverBin << " for midi " | |
99 << crossoverMidi << endl; | |
100 #endif | |
94 } | 101 } |
95 | 102 |
96 void | 103 void |
97 FeatureExtractor::makeChromaFrequencyMap() | 104 FeatureExtractor::makeChromaFrequencyMap() |
98 { | 105 { |