Mercurial > hg > qm-dsp
comparison dsp/keydetection/GetKeyMode.cpp @ 234:60bbe2d98066
* Various changes in progress for debugging key mode plugin
author | Chris Cannam <c.cannam@qmul.ac.uk> |
---|---|
date | Mon, 22 Jan 2007 17:32:09 +0000 |
parents | b478b1e23ab2 |
children | 12cffcc40bbc |
comparison
equal
deleted
inserted
replaced
233:b478b1e23ab2 | 234:60bbe2d98066 |
---|---|
2 // | 2 // |
3 ////////////////////////////////////////////////////////////////////// | 3 ////////////////////////////////////////////////////////////////////// |
4 | 4 |
5 #include "GetKeyMode.h" | 5 #include "GetKeyMode.h" |
6 #include "dsp/maths/MathUtilities.h" | 6 #include "dsp/maths/MathUtilities.h" |
7 #include "base/Pitch.h" | |
8 | |
9 #include <iostream> | |
7 | 10 |
8 // Chords profile | 11 // Chords profile |
9 static double MajProfile[36] = | 12 static double MajProfile[36] = |
10 { 0.0384, 0.0629, 0.0258, 0.0121, 0.0146, 0.0106, 0.0364, 0.0610, 0.0267, | 13 { 0.0384, 0.0629, 0.0258, 0.0121, 0.0146, 0.0106, 0.0364, 0.0610, 0.0267, |
11 0.0126, 0.0121, 0.0086, 0.0364, 0.0623, 0.0279, 0.0275, 0.0414, 0.0186, | 14 0.0126, 0.0121, 0.0086, 0.0364, 0.0623, 0.0279, 0.0275, 0.0414, 0.0186, |
21 | 24 |
22 ////////////////////////////////////////////////////////////////////// | 25 ////////////////////////////////////////////////////////////////////// |
23 // Construction/Destruction | 26 // Construction/Destruction |
24 ////////////////////////////////////////////////////////////////////// | 27 ////////////////////////////////////////////////////////////////////// |
25 | 28 |
26 GetKeyMode::GetKeyMode( double hpcpAverage, double medianAverage ) | 29 GetKeyMode::GetKeyMode( int sampleRate, float tuningFrequency, |
30 double hpcpAverage, double medianAverage ) | |
27 : | 31 : |
28 m_hpcpAverage( hpcpAverage ), | 32 m_hpcpAverage( hpcpAverage ), |
29 m_medianAverage( medianAverage ), | 33 m_medianAverage( medianAverage ), |
30 m_ChrPointer(0), | 34 m_ChrPointer(0), |
31 m_DecimatedBuffer(0), | 35 m_DecimatedBuffer(0), |
38 m_SortedBuffer(0) | 42 m_SortedBuffer(0) |
39 { | 43 { |
40 m_DecimationFactor = 8; | 44 m_DecimationFactor = 8; |
41 | 45 |
42 //Chromagram configuration parameters | 46 //Chromagram configuration parameters |
43 m_CromaConfig.isNormalised = 1; | 47 m_ChromaConfig.isNormalised = 1; |
44 m_CromaConfig.FS = lrint(44100.0/(double)m_DecimationFactor); | 48 m_ChromaConfig.FS = lrint(sampleRate/(double)m_DecimationFactor); |
45 m_CromaConfig.min = 111.0641; | 49 |
46 m_CromaConfig.max = 1.7770e+003; | 50 // m_ChromaConfig.min = 111.0641; |
47 m_CromaConfig.BPO = 36; | 51 // m_ChromaConfig.max = 1.7770e+003; |
48 m_CromaConfig.CQThresh = 0.0054; | 52 |
53 m_ChromaConfig.min = Pitch::getFrequencyForPitch | |
54 (12, 0, tuningFrequency); | |
55 m_ChromaConfig.max = Pitch::getFrequencyForPitch | |
56 (96, 0, tuningFrequency); | |
57 | |
58 m_ChromaConfig.BPO = 36; | |
59 m_ChromaConfig.CQThresh = 0.0054; | |
49 | 60 |
50 //Chromagram inst. | 61 //Chromagram inst. |
51 m_Chroma = new Chromagram( m_CromaConfig ); | 62 m_Chroma = new Chromagram( m_ChromaConfig ); |
52 | 63 |
53 //Get calculated parameters from chroma object | 64 //Get calculated parameters from chroma object |
54 m_ChromaFrameSize = m_Chroma->getFrameSize(); | 65 m_ChromaFrameSize = m_Chroma->getFrameSize(); |
55 //override hopsize for this application | 66 //override hopsize for this application |
56 m_ChromaHopSize = m_ChromaFrameSize;//m_Chroma->GetHopSize(); | 67 m_ChromaHopSize = m_ChromaFrameSize;//m_Chroma->GetHopSize(); |
57 m_BPO = m_CromaConfig.BPO; | 68 m_BPO = m_ChromaConfig.BPO; |
58 | 69 |
59 //Chromagram average and estimated key median filter lengths | 70 //Chromagram average and estimated key median filter lengths |
60 m_ChromaBuffersize = (int)ceil( m_hpcpAverage * m_CromaConfig.FS/m_ChromaFrameSize ); | 71 m_ChromaBuffersize = (int)ceil( m_hpcpAverage * m_ChromaConfig.FS/m_ChromaFrameSize ); |
61 m_MedianWinsize = (int)ceil( m_medianAverage * m_CromaConfig.FS/m_ChromaFrameSize ); | 72 m_MedianWinsize = (int)ceil( m_medianAverage * m_ChromaConfig.FS/m_ChromaFrameSize ); |
62 | 73 |
63 //Reset counters | 74 //Reset counters |
64 m_bufferindex = 0; | 75 m_bufferindex = 0; |
65 m_ChromaBufferFilling = 0; | 76 m_ChromaBufferFilling = 0; |
66 m_MedianBufferFilling = 0; | 77 m_MedianBufferFilling = 0; |
143 ////////////////////////////////////////////// | 154 ////////////////////////////////////////////// |
144 m_Decimator->process( PCMData, m_DecimatedBuffer); | 155 m_Decimator->process( PCMData, m_DecimatedBuffer); |
145 | 156 |
146 m_ChrPointer = m_Chroma->process( m_DecimatedBuffer ); | 157 m_ChrPointer = m_Chroma->process( m_DecimatedBuffer ); |
147 | 158 |
159 std::cout << "raw chroma: "; | |
160 for (int ii = 0; ii < m_BPO; ++ii) { | |
161 std::cout << m_ChrPointer[ii] << " "; | |
162 } | |
163 std::cout << std::endl; | |
164 | |
148 // populate hpcp values; | 165 // populate hpcp values; |
149 int cbidx; | 166 int cbidx; |
150 for( j = 0; j < m_BPO; j++ ) | 167 for( j = 0; j < m_BPO; j++ ) |
151 { | 168 { |
152 cbidx = (m_bufferindex * m_BPO) + j; | 169 cbidx = (m_bufferindex * m_BPO) + j; |
187 { | 204 { |
188 m_Keys[k] = m_MajCorr[k]; | 205 m_Keys[k] = m_MajCorr[k]; |
189 m_Keys[k+m_BPO] = m_MinCorr[k]; | 206 m_Keys[k+m_BPO] = m_MinCorr[k]; |
190 } | 207 } |
191 | 208 |
209 std::cout << "raw keys: "; | |
210 for (int ii = 0; ii < 2*m_BPO; ++ii) { | |
211 std::cout << m_Keys[ii] << " "; | |
212 } | |
213 std::cout << std::endl; | |
192 | 214 |
193 double dummy; | 215 double dummy; |
194 key = 1 + (int)ceil( (double)MathUtilities::getMax( m_Keys, 2* m_BPO, &dummy )/3 ); | 216 key = /*1 +*/ (int)ceil( (double)MathUtilities::getMax( m_Keys, 2* m_BPO, &dummy )/3 ); |
217 | |
218 std::cout << "key pre-sorting: " << key << std::endl; | |
195 | 219 |
196 | 220 |
197 //Median filtering | 221 //Median filtering |
198 | 222 |
199 // track Median buffer initial filling | 223 // track Median buffer initial filling |
220 | 244 |
221 | 245 |
222 //quicksort | 246 //quicksort |
223 qsort(m_SortedBuffer, m_MedianBufferFilling, sizeof(unsigned int), MathUtilities::compareInt); | 247 qsort(m_SortedBuffer, m_MedianBufferFilling, sizeof(unsigned int), MathUtilities::compareInt); |
224 | 248 |
249 std::cout << "sorted: "; | |
250 for (int ii = 0; ii < m_MedianBufferFilling; ++ii) { | |
251 std::cout << m_SortedBuffer[ii] << " "; | |
252 } | |
253 std::cout << std::endl; | |
254 | |
225 int sortlength = m_MedianBufferFilling; | 255 int sortlength = m_MedianBufferFilling; |
226 int midpoint = (int)ceil((double)sortlength/2); | 256 int midpoint = (int)ceil((double)sortlength/2); |
227 | 257 |
228 if( midpoint <= 0 ) | 258 if( midpoint <= 0 ) |
229 midpoint = 1; | 259 midpoint = 1; |