Skip to content

Commit 1e24a7c

Browse files
committed
use std::fill and std::copy to get around the range check in the inner loop.
1 parent f6bcae5 commit 1e24a7c

1 file changed

Lines changed: 16 additions & 5 deletions

File tree

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

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,15 +109,15 @@ TempoTrackV2::calculateBeatPeriod(const vector<double> &df,
109109
// then call viterbi decoding with weight vector and transition matrix
110110
// and get best path
111111

112-
int wv_len = 128;
112+
const int wv_len = 128;
113113

114114
// MEPD 28/11/12
115115
// the default value of inputtempo in the beat tracking plugin is 120
116116
// so if the user specifies a different inputtempo, the rayparam will be updated
117117
// accordingly.
118118
// note: 60*44100/512 is a magic number
119119
// this might (will?) break if a user specifies a different frame rate for the onset detection function
120-
double rayparam = (60*44100/512)/inputtempo;
120+
const double rayparam = (60 * 44100 / 512.0) / inputtempo;
121121

122122
// make rayleigh weighting curve
123123
d_vec_t wv(wv_len);
@@ -152,10 +152,21 @@ TempoTrackV2::calculateBeatPeriod(const vector<double> &df,
152152

153153
// Loop over the onset detection function half a window padding on both ends
154154
for (int i = -winlen / 2; i < df_len - winlen / 2; i += hopsize) {
155-
for (int k = 0; k < winlen; k++) {
156-
int j = i + k;
157-
dfframe[k] = (j >= 0 && j < df_len) ? df[j] : 0.0;
155+
int k = 0;
156+
int l = winlen;
157+
158+
if (i < 0) {
159+
k = -i;
160+
std::fill(dfframe.begin(), dfframe.begin() + k, 0.0);
161+
}
162+
163+
if (i + l > df_len) {
164+
l = df_len - i;
165+
std::fill(dfframe.begin() + l, dfframe.end(), 0.0);
158166
}
167+
168+
std::copy(df.begin() + i + k, df.begin() + i + l,
169+
dfframe.begin() + k);
159170

160171
// Apply the resonator comb filter (RCF) bank to the window
161172
// The result is a vector of filter responses for different periods.

0 commit comments

Comments
 (0)