Compare commits
No commits in common. "c6fda9449d6cd4d871980c806c07fbc5b949e467" and "ac0e189b80fd03a39e8896182fe0852896ee4445" have entirely different histories.
c6fda9449d
...
ac0e189b80
2
main.py
2
main.py
|
@ -13,7 +13,7 @@ def main():
|
|||
offset = timing.offset.total_seconds() * 1000
|
||||
print(beatmap.audio_filename)
|
||||
|
||||
data = sound_process.process_song(beatmap.audio_filename, int(bpm), offset0=offset, n_iter_2=-1)
|
||||
data = sound_process.process_song(beatmap.audio_filename, int(bpm), offset0=offset, n_iter_2=32)
|
||||
# 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]
|
||||
|
||||
|
|
|
@ -335,36 +335,7 @@ def snap(data, sample_rate, bpm, divisor, show=False):
|
|||
|
||||
return new
|
||||
|
||||
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):
|
||||
def snap2(data, sample_rate, bpm, first_offset=0, div=4, show=False):
|
||||
"""
|
||||
data : list(int)
|
||||
sample_rate : int
|
||||
|
@ -373,9 +344,6 @@ def snap2(data, sample_rate, bpm, first_offset=0, div=4, show=False, adjust=Fals
|
|||
|
||||
song_len = int(len(data)/sample_rate)
|
||||
|
||||
indexes = []
|
||||
app = True
|
||||
|
||||
reduced = [0 for i in range(song_len*1000)]
|
||||
new = [0 for i in range(song_len*1000)]
|
||||
|
||||
|
@ -399,24 +367,13 @@ def snap2(data, sample_rate, bpm, first_offset=0, div=4, show=False, adjust=Fals
|
|||
if(j/1000 > current_t):
|
||||
k += 1
|
||||
current_t = first_offset + k*60/(bpm*div)
|
||||
app = True
|
||||
|
||||
y = int(current_t*1000)
|
||||
if(y < len(new)):
|
||||
new[y] = max(new[y], reduced[j])
|
||||
|
||||
if(app):
|
||||
indexes.append(y)
|
||||
app = False
|
||||
|
||||
print("Snap done")
|
||||
|
||||
if(adjust):
|
||||
print("Len :", len(indexes))
|
||||
|
||||
new = adjust_timings(reduced, new, indexes)
|
||||
|
||||
|
||||
if(show):
|
||||
new2 = [0.9 if new[i] != 0 else 0 for i in range(len(new))]
|
||||
|
||||
|
@ -490,7 +447,7 @@ def process_song(filename, bpm, offset0=0, div_len_factor=1, n_iter_2=-1, thresh
|
|||
song_len = get_songlen(filename)
|
||||
|
||||
if(n_iter == -1):
|
||||
n_iter = int((song_len-offset/1000)/div_len)-1
|
||||
n_iter = int((song_len-offset/1000)/div_len)-4
|
||||
|
||||
filtered_name = f"{filename}_trimmed.wav"
|
||||
|
||||
|
@ -498,7 +455,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)
|
||||
datares = filter_n_percent_serial(filtered_name, offset, n_iter, div_len, threshold)
|
||||
#datares = snap(datares, 44100, bpm, 4, True)
|
||||
datares = snap2(datares, 44100, bpm, first_offset=offset, div=4, show=True, adjust=True)
|
||||
datares = snap2(datares, 44100, bpm, first_offset=offset, div=4, show=True)
|
||||
frequencies = get_freq(filtered_name, offset, div_len, div_len*n_iter, datares, True)
|
||||
Path(f"{filename}_trimmed.wav").unlink()
|
||||
return convert_tuple(datares, frequencies)
|
||||
|
|
Loading…
Reference in New Issue