32def computeNoveltyFunction(cNoveltyName, x, f_s, afWindow=None, iBlockLength=4096, iHopLength=512):
36 afWindow = ToolComputeHann(iBlockLength)
38 assert(afWindow.shape[0] == iBlockLength),
"parameter error: invalid window dimension"
40 hNoveltyFunc = getattr(pyACA,
"Novelty" + cNoveltyName)
43 fLenSmoothLpInS = 0.07
44 fLenThreshLpInS = 0.14
45 iLenSmoothLp = np.max([2, math.ceil(fLenSmoothLpInS * f_s / iHopLength)])
46 iLenThreshLp = np.max([2, math.ceil(fLenThreshLpInS * f_s / iHopLength)])
49 x = ToolPreprocAudio(x)
52 [X, f, t] = computeSpectrogram(x, f_s,
None, iBlockLength, iHopLength)
55 d = hNoveltyFunc(X, f_s)
58 b = np.ones(iLenSmoothLp) / iLenSmoothLp
63 iLenThreshLp = min(iLenThreshLp, np.floor(len(d)/3))
64 b = np.ones(iLenThreshLp) / iLenThreshLp
65 G_T = .4 * np.mean(d[np.arange(1, d.shape[0])]) + filtfilt(b, 1, d)
68 iPeaks = find_peaks(d - G_T, height=0)
70 return d, t, iPeaks[0]