Beispiel #1
0
def test_pitchgram_on_single_tone_should_have_peak_at_that_tone():
    pitch = 12 + 7  # G5
    f = Tuning().pitch_to_freq(pitch)
    fs = 44100
    x = sine(sample_time(0, 1, fs=fs), freq=f)
    frame_size = 4096
    hop_size = 2048
    output_frame_size = hop_size
    signal_frames = SignalFrames(x,
                                 frame_size,
                                 hop_size,
                                 sample_rate=fs,
                                 mono_mix=True)
    bin_range = [-48, 67]
    x_pitchgram = pitchgram(signal_frames,
                            output_frame_size,
                            magnitudes='power_db',
                            bin_range=bin_range,
                            bin_division=1)

    max_bin_expected = pitch - bin_range[0]
    max_bin_actual = x_pitchgram.mean(axis=0).argmax()

    assert x_pitchgram.shape == (21, 115), x_pitchgram.shape
    assert max_bin_actual == max_bin_expected
Beispiel #2
0
def test_reassigned_pitchgram_values_should_be_in_proper_range():
    frame_size = 4096
    hop_size = frame_size
    output_frame_size = 1024
    audio_file = os.path.join(DATA_DIR, 'she_brings_to_me.wav')
    signal_frames = SignalFrames(audio_file, frame_size, hop_size, mono_mix=True)
    X_r = pitchgram(signal_frames, output_frame_size, magnitudes='power_db')
    assert np.all(X_r >= -120), 'min value: %f should be >= -120' % X_r.min()
    assert np.all(X_r <= 0), 'max value: %f should be <= 0' % X_r.max()
Beispiel #3
0
def test_split_to_frames():
    signal_frames = SignalFrames(np.arange(23),
                                 frame_size=8,
                                 hop_size=6,
                                 sample_rate=44100)
    assert np.allclose(
        np.array([
            [0, 1, 2, 3, 4, 5, 6, 7],
            [6, 7, 8, 9, 10, 11, 12, 13],
            [12, 13, 14, 15, 16, 17, 18, 19],
            [18, 19, 20, 21, 22, 0, 0, 0],
        ]), signal_frames.frames)
Beispiel #4
0
def test_spectrogram_db_magnituds_should_be_in_proper_range():
    frame_size = 4096
    hop_size = 4096
    audio_file = os.path.join(DATA_DIR, 'she_brings_to_me.wav')
    signal_frames = SignalFrames(audio_file,
                                 frame_size,
                                 hop_size,
                                 mono_mix=True)
    w = create_window(frame_size)
    X = stft_spectrogram(signal_frames.frames, w, magnitudes='power_db')
    assert np.all(X >= -120), 'min value: %f should be >= -120' % X.min()
    assert np.all(X <= 0), 'max value: %f should be <= 0' % X.max()