Skip to content

Commit 9afe0e6

Browse files
committed
Reuse d_vec_t txwt
1 parent 924b46b commit 9afe0e6

1 file changed

Lines changed: 19 additions & 11 deletions

File tree

lib/qm-dsp/dsp/tempotracking/TempoTrackV2.cpp

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,10 @@ TempoTrackV2::calculateBeats(const vector<double> &df,
403403
// std::cerr << "alpha" << alpha << std::endl;
404404
// std::cerr << "tightness" << tightness << std::endl;
405405

406+
int old_period = 0;
407+
int txwt_len = 0;
408+
d_vec_t txwt;
409+
406410
// main loop
407411
for (int i = 0; i < df_len; i++) {
408412
// df contains the magnitude of the onsets
@@ -417,17 +421,21 @@ TempoTrackV2::calculateBeats(const vector<double> &df,
417421

418422
int period = beat_period[i/128];
419423
int prange_min = period * -2;
420-
int prange_max = period / -2;
421-
422-
// transition range
423-
int txwt_len = prange_max - prange_min + 1;
424-
d_vec_t txwt (txwt_len);
425-
426-
for (int j = 0; j < txwt_len; j++) {
427-
double mu = double(period);
428-
txwt[j] = exp( -0.5*pow(tightness * log((round(2*mu)-j)/mu),2));
429-
}
430-
424+
if (period != old_period) {
425+
old_period = period;
426+
int prange_max = period / -2;
427+
428+
// transition range
429+
txwt_len = prange_max - prange_min + 1;
430+
431+
txwt.clear();
432+
txwt.reserve(txwt_len);
433+
for (int j = 0; j < txwt_len; j++) {
434+
double mu = double(period);
435+
txwt.push_back(exp( -0.5*pow(tightness * log((round(2*mu)-j)/mu),2)));
436+
}
437+
}
438+
431439
// loop over the region in cumscore of one period in the past
432440
// to check for resonance using the txwt pattern.
433441
double vv = 0; // the maximum value, high if there is likely beat

0 commit comments

Comments
 (0)