19def computeKey(x, f_s, afWindow=None, iBlockLength=4096, iHopLength=2048):
23 afWindow = ToolComputeHann(iBlockLength)
25 assert(afWindow.shape[0] == iBlockLength),
"parameter error: invalid window dimension"
28 cKeyNames = np.array([
'C Maj',
'C# Maj',
'D Maj',
'D# Maj',
'E Maj',
'F Maj',
'F# Maj',
'G Maj',
'G# Maj',
'A Maj',
'A# Maj',
'B Maj',
29 'c min',
'c# min',
'd min',
'd# min',
'e min',
'f min',
'f# min',
'g min',
'g# min',
'a min',
'a# min',
'b min'])
32 t_pc = np.array([[6.35, 2.23, 3.48, 2.33, 4.38, 4.09, 2.52, 5.19, 2.39, 3.66, 2.29, 2.88],
33 [6.33, 2.68, 3.52, 5.38, 2.60, 3.53, 2.54, 4.75, 3.98, 2.69, 3.34, 3.17]])
34 t_pc = t_pc / t_pc.sum(axis=1, keepdims=
True)
37 v_pc, t = computeFeature(
"SpectralPitchChroma", x, f_s, afWindow, iBlockLength, iHopLength)
40 v_pc = v_pc.mean(axis=1)
43 d = np.zeros(t_pc.shape)
44 v_pc = np.concatenate((v_pc, v_pc), axis=0).reshape(2, 12)
45 for i
in range(0, 12):
46 d[:, i] = np.sum(np.abs(v_pc - np.roll(t_pc, i, axis=1)), axis=1)
51 cKey = cKeyNames[iKeyIdx]