Example #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
Example #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
Example #3
0
def ALOTC_d4(t_1, t_2, gt):
    t_1, t_2 = t_1 / 4, t_2 / 4
    gt = int(gt)
    if abs((gt - t_1) / gt) <= 0.08 or abs((gt - t_2) / gt) <= 0.08:
        p = 1
    else:
        p = 0
    return p


if __name__ == "__main__":

    time.time()

    d = BallroomData()
    # genres = ["Cha Cha", "Jive", "Quickstep", "Rumba", "Samba", "Tango", "Viennese Waltz", "Slow Waltz"]
    genres = [
        "Jive", "Quickstep", "Rumba", "Samba", "Tango", "Viennese Waltz",
        "Slow Waltz"
    ]
    g_id = 0

    tStart = time.time()
    try:
        # d = BallroomData()
        genres = [
            "Cha Cha", "Jive", "Quickstep", "Rumba", "Samba", "Tango",
            "Viennese Waltz", "Slow Waltz"
        ]
        genres_ALOTC = [0, 0, 0, 0, 0, 0, 0, 0]
Example #4
0
    return p


def ALOTC(t_1, t_2, gt):
    gt = int(gt)
    if abs((gt - t_1) / gt) <= 0.08 or abs((gt - t_2) / gt) <= 0.08:
        p = 1
    else:
        p = 0
    return p


if __name__ == "__main__":

    d = BallroomData()
    # for test
    clicks = ["60.mp3", "78.mp3", "120.mp3", "134.mp3", "160.mp3", "171.mp3"]

    for name in clicks:
        print(name)
        aud, sr = librosa.load(os.path.join(".", "click", name))
        gt = name.split(".mp3")[0]

        total_time = aud.shape[0] / sr

        D = fourier_tempogram(aud)

        s = D.shape[1]  # 2048 22050

        f_tempo_list = []
Example #5
0
File: Q7.py Project: exeex/mir-hw2
import os
import librosa
import librosa.display
import matplotlib.pyplot as plt
import numpy as np
from dataset import BallroomData, StdData
from tempogram import fourier_tempogram
import librosa.display
import scipy.signal


def sigmoid(x):
    return 1 / (1 + np.exp(-x))


dataset = BallroomData()
# dataset = StdData()

P_total = []
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]
Example #6
0
    for i in range(len(head_list)):
        for x in range(len(tempo_list1)):
            if head_list[i] == tempo_list1[x]:
                head_cnt[i] = head_cnt[i] + tempo_cnt1[x]
        for y in range(len(tempo_list2)):
            if head_list[i] == tempo_list2[y]:
                head_cnt[i] = head_cnt[i] + tempo_cnt2[y]

    return head_list, head_cnt


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
Example #7
0
                                                          T2_intensity)


'''
click is truth
171/47.67487108013937 = 3.586795226201168
160/44.8704668989547 = 3.5658198155216287
134/37.85945644599303 = 3.539406335406653
120/32.95174912891986 =3.641688322234855
78/too dirty (drum sounds)
60/32.95174912891986

'''

if __name__ == "__main__":
    d = BallroomData()

    song_id = 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]):
Example #8
0
        T2_idx = pair[2][0] + 19
        T2_intensity = pair[2][1] + 19

    sr = D.shape[1] / total_time * 32
    hz_per_idx = sr / 2 / D.shape[0]
    bpm_per_idx = hz_per_idx * 60
    # y= ax+b

    print(bpm_per_idx)

    # TODO: find peak (T1,T2)

    return (T1_idx * bpm_per_idx, T2_idx * bpm_per_idx), (T1_intensity, T2_intensity)


dataset = BallroomData()
# dataset = StdData()

song_id = 10

# 50

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

sr_new = sr / 512

D = fourier_tempogram(aud)

for t in range(D.shape[1]):
    if t == 20:
Example #9
0
import os
import librosa
import librosa.display
import matplotlib.pyplot as plt
import numpy as np
from dataset import BallroomData

dataset = BallroomData()

aud, sr = dataset[0]
tempo, beats = librosa.beat.beat_track(aud)

onset_env = librosa.onset.onset_strength(aud, sr=sr, aggregate=np.median)

hop_length = 512
plt.figure(figsize=(8, 4))
times = librosa.frames_to_time(np.arange(len(onset_env)),
                               sr=sr,
                               hop_length=hop_length)
plt.plot(times, librosa.util.normalize(onset_env), label='Onset strength')
plt.vlines(times[beats],
           0,
           1,
           alpha=0.5,
           color='r',
           linestyle='--',
           label='Beats')
plt.legend(frameon=True, framealpha=0.75)

# Limit the plot to a 15-second window
plt.xlim(15, 30)
Example #10
0
        tt1 = 1
    else:
        tt1 = 0
    if abs((gt - t_2) / gt) <= 0.08:
        tt2 = 1
    else:
        tt2 = 0
    p = saliency * tt1 + (1 - saliency) * tt2

    return p


if __name__ == '__main__':
    tStart = time.time()
    try:
        data = BallroomData()
        genres = [
            "Cha Cha", "Jive", "Quickstep", "Rumba", "Samba", "Tango",
            "Viennese Waltz", "Slow Waltz"
        ]
        genres_ALOTC = [0, 0, 0, 0, 0, 0, 0, 0]
        genres_ps = [0, 0, 0, 0, 0, 0, 0, 0]

        ans1_avg = [0, 0, 0, 0, 0, 0, 0, 0]
        ans2_avg = [0, 0, 0, 0, 0, 0, 0, 0]
        ans3_avg = [0, 0, 0, 0, 0, 0, 0, 0]

        g_id = 0
        for genre_name in genres:
            try:
                total_a = 0
Example #11
0
    elif name == "VienneseWaltz" or name == "Viennese Waltz":
        return 338, 403
    elif name == "Samba":
        return 403, 489
    elif name == "ChaChaCha" or name == "Cha Cha":
        return 489, 600
    elif name == "Rumba":
        return 600, 698
    else:
        print("!! Wrong Genre Name !!")
        return 0, 0


if __name__ == '__main__':

    dataset = BallroomData()
    # 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)