Compare commits
4 Commits
98fe75209c
...
4156bc8c26
Author | SHA1 | Date |
---|---|---|
|
4156bc8c26 | |
|
d88a84db71 | |
|
e53df74d68 | |
|
cd68bb0058 |
10
main.py
10
main.py
|
@ -3,22 +3,22 @@ import slider as sl
|
|||
from datetime import timedelta
|
||||
import place
|
||||
import sound_process
|
||||
|
||||
def alexandre_process(bpm, offset, filename):
|
||||
pass
|
||||
import numpy as np
|
||||
|
||||
def main():
|
||||
filename = fd.askopenfilename()
|
||||
beatmap = sl.Beatmap.from_path(filename)
|
||||
timing = beatmap.timing_points[0]
|
||||
bpm = timing.bpm
|
||||
offset = timing.offset.total_seconds() * 10e3
|
||||
offset = timing.offset.total_seconds() * 1000
|
||||
print(beatmap.audio_filename)
|
||||
|
||||
timings, amplitudes, freqs = sound_process.process_song(beatmap.audio_filename, int(bpm), offset0=offset, n_iter_2=48)
|
||||
data = sound_process.process_song(beatmap.audio_filename, int(bpm), offset0=offset)
|
||||
# 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]
|
||||
|
||||
beatmap._hit_objects = place.greedy(bpm, offset, timings, amplitudes)
|
||||
beatmap.display_name = "TIPE's Extra"
|
||||
#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.write_path("rewrite.osu")
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@ import os
|
|||
import random
|
||||
from pathlib import Path
|
||||
from time import sleep
|
||||
from datetime import timedelta
|
||||
|
||||
print("Starting...\n")
|
||||
|
||||
|
@ -283,8 +284,20 @@ def get_freq(song_name, offset, step, songlen, data, display=False):
|
|||
|
||||
return frequencies
|
||||
|
||||
def is_data_stereo(raw_global_data:list) -> bool:
|
||||
"""
|
||||
raw_global_data : list
|
||||
"""
|
||||
try:
|
||||
assert(raw_global_data[0][0])
|
||||
except IndexError:
|
||||
return False
|
||||
except AssertionError:
|
||||
return True
|
||||
return True
|
||||
|
||||
def void_freq(song_name, offset, songlen, increment, minfreq, maxfreq, upperthr, ampthr, ampfreq, ampval, leniency, write, linear, is_stereo, output_file="trimmed.wav"):
|
||||
|
||||
def void_freq(song_name, offset, songlen, increment, minfreq, maxfreq, upperthr, ampthr, ampfreq, ampval, leniency, write, linear, output_file="trimmed.wav"):
|
||||
"""
|
||||
song_name : string
|
||||
offset : int
|
||||
|
@ -315,7 +328,7 @@ def void_freq(song_name, offset, songlen, increment, minfreq, maxfreq, upperthr,
|
|||
subprocess.run(["clear"])
|
||||
subprocess.run(["rm", "crop.wav"])
|
||||
|
||||
if(is_stereo):
|
||||
if(is_data_stereo(raw_global_data)):
|
||||
print("Converting to mono...")
|
||||
for x in range(len(raw_global_data)):
|
||||
global_data[x] = raw_global_data[x][0]/2 + raw_global_data[x][1]/2
|
||||
|
@ -412,9 +425,9 @@ def test_sample(timelist):
|
|||
|
||||
def convert_tuple(datares, freq):
|
||||
"""
|
||||
Takes datares and converts it to a list of tuples (amplitude, time in ms)
|
||||
Takes datares and converts it to a list of tuples (amplitude, datetimes)
|
||||
"""
|
||||
return [(i, datares[i], freq[i]) for i in range(len(datares)) if datares[i] > 0]
|
||||
return [(timedelta(milliseconds=i), datares[i], freq[i]) for i in range(len(datares)) if datares[i] > 0]
|
||||
|
||||
def get_songlen(filename):
|
||||
"""
|
||||
|
@ -425,6 +438,20 @@ def get_songlen(filename):
|
|||
|
||||
return (len(global_data)/sample_rate)
|
||||
|
||||
def convert_to_wav(song_name:str, output_file="audio.wav") -> str:
|
||||
"""
|
||||
Converts the song to .wav, only if it's not already in wave format.
|
||||
Currently relies on file extension.
|
||||
Returns: the song_name that should be used afterwards.
|
||||
"""
|
||||
extension = Path(song_name).suffix
|
||||
match extension:
|
||||
case ".mp3" | ".ogg":
|
||||
print("Converting to .wav...")
|
||||
subprocess.run(["ffmpeg", "-y", "-i", song_name, output_file])
|
||||
return output_file
|
||||
return song_name
|
||||
|
||||
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)
|
||||
|
@ -436,6 +463,8 @@ def process_song(filename, bpm, offset0=0, div_len_factor=1, n_iter_2=-1, thresh
|
|||
divisor : int [+] (beat divisor used to snap the notes, default is 4)
|
||||
"""
|
||||
|
||||
filename = convert_to_wav(filename)
|
||||
|
||||
offset = offset0/1000
|
||||
|
||||
div_len = div_len_factor*60/bpm-0.01
|
||||
|
@ -448,7 +477,7 @@ def process_song(filename, bpm, offset0=0, div_len_factor=1, n_iter_2=-1, thresh
|
|||
|
||||
filtered_name = f"{filename}_trimmed.wav"
|
||||
|
||||
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, 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)
|
||||
|
@ -456,7 +485,6 @@ def process_song(filename, bpm, offset0=0, div_len_factor=1, n_iter_2=-1, thresh
|
|||
Path(f"{filename}_trimmed.wav").unlink()
|
||||
return convert_tuple(datares, frequencies)
|
||||
|
||||
|
||||
def main():
|
||||
data = process_song("tetris_4.wav", 160, n_iter_2 = 64)
|
||||
#print(data)
|
||||
|
|
Loading…
Reference in New Issue