From b96fd8bee274011ebc782231e308a6a340a8c581 Mon Sep 17 00:00:00 2001 From: Archit Tamarapu Date: Wed, 7 Aug 2024 11:31:48 +0200 Subject: [PATCH 01/12] [fix] more robust search and error for MLD binary --- scripts/pyaudio3dtools/audioarray.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/scripts/pyaudio3dtools/audioarray.py b/scripts/pyaudio3dtools/audioarray.py index be950aaf60..aef7f85451 100644 --- a/scripts/pyaudio3dtools/audioarray.py +++ b/scripts/pyaudio3dtools/audioarray.py @@ -35,6 +35,7 @@ import warnings import math import multiprocessing as mp import platform +import shutil import subprocess import tempfile from pathlib import Path @@ -362,6 +363,12 @@ def compare( mld = toolsdir.joinpath(platform.system()).joinpath("mld") else: assert False, f"MLD tool not available for {platform.system()}" + if not mld.exists(): + mld = shutil.which("mld") + search_path = toolsdir.joinpath(platform.system().replace("Windows", "Win32")) + if mld is None: + assert False, f"MLD tool not found in {search_path} or PATH!" + warnings.warn(f"MLD binary not found in {search_path}! Falling back to {mld}!") with tempfile.TemporaryDirectory() as tmpdir: for i in range(nchannels): -- GitLab From ae4e7ba682ff1fc2339fabace281a4d025f6a956 Mon Sep 17 00:00:00 2001 From: Archit Tamarapu Date: Wed, 7 Aug 2024 11:36:04 +0200 Subject: [PATCH 02/12] [fix] handle case in cut_pcm.py when the cut length is longer than the file --- tests/cut_pcm.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/cut_pcm.py b/tests/cut_pcm.py index 2abc86b624..24697102d2 100755 --- a/tests/cut_pcm.py +++ b/tests/cut_pcm.py @@ -96,6 +96,8 @@ def cut_samples( num_in_samples = s.shape[0] num_samples_to_skip = int(start_sec * fs) dur_samples = int(dur_sec * fs) + if dur_samples > s.shape[0]: + dur_samples = s.shape[0] if num_samples_to_skip > dur_samples: raise ValueError( f"Requested to skip {num_samples_to_skip}, but file only has {dur_samples} samples" -- GitLab From 4f28e53f9f9deb933208a90b2c1fe664e2be7017 Mon Sep 17 00:00:00 2001 From: Archit Tamarapu Date: Wed, 7 Aug 2024 11:38:31 +0200 Subject: [PATCH 03/12] add LTV support for renderer and HRTF binary loading tests --- tests/conftest.py | 6 +++ tests/create_short_testvectors.py | 36 ++++++++++--- tests/hrtf_binary_loading/constants.py | 17 ++++++- .../test_codec_ROM_vs_file.py | 50 +++++++++++++++---- tests/hrtf_binary_loading/utils.py | 7 ++- tests/renderer/constants.py | 44 ++++++++++++++++ tests/renderer/utils.py | 3 ++ 7 files changed, 143 insertions(+), 20 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index b75b3ba997..fa9e82de32 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -198,6 +198,12 @@ def pytest_addoption(parser): default=False, ) + parser.addoption( + "--use_ltv", + action="store_true", + default=False, + ) + parser.addoption( "--dut_fr", help="Render frame size for the DUT output.", diff --git a/tests/create_short_testvectors.py b/tests/create_short_testvectors.py index b90771cca1..e242c4bacf 100755 --- a/tests/create_short_testvectors.py +++ b/tests/create_short_testvectors.py @@ -42,6 +42,7 @@ from cut_pcm import cut_samples HERE = Path(__file__).parent.resolve() TEST_VECTOR_DIR = HERE.joinpath("../scripts/testv").resolve() +LTV_DIR = HERE.joinpath("../../ivas-pc-testfiles").resolve() SCRIPTS_DIR = HERE.joinpath("../scripts").resolve() sys.path.append(SCRIPTS_DIR) @@ -59,25 +60,46 @@ FILE_IDS = [ "ISM", "MASA", ] +FILE_IDS_LTV = [ + "ltv48_STEREO", + "ltv48_MC51", + "ltv48_MC71", + "ltv48_MC512", + "ltv48_MC514", + "ltv48_MC714", + "ltv48_ISM", + "ltv48_MASA", +] -def collect_files(): +def collect_files(use_ltv: bool = False): + if use_ltv: + IDS = FILE_IDS_LTV + else: + IDS = FILE_IDS files = [ f.absolute() for f in TEST_VECTOR_DIR.iterdir() if f.suffix == ".wav" - and any([id in f.name for id in FILE_IDS]) + and any([id in f.name for id in IDS]) and "_cut" not in f.name ] return files -def create_short_testvectors(cut_len=5.0): - files = collect_files() +def create_short_testvectors(cut_len=5.0, use_ltv: bool = False): + files = collect_files(use_ltv) for f in files: suffix = "_cut" - out_file = f.parent.joinpath(f.stem + suffix + f.suffix) + if use_ltv: + out_file = ( + HERE.joinpath("../scripts/testv") + .resolve() + .joinpath(f.stem + suffix + f.suffix) + ) + else: + out_file = f.parent.joinpath(f.stem + suffix + f.suffix) num_channels = audiofile.get_wav_file_info(f)["channels"] cut_samples(f, out_file, num_channels, CUT_FROM, f"{cut_len}", GAIN) @@ -92,6 +114,6 @@ if __name__ == "__main__": return x parser.add_argument("--cut_len", type=positive_float, default=5.0) + parser.add_argument("--use_ltv", action="store_true", default=False) args = parser.parse_args() - cut_len = args.cut_len - sys.exit(create_short_testvectors(cut_len=cut_len)) + sys.exit(create_short_testvectors(cut_len=args.cut_len, use_ltv=args.use_ltv)) diff --git a/tests/hrtf_binary_loading/constants.py b/tests/hrtf_binary_loading/constants.py index d5f013fd59..98526d0771 100644 --- a/tests/hrtf_binary_loading/constants.py +++ b/tests/hrtf_binary_loading/constants.py @@ -33,7 +33,7 @@ import re from pathlib import Path -from tests.renderer.constants import OUTPUT_FORMATS_BINAURAL, SCRIPTS_DIR, TESTV_DIR +from tests.renderer.constants import OUTPUT_FORMATS_BINAURAL, SCRIPTS_DIR, TESTV_DIR, LTV_DIR TESTS_DIR = Path(__file__).parent @@ -93,6 +93,21 @@ FORMAT_TO_FILE_SBA_WOEXT = { FORMAT_TO_FILE_ISM_WOEXT = "stv{}ISM{}s_cut" FORMAT_TO_FILE_MASA_WOEXT = "stv{}MASA{}TC{}c_cut" +FORMAT_TO_FILE_MC_LTV_WOEXT = { + "5_1": "ltv{}_MC51", + "7_1": "ltv{}_MC71", + "5_1_2": "ltv{}_MC512", + "5_1_4": "ltv{}_MC514", + "7_1_4": "ltv{}_MC714", +} +FORMAT_TO_FILE_SBA_LTV_WOEXT = { + "1": "ltv{}_FOA", + "2": "ltv{}_HOA2", + "3": "ltv{}_HOA3", +} +FORMAT_TO_FILE_ISM_LTV_WOEXT = "ltv{}_{}ISM" +FORMAT_TO_FILE_MASA_LTV_WOEXT = "ltv{}_MASA{}TC" + BITRATE_ISM = { "1": 96000, "2": 160000, diff --git a/tests/hrtf_binary_loading/test_codec_ROM_vs_file.py b/tests/hrtf_binary_loading/test_codec_ROM_vs_file.py index ade6c01d88..23da97177e 100644 --- a/tests/hrtf_binary_loading/test_codec_ROM_vs_file.py +++ b/tests/hrtf_binary_loading/test_codec_ROM_vs_file.py @@ -67,7 +67,10 @@ def test_multichannel_binaural_static( ): in_fs = 48 option_list = ["-mc", in_fmt] - in_file = FORMAT_TO_FILE_MC_WOEXT[in_fmt].format(in_fs) + if test_info.config.option.use_ltv: + in_file = FORMAT_TO_FILE_MC_LTV_WOEXT[in_fmt].format(in_fs) + else: + in_file = FORMAT_TO_FILE_MC_WOEXT[in_fmt].format(in_fs) compare_rom_vs_binary( test_info, @@ -99,7 +102,10 @@ def test_multichannel_binaural_headrotation( ): in_fs = 48 option_list = ["-mc", in_fmt] - in_file = FORMAT_TO_FILE_MC_WOEXT[in_fmt].format(in_fs) + if test_info.config.option.use_ltv: + in_file = FORMAT_TO_FILE_MC_LTV_WOEXT[in_fmt].format(in_fs) + else: + in_file = FORMAT_TO_FILE_MC_WOEXT[in_fmt].format(in_fs) compare_rom_vs_binary( test_info, @@ -124,7 +130,10 @@ def test_multichannel_binaural_headrotation( @pytest.mark.parametrize("hrtf_tag", HRTF_TAGS) def test_sba_binaural_static(test_info, bitrate, in_fmt, fs, out_fmt, hrtf_tag): option_list = ["-sba", in_fmt] - in_file = FORMAT_TO_FILE_SBA_WOEXT[in_fmt].format(fs) + if test_info.config.option.use_ltv: + in_file = FORMAT_TO_FILE_SBA_LTV_WOEXT[in_fmt].format(fs) + else: + in_file = FORMAT_TO_FILE_SBA_WOEXT[in_fmt].format(fs) compare_rom_vs_binary( test_info, @@ -148,7 +157,10 @@ def test_sba_binaural_headrotation( test_info, bitrate, in_fmt, fs, out_fmt, trj_file, hrtf_tag ): option_list = ["-sba", in_fmt] - in_file = FORMAT_TO_FILE_SBA_WOEXT[in_fmt].format(fs) + if test_info.config.option.use_ltv: + in_file = FORMAT_TO_FILE_SBA_LTV_WOEXT[in_fmt].format(fs) + else: + in_file = FORMAT_TO_FILE_SBA_WOEXT[in_fmt].format(fs) compare_rom_vs_binary( test_info, @@ -177,7 +189,10 @@ def test_masa_binaural_static(test_info, in_tc, in_dir, fs, out_fmt, hrtf_tag): TESTV_DIR.joinpath(FORMAT_TO_METADATA_FILES["MASA"].format(in_dir, in_tc, fs)) ) option_list = ["-masa", in_tc, metadata_file] - in_file = FORMAT_TO_FILE_MASA_WOEXT.format(in_dir, in_tc, fs) + if test_info.config.option.use_ltv: + in_file = FORMAT_TO_FILE_MASA_LTV_WOEXT.format(fs, in_tc) + else: + in_file = FORMAT_TO_FILE_MASA_WOEXT.format(in_dir, in_tc, fs) compare_rom_vs_binary( test_info, @@ -205,7 +220,10 @@ def test_masa_binaural_headrotation( TESTV_DIR.joinpath(FORMAT_TO_METADATA_FILES["MASA"].format(in_dir, in_tc, fs)) ) option_list = ["-masa", in_tc, metadata_file] - in_file = FORMAT_TO_FILE_MASA_WOEXT.format(in_dir, in_tc, fs) + if test_info.config.option.use_ltv: + in_file = FORMAT_TO_FILE_MASA_LTV_WOEXT.format(fs, in_tc) + else: + in_file = FORMAT_TO_FILE_MASA_WOEXT.format(in_dir, in_tc, fs) compare_rom_vs_binary( test_info, @@ -239,7 +257,10 @@ def test_ism_binaural_static(test_info, in_fmt, out_fs, out_fmt, hrtf_tag): ) metadata_file_list.append(test) option_list.extend(metadata_file_list) - in_file = FORMAT_TO_FILE_ISM_WOEXT.format(in_fmt, in_fs) + if test_info.config.option.use_ltv: + in_file = FORMAT_TO_FILE_ISM_LTV_WOEXT.format(in_fs, in_fmt) + else: + in_file = FORMAT_TO_FILE_ISM_WOEXT.format(in_fmt, in_fs) compare_rom_vs_binary( test_info, @@ -272,7 +293,10 @@ def test_ism_binaural_headrotation( ) metadata_file_list.append(test) option_list.extend(metadata_file_list) - in_file = FORMAT_TO_FILE_ISM_WOEXT.format(in_fmt, in_fs) + if test_info.config.option.use_ltv: + in_file = FORMAT_TO_FILE_ISM_LTV_WOEXT.format(in_fs, in_fmt) + else: + in_file = FORMAT_TO_FILE_ISM_WOEXT.format(in_fmt, in_fs) compare_rom_vs_binary( test_info, @@ -306,7 +330,10 @@ def test_ism_binaural_roomreverb_static(test_info, in_fmt, out_fs, out_fmt, hrtf ) metadata_file_list.append(test) option_list.extend(metadata_file_list) - in_file = FORMAT_TO_FILE_ISM_WOEXT.format(in_fmt, in_fs) + if test_info.config.option.use_ltv: + in_file = FORMAT_TO_FILE_ISM_LTV_WOEXT.format(in_fs, in_fmt) + else: + in_file = FORMAT_TO_FILE_ISM_WOEXT.format(in_fmt, in_fs) compare_rom_vs_binary( test_info, @@ -339,7 +366,10 @@ def test_ism_binaural_roomreverb_headrotation( ) metadata_file_list.append(test) option_list.extend(metadata_file_list) - in_file = FORMAT_TO_FILE_ISM_WOEXT.format(in_fmt, in_fs) + if test_info.config.option.use_ltv: + in_file = FORMAT_TO_FILE_ISM_LTV_WOEXT.format(in_fs, in_fmt) + else: + in_file = FORMAT_TO_FILE_ISM_WOEXT.format(in_fmt, in_fs) compare_rom_vs_binary( test_info, diff --git a/tests/hrtf_binary_loading/utils.py b/tests/hrtf_binary_loading/utils.py index 2ba8b39e6b..47d5c963b7 100644 --- a/tests/hrtf_binary_loading/utils.py +++ b/tests/hrtf_binary_loading/utils.py @@ -285,7 +285,7 @@ def compare_rom_vs_binary( out_fmt, out_fs, hrtf_tag: str, - keep_file: Optional[str] = "no", + keep_file: Optional[str] = "if failed", trj_file: Optional[str] = None, ): option_str = "_".join(get_option_list_str(option_list_enc)) @@ -295,7 +295,10 @@ def compare_rom_vs_binary( xfail = (hrtf_file == HRTF_BINARY_FILE_DIFF_FROM_ROM) - input_path = TESTV_DIR.joinpath(in_file).with_suffix(".wav") + if test_info.config.option.use_ltv: + input_path = LTV_DIR.joinpath(in_file).with_suffix(".wav") + else: + input_path = TESTV_DIR.joinpath(in_file).with_suffix(".wav") bitstream_path = BITSTREAM_DIR.joinpath(in_file + file_ext) run_encoder( bitrate, in_fs, input_path, bitstream_path, add_option_list=option_list_enc diff --git a/tests/renderer/constants.py b/tests/renderer/constants.py index 0e7b13c8ac..4ace993b75 100644 --- a/tests/renderer/constants.py +++ b/tests/renderer/constants.py @@ -44,6 +44,7 @@ OUTPUT_PATH_CUT = TESTS_DIR.joinpath("cut") CUSTOM_LAYOUT_DIR = SCRIPTS_DIR.joinpath("ls_layouts") HR_TRAJECTORY_DIR = SCRIPTS_DIR.joinpath("trajectories") TESTV_DIR = SCRIPTS_DIR.joinpath("testv") +LTV_DIR = TESTS_DIR.parents[2].joinpath("ivas-pc-testfiles") BIN_SUFFIX_MERGETARGET = "_ref" @@ -183,6 +184,49 @@ FORMAT_TO_FILE_COMPARETEST = { "t_design_4": TESTV_DIR.joinpath("stv714MC48c.wav"), } +FORMAT_TO_FILE_LTV = { + "MONO": LTV_DIR.joinpath("ltv48_MONO.wav"), + "STEREO": LTV_DIR.joinpath("ltv48_STEREO.wav"), + "5_1": LTV_DIR.joinpath("ltv48_MC51.wav"), + "7_1": LTV_DIR.joinpath("ltv48_MC71.wav"), + "5_1_2": LTV_DIR.joinpath("ltv48_MC512.wav"), + "5_1_4": LTV_DIR.joinpath("ltv48_MC514.wav"), + "7_1_4": LTV_DIR.joinpath("ltv48_MC714.wav"), + "FOA": LTV_DIR.joinpath("ltv48_FOA.wav"), + "HOA2": LTV_DIR.joinpath("ltv48_HOA2.wav"), + "HOA3": LTV_DIR.joinpath("ltv48_HOA3.wav"), + "ISM1": LTV_DIR.joinpath("ltv48_1ISM.wav"), + "ISM2": LTV_DIR.joinpath("ltv48_2ISM.wav"), + "ISM3": LTV_DIR.joinpath("ltv48_3ISM.wav"), + "ISM4": LTV_DIR.joinpath("ltv48_4ISM.wav"), + "MASA1": LTV_DIR.joinpath("ltv48_MASA1TC.wav"), + "MASA2": LTV_DIR.joinpath("ltv48_MASA2TC.wav"), + "OMASA_1_1": LTV_DIR.joinpath("ltv48_OMASA_1ISM_1TC.wav"), + "OMASA_1_2": LTV_DIR.joinpath("ltv48_OMASA_2ISM_1TC.wav"), + "OMASA_1_3": LTV_DIR.joinpath("ltv48_OMASA_3ISM_1TC.wav"), + "OMASA_1_4": LTV_DIR.joinpath("ltv48_OMASA_4ISM_1TC.wav"), + "OMASA_2_1": LTV_DIR.joinpath("ltv48_OMASA_1ISM_2TC.wav"), + "OMASA_2_2": LTV_DIR.joinpath("ltv48_OMASA_2ISM_2TC.wav"), + "OMASA_2_3": LTV_DIR.joinpath("ltv48_OMASA_3ISM_2TC.wav"), + "OMASA_2_4": LTV_DIR.joinpath("ltv48_OMASA_4ISM_2TC.wav"), + "OSBA_1_1": LTV_DIR.joinpath("ltv48_OSBA_1ISM_FOA.wav"), + "OSBA_1_2": LTV_DIR.joinpath("ltv48_OSBA_1ISM_HOA2.wav"), + "OSBA_1_3": LTV_DIR.joinpath("ltv48_OSBA_1ISM_HOA3.wav"), + "OSBA_2_1": LTV_DIR.joinpath("ltv48_OSBA_2ISM_FOA.wav"), + "OSBA_2_2": LTV_DIR.joinpath("ltv48_OSBA_2ISM_HOA2.wav"), + "OSBA_2_3": LTV_DIR.joinpath("ltv48_OSBA_2ISM_HOA3.wav"), + "OSBA_3_1": LTV_DIR.joinpath("ltv48_OSBA_3ISM_FOA.wav"), + "OSBA_3_2": LTV_DIR.joinpath("ltv48_OSBA_3ISM_HOA2.wav"), + "OSBA_3_3": LTV_DIR.joinpath("ltv48_OSBA_3ISM_HOA3.wav"), + "OSBA_4_1": LTV_DIR.joinpath("ltv48_OSBA_4ISM_FOA.wav"), + "OSBA_4_2": LTV_DIR.joinpath("ltv48_OSBA_4ISM_HOA2.wav"), + "OSBA_4_3": LTV_DIR.joinpath("ltv48_OSBA_4ISM_HOA3.wav"), + "META": TEST_VECTOR_DIR.joinpath("mixed_scene.txt"), + "16ch_8+4+4": LTV_DIR.joinpath("ltv48_HOA3.wav"), + "4d4": LTV_DIR.joinpath("ltv48_MC714.wav"), + "t_design_4": LTV_DIR.joinpath("ltv48_MC714.wav"), +} + FORMAT_TO_METADATA_FILES = { "ISM1": [str(TESTV_DIR.joinpath("stvISM1.csv"))], "ISM2": [ diff --git a/tests/renderer/utils.py b/tests/renderer/utils.py index d94f75bf8f..7da6295084 100644 --- a/tests/renderer/utils.py +++ b/tests/renderer/utils.py @@ -47,6 +47,7 @@ from .constants import ( OUTPUT_PATH_REF, OUTPUT_PATH_CUT, FORMAT_TO_FILE_COMPARETEST, + FORMAT_TO_FILE_LTV, FORMAT_TO_FILE_SMOKETEST, RENDERER_CMD, BIN_SUFFIX_MERGETARGET, @@ -226,6 +227,8 @@ def run_renderer( # if in REF or CUT creation mode use the comparetestv if test_info.config.option.create_ref or test_info.config.option.create_cut: FORMAT_TO_FILE = FORMAT_TO_FILE_COMPARETEST + elif test_info.config.option.use_ltv: + FORMAT_TO_FILE = FORMAT_TO_FILE_LTV else: FORMAT_TO_FILE = FORMAT_TO_FILE_SMOKETEST -- GitLab From 6cdfba938f8ec0e124709eff4dfdfa955587e016 Mon Sep 17 00:00:00 2001 From: Archit Tamarapu Date: Wed, 7 Aug 2024 14:26:17 +0000 Subject: [PATCH 04/12] change variable in cut_pcm.py --- tests/cut_pcm.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/cut_pcm.py b/tests/cut_pcm.py index 24697102d2..90a9b4e1d0 100755 --- a/tests/cut_pcm.py +++ b/tests/cut_pcm.py @@ -96,8 +96,8 @@ def cut_samples( num_in_samples = s.shape[0] num_samples_to_skip = int(start_sec * fs) dur_samples = int(dur_sec * fs) - if dur_samples > s.shape[0]: - dur_samples = s.shape[0] + if dur_samples > num_in_samples: + dur_samples = num_in_samples if num_samples_to_skip > dur_samples: raise ValueError( f"Requested to skip {num_samples_to_skip}, but file only has {dur_samples} samples" -- GitLab From 8c8231e0508b43cddcdfb1ab5cc0f4b8884df832 Mon Sep 17 00:00:00 2001 From: Archit Tamarapu Date: Thu, 8 Aug 2024 16:08:52 +0200 Subject: [PATCH 05/12] [fix] add an argument for LTV dir and retrieve correct metadata files since create_short_testvectors doesn't copy them over. formatting. --- tests/conftest.py | 7 ++ tests/create_short_testvectors.py | 56 ++++++------ tests/hrtf_binary_loading/constants.py | 30 ++++++- .../test_codec_ROM_vs_file.py | 88 +++++++++++-------- .../test_renderer_ROM_vs_file.py | 34 ++++--- tests/hrtf_binary_loading/utils.py | 38 ++++---- tests/renderer/constants.py | 4 +- 7 files changed, 158 insertions(+), 99 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index fa9e82de32..db7e2e86f3 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -204,6 +204,13 @@ def pytest_addoption(parser): default=False, ) + parser.addoption( + "--ltv_dir", + action="store", + type=Path, + default=None, + ) + parser.addoption( "--dut_fr", help="Render frame size for the DUT output.", diff --git a/tests/create_short_testvectors.py b/tests/create_short_testvectors.py index e242c4bacf..9d8c4c3a18 100755 --- a/tests/create_short_testvectors.py +++ b/tests/create_short_testvectors.py @@ -42,7 +42,6 @@ from cut_pcm import cut_samples HERE = Path(__file__).parent.resolve() TEST_VECTOR_DIR = HERE.joinpath("../scripts/testv").resolve() -LTV_DIR = HERE.joinpath("../../ivas-pc-testfiles").resolve() SCRIPTS_DIR = HERE.joinpath("../scripts").resolve() sys.path.append(SCRIPTS_DIR) @@ -61,25 +60,34 @@ FILE_IDS = [ "MASA", ] FILE_IDS_LTV = [ - "ltv48_STEREO", - "ltv48_MC51", - "ltv48_MC71", - "ltv48_MC512", - "ltv48_MC514", - "ltv48_MC714", - "ltv48_ISM", - "ltv48_MASA", + s.format(fs) + for s in [ + "ltv{}_STEREO", + "ltv{}_MC51", + "ltv{}_MC71", + "ltv{}_MC512", + "ltv{}_MC514", + "ltv{}_MC714", + "ltv{}_FOA", + "ltv{}_HOA2", + "ltv{}_HOA3", + "ltv{}_1ISM", + "ltv{}_2ISM", + "ltv{}_3ISM", + "ltv{}_4ISM", + "ltv{}_MASA", + ] + for fs in ["16", "32", "48"] ] -def collect_files(use_ltv: bool = False): - if use_ltv: - IDS = FILE_IDS_LTV - else: - IDS = FILE_IDS +def collect_files(use_ltv: bool = False, ltv_dir: Path = None): + IDS = FILE_IDS_LTV if use_ltv else FILE_IDS + SEARCH_DIR = ltv_dir if use_ltv and ltv_dir else TEST_VECTOR_DIR + files = [ f.absolute() - for f in TEST_VECTOR_DIR.iterdir() + for f in SEARCH_DIR.iterdir() if f.suffix == ".wav" and any([id in f.name for id in IDS]) and "_cut" not in f.name @@ -87,19 +95,12 @@ def collect_files(use_ltv: bool = False): return files -def create_short_testvectors(cut_len=5.0, use_ltv: bool = False): - files = collect_files(use_ltv) +def create_short_testvectors(cut_len=5.0, use_ltv: bool = False, ltv_dir: Path = None): + files = collect_files(use_ltv, ltv_dir) for f in files: - suffix = "_cut" - if use_ltv: - out_file = ( - HERE.joinpath("../scripts/testv") - .resolve() - .joinpath(f.stem + suffix + f.suffix) - ) - else: - out_file = f.parent.joinpath(f.stem + suffix + f.suffix) + suffix = "" if use_ltv else "_cut" + out_file = TEST_VECTOR_DIR.joinpath(f.stem + suffix + f.suffix) num_channels = audiofile.get_wav_file_info(f)["channels"] cut_samples(f, out_file, num_channels, CUT_FROM, f"{cut_len}", GAIN) @@ -115,5 +116,6 @@ if __name__ == "__main__": parser.add_argument("--cut_len", type=positive_float, default=5.0) parser.add_argument("--use_ltv", action="store_true", default=False) + parser.add_argument("--ltv_dir", type=Path) args = parser.parse_args() - sys.exit(create_short_testvectors(cut_len=args.cut_len, use_ltv=args.use_ltv)) + sys.exit(create_short_testvectors(args.cut_len, args.use_ltv, args.ltv_dir)) diff --git a/tests/hrtf_binary_loading/constants.py b/tests/hrtf_binary_loading/constants.py index 98526d0771..36d4b465cb 100644 --- a/tests/hrtf_binary_loading/constants.py +++ b/tests/hrtf_binary_loading/constants.py @@ -33,7 +33,12 @@ import re from pathlib import Path -from tests.renderer.constants import OUTPUT_FORMATS_BINAURAL, SCRIPTS_DIR, TESTV_DIR, LTV_DIR +from tests.renderer.constants import ( + LTV_DIR, + OUTPUT_FORMATS_BINAURAL, + SCRIPTS_DIR, + TESTV_DIR, +) TESTS_DIR = Path(__file__).parent @@ -54,7 +59,7 @@ HRTF_BINARY_FILE_SAME_AS_ROM = "ivas_binaural_{}kHz.bin" HRTF_BINARY_FILE_DIFF_FROM_ROM = "ivas_binaural_custom_{}kHz.bin" HRTF_FILES_SAME_AS_ROM_DEFAULT = [HRTF_BINARY_FILE_SAME_AS_ROM] HRTF_FILES_SAME_AS_ROM_CUSTOM = [HRTF_BINARY_FILE_DIFF_FROM_ROM] -HRTF_FILES = [HRTF_BINARY_FILE_SAME_AS_ROM,HRTF_BINARY_FILE_DIFF_FROM_ROM] +HRTF_FILES = [HRTF_BINARY_FILE_SAME_AS_ROM, HRTF_BINARY_FILE_DIFF_FROM_ROM] HRTF_TAG_SAME_AS_ROM = "hrtf_same_as_rom" HRTF_TAG_DIFF_FROM_ROM = "hrtf_diff_from_rom" @@ -116,6 +121,7 @@ BITRATE_ISM = { } FORMAT_TO_METADATA_FILES = {"MASA": "stv{}MASA{}TC{}c.met", "ISM": "stvISM{}.csv"} +FORMAT_TO_METADATA_FILES_LTV = {"MASA": "ltv48_MASA{}TC.met", "ISM": "ltvISM{}.csv"} FORMAT_TO_METADATA_FILES_RENDERER = { "ISM1": [str(TESTV_DIR.joinpath("stvISM1.csv"))], @@ -143,6 +149,26 @@ FORMAT_TO_METADATA_FILES_RENDERER = { "MASA1": [str(TESTV_DIR.joinpath("stv1MASA1TC48c.met"))], "MASA2": [str(TESTV_DIR.joinpath("stv2MASA2TC48c.met"))], } +FORMAT_TO_METADATA_FILES_RENDERER_LTV = { + "ISM1": [str(TESTV_DIR.joinpath("ltvISM1.csv"))], + "ISM2": [ + str(TESTV_DIR.joinpath("ltvISM1.csv")), + str(TESTV_DIR.joinpath("ltvISM2.csv")), + ], + "ISM3": [ + str(TESTV_DIR.joinpath("ltvISM1.csv")), + str(TESTV_DIR.joinpath("ltvISM2.csv")), + str(TESTV_DIR.joinpath("ltvISM3.csv")), + ], + "ISM4": [ + str(TESTV_DIR.joinpath("ltvISM1.csv")), + str(TESTV_DIR.joinpath("ltvISM2.csv")), + str(TESTV_DIR.joinpath("ltvISM3.csv")), + str(TESTV_DIR.joinpath("ltvISM4.csv")), + ], + "MASA1": [str(TESTV_DIR.joinpath("ltv48_MASA1TC.met"))], + "MASA2": [str(TESTV_DIR.joinpath("ltv48_MASA2TC.met"))], +} HR_TRAJECTORIES_TO_TEST = ["headrot_case00_3000_q", "headrot"] diff --git a/tests/hrtf_binary_loading/test_codec_ROM_vs_file.py b/tests/hrtf_binary_loading/test_codec_ROM_vs_file.py index 23da97177e..fb432fd4e7 100644 --- a/tests/hrtf_binary_loading/test_codec_ROM_vs_file.py +++ b/tests/hrtf_binary_loading/test_codec_ROM_vs_file.py @@ -29,18 +29,60 @@ accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and the United Nations Convention on Contracts on the International Sales of Goods. """ -import pytest import itertools +import pytest + from tests.hrtf_binary_loading.utils import * from .constants import ( - HRTF_TAGS, - MC_BITRATE_FOR_FORMAT, HRTF_TAG_DIFF_FROM_ROM, HRTF_TAG_SAME_AS_ROM, + HRTF_TAGS, + MC_BITRATE_FOR_FORMAT, ) + +def get_metadata_file_masa(test_info, in_dir, in_tc, fs): + if test_info.config.option.use_ltv: + if test_info.config.option.ltv_dir: + DIR = test_info.config.option.ltv_dir + else: + DIR = LTV_DIR + metadata_file = str( + DIR.joinpath(FORMAT_TO_METADATA_FILES_LTV["MASA"].format(in_tc)) + ) + else: + metadata_file = str( + TESTV_DIR.joinpath( + FORMAT_TO_METADATA_FILES["MASA"].format(in_dir, in_tc, fs) + ) + ) + + return metadata_file + + +def get_metadata_filelist_ism(test_info, in_fmt, in_fs): + if test_info.config.option.use_ltv: + if test_info.config.option.ltv_dir: + DIR = test_info.config.option.ltv_dir + else: + DIR = LTV_DIR + metadata_file_list = [ + str(DIR.joinpath(FORMAT_TO_METADATA_FILES_LTV["ISM"].format(n + 1))) + for n in range(int(in_fmt)) + ] + else: + metadata_file_list = [ + str( + TESTV_DIR.joinpath(FORMAT_TO_METADATA_FILES["ISM"].format(n + 1, in_fs)) + ) + for n in range(int(in_fmt)) + ] + + return metadata_file_list + + """ Binary file """ @@ -185,9 +227,7 @@ def test_sba_binaural_headrotation( @pytest.mark.parametrize("hrtf_tag", HRTF_TAGS) def test_masa_binaural_static(test_info, in_tc, in_dir, fs, out_fmt, hrtf_tag): bitrate = 256000 - metadata_file = str( - TESTV_DIR.joinpath(FORMAT_TO_METADATA_FILES["MASA"].format(in_dir, in_tc, fs)) - ) + metadata_file = get_metadata_file_masa(test_info, in_dir, in_tc, fs) option_list = ["-masa", in_tc, metadata_file] if test_info.config.option.use_ltv: in_file = FORMAT_TO_FILE_MASA_LTV_WOEXT.format(fs, in_tc) @@ -216,9 +256,7 @@ def test_masa_binaural_headrotation( test_info, in_tc, in_dir, fs, out_fmt, trj_file, hrtf_tag ): bitrate = 256000 - metadata_file = str( - TESTV_DIR.joinpath(FORMAT_TO_METADATA_FILES["MASA"].format(in_dir, in_tc, fs)) - ) + metadata_file = get_metadata_file_masa(test_info, in_dir, in_tc, fs) option_list = ["-masa", in_tc, metadata_file] if test_info.config.option.use_ltv: in_file = FORMAT_TO_FILE_MASA_LTV_WOEXT.format(fs, in_tc) @@ -250,13 +288,7 @@ def test_ism_binaural_static(test_info, in_fmt, out_fs, out_fmt, hrtf_tag): in_fs = 48 bitrate = BITRATE_ISM[in_fmt] option_list = ["-ism", in_fmt] - metadata_file_list = [] - for n in range(int(in_fmt)): - test = str( - TESTV_DIR.joinpath(FORMAT_TO_METADATA_FILES["ISM"].format(n + 1, in_fs)) - ) - metadata_file_list.append(test) - option_list.extend(metadata_file_list) + option_list.extend(get_metadata_filelist_ism(test_info, in_fmt, in_fs)) if test_info.config.option.use_ltv: in_file = FORMAT_TO_FILE_ISM_LTV_WOEXT.format(in_fs, in_fmt) else: @@ -286,13 +318,7 @@ def test_ism_binaural_headrotation( in_fs = 48 bitrate = BITRATE_ISM[in_fmt] option_list = ["-ism", in_fmt] - metadata_file_list = [] - for n in range(int(in_fmt)): - test = str( - TESTV_DIR.joinpath(FORMAT_TO_METADATA_FILES["ISM"].format(n + 1, in_fs)) - ) - metadata_file_list.append(test) - option_list.extend(metadata_file_list) + option_list.extend(get_metadata_filelist_ism(test_info, in_fmt, in_fs)) if test_info.config.option.use_ltv: in_file = FORMAT_TO_FILE_ISM_LTV_WOEXT.format(in_fs, in_fmt) else: @@ -323,13 +349,7 @@ def test_ism_binaural_roomreverb_static(test_info, in_fmt, out_fs, out_fmt, hrtf in_fs = 48 bitrate = BITRATE_ISM[in_fmt] option_list = ["-ism", in_fmt] - metadata_file_list = [] - for n in range(int(in_fmt)): - test = str( - TESTV_DIR.joinpath(FORMAT_TO_METADATA_FILES["ISM"].format(n + 1, in_fs)) - ) - metadata_file_list.append(test) - option_list.extend(metadata_file_list) + option_list.extend(get_metadata_filelist_ism(test_info, in_fmt, in_fs)) if test_info.config.option.use_ltv: in_file = FORMAT_TO_FILE_ISM_LTV_WOEXT.format(in_fs, in_fmt) else: @@ -359,13 +379,7 @@ def test_ism_binaural_roomreverb_headrotation( in_fs = 48 bitrate = BITRATE_ISM[in_fmt] option_list = ["-ism", in_fmt] - metadata_file_list = [] - for n in range(int(in_fmt)): - test = str( - TESTV_DIR.joinpath(FORMAT_TO_METADATA_FILES["ISM"].format(n + 1, in_fs)) - ) - metadata_file_list.append(test) - option_list.extend(metadata_file_list) + option_list.extend(get_metadata_filelist_ism(test_info, in_fmt, in_fs)) if test_info.config.option.use_ltv: in_file = FORMAT_TO_FILE_ISM_LTV_WOEXT.format(in_fs, in_fmt) else: diff --git a/tests/hrtf_binary_loading/test_renderer_ROM_vs_file.py b/tests/hrtf_binary_loading/test_renderer_ROM_vs_file.py index 5b81328563..8b22b82bed 100644 --- a/tests/hrtf_binary_loading/test_renderer_ROM_vs_file.py +++ b/tests/hrtf_binary_loading/test_renderer_ROM_vs_file.py @@ -45,6 +45,22 @@ from tests.renderer.constants import ( from .constants import HRTF_TAGS + +def get_metadata_files(test_info, in_fmt): + try: + if test_info.config.option.use_ltv: + metadata_files = FORMAT_TO_METADATA_FILES_RENDERER_LTV[in_fmt] + if test_info.config.option.ltv_dir: + metadata_files = [ + m.replace(str(TESTV_DIR), str(test_info.config.option.ltv_dir)) + for m in metadata_files + ] + except Exception: + metadata_files = None + + return metadata_files + + """ Ambisonics """ @@ -128,17 +144,12 @@ def test_ism_binaural_static_with_binary_hrir( test_info, in_fmt, out_fmt, frame_size, hrtf_tag ): - try: - in_meta_files = FORMAT_TO_METADATA_FILES_RENDERER[in_fmt] - except: - in_meta_files = None - compare_renderer_vs_renderer_with_binary_hrir( test_info, in_fmt, out_fmt, hrtf_tag, - in_meta_files=in_meta_files, + in_meta_files=get_metadata_files(test_info, in_fmt), frame_size=frame_size, ) @@ -152,18 +163,13 @@ def test_ism_binaural_headrotation_with_binary_hrir( test_info, in_fmt, out_fmt, trj_file, frame_size, hrtf_tag ): - try: - in_meta_files = FORMAT_TO_METADATA_FILES_RENDERER[in_fmt] - except: - in_meta_files = None - compare_renderer_vs_renderer_with_binary_hrir( test_info, in_fmt, out_fmt, hrtf_tag, trj_file=HR_TRAJECTORY_DIR.joinpath(f"{trj_file}.csv"), - in_meta_files=in_meta_files, + in_meta_files=get_metadata_files(test_info, in_fmt), frame_size=frame_size, ) @@ -184,7 +190,7 @@ def test_masa_binaural_static_with_binary_hrir( in_fmt, out_fmt, hrtf_tag, - in_meta_files=FORMAT_TO_METADATA_FILES_RENDERER[in_fmt], + in_meta_files=get_metadata_files(test_info, in_fmt), ) @@ -202,7 +208,7 @@ def test_masa_binaural_headrotation_with_binary_hrir( out_fmt, hrtf_tag, trj_file=HR_TRAJECTORY_DIR.joinpath(f"{trj_file}.csv"), - in_meta_files=FORMAT_TO_METADATA_FILES_RENDERER[in_fmt], + in_meta_files=get_metadata_files(test_info, in_fmt), ) diff --git a/tests/hrtf_binary_loading/utils.py b/tests/hrtf_binary_loading/utils.py index 47d5c963b7..766e504900 100644 --- a/tests/hrtf_binary_loading/utils.py +++ b/tests/hrtf_binary_loading/utils.py @@ -293,7 +293,7 @@ def compare_rom_vs_binary( hrtf_file = HRTF_FILE_FOR_TAG[hrtf_tag] - xfail = (hrtf_file == HRTF_BINARY_FILE_DIFF_FROM_ROM) + xfail = hrtf_file == HRTF_BINARY_FILE_DIFF_FROM_ROM if test_info.config.option.use_ltv: input_path = LTV_DIR.joinpath(in_file).with_suffix(".wav") @@ -327,14 +327,16 @@ def compare_rom_vs_binary( ) out_bin, out_bin_fs = pyaudio3dtools.audiofile.readfile(out_bin_path) - [diff_found, snr, gain_b, max_diff] = check_BE(test_info, out_rom, out_rom_fs, out_bin, out_bin_fs, 0) + [diff_found, snr, gain_b, max_diff] = check_BE( + test_info, out_rom, out_rom_fs, out_bin, out_bin_fs, 0 + ) if keep_file == "no": os.remove(bitstream_path) os.remove(out_rom_path) os.remove(out_bin_path) - + if diff_found and not xfail: - pytest.fail( + pytest.xfail( f"CuT not BE to REF! SNR : {snr:3.2f} dB, Gain CuT: {gain_b:1.3f}, Max Diff = {int(max_diff)}" ) elif not diff_found and xfail: @@ -364,7 +366,7 @@ def compare_renderer_vs_renderer_with_binary_hrir( keep_file="if failed", ): hrtf_file = HRTF_FILE_FOR_TAG[hrtf_tag] - xfail = (hrtf_file == HRTF_BINARY_FILE_DIFF_FROM_ROM) + xfail = hrtf_file == HRTF_BINARY_FILE_DIFF_FROM_ROM hrtf_file_dir = SCRIPTS_DIR.joinpath( "binauralRenderer_interface/binaural_renderers_hrtf_data" @@ -409,28 +411,31 @@ def compare_renderer_vs_renderer_with_binary_hrir( ref, ref_fs = pyaudio3dtools.audiofile.readfile(ref_out) cut, cut_fs = pyaudio3dtools.audiofile.readfile(cut_out) - [diff_found, snr, gain_b, max_diff] = check_BE(test_info, ref, ref_fs, cut, cut_fs, 0) + [diff_found, snr, gain_b, max_diff] = check_BE( + test_info, ref, ref_fs, cut, cut_fs, 0 + ) if keep_file == "no": os.remove(ref_out) os.remove(cut_out) - + if diff_found and not xfail: if keep_file != "if failed": os.remove(ref_out) os.remove(cut_out) pytest.fail( f"CuT not BE to REF! SNR : {snr:3.2f} dB, Gain CuT: {gain_b:1.3f}, Max Diff = {int(max_diff)}" - ) + ) elif not diff_found and xfail: if keep_file != "if failed": os.remove(ref_out) os.remove(cut_out) - pytest.fail("Difference expected, but none found.") + pytest.fail("Difference expected, but none found.") else: if keep_file == "if failed": os.remove(ref_out) os.remove(cut_out) - + + def compare_renderer_with_binary_fix_vs_with_binary_float( test_info, in_fmt, @@ -455,12 +460,12 @@ def compare_renderer_with_binary_fix_vs_with_binary_float( "binauralRenderer_interface/binaural_renderers_hrtf_data" ) hrtf_file_path = hrtf_file_dir.joinpath(hrtf_file.format(48)) - + hrtf_file_dir_fx = SCRIPTS_DIR.joinpath( "binauralRenderer_interface/binaural_renderers_hrtf_data" ) hrtf_file_path_fx = hrtf_file_dir_fx.joinpath(hrtf_file_fx.format(48)) - + ref_out = run_renderer( None, list(), @@ -501,12 +506,14 @@ def compare_renderer_with_binary_fix_vs_with_binary_float( ref, ref_fs = pyaudio3dtools.audiofile.readfile(ref_out) cut, cut_fs = pyaudio3dtools.audiofile.readfile(cut_out) - [diff_found, snr, gain_b, max_diff] = check_BE(test_info, ref, ref_fs, cut, cut_fs, 2) + [diff_found, snr, gain_b, max_diff] = check_BE( + test_info, ref, ref_fs, cut, cut_fs, 2 + ) if keep_file == "no": os.remove(ref_out) os.remove(cut_out) - if diff_found : + if diff_found: if keep_file != "if failed": os.remove(ref_out) os.remove(cut_out) @@ -517,6 +524,3 @@ def compare_renderer_with_binary_fix_vs_with_binary_float( if keep_file == "if failed": os.remove(ref_out) os.remove(cut_out) - - - diff --git a/tests/renderer/constants.py b/tests/renderer/constants.py index 4ace993b75..b7326a0a78 100644 --- a/tests/renderer/constants.py +++ b/tests/renderer/constants.py @@ -44,7 +44,7 @@ OUTPUT_PATH_CUT = TESTS_DIR.joinpath("cut") CUSTOM_LAYOUT_DIR = SCRIPTS_DIR.joinpath("ls_layouts") HR_TRAJECTORY_DIR = SCRIPTS_DIR.joinpath("trajectories") TESTV_DIR = SCRIPTS_DIR.joinpath("testv") -LTV_DIR = TESTS_DIR.parents[2].joinpath("ivas-pc-testfiles") +LTV_DIR = TESTV_DIR BIN_SUFFIX_MERGETARGET = "_ref" @@ -223,7 +223,7 @@ FORMAT_TO_FILE_LTV = { "OSBA_4_3": LTV_DIR.joinpath("ltv48_OSBA_4ISM_HOA3.wav"), "META": TEST_VECTOR_DIR.joinpath("mixed_scene.txt"), "16ch_8+4+4": LTV_DIR.joinpath("ltv48_HOA3.wav"), - "4d4": LTV_DIR.joinpath("ltv48_MC714.wav"), + "4d4": LTV_DIR.joinpath("ltv48_MC71.wav"), "t_design_4": LTV_DIR.joinpath("ltv48_MC714.wav"), } -- GitLab From 9fc217bed1203e0294f8b34b97b26f9e9fcd7f37 Mon Sep 17 00:00:00 2001 From: Archit Tamarapu Date: Thu, 8 Aug 2024 18:09:19 +0200 Subject: [PATCH 06/12] [fix] missing metadata files for regular test without LTV --- tests/hrtf_binary_loading/test_renderer_ROM_vs_file.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/hrtf_binary_loading/test_renderer_ROM_vs_file.py b/tests/hrtf_binary_loading/test_renderer_ROM_vs_file.py index 8b22b82bed..f27c172bd5 100644 --- a/tests/hrtf_binary_loading/test_renderer_ROM_vs_file.py +++ b/tests/hrtf_binary_loading/test_renderer_ROM_vs_file.py @@ -55,6 +55,8 @@ def get_metadata_files(test_info, in_fmt): m.replace(str(TESTV_DIR), str(test_info.config.option.ltv_dir)) for m in metadata_files ] + else: + metadata_files = FORMAT_TO_METADATA_FILES_RENDERER[in_fmt] except Exception: metadata_files = None -- GitLab From 572a7e3518648cc963cf3ba81ed67194144ceb32 Mon Sep 17 00:00:00 2001 From: Archit Tamarapu Date: Mon, 12 Aug 2024 11:22:47 +0200 Subject: [PATCH 07/12] [fix] leftover from local debugging --- tests/hrtf_binary_loading/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/hrtf_binary_loading/utils.py b/tests/hrtf_binary_loading/utils.py index 766e504900..2486f14957 100644 --- a/tests/hrtf_binary_loading/utils.py +++ b/tests/hrtf_binary_loading/utils.py @@ -336,7 +336,7 @@ def compare_rom_vs_binary( os.remove(out_bin_path) if diff_found and not xfail: - pytest.xfail( + pytest.fail( f"CuT not BE to REF! SNR : {snr:3.2f} dB, Gain CuT: {gain_b:1.3f}, Max Diff = {int(max_diff)}" ) elif not diff_found and xfail: -- GitLab From 6d31c79b341873d930ed74756b7ac68a0f7b89a7 Mon Sep 17 00:00:00 2001 From: Archit Tamarapu Date: Wed, 14 Aug 2024 11:36:46 +0200 Subject: [PATCH 08/12] [fix] --ltv_dir argument does not update actual path --- tests/hrtf_binary_loading/utils.py | 5 ++++- tests/renderer/utils.py | 17 +++++++++++++---- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/tests/hrtf_binary_loading/utils.py b/tests/hrtf_binary_loading/utils.py index 2486f14957..b0077edf08 100644 --- a/tests/hrtf_binary_loading/utils.py +++ b/tests/hrtf_binary_loading/utils.py @@ -296,7 +296,10 @@ def compare_rom_vs_binary( xfail = hrtf_file == HRTF_BINARY_FILE_DIFF_FROM_ROM if test_info.config.option.use_ltv: - input_path = LTV_DIR.joinpath(in_file).with_suffix(".wav") + ltv_dir = LTV_DIR + if test_info.config.option.ltv_dir: + ltv_dir = test_info.config.option.ltv_dir + input_path = ltv_dir.joinpath(in_file).with_suffix(".wav") else: input_path = TESTV_DIR.joinpath(in_file).with_suffix(".wav") bitstream_path = BITSTREAM_DIR.joinpath(in_file + file_ext) diff --git a/tests/renderer/utils.py b/tests/renderer/utils.py index 7da6295084..4bf4316553 100644 --- a/tests/renderer/utils.py +++ b/tests/renderer/utils.py @@ -43,6 +43,7 @@ import pytest from .compare_audio import compare_audio_arrays from .constants import ( + LTV_DIR, SCRIPTS_DIR, OUTPUT_PATH_REF, OUTPUT_PATH_CUT, @@ -122,7 +123,7 @@ def check_BE( cut: np.ndarray, cut_fs: int, atol: int = 2, -)->tuple: +) -> tuple: if ref is None or np.array_equal(ref, np.zeros_like(ref)): pytest.fail("REF signal does not exist or is zero!") @@ -141,9 +142,10 @@ def check_BE( # check max_diff as well, since compare_audio_arrays will try to adjust for small delay differences diff_found = not np.allclose(ref, cut, rtol=0, atol=atol) and max_diff > atol - + return diff_found, snr, gain_b, max_diff + def run_renderer( record_property, props_to_record, @@ -228,7 +230,14 @@ def run_renderer( if test_info.config.option.create_ref or test_info.config.option.create_cut: FORMAT_TO_FILE = FORMAT_TO_FILE_COMPARETEST elif test_info.config.option.use_ltv: - FORMAT_TO_FILE = FORMAT_TO_FILE_LTV + if test_info.config.option.ltv_dir: + FORMAT_TO_FILE = dict() + for k, v in FORMAT_TO_FILE_LTV: + FORMAT_TO_FILE[k] = str(v).replace( + LTV_DIR, test_info.config.option.ltv_dir + ) + else: + FORMAT_TO_FILE = FORMAT_TO_FILE_LTV else: FORMAT_TO_FILE = FORMAT_TO_FILE_SMOKETEST @@ -361,7 +370,7 @@ def compare_renderer_args( ) cut, cut_fs = readfile(out_file_cut) [diff_found, snr, gain_b, max_diff] = check_BE(test_info, ref, ref_fs, cut, cut_fs) - if diff_found : + if diff_found: pytest.fail( f"CuT not BE to REF! SNR : {snr:3.2f} dB, Gain CuT: {gain_b:1.3f}, Max Diff = {int(max_diff)}" ) -- GitLab From 9877830f92e8482a94649b4ee8f6243d754296a4 Mon Sep 17 00:00:00 2001 From: Archit Tamarapu Date: Wed, 14 Aug 2024 11:43:32 +0200 Subject: [PATCH 09/12] refactor checks for MLD binary --- scripts/pyaudio3dtools/audioarray.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/scripts/pyaudio3dtools/audioarray.py b/scripts/pyaudio3dtools/audioarray.py index aef7f85451..06c3d42171 100644 --- a/scripts/pyaudio3dtools/audioarray.py +++ b/scripts/pyaudio3dtools/audioarray.py @@ -357,17 +357,17 @@ def compare( if get_mld: mld_max = 0 toolsdir = Path(__file__).parent.parent.joinpath("tools") - if platform.system() == "Windows": - mld = toolsdir.joinpath("Win32").joinpath("mld.exe") - elif platform.system() in ["Linux", "Darwin"]: - mld = toolsdir.joinpath(platform.system()).joinpath("mld") - else: - assert False, f"MLD tool not available for {platform.system()}" + + curr_platform = platform.system() + if curr_platform not in {"Windows", "Linux", "Darwin"}: + raise NotImplementedError(f"MLD tool not available for {curr_platform}") + search_path = toolsdir.joinpath(curr_platform.replace("Windows", "Win32")) + mld = search_path.joinpath("mld") + if not mld.exists(): mld = shutil.which("mld") - search_path = toolsdir.joinpath(platform.system().replace("Windows", "Win32")) if mld is None: - assert False, f"MLD tool not found in {search_path} or PATH!" + raise FileNotFoundError(f"MLD tool not found in {search_path} or PATH!") warnings.warn(f"MLD binary not found in {search_path}! Falling back to {mld}!") with tempfile.TemporaryDirectory() as tmpdir: -- GitLab From 4c56e2d61689b1eb564fcbdaba3bd38c4e3a7a01 Mon Sep 17 00:00:00 2001 From: Archit Tamarapu Date: Wed, 14 Aug 2024 11:50:13 +0200 Subject: [PATCH 10/12] [fix] checks in cut_pcm.py --- tests/cut_pcm.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/cut_pcm.py b/tests/cut_pcm.py index 90a9b4e1d0..93395ff4cb 100755 --- a/tests/cut_pcm.py +++ b/tests/cut_pcm.py @@ -96,12 +96,12 @@ def cut_samples( num_in_samples = s.shape[0] num_samples_to_skip = int(start_sec * fs) dur_samples = int(dur_sec * fs) - if dur_samples > num_in_samples: - dur_samples = num_in_samples - if num_samples_to_skip > dur_samples: + if num_samples_to_skip > num_in_samples: raise ValueError( - f"Requested to skip {num_samples_to_skip}, but file only has {dur_samples} samples" + f"Requested to skip {num_samples_to_skip}, but file only has {num_in_samples} samples" ) + if dur_samples > (num_in_samples - num_samples_to_skip): + dur_samples = num_in_samples - num_samples_to_skip s_out = s[num_samples_to_skip : num_samples_to_skip + dur_samples, :] * gain_f -- GitLab From 26fc5d2de955f20f4b38426f241ca221a4ddbe83 Mon Sep 17 00:00:00 2001 From: Archit Tamarapu Date: Wed, 14 Aug 2024 11:55:41 +0200 Subject: [PATCH 11/12] [fix] typo in loop over dictionary --- tests/renderer/utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/renderer/utils.py b/tests/renderer/utils.py index 4bf4316553..f987fe4229 100644 --- a/tests/renderer/utils.py +++ b/tests/renderer/utils.py @@ -232,9 +232,9 @@ def run_renderer( elif test_info.config.option.use_ltv: if test_info.config.option.ltv_dir: FORMAT_TO_FILE = dict() - for k, v in FORMAT_TO_FILE_LTV: + for k, v in FORMAT_TO_FILE_LTV.items(): FORMAT_TO_FILE[k] = str(v).replace( - LTV_DIR, test_info.config.option.ltv_dir + str(LTV_DIR), str(test_info.config.option.ltv_dir) ) else: FORMAT_TO_FILE = FORMAT_TO_FILE_LTV -- GitLab From 687b967a7a7e84ef390e7eae4e3512110e1571c4 Mon Sep 17 00:00:00 2001 From: Archit Tamarapu Date: Wed, 14 Aug 2024 12:45:28 +0200 Subject: [PATCH 12/12] [fix] minor adjustment for cut_pcm where all samples could be skipped without error --- tests/cut_pcm.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/cut_pcm.py b/tests/cut_pcm.py index 93395ff4cb..9b9375b613 100755 --- a/tests/cut_pcm.py +++ b/tests/cut_pcm.py @@ -96,7 +96,7 @@ def cut_samples( num_in_samples = s.shape[0] num_samples_to_skip = int(start_sec * fs) dur_samples = int(dur_sec * fs) - if num_samples_to_skip > num_in_samples: + if num_samples_to_skip >= num_in_samples: raise ValueError( f"Requested to skip {num_samples_to_skip}, but file only has {num_in_samples} samples" ) -- GitLab