diff --git a/ivas_processing_scripts/audiotools/__init__.py b/ivas_processing_scripts/audiotools/__init__.py index b4d7aa1955d49343c87daa498ad28c3c13f11d17..f392771dc5b43206c0aac7d4fb08e0d90ce42e9c 100755 --- a/ivas_processing_scripts/audiotools/__init__.py +++ b/ivas_processing_scripts/audiotools/__init__.py @@ -34,7 +34,7 @@ import argparse from itertools import repeat from pathlib import Path -from ivas_processing_scripts.audiotools.constants import AUDIO_FORMATS +from ivas_processing_scripts.audiotools.constants import AUDIO_FORMATS, BINAURAL_LFE_GAIN from ivas_processing_scripts.audiotools.convert import convert_file from ivas_processing_scripts.utils import apply_func_parallel @@ -82,7 +82,7 @@ def add_processing_args(group, input=True): f"-{ps}mk", f"--{p}_mask", type=str, - help="Apply filtering with mask ((HP50, 20KBP or None; default = %(default)s)", + help="Apply filtering with mask (HP50, 20KBP or None; default = %(default)s)", default=None, ) group.add_argument( @@ -182,7 +182,7 @@ def get_args(): "--bin_lfe_gain", type=float, help="Render LFE to binaural output with the specified gain (only valid for channel-based input, default = %(default)s)", - default=None, + default=BINAURAL_LFE_GAIN, ) output_parser.add_argument( "-mnru", diff --git a/other/lp16k.py b/other/lp16k.py new file mode 100755 index 0000000000000000000000000000000000000000..975356aa07538a9ba5aacba837ecc55f3d101cb7 --- /dev/null +++ b/other/lp16k.py @@ -0,0 +1,76 @@ +#!/usr/bin/python3 +import argparse +import multiprocessing as mp +import sys +from pathlib import Path +from time import sleep + +sys.path.append(str(Path(__file__).parent.parent)) +from ivas_processing_scripts.audiotools.audio import fromfile +from ivas_processing_scripts.audiotools.audiofile import write +from ivas_processing_scripts.audiotools.wrappers.filter import resample_itu +from ivas_processing_scripts.utils import progressbar_update, spinner + + +def lp16k(in_file, out_file): + x = fromfile("STEREO", in_file) + if x.fs != 48000: + raise ValueError( + f"Unsupported sampling rate {x.fs//1000} kHz for input file {in_file} - only 48 kHz is supported!" + ) + + # resample ITU only returns the audio array + # but uses the sampling rate stored in the audio object + # so we need to correctly set it after each call + x.audio = resample_itu(x, 96000) + x.fs = 96000 + + x.audio = resample_itu(x, 32000) + x.fs = 32000 + + x.audio = resample_itu(x, 96000) + x.fs = 96000 + + x.audio = resample_itu(x, 48000) + x.fs = 48000 + + write(out_file, x.audio, x.fs) + + +def main(args): + # list input files and create function arguments + in_files = list(args.in_dir.glob("*.wav")) + func_args = [(f, args.out_dir.joinpath(f.name)) for f in in_files] + + if not args.out_dir.exists(): + args.out_dir.mkdir() + + # progressbar and multiprocessing setup + count = len(func_args) + width = 80 + + p = mp.Pool() + results = p.starmap_async(lp16k, func_args) + + # apply function in parallel + progressbar_update(0, count, width) + while not results.ready(): + progressbar_update(count - int(results._number_left), count, width) + spinner() + sleep(0.1) + progressbar_update(count, count, width) + print("\n", flush=True, file=sys.stdout) + results.get() + + p.close() + p.join() + + +if __name__ == "__main__": + parser = argparse.ArgumentParser(description="Script to lowpass audio to 16 kHz") + parser.add_argument("in_dir", help="Input directory", type=Path) + parser.add_argument("out_dir", help="Output directory", type=Path) + + args = parser.parse_args() + + main(args)