diff --git a/scripts/pyaudio3dtools/audioarray.py b/scripts/pyaudio3dtools/audioarray.py index be950aaf6013ae5d24034e0346608c7a05edf001..06c3d42171390c1a7fe39618fe7a230389b53ddf 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 @@ -356,12 +357,18 @@ 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") + if mld is None: + 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: for i in range(nchannels): diff --git a/tests/conftest.py b/tests/conftest.py index b75b3ba9979b4bafc1646d70e8e91b446fc0f374..db7e2e86f3defa9074e1e87b4f48e36f65011724 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -198,6 +198,19 @@ def pytest_addoption(parser): default=False, ) + parser.addoption( + "--use_ltv", + action="store_true", + 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 b90771cca18eac9f2ee65c5f7d548f896a41c39e..9d8c4c3a1851dd095830c11de8ceff61eac3d6b3 100755 --- a/tests/create_short_testvectors.py +++ b/tests/create_short_testvectors.py @@ -59,25 +59,48 @@ FILE_IDS = [ "ISM", "MASA", ] +FILE_IDS_LTV = [ + 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, 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 -def collect_files(): 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 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, ltv_dir: Path = None): + files = collect_files(use_ltv, ltv_dir) for f in files: - suffix = "_cut" - 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) @@ -92,6 +115,7 @@ 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) + parser.add_argument("--ltv_dir", type=Path) args = parser.parse_args() - cut_len = args.cut_len - sys.exit(create_short_testvectors(cut_len=cut_len)) + sys.exit(create_short_testvectors(args.cut_len, args.use_ltv, args.ltv_dir)) diff --git a/tests/cut_pcm.py b/tests/cut_pcm.py index 2abc86b624ff698cb4f216b6943cce067211c7b5..9b9375b613f74fc5cd4127df0f9ed3137a552ed7 100755 --- a/tests/cut_pcm.py +++ b/tests/cut_pcm.py @@ -96,10 +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 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 diff --git a/tests/hrtf_binary_loading/constants.py b/tests/hrtf_binary_loading/constants.py index d5f013fd59184fffb529dda40d655ff428eda431..36d4b465cbfab507277e85e86b3f447019d6c4e9 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 +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" @@ -93,6 +98,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, @@ -101,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"))], @@ -128,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 ade6c01d887b54768a382f66d228633fd308d6bd..fb432fd4e738627e705cd36937741b174845c6a8 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 """ @@ -67,7 +109,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 +144,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 +172,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 +199,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, @@ -173,11 +227,12 @@ 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] - 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, @@ -201,11 +256,12 @@ 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] - 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, @@ -232,14 +288,11 @@ 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) - in_file = FORMAT_TO_FILE_ISM_WOEXT.format(in_fmt, in_fs) + 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: + in_file = FORMAT_TO_FILE_ISM_WOEXT.format(in_fmt, in_fs) compare_rom_vs_binary( test_info, @@ -265,14 +318,11 @@ 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) - in_file = FORMAT_TO_FILE_ISM_WOEXT.format(in_fmt, in_fs) + 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: + in_file = FORMAT_TO_FILE_ISM_WOEXT.format(in_fmt, in_fs) compare_rom_vs_binary( test_info, @@ -299,14 +349,11 @@ 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) - in_file = FORMAT_TO_FILE_ISM_WOEXT.format(in_fmt, in_fs) + 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: + in_file = FORMAT_TO_FILE_ISM_WOEXT.format(in_fmt, in_fs) compare_rom_vs_binary( test_info, @@ -332,14 +379,11 @@ 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) - in_file = FORMAT_TO_FILE_ISM_WOEXT.format(in_fmt, in_fs) + 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: + 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/test_renderer_ROM_vs_file.py b/tests/hrtf_binary_loading/test_renderer_ROM_vs_file.py index 5b8132856371e1bc5e28b4c790fb312d13f38e90..f27c172bd503b9062dce603df798e5a5e1f76edc 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,24 @@ 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 + ] + else: + metadata_files = FORMAT_TO_METADATA_FILES_RENDERER[in_fmt] + except Exception: + metadata_files = None + + return metadata_files + + """ Ambisonics """ @@ -128,17 +146,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 +165,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 +192,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 +210,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 2ba8b39e6b43225b30e280648cec15a58f32be28..b0077edf082fba180c82482b51bae7995edcb40f 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)) @@ -293,9 +293,15 @@ 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 - input_path = TESTV_DIR.joinpath(in_file).with_suffix(".wav") + if test_info.config.option.use_ltv: + 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) run_encoder( bitrate, in_fs, input_path, bitstream_path, add_option_list=option_list_enc @@ -324,12 +330,14 @@ 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( f"CuT not BE to REF! SNR : {snr:3.2f} dB, Gain CuT: {gain_b:1.3f}, Max Diff = {int(max_diff)}" @@ -361,7 +369,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" @@ -406,28 +414,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, @@ -452,12 +463,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(), @@ -498,12 +509,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) @@ -514,6 +527,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 0e7b13c8ac61f4f761b40c9963befb180673f1ee..b7326a0a7864f5b69c5f86f6cfb81adc1213cf3b 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 = TESTV_DIR 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_MC71.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 d94f75bf8fce939bca6d471912581f97e1a4bf18..f987fe4229052d420f454692ede3b7a4f4b9310f 100644 --- a/tests/renderer/utils.py +++ b/tests/renderer/utils.py @@ -43,10 +43,12 @@ import pytest from .compare_audio import compare_audio_arrays from .constants import ( + LTV_DIR, SCRIPTS_DIR, OUTPUT_PATH_REF, OUTPUT_PATH_CUT, FORMAT_TO_FILE_COMPARETEST, + FORMAT_TO_FILE_LTV, FORMAT_TO_FILE_SMOKETEST, RENDERER_CMD, BIN_SUFFIX_MERGETARGET, @@ -121,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!") @@ -140,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, @@ -226,6 +229,15 @@ 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: + if test_info.config.option.ltv_dir: + FORMAT_TO_FILE = dict() + for k, v in FORMAT_TO_FILE_LTV.items(): + FORMAT_TO_FILE[k] = str(v).replace( + str(LTV_DIR), str(test_info.config.option.ltv_dir) + ) + else: + FORMAT_TO_FILE = FORMAT_TO_FILE_LTV else: FORMAT_TO_FILE = FORMAT_TO_FILE_SMOKETEST @@ -358,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)}" )