zcr input filewav

This commit is contained in:
Luca Conte 2024-06-11 09:32:21 +02:00
parent f1d7f2ad1f
commit 68de8ffbc6
3 changed files with 34 additions and 8 deletions

View file

@ -40,6 +40,20 @@ def plotting_stuffs():
plt.show()
plt.hist(cent[0], color = 'blue', edgecolor = 'black', bins = int(cent.max()/100))
plt.show()
plt.hist(zcr[0], color = 'green', edgecolor = 'black', bins = 10)
plt.show()
plt.figure(figsize=(150, 17))
t = librosa.frames_to_time(range(zcr.size), hop_length=flength)
ax = plt.subplot(3, 1, 1)
plt.xticks(np.arange(0, 12103, step=1))
plt.plot(t, zcr[0], color="r")
plt.ylim((zcr.min(), zcr.max()))
plt.title("ZCR")
plt.show()
def f(t):
return 1.0025+0.002*np.sin(1.25*3.14*t/30)
@ -56,7 +70,8 @@ strength_max = 0.73
# Assuming that into "generated" directoruy U've already create "project_name" subfolder
audio_input_file = '/home/lalo/data/studio_suono/ardourprojects/space/export/star_r1_sessione_20240310_msub07.wav'
#audio_input_file = '/home/lalo/data/studio_suono/ardourprojects/space/export/star_r1_sessione_20240310_msub07.wav'
audio_input_file = "/home/luca-conte/Musica/ardour_projects/end_titles/export/end_titles_draft_r1_sessione.wav"
#audio_input_file = '/home/lalo/data/studio_grafica/deforum/wilson_r1_mm_sample2.wav'
#audio_input_file = '/home/lalo/data/studio_suono/spx/231104_001_m01.wav'
#audio_input_file = '/home/lalo/data/studio_grafica/deforum/eucrasy_r1_sample.wav'
@ -77,7 +92,7 @@ flength = 22050//fps
wave, sr = librosa.load(audio_input_file)
rms = librosa.feature.rms(y=wave, frame_length=flength, hop_length=flength)
zcr = librosa.feature.zero_crossing_rate(y=wave,frame_length=flength,hop_length=flength)
#rms = librosa.feature.rms(y=wave, frame_length=735, hop_length=735)
cent = librosa.feature.spectral_centroid(y=wave, sr=sr,n_fft=flength, hop_length=flength)
duration = int(math.ceil(librosa.get_duration(y=wave, sr=sr)))
@ -122,6 +137,13 @@ try:
for frame in range(cent.size):
print(str(frame) + ":(" + str(transformXYrandom(1)) + "),", end="")
print("")
print("-----ZERO CROSSING RATE----------")
print("")
for frame in range(zcr.size):
print(str(frame) + ":(" + str(zcr[0][frame]) + "),", end="")
print("RMS SIZE: " + str(len(rms[0])))
print("Rms min/max: " + str(rms.min()) + "/" + str(rms.max()))
print("CEN SIZE: " + str(len(cent[0])))

BIN
dummy.wav Normal file

Binary file not shown.

View file

@ -42,10 +42,10 @@ def main():
pass
def anlyzeSound():
def anlyzeSound(audio_input_file):
# Assuming that into "generated" directoruy U've already create "project_name" subfolder
#audio_input_file = '/home/lalo/data/studio_grafica/deforum/stars_clip_r2.wav'
audio_input_file = '/home/lalo/data/studio_suono/ardourprojects/space/export/star_r1_sessione_20240310_msub07.wav'
#audio_input_file = '/home/lalo/data/studio_suono/ardourprojects/space/export/star_r1_sessione_20240310_msub07.wav'
#audio_input_file = '/home/lalo/data/studio_suono/spx/231104_001_m01.wav'
#audio_input_file = '/home/lalo/data/studio_grafica/deforum/eucrasy_r1_sample.wav'
#audio_input_file = '/home/lalo/data/studio_grafica/deforum/eucrasy_r1.wav'
@ -104,18 +104,22 @@ def width_option(default=1024, **attrs):
@click.option('--width', required=True, type=int, default=1024)
@click.option('--height', required=True, type=int, default=1024)
@click.option('--seed', required=False, type=int, default=None)
@click.option('--out-dir', required=True, type=str, default=tempfile.gettempdir())
@click.option('--framestart', required=False, type=int, default=1)
@click.option('--framestop', required=False, type=int, default=-1)
@click.option('--audiofile', required=True, type=str, default='./dummy.wav')
@click.option('--preset', type=click.Choice(["random"] + sorted(GENERATOR_PRESETS)))
@click.pass_context
def genframes(ctx,width, height,preset, seed, framestart, framestop):
rms, centroids = anlyzeSound()
def genframes(ctx,width, height,preset, seed, framestart, framestop, audiofile, out_dir):
rms, centroids = anlyzeSound(audiofile)
if not seed:
seed = random.randint(1, MAX_SEED_VALUE)
print(f"(total frames: {len(rms[0])}) (framestart: {framestart}) (framestop: {framestop})")
time_dividend =10000
time_dividend =500
s = interp1d([min(rms[0]), max(rms[0])], [0, 0.9])
trms=rms[0]
if framestop<0:
@ -125,7 +129,7 @@ def genframes(ctx,width, height,preset, seed, framestart, framestop):
speed=float(format(trms[frame],'.3f'))
#print(f"(speed: {speed}) (trms: {trms[frame]}) )")
time = (float)((frame % time_dividend)/time_dividend)
filename = "/tmp/"+ preset + "_" + str(seed)+ "_" + str(frame).zfill(10) +".png"
filename = out_dir+ '/' + preset + "_" + str(seed)+ "_" + str(frame).zfill(10) +".png"
print(f"(speed: {speed}) (time: {time}) (filename: {filename})")
generate(1080,1080,time,speed,seed,filename,False,False,False,False,False,False,"",False,False,preset)
#generate(1024,1024,ftime,1,seed,"/tmp/" + str(frame).zfill(10) +".png",False,False,False,False,False,False,"",False,False,preset_name)