Major error fixes
This commit is contained in:
parent
f1aebaaaab
commit
0574c4c509
3
main.py
3
main.py
|
@ -15,7 +15,8 @@ def main():
|
||||||
offset = timing.offset.total_seconds() * 10e3
|
offset = timing.offset.total_seconds() * 10e3
|
||||||
print(beatmap.audio_filename)
|
print(beatmap.audio_filename)
|
||||||
|
|
||||||
timings, amplitudes, freqs = sound_process.process_song(beatmap.audio_filename, bpm, offset=offset)
|
timings, amplitudes, freqs = sound_process.process_song(beatmap.audio_filename, int(bpm), offset0=offset, n_iter_2=48)
|
||||||
|
# NOTE : remove n_iter_2 to map the whole music
|
||||||
|
|
||||||
beatmap._hit_objects = place.greedy(bpm, offset, timings, amplitudes)
|
beatmap._hit_objects = place.greedy(bpm, offset, timings, amplitudes)
|
||||||
#beatmap._hit_objects = [sl.Slider(sl.Position(0, 0), timedelta(milliseconds=3), timedelta(milliseconds=130), 0, sl.curve.Linear([sl.Position(0, 0), sl.Position(100, 100)], 100), 100, 2, 1, 1, 1, timing.ms_per_beat, [], [],)]
|
#beatmap._hit_objects = [sl.Slider(sl.Position(0, 0), timedelta(milliseconds=3), timedelta(milliseconds=130), 0, sl.curve.Linear([sl.Position(0, 0), sl.Position(100, 100)], 100), 100, 2, 1, 1, 1, timing.ms_per_beat, [], [],)]
|
||||||
|
|
|
@ -144,8 +144,10 @@ def filter_n_percent_serial(song_name, offset, n_iter, step, threshold):
|
||||||
|
|
||||||
for i in range(n_iter):
|
for i in range(n_iter):
|
||||||
print(i, "/", n_iter)
|
print(i, "/", n_iter)
|
||||||
|
print(i * step)
|
||||||
song_data = global_data[int(i*step*sample_rate):int((i+1)*step*sample_rate)]
|
song_data = global_data[int(i*step*sample_rate):int((i+1)*step*sample_rate)]
|
||||||
|
|
||||||
|
if(len(song_data) != 0):
|
||||||
mx = max(song_data)
|
mx = max(song_data)
|
||||||
|
|
||||||
is_locked = [False for i in range(len(song_data))]
|
is_locked = [False for i in range(len(song_data))]
|
||||||
|
@ -234,6 +236,9 @@ def compress(Zxx):
|
||||||
res = []
|
res = []
|
||||||
|
|
||||||
def get_freq(song_name, offset, step, songlen, data, display=False):
|
def get_freq(song_name, offset, step, songlen, data, display=False):
|
||||||
|
"""
|
||||||
|
for a given list of amplitudes, returns the corresponding peak frequencies
|
||||||
|
"""
|
||||||
fft_list = []
|
fft_list = []
|
||||||
times = []
|
times = []
|
||||||
current_time = offset
|
current_time = offset
|
||||||
|
@ -269,7 +274,7 @@ def get_freq(song_name, offset, step, songlen, data, display=False):
|
||||||
frequencies[s] = 0
|
frequencies[s] = 0
|
||||||
|
|
||||||
if(display):
|
if(display):
|
||||||
plt.plot([t/1000 for t in range(len(data))], frequencies)
|
plt.plot([offset+t/1000 for t in range(len(data))], frequencies)
|
||||||
plt.grid()
|
plt.grid()
|
||||||
plt.xlabel("Time (s)")
|
plt.xlabel("Time (s)")
|
||||||
plt.ylabel("Dominant frequency (Hz)")
|
plt.ylabel("Dominant frequency (Hz)")
|
||||||
|
@ -279,7 +284,7 @@ def get_freq(song_name, offset, step, songlen, data, display=False):
|
||||||
return frequencies
|
return frequencies
|
||||||
|
|
||||||
|
|
||||||
def void_freq(song_name, offset, songlen, increment, minfreq, maxfreq, upperthr, ampthr, ampfreq, ampval, leniency, write, linear, output_file="trimmed.wav"):
|
def void_freq(song_name, offset, songlen, increment, minfreq, maxfreq, upperthr, ampthr, ampfreq, ampval, leniency, write, linear, is_stereo, output_file="trimmed.wav"):
|
||||||
"""
|
"""
|
||||||
song_name : string
|
song_name : string
|
||||||
offset : int
|
offset : int
|
||||||
|
@ -302,12 +307,22 @@ def void_freq(song_name, offset, songlen, increment, minfreq, maxfreq, upperthr,
|
||||||
|
|
||||||
subprocess.run(["ffmpeg", "-ss", str(offset), "-t", str(songlen+offset), "-i", song_name, "crop.wav"])
|
subprocess.run(["ffmpeg", "-ss", str(offset), "-t", str(songlen+offset), "-i", song_name, "crop.wav"])
|
||||||
|
|
||||||
sample_rate, global_data = wavfile.read("crop.wav")
|
sample_rate, raw_global_data = wavfile.read("crop.wav")
|
||||||
blit = int(sample_rate*increment)
|
blit = int(sample_rate*increment)
|
||||||
|
|
||||||
|
global_data = [0 for i in range(len(raw_global_data))]
|
||||||
|
|
||||||
subprocess.run(["clear"])
|
subprocess.run(["clear"])
|
||||||
subprocess.run(["rm", "crop.wav"])
|
subprocess.run(["rm", "crop.wav"])
|
||||||
|
|
||||||
|
if(is_stereo):
|
||||||
|
print("Converting to mono...")
|
||||||
|
for x in range(len(raw_global_data)):
|
||||||
|
global_data[x] = raw_global_data[x][0] + raw_global_data[x][1]
|
||||||
|
|
||||||
|
else:
|
||||||
|
global_data = raw_global_data
|
||||||
|
|
||||||
#print("Blit :", blit)
|
#print("Blit :", blit)
|
||||||
|
|
||||||
pfreq = scipy.fft.rfftfreq(blit, 1/sample_rate)
|
pfreq = scipy.fft.rfftfreq(blit, 1/sample_rate)
|
||||||
|
@ -406,10 +421,11 @@ def get_songlen(filename):
|
||||||
retrieves the length of the song in seconds
|
retrieves the length of the song in seconds
|
||||||
"""
|
"""
|
||||||
sample_rate, global_data = wavfile.read(filename)
|
sample_rate, global_data = wavfile.read(filename)
|
||||||
|
print("LEN :", len(global_data)/sample_rate)
|
||||||
|
|
||||||
return (len(global_data)/sample_rate)
|
return (len(global_data)/sample_rate)
|
||||||
|
|
||||||
def process_song(filename, bpm, offset=0, div_len_factor=1, n_iter_2=-1, threshold=0.5, divisor=4):
|
def process_song(filename, bpm, offset0=0, div_len_factor=1, n_iter_2=-1, threshold=0.5, divisor=4):
|
||||||
"""
|
"""
|
||||||
filename : string (name of the song)
|
filename : string (name of the song)
|
||||||
offset : int [+] (song mapping will start from this time in seconds, default is 0)
|
offset : int [+] (song mapping will start from this time in seconds, default is 0)
|
||||||
|
@ -420,21 +436,24 @@ def process_song(filename, bpm, offset=0, div_len_factor=1, n_iter_2=-1, thresho
|
||||||
divisor : int [+] (beat divisor used to snap the notes, default is 4)
|
divisor : int [+] (beat divisor used to snap the notes, default is 4)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
offset = offset0/1000
|
||||||
|
|
||||||
div_len = div_len_factor*60/bpm-0.01
|
div_len = div_len_factor*60/bpm-0.01
|
||||||
|
|
||||||
n_iter = n_iter_2
|
n_iter = n_iter_2
|
||||||
if(n_iter == -1):
|
|
||||||
song_len = get_songlen(filename)
|
song_len = get_songlen(filename)
|
||||||
n_iter = int(song_len/div_len)-1/3
|
|
||||||
|
if(n_iter == -1):
|
||||||
|
n_iter = int((song_len-offset/1000)/div_len)-4
|
||||||
|
|
||||||
filtered_name = f"{filename}_trimmed.wav"
|
filtered_name = f"{filename}_trimmed.wav"
|
||||||
|
|
||||||
void_freq(filename, offset, offset+div_len*(n_iter+1)+0.01, 4*60/bpm, minfreq=0, maxfreq=330, upperthr=5000, ampthr=60, ampfreq = 1200, ampval = 5.0, leniency = 0.005, write=True, linear=False, output_file=filtered_name)
|
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, is_stereo=True, 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)
|
#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 = filter_n_percent_serial(filtered_name, offset, n_iter, div_len, threshold)
|
||||||
datares = snap(datares, 44100, bpm, 4, True)
|
datares = snap(datares, 44100, bpm, 4, True)
|
||||||
frequencies = get_freq(filtered_name, offset, div_len, div_len*n_iter, datares, True)
|
frequencies = get_freq(filtered_name, offset, div_len, div_len*n_iter, datares, True)
|
||||||
#Path(f"{filename}_trimmed.wav").unlink()
|
Path(f"{filename}_trimmed.wav").unlink()
|
||||||
return convert_tuple(datares, frequencies)
|
return convert_tuple(datares, frequencies)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue