@@ -200,15 +200,33 @@ TempoTrackV2::get_rcf(const d_vec_t &dfframe_in, const d_vec_t &wv, d_vec_t &rcf
200200 acf[lag] = double (sum/ (dfframe_len - lag));
201201 }
202202
203- // now apply comb filtering
204- int numelem = 4 ;
203+ // Peaks in the autocorrelation function (acf) occur at lags corresponding
204+ // to the beat period and on every integer multiples of that. In the next
205+ // step we sum up four iterations of them.
205206
206- for (int i = 2 ; i < rcf_len; i++) { // max beat period
207- for (int a = 1 ; a <= numelem; a++) { // number of comb elements
208- for (int b = 1 -a; b <= a-1 ; b++) { // general state using normalisation of comb elements
209- rcf[i-1 ] += ( acf[(a*i+b)-1 ]*wv[i-1 ] ) / (2 .*a-1 .); // calculate value for comb filter row
210- }
211- }
207+ // Let's assume we have find a peak at 43, it is actually in the range of
208+ // 42.5 .. 43.5 and also found at 85 .. 87, 127,5 .. 130,5 and 170 .. 174
209+ // So we need also consider the neigbours in case of harmonics.
210+
211+ rcf[0 ] = 0 ;
212+ for (int i = 1 ; i < rcf_len; i++) { // max beat period
213+ rcf[i] = acf[i];
214+
215+ rcf[i] += acf[i * 2 - 1 ] / 4 ;
216+ rcf[i] += acf[i * 2 ] / 2 ;
217+ rcf[i] += acf[i * 2 + 2 ] / 4 ;
218+
219+ rcf[i] += acf[i * 3 - 1 ] / 3 ;
220+ rcf[i] += acf[i * 3 ] / 3 ;
221+ rcf[i] += acf[i * 3 + 1 ] / 3 ;
222+
223+ rcf[i] += acf[i * 4 - 2 ] / 8 ;
224+ rcf[i] += acf[i * 4 - 1 ] / 4 ;
225+ rcf[i] += acf[i * 4 ] / 4 ;
226+ rcf[i] += acf[i * 4 + 1 ] / 4 ;
227+ rcf[i] += acf[i * 4 + 2 ] / 8 ;
228+
229+ rcf[i] *= wv[i];
212230 }
213231
214232 // apply adaptive threshold to rcf
0 commit comments