#NEWLINE# def test_spectral_centroid_synthetic( ) : #NEWLINE# #INDENT# k = 5 #NEWLINE# def __test( S , freq , sr , n_fft ) : #NEWLINE# #INDENT# cent = librosa . feature . spectral_centroid ( S = S , freq = freq ) #NEWLINE# if ( freq is None ) : #NEWLINE# #INDENT# freq = librosa . fft_frequencies ( sr = sr , n_fft = n_fft ) #NEWLINE# #UNINDENT# assert np . allclose ( cent , freq [ k ] ) #NEWLINE# #UNINDENT# sr = 22050 #NEWLINE# n_fft = 1024 #NEWLINE# S = np . zeros ( ( ( 1 + ( n_fft // 2 ) ) , 10 ) ) #NEWLINE# S [ k , : ] = 1.0 #NEWLINE# ( yield ( __test , S , None , sr , n_fft ) ) #NEWLINE# freq = librosa . fft_frequencies ( sr = sr , n_fft = n_fft ) #NEWLINE# ( yield ( __test , S , freq , sr , n_fft ) ) #NEWLINE# freq *= 3 #NEWLINE# ( yield ( __test , S , freq , sr , n_fft ) ) #NEWLINE# freq = np . random . randn ( * S . shape ) #NEWLINE# ( yield ( __test , S , freq , sr , n_fft ) )