diff --git a/audio.wav b/audio.wav index e12b9b6..518fc1e 100644 Binary files a/audio.wav and b/audio.wav differ diff --git a/cleaned_sp.py b/cleaned_sp.py index ab3a714..f206a77 100644 --- a/cleaned_sp.py +++ b/cleaned_sp.py @@ -180,7 +180,7 @@ def keep_highest(song_name, offset, songlen, segsize, count, output_name, minfre a_ampl = 0 - # -------------------------------------------- Clean with freq -------------------------------------------- # + # -------------------------------------------- Compute freqs -------------------------------------------- # ssize_0 = segsize/3 locf = [] # frequencies @@ -209,6 +209,32 @@ def keep_highest(song_name, offset, songlen, segsize, count, output_name, minfre locf.append(fmax) + # -------------------------------------------- Merge -------------------------------------------- # + + k = 0 + while(k < len(locs)): + delta_t = 0 + if(type(loct[k]) == float): + delta_t += loct[k] + else: + delta_t += (loct[k][0] + loct[k][1])/2 + + if(type(loct[k-1]) == float): + delta_t -= loct[k-1] + else: + delta_t -= (loct[k-1][0] + loct[k-1][1])/2 + if(k > 0 and np.abs(delta_t) < segsize and np.abs(locs[k] - locs[k-1]) < 50 and is_note_within(locf[k], locf[k-1])): + loct[k-1] = [loct[k-1], loct[k]] + locs[k-1] = (locs[k-1] + locs[k])/2 + loct[k] = -1 + locs[k] = -1 + locf[k] = -1 + loct.remove(-1) + locs.remove(-1) + locf.remove(-1) + k += 1 + + # -------------------------------------------- Plot -------------------------------------------- # plt_loct_all = [] @@ -228,10 +254,11 @@ def keep_highest(song_name, offset, songlen, segsize, count, output_name, minfre plt_slids.append(locs[i]) plt_slids.append(locs[i]) - plt.plot(new_new_t, new_new_amps, "y-") - plt.plot(plt_loct, plt_locs, "ro") - plt.plot(plt_slidt, plt_slids, "go") - plt.plot(plt_loct_all, locf, "mo") + plt.plot(new_new_t, new_new_amps, "y-", label="amplitude (ua)") + plt.plot(plt_loct, plt_locs, "ro", label="circles") + plt.plot(plt_slidt, plt_slids, "go", label="sliders") + plt.plot(plt_loct_all, locf, "mo", label="frequencies (Hz)") + plt.legend(loc="upper left") '''plt.plot(new_times, new_freqs) plt.plot(new_times, [elt*1000/mx for elt in new_ampls]) @@ -241,7 +268,7 @@ def keep_highest(song_name, offset, songlen, segsize, count, output_name, minfre # -------------------------------------------- Write -------------------------------------------- # - return (loct, locs) # amplitude result, sliders and frequency result + return (loct, locs) def convert_to_wav(song_name:str, output_file="audio.wav") -> str: """ @@ -306,14 +333,14 @@ BPM = 149.3 SEGSIZE = 1/(BPM/60) wavved_song = convert_to_wav("songs/ctype.mp3") ''' - +''' # tetris_2 SONG_LEN = 10 OFFSET = 0 BPM = 157 SEGSIZE = 1/(BPM/60) wavved_song = convert_to_wav("songs/tetris_2.wav") - +''' ''' # test SONG_LEN = 1 @@ -331,20 +358,20 @@ wavved_song = convert_to_wav("songs/furioso melodia.mp3") ''' ''' # E -SONG_LEN = 30 +SONG_LEN = 15 OFFSET = 2.641 BPM = 155 SEGSIZE = 1/(BPM/60) wavved_song = convert_to_wav("songs/rushe.mp3") ''' -''' + # Tsubaki SONG_LEN = 10 OFFSET = 35.659 BPM = 199 SEGSIZE = 1/(BPM/60) wavved_song = convert_to_wav("songs/TSUBAKI.mp3") -''' + ''' # death SONG_LEN = 8