bpms = 60.0 * fft_res / (numpy.arange(1, ac_window+1))
// Smooth the autocorrelation by a log-normal distribution
x_corr = x_corr * numpy.exp(-0.5 * ((numpy.log2(bpms / start_bpm)) / BPM_STD)**2)
// Get the local maximum of weighted correlation
x_peaks = librosa.localmax(x_corr)
// Zero out all peaks before the first negative
x_peaks[:numpy.argmax(x_corr < 0)] = False
// Find the largest (local) max
start_period = numpy.argmax(x_peaks * x_corr)
// Choose the best peak out of .33, .5, 2, 3 * start_period
candidates = numpy.multiply(start_period, [1.0/3, 1.0/2, 1.0, 2.0, 3.0])
candidates = candidates.astype(int)
candidates = candidates[candidates < ac_window]
best_period = numpy.argmax(x_corr[candidates])