Compare commits
2 Commits
ac0e189b80
...
c6fda9449d
Author | SHA1 | Date |
---|---|---|
|
c6fda9449d | |
|
f28e50e643 |
2
main.py
2
main.py
|
@ -13,7 +13,7 @@ def main():
|
||||||
offset = timing.offset.total_seconds() * 1000
|
offset = timing.offset.total_seconds() * 1000
|
||||||
print(beatmap.audio_filename)
|
print(beatmap.audio_filename)
|
||||||
|
|
||||||
data = sound_process.process_song(beatmap.audio_filename, int(bpm), offset0=offset, n_iter_2=32)
|
data = sound_process.process_song(beatmap.audio_filename, int(bpm), offset0=offset, n_iter_2=-1)
|
||||||
# NOTE : remove n_iter_2 to map the whole music
|
# NOTE : remove n_iter_2 to map the whole music
|
||||||
timings, amplitudes, freqs = [x[0] for x in data], [x[1] for x in data], [x[2] for x in data]
|
timings, amplitudes, freqs = [x[0] for x in data], [x[1] for x in data], [x[2] for x in data]
|
||||||
|
|
||||||
|
|
|
@ -335,7 +335,36 @@ def snap(data, sample_rate, bpm, divisor, show=False):
|
||||||
|
|
||||||
return new
|
return new
|
||||||
|
|
||||||
def snap2(data, sample_rate, bpm, first_offset=0, div=4, show=False):
|
def adjust_timings(raw_data, snapped_data, indexes, thr=100):
|
||||||
|
"""
|
||||||
|
adjusts weirdly snapped notes
|
||||||
|
"""
|
||||||
|
current = 0
|
||||||
|
|
||||||
|
while(current < len(indexes)):
|
||||||
|
|
||||||
|
if(current < len(indexes) - 3 and current % 2 == 1): # on a 1/4 beat
|
||||||
|
if(snapped_data[indexes[current]] > thr and snapped_data[indexes[current+1]] > thr and snapped_data[indexes[current+2]] > thr and snapped_data[indexes[current+3]] <= thr):
|
||||||
|
# -XXX_
|
||||||
|
snapped_data[indexes[current+3]] = snapped_data[indexes[current+2]]
|
||||||
|
snapped_data[indexes[current+2]] = 0
|
||||||
|
|
||||||
|
if(current > 0 and current < len(indexes) - 1 and current % 2 == 1):
|
||||||
|
if(snapped_data[indexes[current]] > thr and (snapped_data[indexes[current+1]] < thr or snapped_data[indexes[current-1]] < thr)):
|
||||||
|
#_X_
|
||||||
|
'''if(snapped_data[indexes[current-1]] < thr and raw_data[indexes[current-1]] > raw_data[indexes[current+1]]):
|
||||||
|
snapped_data[indexes[current-1]] = snapped_data[indexes[current]]
|
||||||
|
else:
|
||||||
|
snapped_data[indexes[current+1]] = snapped_data[indexes[current]]'''
|
||||||
|
|
||||||
|
snapped_data[indexes[current]] = 0
|
||||||
|
|
||||||
|
current += 1
|
||||||
|
|
||||||
|
print("Resnap done")
|
||||||
|
return snapped_data
|
||||||
|
|
||||||
|
def snap2(data, sample_rate, bpm, first_offset=0, div=4, show=False, adjust=False):
|
||||||
"""
|
"""
|
||||||
data : list(int)
|
data : list(int)
|
||||||
sample_rate : int
|
sample_rate : int
|
||||||
|
@ -344,6 +373,9 @@ def snap2(data, sample_rate, bpm, first_offset=0, div=4, show=False):
|
||||||
|
|
||||||
song_len = int(len(data)/sample_rate)
|
song_len = int(len(data)/sample_rate)
|
||||||
|
|
||||||
|
indexes = []
|
||||||
|
app = True
|
||||||
|
|
||||||
reduced = [0 for i in range(song_len*1000)]
|
reduced = [0 for i in range(song_len*1000)]
|
||||||
new = [0 for i in range(song_len*1000)]
|
new = [0 for i in range(song_len*1000)]
|
||||||
|
|
||||||
|
@ -367,13 +399,24 @@ def snap2(data, sample_rate, bpm, first_offset=0, div=4, show=False):
|
||||||
if(j/1000 > current_t):
|
if(j/1000 > current_t):
|
||||||
k += 1
|
k += 1
|
||||||
current_t = first_offset + k*60/(bpm*div)
|
current_t = first_offset + k*60/(bpm*div)
|
||||||
|
app = True
|
||||||
|
|
||||||
y = int(current_t*1000)
|
y = int(current_t*1000)
|
||||||
if(y < len(new)):
|
if(y < len(new)):
|
||||||
new[y] = max(new[y], reduced[j])
|
new[y] = max(new[y], reduced[j])
|
||||||
|
|
||||||
print("Snap done")
|
if(app):
|
||||||
|
indexes.append(y)
|
||||||
|
app = False
|
||||||
|
|
||||||
|
print("Snap done")
|
||||||
|
|
||||||
|
if(adjust):
|
||||||
|
print("Len :", len(indexes))
|
||||||
|
|
||||||
|
new = adjust_timings(reduced, new, indexes)
|
||||||
|
|
||||||
|
|
||||||
if(show):
|
if(show):
|
||||||
new2 = [0.9 if new[i] != 0 else 0 for i in range(len(new))]
|
new2 = [0.9 if new[i] != 0 else 0 for i in range(len(new))]
|
||||||
|
|
||||||
|
@ -409,7 +452,7 @@ def snap2(data, sample_rate, bpm, first_offset=0, div=4, show=False):
|
||||||
plt.ylabel("Amplitude")
|
plt.ylabel("Amplitude")
|
||||||
plt.grid()
|
plt.grid()
|
||||||
plt.show()
|
plt.show()
|
||||||
|
|
||||||
return new
|
return new
|
||||||
|
|
||||||
def convert_to_wav(song_name:str, output_file="audio.wav") -> str:
|
def convert_to_wav(song_name:str, output_file="audio.wav") -> str:
|
||||||
|
@ -447,7 +490,7 @@ def process_song(filename, bpm, offset0=0, div_len_factor=1, n_iter_2=-1, thresh
|
||||||
song_len = get_songlen(filename)
|
song_len = get_songlen(filename)
|
||||||
|
|
||||||
if(n_iter == -1):
|
if(n_iter == -1):
|
||||||
n_iter = int((song_len-offset/1000)/div_len)-4
|
n_iter = int((song_len-offset/1000)/div_len)-1
|
||||||
|
|
||||||
filtered_name = f"{filename}_trimmed.wav"
|
filtered_name = f"{filename}_trimmed.wav"
|
||||||
|
|
||||||
|
@ -455,7 +498,7 @@ def process_song(filename, bpm, offset0=0, div_len_factor=1, n_iter_2=-1, thresh
|
||||||
#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)
|
||||||
datares = snap2(datares, 44100, bpm, first_offset=offset, div=4, show=True)
|
datares = snap2(datares, 44100, bpm, first_offset=offset, div=4, show=True, adjust=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