Output dynamically normalised songs at the end

This commit is contained in:
RealStickman 2022-11-14 20:15:52 +01:00
parent 3878242b9f
commit c4ff68d176

59
main.py
View File

@ -26,7 +26,7 @@ import time
from random import randint from random import randint
from itertools import repeat from typing import Any, Optional
""" """
@ -121,7 +121,7 @@ def loudness_info(inputfile) -> dict[str, str]:
return loudness return loudness
def convert(inputfile, outputfile, loudness, nonlinear): def convert(inputfile, outputfile, loudness) -> Optional[list[Any]]:
print("Working on ", os.path.basename(inputfile)) print("Working on ", os.path.basename(inputfile))
# coverpath = os.path.join(os.path.dirname(inputfile), "cover.jpg") # coverpath = os.path.join(os.path.dirname(inputfile), "cover.jpg")
# NOTE including covers into ogg/opus containers currently doesn't work # NOTE including covers into ogg/opus containers currently doesn't work
@ -133,7 +133,7 @@ def convert(inputfile, outputfile, loudness, nonlinear):
"-filter:a" "-filter:a"
" " " "
"loudnorm=I=-30.0:" "loudnorm=I=-30.0:"
"LRA=5.0:" "LRA=9.0:"
"measured_I={input_i}:" "measured_I={input_i}:"
"measured_LRA={input_lra}:" "measured_LRA={input_lra}:"
"measured_tp={input_tp}:measured_thresh={input_thresh}:" "measured_tp={input_tp}:measured_thresh={input_thresh}:"
@ -170,10 +170,11 @@ def convert(inputfile, outputfile, loudness, nonlinear):
# decode json to dict # decode json to dict
loudness_new: dict[str, str] = json.loads(loudness_json) loudness_new: dict[str, str] = json.loads(loudness_json)
if loudness_new["normalization_type"] != "linear": if loudness_new["normalization_type"] != "linear":
nonlinear.append([inputfile, loudness_new]) nonlinear: list[Any] = [inputfile, loudness_new]
return nonlinear
def main(inputfile: str, nonlinear: list): def main(inputfile: str) -> Optional[list[Any]]:
""" """
Main program loop Main program loop
@ -205,15 +206,13 @@ def main(inputfile: str, nonlinear: list):
# remove_picture(inputfile=inputfile) # remove_picture(inputfile=inputfile)
loudness = loudness_info(inputfile=inputfile) loudness = loudness_info(inputfile=inputfile)
convert( nonlinear: Optional[list[Any]] = convert(
inputfile=inputfile, inputfile=inputfile,
outputfile=outputfile, outputfile=outputfile,
loudness=loudness, loudness=loudness,
nonlinear=nonlinear,
) )
# FIXME the dictionary works here return nonlinear
print(nonlinear)
if __name__ == "__main__": if __name__ == "__main__":
@ -258,7 +257,7 @@ if __name__ == "__main__":
timefile = os.path.join(srcfolder, "run.time") timefile = os.path.join(srcfolder, "run.time")
# list of non-linear normalizations # list of non-linear normalizations
nonlinear: list[str] = [] nonlinear_all: Optional[list[Any]] = []
# get time of previous run # get time of previous run
if reset: if reset:
@ -271,7 +270,7 @@ if __name__ == "__main__":
# print(timeprev) # print(timeprev)
musicfiles = [] musicfiles: list[str] = []
for root, dirs, files in os.walk(srcfolder): for root, dirs, files in os.walk(srcfolder):
# ignore the "normalized" subfolder # ignore the "normalized" subfolder
dirs[:] = [d for d in dirs if d not in ["normalized"]] dirs[:] = [d for d in dirs if d not in ["normalized"]]
@ -285,44 +284,14 @@ if __name__ == "__main__":
# print(musicfiles) # print(musicfiles)
with Pool(cpu) as p: with Pool(cpu) as p:
p.starmap(main, zip(musicfiles, repeat(nonlinear))) nonlinear_all: Optional[list[Any]] = p.map(main, musicfiles)
# write this run's time into file # write this run's time into file
with open(timefile, "w") as file: with open(timefile, "w") as file:
file.write(str(starttime)) file.write(str(starttime))
# FIXME empty dictionary here
print("Dynamically normalized music:") print("Dynamically normalized music:")
print(nonlinear) for i in nonlinear_all:
# NOTE ignore empty and "None" values
""" if i:
from multiprocessing.pool import ThreadPool
def test(i):
return([i,{"2":i*2,"3":i*3}])
list = [1,2,3,4,5]
with ThreadPool(8) as t:
out = t.starmap(test,zip(list))
for i in out:
print(i) print(i)
from multiprocessing import Pool
def test(i):
return([i,{"2":i*2,"3":i*3}])
if __name__ == "__main__":
list = [1,2,3,4,5]
with Pool(7) as p:
out = p.starmap(test,zip(list))
for i in out:
print(i)
"""