comparison chromamethods.cpp @ 115:526250b06fe0 monophonicness

some comments, some variable renamings
author Matthias Mauch <mail@matthiasmauch.net>
date Thu, 31 Mar 2011 14:26:53 +0100
parents 846b552ea3b0
children 7a8956e903e1
comparison
equal deleted inserted replaced
114:3f104bceac99 115:526250b06fe0
36 using namespace std; 36 using namespace std;
37 using namespace boost; 37 using namespace boost;
38 38
39 39
40 /** Special Convolution 40 /** Special Convolution
41 special convolution is as long as the convolvee, i.e. the first argument. in the valid core part of the 41 Special convolution is as long as the convolvee, i.e. the first argument.
42 convolution it contains the usual convolution values, but the pads at the beginning (ending) have the same values 42 In the "valid" core part of the convolution it contains the usual convolution
43 as the first (last) valid convolution bin. 43 values, but the parts at the beginning (ending) that would normally be
44 calculated using zero padding simply have the same values as the first
45 (last) valid convolution bin.
44 **/ 46 **/
45 47
46 vector<float> SpecialConvolution(vector<float> convolvee, vector<float> kernel) 48 vector<float> SpecialConvolution(vector<float> convolvee, vector<float> kernel)
47 { 49 {
48 float s; 50 float s;
68 for (n = 0; n < lenKernel/2; n++) Z[n] = Z[lenKernel/2]; 70 for (n = 0; n < lenKernel/2; n++) Z[n] = Z[lenKernel/2];
69 for (n = lenConvolvee; n < lenConvolvee +lenKernel/2; n++) Z[n - lenKernel/2] = 71 for (n = lenConvolvee; n < lenConvolvee +lenKernel/2; n++) Z[n - lenKernel/2] =
70 Z[lenConvolvee - lenKernel/2 - 1]; 72 Z[lenConvolvee - lenKernel/2 - 1];
71 return Z; 73 return Z;
72 } 74 }
73
74 // vector<float> FftBin2Frequency(vector<float> binnumbers, int fs, int blocksize)
75 // {
76 // vector<float> freq(binnumbers.size, 0.0);
77 // for (unsigned i = 0; i < binnumbers.size; ++i) {
78 // freq[i] = (binnumbers[i]-1.0) * fs * 1.0 / blocksize;
79 // }
80 // return freq;
81 // }
82 75
83 float cospuls(float x, float centre, float width) 76 float cospuls(float x, float centre, float width)
84 { 77 {
85 float recipwidth = 1.0/width; 78 float recipwidth = 1.0/width;
86 if (abs(x - centre) <= 0.5 * width) { 79 if (abs(x - centre) <= 0.5 * width) {
101 out = 0; 94 out = 0;
102 } 95 }
103 return out; 96 return out;
104 } 97 }
105 98
99 /**
100 * Calculates a matrix that can be used to linearly map from the magnitude spectrum to a pitch-scale spectrum.
101 * @return this always returns true, which is a bit stupid, really. The main purpose of the function is to change the values in the "matrix" pointed to by *outmatrix
102 */
106 bool logFreqMatrix(int fs, int blocksize, float *outmatrix) { 103 bool logFreqMatrix(int fs, int blocksize, float *outmatrix) {
104 // TODO: rewrite so that everyone understands what is done here.
105 // TODO: make this more general, such that it works with all minoctave, maxoctave and whatever nBPS (or check if it already does)
107 106
108 int binspersemitone = nBPS; 107 int binspersemitone = nBPS;
109 int minoctave = 0; // this must be 0 108 int minoctave = 0; // this must be 0
110 int maxoctave = 7; // this must be 7 109 int maxoctave = 7; // this must be 7
111 int oversampling = 80; 110 int oversampling = 80;
126 // pitch-spaced frequency vector 125 // pitch-spaced frequency vector
127 int minMIDI = 21 + minoctave * 12 - 1; // this includes one additional semitone! 126 int minMIDI = 21 + minoctave * 12 - 1; // this includes one additional semitone!
128 int maxMIDI = 21 + maxoctave * 12; // this includes one additional semitone! 127 int maxMIDI = 21 + maxoctave * 12; // this includes one additional semitone!
129 vector<float> cq_f; 128 vector<float> cq_f;
130 float oob = 1.0/binspersemitone; // one over binspersemitone 129 float oob = 1.0/binspersemitone; // one over binspersemitone
131 // cq_f.push_back(440 * pow(2.0,0.083333 * (minMIDI-69))); // 0.083333 is approx 1/12
132 // cq_f.push_back(440 * pow(2.0,0.083333 * (minMIDI+oob-69)));
133 for (int i = minMIDI; i < maxMIDI; ++i) { 130 for (int i = minMIDI; i < maxMIDI; ++i) {
134 for (int k = 0; k < binspersemitone; ++k) { 131 for (int k = 0; k < binspersemitone; ++k) {
135 cq_f.push_back(440 * pow(2.0,0.083333333333 * (i+oob*k-69))); 132 cq_f.push_back(440 * pow(2.0,0.083333333333 * (i+oob*k-69)));
136 } 133 }
137 } 134 }
159 for (int iOS = curr_start; iOS < curr_end; ++iOS) { 156 for (int iOS = curr_start; iOS < curr_end; ++iOS) {
160 cq_activation = pitchCospuls(oversampled_f[iOS],cq_f[iCQ],binspersemitone*12); 157 cq_activation = pitchCospuls(oversampled_f[iOS],cq_f[iCQ],binspersemitone*12);
161 // cerr << oversampled_f[iOS] << " " << cq_f[iCQ] << " " << cq_activation << endl; 158 // cerr << oversampled_f[iOS] << " " << cq_f[iCQ] << " " << cq_activation << endl;
162 outmatrix[iFFT + nFFT * iCQ] += cq_activation * fft_activation[iOS-curr_start]; 159 outmatrix[iFFT + nFFT * iCQ] += cq_activation * fft_activation[iOS-curr_start];
163 } 160 }
164 // if (iCQ == 1 || iCQ == 2) { 161 }
165 // cerr << " " << outmatrix[iFFT + nFFT * iCQ] << endl;
166 // }
167 }
168 } 162 }
169 } 163 }
170 return true; 164 return true;
171 } 165 }
172 166
173 void dictionaryMatrix(float* dm, float s_param) { 167 void dictionaryMatrix(float* dm, float s_param) {
168 // TODO: make this more general, such that it works with all minoctave, maxoctave and even more than one note per semitone
174 int binspersemitone = nBPS; 169 int binspersemitone = nBPS;
175 int minoctave = 0; // this must be 0 170 int minoctave = 0; // this must be 0
176 int maxoctave = 7; // this must be 7 171 int maxoctave = 7; // this must be 7
177 // float s_param = 0.7;
178 172
179 // pitch-spaced frequency vector 173 // pitch-spaced frequency vector
180 int minMIDI = 21 + minoctave * 12 - 1; // this includes one additional semitone! 174 int minMIDI = 21 + minoctave * 12 - 1; // this includes one additional semitone!
181 int maxMIDI = 21 + maxoctave * 12; // this includes one additional semitone! 175 int maxMIDI = 21 + maxoctave * 12; // this includes one additional semitone!
182 vector<float> cq_f; 176 vector<float> cq_f;
183 float oob = 1.0/binspersemitone; // one over binspersemitone 177 float oob = 1.0/binspersemitone; // one over binspersemitone
184 // cq_f.push_back(440 * pow(2.0,0.083333 * (minMIDI-69))); // 0.083333 is approx 1/12
185 // cq_f.push_back(440 * pow(2.0,0.083333 * (minMIDI+oob-69)));
186 for (int i = minMIDI; i < maxMIDI; ++i) { 178 for (int i = minMIDI; i < maxMIDI; ++i) {
187 for (int k = 0; k < binspersemitone; ++k) { 179 for (int k = 0; k < binspersemitone; ++k) {
188 cq_f.push_back(440 * pow(2.0,0.083333333333 * (i+oob*k-69))); 180 cq_f.push_back(440 * pow(2.0,0.083333333333 * (i+oob*k-69)));
189 } 181 }
190 } 182 }
191 // cq_f.push_back(440 * pow(2.0,0.083333 * (minMIDI-oob-69)));
192 cq_f.push_back(440 * pow(2.0,0.083333 * (maxMIDI-69))); 183 cq_f.push_back(440 * pow(2.0,0.083333 * (maxMIDI-69)));
193 184
194 float curr_f; 185 float curr_f;
195 float floatbin; 186 float floatbin;
196 float curr_amp; 187 float curr_amp;
210 // dm[iNote + nNote * iOut] += 1 * curr_amp; 201 // dm[iNote + nNote * iOut] += 1 * curr_amp;
211 } 202 }
212 } 203 }
213 } 204 }
214 } 205 }
215
216
217 } 206 }
218 207
219 static 208 static
220 std::vector<std::string> 209 std::vector<std::string>
221 getPluginPath() 210 getPluginPath()
348 } 337 }
349 } 338 }
350 return chordvalues; 339 return chordvalues;
351 } 340 }
352 341
353 vector<string> chordDictionary(vector<float> *mchorddict, vector<vector<int> > *m_chordnotes, float boostN, float useHarte) { 342 vector<string> chordDictionary(vector<float> *mchorddict, vector<vector<int> > *m_chordnotes, float boostN, float harte_syntax) {
354 343
355 typedef tokenizer<char_separator<char> > Tok; 344 typedef tokenizer<char_separator<char> > Tok;
356 char_separator<char> sep(",; ","="); 345 char_separator<char> sep(",; ","=");
357 346
358 string chordDictBase("chord.dict"); 347 string chordDictBase("chord.dict");
386 // int iElement = 0; 375 // int iElement = 0;
387 int nChord = 0; 376 int nChord = 0;
388 377
389 vector<float> tempChordDict = staticChordvalues(); 378 vector<float> tempChordDict = staticChordvalues();
390 vector<string> tempChordNames = staticChordnames(); 379 vector<string> tempChordNames = staticChordnames();
391 if (useHarte == 1.0) { 380 if (harte_syntax == 1.0) {
392 tempChordNames.erase(tempChordNames.begin(),tempChordNames.begin()+tempChordNames.size()/2); 381 tempChordNames.erase(tempChordNames.begin(),tempChordNames.begin()+tempChordNames.size()/2);
393 } else { 382 } else {
394 tempChordNames.erase(tempChordNames.begin()+tempChordNames.size()/2,tempChordNames.begin()+tempChordNames.size()); 383 tempChordNames.erase(tempChordNames.begin()+tempChordNames.size()/2,tempChordNames.begin()+tempChordNames.size());
395 } 384 }
396 385
433 vector<int> tempchordnotes; 422 vector<int> tempchordnotes;
434 // add bass slash notation 423 // add bass slash notation
435 string slashNotation = ""; 424 string slashNotation = "";
436 for (int kSemitone = 1; kSemitone < 12; kSemitone++) { 425 for (int kSemitone = 1; kSemitone < 12; kSemitone++) {
437 if (tempChordDict[24*iType+(kSemitone) % 12] > 0.99) { 426 if (tempChordDict[24*iType+(kSemitone) % 12] > 0.99) {
438 if (useHarte == 0.0) { 427 if (harte_syntax == 0.0) {
439 slashNotation = bassnames[iSemitone][kSemitone]; 428 slashNotation = bassnames[iSemitone][kSemitone];
440 } else { 429 } else {
441 slashNotation = bassnames[12][kSemitone]; 430 slashNotation = bassnames[12][kSemitone];
442 } 431 }
443 } 432 }