From 3d727f3fecc5fa93ec390de6bc9e4c9ba7836d6c Mon Sep 17 00:00:00 2001 From: Thibaud Date: Wed, 29 May 2024 16:35:33 +0200 Subject: [PATCH 1/3] Add frequence_process plotting to compare original with detected --- frequence_process.py | 29 +++++++++++++++++++++++++++++ sound_process.py | 6 +++--- 2 files changed, 32 insertions(+), 3 deletions(-) create mode 100644 frequence_process.py diff --git a/frequence_process.py b/frequence_process.py new file mode 100644 index 0000000..5d07d28 --- /dev/null +++ b/frequence_process.py @@ -0,0 +1,29 @@ +import slider as sl +import sound_process +from tkinter import filedialog as fd +from matplotlib import pyplot as plt + +def process_with_map(): + filename = fd.askopenfilename() + beatmap = sl.Beatmap.from_path(filename) + timing = beatmap.timing_points[0] + bpm = timing.bpm + offset = timing.offset.total_seconds() * 1000 + data = sound_process.process_song(beatmap.audio_filename, bpm, offset0=offset) + + timings, amplitudes, freqs = [x[0].total_seconds() for x in data], [x[1] for x in data], [x[2] for x in data] + + original_times = [x.time.total_seconds() for x in beatmap.hit_objects(spinners=False) if x.time.total_seconds() <= timings[len(timings) - 1]] + + #bx.scatter(original_times, ys=10, zs=0) + plt.scatter(timings, amplitudes, marker="x", c="red") + for x in original_times: + plt.axvline(x=x) + + plt.show() + +def main(): + process_with_map() + +if __name__ == "__main__": + main() diff --git a/sound_process.py b/sound_process.py index 9df7306..39db92d 100755 --- a/sound_process.py +++ b/sound_process.py @@ -480,13 +480,13 @@ def process_song(filename, bpm, offset0=0, div_len_factor=1, n_iter_2=-1, thresh void_freq(filename, offset, min(song_len, offset+div_len*(n_iter+1)+0.01), 4*60/bpm, minfreq=0, maxfreq=220, upperthr=5000, ampthr=60, ampfreq = 1200, ampval = 5.0, leniency = 0.005, write=True, linear=False, output_file=filtered_name) #void_freq(filename, offset, offset+div_len*(n_iter+1)+0.01, 4*60/bpm, minfreq=0, maxfreq=330, upperthr=2500, ampthr=60, ampfreq = 1200, ampval = 1/2000, leniency = 0.0, write=True, linear=True, output_file=filtered_name) datares = filter_n_percent_serial(filtered_name, offset, n_iter, div_len, threshold) - datares = snap(datares, 44100, bpm, 4, True) - frequencies = get_freq(filtered_name, offset, div_len, div_len*n_iter, datares, True) + datares = snap(datares, 44100, bpm, 4, False) + frequencies = get_freq(filtered_name, offset, div_len, div_len*n_iter, datares, False) Path(f"{filename}_trimmed.wav").unlink() return convert_tuple(datares, frequencies) def main(): - data = process_song("tetris_4.wav", 160, n_iter_2 = 64) + data = process_song("audio.mp3", 160, n_iter_2 = 64) #print(data) print("Program finished with return 0") From 895573174234abec48ef1f037683a7b934064325 Mon Sep 17 00:00:00 2001 From: Thibaud Date: Thu, 30 May 2024 20:45:53 +0200 Subject: [PATCH 2/3] Add n_iter in frequence_process.py... (still broken) --- frequence_process.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frequence_process.py b/frequence_process.py index 5d07d28..079ce1a 100644 --- a/frequence_process.py +++ b/frequence_process.py @@ -9,7 +9,7 @@ def process_with_map(): timing = beatmap.timing_points[0] bpm = timing.bpm offset = timing.offset.total_seconds() * 1000 - data = sound_process.process_song(beatmap.audio_filename, bpm, offset0=offset) + data = sound_process.process_song(beatmap.audio_filename, bpm, offset0=offset, n_iter_2=48) timings, amplitudes, freqs = [x[0].total_seconds() for x in data], [x[1] for x in data], [x[2] for x in data] From fb1a0dc027fb3010d21ba630ed2b97f10bc30776 Mon Sep 17 00:00:00 2001 From: Thibaud Date: Fri, 31 May 2024 13:30:44 +0200 Subject: [PATCH 3/3] Rename frequence_process to better reflect functionality --- frequence_process.py => compare_plot.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) rename frequence_process.py => compare_plot.py (95%) diff --git a/frequence_process.py b/compare_plot.py similarity index 95% rename from frequence_process.py rename to compare_plot.py index 079ce1a..2804b4c 100644 --- a/frequence_process.py +++ b/compare_plot.py @@ -3,7 +3,7 @@ import sound_process from tkinter import filedialog as fd from matplotlib import pyplot as plt -def process_with_map(): +def compare_plot(): filename = fd.askopenfilename() beatmap = sl.Beatmap.from_path(filename) timing = beatmap.timing_points[0] @@ -23,7 +23,7 @@ def process_with_map(): plt.show() def main(): - process_with_map() + compare_plot() if __name__ == "__main__": main()