Exemplo n.º 1
0
def get_tempo_info(file_number):
    # get data
    d = BallroomData()

    # wav name
    wav_name = d.file_name(file_number)
    # ground truth
    aaagt_bpm = d.get_gt_bpm(file_number)
    # load file for librosa
    y, sr = d[file_number]

    onset_env = librosa.onset.onset_strength(y, sr=sr)
    # Static tempo
    aaatempo = librosa.beat.tempo(onset_envelope=onset_env, sr=sr)

    # Dynamic tempo
    dtempo = librosa.beat.tempo(onset_envelope=onset_env, sr=sr, aggregate=None)
    # Dynamic tempo distribution
    zapple = get_tempo_distribu(dtempo)
    aaatempo_list = zapple[0]
    aaatempo_cnt = zapple[1]

    # # --- print info ---
    # print("filename = ", wav_name)
    # print("gt = ", aaagt_bpm)
    # print("static = ", aaatempo[0])
    # print("----- guess ------ ------")
    # dis_lan = len(aaatempo_cnt)
    # for i in range(dis_lan):
    #     print("%18.14f" % aaatempo_list[i], "%6d" % aaatempo_cnt[i])
    #     # print(str(aaatempo_list[i]), str(aaatempo_cnt[i]))
    # print("----- ----- ------ ------\n\n")
    # # --- ----- ---- ---

    return aaagt_bpm, aaatempo, aaatempo_list, aaatempo_cnt
Exemplo n.º 2
0
def get_tempo_info(file_number):
    # get data
    d = BallroomData()

    # wav name
    wav_name = d.file_name(file_number)
    # ground truth
    aaagt_bpm = d.get_gt_bpm(file_number)
    # load file for librosa
    y, sr = d[file_number]

    onset_env = librosa.onset.onset_strength(y, sr=sr)
    # Static tempo
    aaatempo = librosa.beat.tempo(onset_envelope=onset_env, sr=sr)

    # Dynamic tempo
    dtempo = librosa.beat.tempo(onset_envelope=onset_env, sr=sr, aggregate=None)
    # Dynamic tempo distribution
    zapple = get_tempo_distribu(dtempo)
    aaatempo_list = zapple[0]
    aaatempo_cnt = zapple[1]

    return aaagt_bpm, aaatempo, aaatempo_list, aaatempo_cnt
Exemplo n.º 3
0
                        s = D.shape[1]  # 2048 22050

                        f_tempo_list = []

                        for t in range(D.shape[1]):
                            # get every most tempo and list them
                            f_tempo_list.append(
                                ff_get_two_tempo(D, t, total_time)[0][0])

                        # get t1 t2 by using the most exist
                        tempo_list, tempo_cnt = get_tempo_distribu(
                            f_tempo_list)
                        t_1, t_2 = f_get_two_tempo_total(tempo_list, tempo_cnt)

                        # TODO: remember gt
                        gt = d.get_gt_bpm(file_number)

                        print("gt =", gt, "t1 =", t_1, " t2 =", t_2)

                        # calculat saliency
                        ps = []

                        for ttt in range(D.shape[1]):
                            # fet ft
                            ft1, ft2 = get_two_f_t(D, ttt, total_time, t_1,
                                                   t_2)
                            # get p-score
                            ps.append(p_score_d4(t_1, t_2, ft1, ft2, gt))

                        # # print ps list
                        # print("---p-score list---\n", ps)
Exemplo n.º 4
0
Arquivo: Q7.py Projeto: exeex/mir-hw2
R_total = []
F_total = []

for song_id in range(len(dataset)):

    genre = dataset.get_genre(song_id)

    if genre != "Waltz":
        print(genre)
        continue

    aud, sr = dataset[0]

    bpm = librosa.beat.tempo(aud)
    beats_gt, beats_num = dataset.get_gg(song_id)
    print(bpm, dataset.get_gt_bpm(song_id))

    onset_frames = librosa.onset.onset_detect(y=aud, sr=sr)
    librosa.frames_to_time(onset_frames, sr=sr)
    o_env = librosa.onset.onset_strength(aud, sr=sr)
    # o_env = scipy.signal.medfilt(o_env,3)
    o_env = sigmoid(o_env * 0.5)

    tempo, beats = librosa.beat.beat_track(onset_envelope=o_env, sr=sr)

    times = librosa.frames_to_time(np.arange(len(o_env)), sr=sr)
    onset_frames = librosa.onset.onset_detect(onset_envelope=o_env, sr=sr)

    # plt.figure()
    #
    # plt.title('Power spectrogram')
Exemplo n.º 5
0
if __name__ == '__main__':
    total_of_total = 0

    d = BallroomData()

    for target_tempo in range(119, 123, 1):

        t_zapple = [], []
        total = 0
        print("target tempo = ", target_tempo)

        for file_number in range(len(d) - 1):
            # ground truth

            aaagt_bpm = d.get_gt_bpm(file_number)
            if aaagt_bpm == target_tempo:
                # wav name
                wav_name = d.file_name(file_number)
                # ground truth
                aaagt_bpm = d.get_gt_bpm(file_number)
                # load file for librosa
                y, sr = d[file_number]

                onset_env = librosa.onset.onset_strength(y, sr=sr)
                # Static tempo
                aaatempo = librosa.beat.tempo(onset_envelope=onset_env, sr=sr)

                # Dynamic tempo
                dtempo = librosa.beat.tempo(onset_envelope=onset_env,
                                            sr=sr,
Exemplo n.º 6
0
    # 50

    aud, sr = d[song_id]
    total_time = aud.shape[0] / sr

    D = fourier_tempogram(aud)

    s = D.shape[1]  # 2048 20050

    tempo_list = []

    for t in range(D.shape[1]):
        tempo_list.append(f_get_two_tempo(D, t, total_time)[0][0])
        # print("f_get_two_tempo", end=' : ')
        # print("- - - - - - - - - - - - - - - - - - - - - - - - - - "
        #       "(t%d)" % t, f_get_two_tempo(D, t, total_time))
    print(".")
    tempo_list, tempo_cnt = get_tempo_distribu(tempo_list)
    t_1, t_2 = f_get_two_tempo_tatal(tempo_list, tempo_cnt)
    print("t1 = ", t_1, " t2 = ", t_2)

    # print(dataset.get_genre(song_id))
    print("gt = ", end='')
    print(d.get_gt_bpm(song_id))

    librosa.display.specshow(D[20:, :])
    # plt.show()

    print(".")
Exemplo n.º 7
0
    # dataset = StdData()

    P_total = []
    R_total = []
    F_total = []
    genres = ["Cha Cha", "Slow Waltz"]
    for genre in genres:
        rng_h, rng_t = qui_genre_rng(genre)
        print(genre)
        for song_id in range(rng_h, rng_t):

            aud, sr = dataset[0]

            bpm = librosa.beat.tempo(aud)
            beats_gt, beats_num = dataset.get_gg(song_id)
            print("bpm =", bpm, "gt =", dataset.get_gt_bpm(song_id), end=',')

            onset_frames = librosa.onset.onset_detect(y=aud, sr=sr)
            librosa.frames_to_time(onset_frames, sr=sr)
            o_env = librosa.onset.onset_strength(aud, sr=sr)
            # o_env = scipy.signal.medfilt(o_env,3)
            o_env = sigmoid(o_env * 0.5)

            tempo, beats = librosa.beat.beat_track(onset_envelope=o_env, sr=sr)

            times = librosa.frames_to_time(np.arange(len(o_env)), sr=sr)
            onset_frames = librosa.onset.onset_detect(onset_envelope=o_env,
                                                      sr=sr)

            beats = times[beats]