From cb832412f16bd4999cf2b6b76ef69ecf89573bae Mon Sep 17 00:00:00 2001 From: Jan Kiene Date: Mon, 4 Nov 2024 12:34:45 +0100 Subject: [PATCH] add ctest measurement output for ssnr script --- scripts/ssnr.py | 60 ++++++++++++++++++++++++++++--------------------- 1 file changed, 34 insertions(+), 26 deletions(-) diff --git a/scripts/ssnr.py b/scripts/ssnr.py index 89ac4c6bf9..3bcd309c1e 100644 --- a/scripts/ssnr.py +++ b/scripts/ssnr.py @@ -4,31 +4,6 @@ import pathlib from pyaudio3dtools import audiofile, audioarray -def main(args): - ref_sig, fs_ref = audiofile.readfile(args.ref_file) - test_sig, fs_test = audiofile.readfile(args.test_file) - - if fs_ref != fs_test: - print("Files need to have same sampling rate!") - return -1 - - len_seg = int(20 * fs_ref / 1000) - print(len_seg, ref_sig.shape, test_sig.shape) - ssnr = audioarray.ssnr( - ref_sig, - test_sig, - len_seg, - args.thresh_low, - args.thresh_high, - args.apply_thresholds_on_ref_only, - ) - - for i, s in enumerate(ssnr, start=1): - print(f"Channel {i}: {s}") - - return 0 - - if __name__ == "__main__": parser = argparse.ArgumentParser() parser.add_argument("ref_file", type=pathlib.Path, help="Reference signal wav file") @@ -56,7 +31,40 @@ if __name__ == "__main__": help="Use this to apply the thresholding on signal power to the reference signal only.\n" "This makes the implementation behaviour conform to the MPEG-D conformance spec.", ) + parser.add_argument( + "--print-ctest-measurement", + action="store_true", + default=False, + help="Print easy to parse single SSNR value", + ) args = parser.parse_args() - sys.exit(main(args)) + ref_sig, fs_ref = audiofile.readfile(args.ref_file) + test_sig, fs_test = audiofile.readfile(args.test_file) + + if fs_ref != fs_test: + print("Files need to have same sampling rate!") + sys.exit(1) + + len_seg = int(20 * fs_ref / 1000) + print(len_seg, ref_sig.shape, test_sig.shape) + ssnr = audioarray.ssnr( + ref_sig, + test_sig, + len_seg, + args.thresh_low, + args.thresh_high, + args.apply_thresholds_on_ref_only, + ) + + for i, s in enumerate(ssnr, start=1): + print(f"Channel {i}: {s}") + + if args.print_ctest_measurement: + min_ssnr = ssnr.min() + print( + f'{min_ssnr}' + ) + + sys.exit(0) -- GitLab