Compare commits
2 Commits
8834b4929a
...
568a467a27
Author | SHA1 | Date |
---|---|---|
|
568a467a27 | |
|
4ac58100fb |
47
place.py
47
place.py
|
@ -12,7 +12,8 @@ def beatify(bpm:float, offset:int, time:timedelta) -> float:
|
|||
def debeatify(bpm:float, offset:int, beat:int) -> timedelta:
|
||||
return timedelta(milliseconds=(beat*60000/bpm) + offset)
|
||||
|
||||
def f(intensity): return np.pi/2 - np.arctan(2*intensity - 5)
|
||||
#def f(intensity): return np.pi/2 - np.arctan(2*intensity) + np.pi/5
|
||||
def f(intensity): return np.pi/2
|
||||
|
||||
def greedy(bpm:int, offset:int, timings:list, amplitudes:list):
|
||||
"""
|
||||
|
@ -20,15 +21,20 @@ def greedy(bpm:int, offset:int, timings:list, amplitudes:list):
|
|||
output: list of object type / position
|
||||
"""
|
||||
flow = 1
|
||||
notes = [sl.HitObject(0, timedelta(milliseconds=0), 0)] * len(timings)
|
||||
notes = [sl.HitObject(sl.Position(260, 188), timedelta(milliseconds=0), 0)] * len(timings)
|
||||
beats = [beatify(bpm, offset, timing) for timing in timings]
|
||||
last_position = (260, 188)
|
||||
max_x, max_y, min_x, min_y = -np.inf, -np.inf, np.inf, np.inf
|
||||
for (delta, note_beat, intensity, i) in zip(timings, beats, amplitudes, range(len(timings))):
|
||||
try:
|
||||
print(notes[i-1].position.x)
|
||||
duration = note_beat - beats[i + 1]
|
||||
"""
|
||||
if duration in (QUARTER, HALF):
|
||||
notes[i] = sl.Circle(sl.Position(0, 0), delta, 0)
|
||||
notes[i] = sl.Circle(sl.Position(0, 0), delta, 0)
|
||||
"""
|
||||
"""
|
||||
elif duration % 2 == 0:
|
||||
rhythms.insert(0, f"slider {duration}")
|
||||
else:
|
||||
|
@ -37,17 +43,36 @@ def greedy(bpm:int, offset:int, timings:list, amplitudes:list):
|
|||
except IndexError:
|
||||
notes[i] = sl.Circle(sl.Position(0, 0), delta, 0)
|
||||
# TODO mettre à jour flow
|
||||
"""
|
||||
|
||||
if len(notes) > 2:
|
||||
angle = flow * f(rhythm.intensite)
|
||||
x1, y1 = notes[i-2].position
|
||||
x2, y2 = notes[i-1].position
|
||||
old_angle = np.arctan2((y1, y2), (x1, x2))
|
||||
x3 = x2 + (intensity * np.cos(angle + old_angle))
|
||||
y3 = y2 + (intensity * np.sin(angle + old_angle))
|
||||
if duration == QUARTER:
|
||||
x2, y2 = int(notes[i-1].position.x), int(notes[i-1].position.y)
|
||||
notes[i] = sl.Circle(sl.Position(x2, y2), delta, 0)
|
||||
|
||||
else:
|
||||
pass
|
||||
"""
|
||||
angle = flow * f(intensity/100)
|
||||
x1, y1 = int(notes[i-2].position.x), int(notes[i-2].position.y)
|
||||
x2, y2 = int(notes[i-1].position.x), int(notes[i-1].position.y)
|
||||
old_angle = np.arctan2([y2-y1], [x2-x1])
|
||||
x3 = x2 + (duration*intensity * np.cos(angle + old_angle))
|
||||
y3 = y2 + (duration*intensity * np.sin(angle + old_angle))
|
||||
notes[i] = sl.Circle(sl.Position(int(x3[0]), int(y3[0])), delta, 0)
|
||||
else:
|
||||
notes[i] = sl.Circle(sl.Position(260, 188), delta, 0)
|
||||
if notes[i].position.x > max_x:
|
||||
max_x = notes[i].position.x
|
||||
elif notes[i].position.x < min_x:
|
||||
min_x = notes[i].position.x
|
||||
if notes[i].position.y > max_y:
|
||||
max_y = notes[i].position.y
|
||||
elif notes[i].position.y < min_y:
|
||||
min_y = notes[i].position.y
|
||||
factor_x = 1/(max_x - min_x)
|
||||
factor_y = 1/(max_y - min_y)
|
||||
for note in notes:
|
||||
note.position = sl.Position((note.position.x-min_x)*factor_x*512, (note.position.y-min_y)*factor_y*384)
|
||||
print(note.position.x, note.position.y)
|
||||
|
||||
return notes
|
||||
|
||||
|
||||
|
|
|
@ -30,12 +30,12 @@ def filter_n_percent_serial(song_name, offset, n_iter, step, threshold):
|
|||
filter data associated with song_name to keep only the highest threshold% values
|
||||
"""
|
||||
|
||||
subprocess.run(["ffmpeg", "-ss", str(offset), "-t", str(offset+step*n_iter), "-i", song_name, "crop.wav"])
|
||||
subprocess.run(["ffmpeg", "-ss", str(offset), "-t", str(offset+step*n_iter), "-i", song_name, "crop.wav"], shell=True)
|
||||
|
||||
sample_rate, global_data = wavfile.read('crop.wav')
|
||||
|
||||
subprocess.run(["clear"])
|
||||
subprocess.run(["rm", "crop.wav"])
|
||||
subprocess.run(["clear"], shell=True)
|
||||
subprocess.run(["rm", "crop.wav"], shell=True)
|
||||
|
||||
for i in range(n_iter):
|
||||
print(i, "/", n_iter)
|
||||
|
@ -97,13 +97,13 @@ def get_freq(song_name, times, width=1000, display=False):
|
|||
for a given list of times (in seconds), returns the corresponding peak frequencies
|
||||
"""
|
||||
|
||||
subprocess.run(["ffmpeg", "-ss", str(0), "-t", str(max(np.array(times))), "-i", song_name, "crop.wav"])
|
||||
subprocess.run(["ffmpeg", "-ss", str(0), "-t", str(max(np.array(times))), "-i", song_name, "crop.wav"], shell=True)
|
||||
|
||||
sample_rate, global_data = wavfile.read(song_name)
|
||||
#blit = int(sample_rate*step)
|
||||
|
||||
subprocess.run(["clear"])
|
||||
subprocess.run(["rm", "crop.wav"])
|
||||
subprocess.run(["clear"], shell=True)
|
||||
subprocess.run(["rm", "crop.wav"], shell=True)
|
||||
|
||||
pfreq = scipy.fft.rfftfreq(2*width, 1/sample_rate)
|
||||
|
||||
|
@ -166,15 +166,15 @@ def void_freq(song_name, offset, songlen, increment, minfreq, maxfreq, upperthr,
|
|||
current_time = offset
|
||||
k = 0
|
||||
|
||||
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"], shell=True)
|
||||
|
||||
sample_rate, raw_global_data = wavfile.read("crop.wav")
|
||||
blit = int(sample_rate*increment)
|
||||
|
||||
global_data = [0 for i in range(len(raw_global_data))]
|
||||
|
||||
subprocess.run(["clear"])
|
||||
subprocess.run(["rm", "crop.wav"])
|
||||
#subprocess.run(["clear"])
|
||||
subprocess.run(["rm", "crop.wav"], shell=True)
|
||||
|
||||
a = 0
|
||||
|
||||
|
@ -284,7 +284,7 @@ def convert_to_wav(song_name:str, output_file="audio.wav") -> str:
|
|||
match extension:
|
||||
case ".mp3" | ".ogg":
|
||||
print("Converting to .wav...")
|
||||
subprocess.run(["ffmpeg", "-y", "-i", song_name, output_file])
|
||||
subprocess.run(["ffmpeg", "-y", "-i", song_name, output_file], shell=True)
|
||||
return output_file
|
||||
return song_name
|
||||
|
||||
|
@ -454,13 +454,13 @@ def fct(song_name, offset, increment, songlen, maxfreq, display):
|
|||
current_time = offset
|
||||
k = 0
|
||||
while(current_time <= songlen):
|
||||
subprocess.run(["ffmpeg", "-ss", str(current_time), "-t", str(increment), "-i", song_name, "crop.wav"])
|
||||
subprocess.run(["ffmpeg", "-ss", str(current_time), "-t", str(increment), "-i", song_name, "crop.wav"], shell=True)
|
||||
|
||||
sample_rate, audio_data = wavfile.read('crop.wav')
|
||||
size = audio_data.size
|
||||
|
||||
#subprocess.run(["clear"])
|
||||
subprocess.run(["rm", "crop.wav"])
|
||||
subprocess.run(["rm", "crop.wav"], shell=True)
|
||||
|
||||
# do stuff here
|
||||
#f, t, Zxx = signal.stft(audio_data, sample_rate, nperseg=1000)
|
||||
|
@ -603,12 +603,12 @@ def extract_peaks_v2(song_data, sample_rate, offset, display, threshold, seglen)
|
|||
return (t, song_data)
|
||||
|
||||
def peaks(song_name, offset, length, display, thr):
|
||||
subprocess.run(["ffmpeg", "-ss", str(offset), "-t", str(length), "-i", song_name, "crop.wav"])
|
||||
subprocess.run(["ffmpeg", "-ss", str(offset), "-t", str(length), "-i", song_name, "crop.wav"], shell=True)
|
||||
|
||||
sample_rate, audio_data = wavfile.read('crop.wav')
|
||||
|
||||
subprocess.run(["clear"])
|
||||
subprocess.run(["rm", "crop.wav"])
|
||||
#subprocess.run(["clear"])
|
||||
subprocess.run(["rm", "crop.wav"], shell=True)
|
||||
|
||||
#return extract_peaks(audio_data, sample_rate, offset, display, thr)
|
||||
return extract_peaks_v2(audio_data, sample_rate, offset, display, thr, 44100*2)
|
||||
|
@ -813,12 +813,12 @@ def filter_n_percent(song_name, offset, length, threshold, reduce, show):
|
|||
# threshold is in ]0, 100]
|
||||
# filter data associated with song_name to keep only the highest threshold% values
|
||||
|
||||
subprocess.run(["ffmpeg", "-ss", str(offset), "-t", str(length), "-i", song_name, "crop.wav"])
|
||||
subprocess.run(["ffmpeg", "-ss", str(offset), "-t", str(length), "-i", song_name, "crop.wav"], shell=True)
|
||||
|
||||
sample_rate, song_data = wavfile.read('crop.wav')
|
||||
|
||||
subprocess.run(["clear"])
|
||||
subprocess.run(["rm", "crop.wav"])
|
||||
subprocess.run(["clear"], shell=True)
|
||||
subprocess.run(["rm", "crop.wav"], shell=True)
|
||||
|
||||
if(reduce):
|
||||
(song_data,e) = to_ms(song_data, 44100, 1)
|
||||
|
|
Loading…
Reference in New Issue