def test_iirt_multi(y_multi, center): y, sr = y_multi Call = librosa.iirt(y=y, sr=sr, center=center) C0 = librosa.iirt(y=y[0], sr=sr, center=center) C1 = librosa.iirt(y=y[1], sr=sr, center=center) assert np.allclose(Call[0], C0) assert np.allclose(Call[1], C1) assert not np.allclose(C0, C1)
def test_iirt(): gt = scipy.io.loadmat(os.path.join('tests', 'data', 'features-CT-cqt'), squeeze_me=True)['f_cqt'] y, sr = librosa.load(os.path.join('tests', 'data', 'test1_44100.wav')) mut1 = librosa.iirt(y, hop_length=2205, win_length=4410, flayout='ba') assert np.allclose(mut1, gt[23:108, :mut1.shape[1]], atol=1.8) mut2 = librosa.iirt(y, hop_length=2205, win_length=4410, flayout='sos') assert np.allclose(mut2, gt[23:108, :mut2.shape[1]], atol=1.8)
def test_iirt(): gt = scipy.io.loadmat(os.path.join('data', 'features-CT-cqt'), squeeze_me=True)['f_cqt'] y, sr = librosa.load(os.path.join('data', 'test1_44100.wav')) mut = librosa.iirt(y, hop_length=2205, win_length=4410) assert np.allclose(mut, gt[23:108, :mut.shape[1]], atol=1.8)
def extract_iir_chroma(x, sr): hop_length = sr / FEATURE_RATE assert (hop_length).is_integer() X = librosa.iirt(x, sr=sr, win_length=hop_length * 2, hop_length=hop_length, center=True) times = np.arange(X.shape[1]) * (hop_length / sr) fmin = librosa.midi_to_hz(24) f_chroma = librosa.feature.chroma_cqt(C=X, fmin=fmin, bins_per_octave=12, n_octaves=7) return f_chroma, times
def get_chromagram(recording, sr, frame_length, hopsize, stft=False, **kwargs): """ Compute a chromagram either using STFT or a multirate filter bank (IIRT) Args: See individual methods Returns: A chromagram """ tuning = kwargs.get('tuning', 0.0) norm = kwargs.get('norm', None) if stft: window = kwargs.get('window', None) return music_parser.compute_one_chromagram(recording, sr, norm=norm, hop_length=hopsize, n_fft=frame_length, window=window, tuning=tuning) else: midi = kwargs.get('herz', 21) flayout = kwargs.get('flayout', 'sos') bins_per_octave = kwargs.get('bins_per_octave', 12) n_octaves = kwargs.get('n_octaves', 7) center_freqs, sample_rates = music_parser.mr_frequencies_A0( tuning=tuning) time_freq = librosa.iirt(recording, sr=sr, win_length=frame_length, hop_length=hopsize, flayout=flayout, tuning=tuning, center_freqs=center_freqs, sample_rates=sample_rates) return librosa.feature.chroma_cqt(C=time_freq, bins_per_octave=bins_per_octave, n_octaves=n_octaves, fmin=librosa.midi_to_hz(midi), norm=norm)
def test_iirt_flayout2(): y, sr = librosa.load(os.path.join('tests', 'data', 'test1_44100.wav')) with pytest.warns(FutureWarning): librosa.iirt(y, hop_length=2205, win_length=4410)
def test_iirt_flayout1(): y, sr = librosa.load(os.path.join('tests', 'data', 'test1_44100.wav')) librosa.iirt(y, hop_length=2205, win_length=4410, flayout='foo')
# #STFT vs IIRT Visualization for Reference Recording # center_freqs, sample_rates = music_parser.mr_frequencies_A0(tuning=0.0) # D = librosa.iirt(ref_recording, sr=sr, win_length= frame_length, hop_length= hopsize, flayout = 'sos', tuning= ref_tuning, center_freqs= center_freqs, sample_rates = sample_rates) # C = librosa.stft(ref_recording, n_fft= frame_length, hop_length= hopsize, window= window, center = True, pad_mode = 'constant') # vis.plot_STFT_vs_IIRT(D, C, sr, hopsize) # plt.show() print('Recording successfully imported and parameters extracted') ##Onset detection center_freqs, sample_rates = music_parser.mr_frequencies_A0(tuning=0.0) # ref_filtered = librosa.iirt(ref_recording, sr=sr, win_length= frame_length, hop_length= hopsize, flayout = 'sos', tuning= ref_tuning, center_freqs=center_freqs, sample_rates=sample_rates) test_filtered = librosa.iirt(test_recording, sr=sr, win_length=frame_length, hop_length=hopsize, flayout='sos', tuning=test_tuning, center_freqs=center_freqs, sample_rates=sample_rates) #new Parameters fs = 22050 fs_frame_length = 4410 fs_hopsize = int(fs_frame_length / 2) #Compute novelty spectrum # ref_nov, ref_Fs_nov = pre.compute_novelty_spectrum(ref_filtered, Fs=fs, N= fs_frame_length, H= fs_hopsize, gamma=10) test_nov, test_Fs_nov = pre.compute_novelty_spectrum(test_filtered, Fs=fs, N=fs_frame_length, H=fs_hopsize,