comparison dsp/keydetection/GetKeyMode.cpp @ 40:163f6e03e9e7

* Add key strength output; increase chromagram lower bound so as to shorten hop size
author cannam
date Fri, 01 Feb 2008 16:45:49 +0000
parents ad645e404d0c
children b4921bfd2aea
comparison
equal deleted inserted replaced
39:200677638f5b 40:163f6e03e9e7
21 { 0.0375, 0.0682, 0.0299, 0.0119, 0.0138, 0.0093, 0.0296, 0.0543, 0.0257, 21 { 0.0375, 0.0682, 0.0299, 0.0119, 0.0138, 0.0093, 0.0296, 0.0543, 0.0257,
22 0.0292, 0.0519, 0.0246, 0.0159, 0.0234, 0.0135, 0.0291, 0.0544, 0.0248, 22 0.0292, 0.0519, 0.0246, 0.0159, 0.0234, 0.0135, 0.0291, 0.0544, 0.0248,
23 0.0137, 0.0176, 0.0104, 0.0352, 0.0670, 0.0302, 0.0222, 0.0349, 0.0164, 23 0.0137, 0.0176, 0.0104, 0.0352, 0.0670, 0.0302, 0.0222, 0.0349, 0.0164,
24 0.0174, 0.0297, 0.0166, 0.0222, 0.0401, 0.0202, 0.0175, 0.0270, 0.0146}; 24 0.0174, 0.0297, 0.0166, 0.0222, 0.0401, 0.0202, 0.0175, 0.0270, 0.0146};
25 // 25 //
26
26 27
27 ////////////////////////////////////////////////////////////////////// 28 //////////////////////////////////////////////////////////////////////
28 // Construction/Destruction 29 // Construction/Destruction
29 ////////////////////////////////////////////////////////////////////// 30 //////////////////////////////////////////////////////////////////////
30 31
38 m_MeanHPCP(0), 39 m_MeanHPCP(0),
39 m_MajCorr(0), 40 m_MajCorr(0),
40 m_MinCorr(0), 41 m_MinCorr(0),
41 m_Keys(0), 42 m_Keys(0),
42 m_MedianFilterBuffer(0), 43 m_MedianFilterBuffer(0),
43 m_SortedBuffer(0) 44 m_SortedBuffer(0),
45 m_keyStrengths(0)
44 { 46 {
45 m_DecimationFactor = 8; 47 m_DecimationFactor = 8;
46 48
47 // Chromagram configuration parameters 49 // Chromagram configuration parameters
48 m_ChromaConfig.normalise = MathUtilities::NormaliseUnitMax; 50 m_ChromaConfig.normalise = MathUtilities::NormaliseUnitMax;
49 m_ChromaConfig.FS = lrint(sampleRate/(double)m_DecimationFactor); 51 m_ChromaConfig.FS = lrint(sampleRate/(double)m_DecimationFactor);
50 52
51 // Set C (= MIDI #12) as our base : 53 // Set C (= MIDI #12) as our base :
52 // This implies that key = 1 => Cmaj, key = 12 => Bmaj, key = 13 => Cmin, etc. 54 // This implies that key = 1 => Cmaj, key = 12 => Bmaj, key = 13 => Cmin, etc.
53 m_ChromaConfig.min = Pitch::getFrequencyForPitch 55 m_ChromaConfig.min = Pitch::getFrequencyForPitch
54 (12, 0, tuningFrequency); 56 (48, 0, tuningFrequency);
55 m_ChromaConfig.max = Pitch::getFrequencyForPitch 57 m_ChromaConfig.max = Pitch::getFrequencyForPitch
56 (96, 0, tuningFrequency); 58 (96, 0, tuningFrequency);
57 59
58 m_ChromaConfig.BPO = 36; 60 m_ChromaConfig.BPO = 36;
59 m_ChromaConfig.CQThresh = 0.0054; 61 m_ChromaConfig.CQThresh = 0.0054;
65 m_ChromaFrameSize = m_Chroma->getFrameSize(); 67 m_ChromaFrameSize = m_Chroma->getFrameSize();
66 // override hopsize for this application 68 // override hopsize for this application
67 m_ChromaHopSize = m_ChromaFrameSize; 69 m_ChromaHopSize = m_ChromaFrameSize;
68 m_BPO = m_ChromaConfig.BPO; 70 m_BPO = m_ChromaConfig.BPO;
69 71
72 // std::cerr << "chroma frame size = " << m_ChromaFrameSize << ", decimation factor = " << m_DecimationFactor << " therefore block size = " << getBlockSize() << std::endl;
73
70 // Chromagram average and estimated key median filter lengths 74 // Chromagram average and estimated key median filter lengths
71 m_ChromaBuffersize = (int)ceil( m_hpcpAverage * m_ChromaConfig.FS/m_ChromaFrameSize ); 75 m_ChromaBuffersize = (int)ceil( m_hpcpAverage * m_ChromaConfig.FS/m_ChromaFrameSize );
72 m_MedianWinsize = (int)ceil( m_medianAverage * m_ChromaConfig.FS/m_ChromaFrameSize ); 76 m_MedianWinsize = (int)ceil( m_medianAverage * m_ChromaConfig.FS/m_ChromaFrameSize );
73 77
74 // Reset counters 78 // Reset counters
94 m_SortedBuffer = new int[ m_MedianWinsize ]; 98 m_SortedBuffer = new int[ m_MedianWinsize ];
95 memset( m_SortedBuffer, 0, sizeof(int)*m_MedianWinsize); 99 memset( m_SortedBuffer, 0, sizeof(int)*m_MedianWinsize);
96 100
97 m_Decimator = new Decimator 101 m_Decimator = new Decimator
98 ( m_ChromaFrameSize*m_DecimationFactor, m_DecimationFactor ); 102 ( m_ChromaFrameSize*m_DecimationFactor, m_DecimationFactor );
103
104 m_keyStrengths = new double[24];
99 } 105 }
100 106
101 GetKeyMode::~GetKeyMode() 107 GetKeyMode::~GetKeyMode()
102 { 108 {
103 109
110 delete [] m_MajCorr; 116 delete [] m_MajCorr;
111 delete [] m_MinCorr; 117 delete [] m_MinCorr;
112 delete [] m_Keys; 118 delete [] m_Keys;
113 delete [] m_MedianFilterBuffer; 119 delete [] m_MedianFilterBuffer;
114 delete [] m_SortedBuffer; 120 delete [] m_SortedBuffer;
121
122 delete[] m_keyStrengths;
115 } 123 }
116 124
117 double GetKeyMode::krumCorr(double *pData1, double *pData2, unsigned int length) 125 double GetKeyMode::krumCorr(double *pData1, double *pData2, unsigned int length)
118 { 126 {
119 double retVal= 0.0; 127 double retVal= 0.0;
212 { 220 {
213 m_Keys[k] = m_MajCorr[k]; 221 m_Keys[k] = m_MajCorr[k];
214 m_Keys[k+m_BPO] = m_MinCorr[k]; 222 m_Keys[k+m_BPO] = m_MinCorr[k];
215 } 223 }
216 224
225 for (k = 0; k < 24; ++k) {
226 m_keyStrengths[k] = 0;
227 }
228
229 for( k = 0; k < m_BPO*2; k++ )
230 {
231 m_keyStrengths[k/(m_BPO/12)] += m_Keys[k];
232 }
217 233
218 /* 234 /*
219 std::cout << "raw keys: "; 235 std::cout << "raw keys: ";
220 for (int ii = 0; ii < 2*m_BPO; ++ii) { 236 for (int ii = 0; ii < 2*m_BPO; ++ii) {
221 std::cout << m_Keys[ii] << " "; 237 std::cout << m_Keys[ii] << " ";