Commit 09a2a479 authored by emerit's avatar emerit
Browse files

add tests to compare hrtf file loading fix and float

parent 51e8c888
Loading
Loading
Loading
Loading
+9 −2
Original line number Diff line number Diff line
@@ -54,14 +54,21 @@ HRTF_BINARY_FILE_SAME_AS_ROM = "ivas_binaural_{}kHz.bin"
HRTF_BINARY_FILE_SAME_AS_ROM_FX = "ivas_binaural_fx_{}kHz.bin"
HRTF_BINARY_FILE_DIFF_FROM_ROM = "ivas_binaural_custom_{}kHz.bin"
HRTF_BINARY_FILE_DIFF_FROM_ROM_FX = "ivas_binaural_custom_fx_{}kHz.bin"
HRTF_FILES_SAME_AS_ROM_DEFAULT = [HRTF_BINARY_FILE_SAME_AS_ROM, HRTF_BINARY_FILE_SAME_AS_ROM_FX]
HRTF_FILES_SAME_AS_ROM_CUSTOM = [HRTF_BINARY_FILE_DIFF_FROM_ROM, HRTF_BINARY_FILE_DIFF_FROM_ROM_FX]
HRTF_FILES = [HRTF_BINARY_FILE_SAME_AS_ROM, HRTF_BINARY_FILE_SAME_AS_ROM_FX, HRTF_BINARY_FILE_DIFF_FROM_ROM,HRTF_BINARY_FILE_DIFF_FROM_ROM_FX]
DEFAULT_BIN_FILE_FX_FLAG = 0x1000

HRTF_TAG_FIX_AS_FLOAT = "hrtf_fix_as_float"
HRTF_TAG_FIX_AS_FLOAT_CUSTOM = "hrtf_fix_as_float_custom"
HRTF_TAG_SAME_AS_ROM = "hrtf_same_as_rom"
HRTF_TAG_SAME_AS_ROM_FX = "hrtf_same_as_rom_fx"
HRTF_TAG_DIFF_FROM_ROM = "hrtf_diff_from_rom"
HRTF_TAG_DIFF_FROM_ROM_FX = "hrtf_diff_from_rom_fx"
HRTF_TAGS = [HRTF_TAG_SAME_AS_ROM, HRTF_TAG_SAME_AS_ROM_FX, HRTF_TAG_DIFF_FROM_ROM, HRTF_TAG_DIFF_FROM_ROM_FX]
HRTF_TAGS_FX_AS_FLOAT = [HRTF_TAG_FIX_AS_FLOAT, HRTF_TAG_FIX_AS_FLOAT_CUSTOM]
HRTF_TAGS = [HRTF_TAG_SAME_AS_ROM, HRTF_TAG_DIFF_FROM_ROM]
HRTF_FILES_FOR_FX_SAME_AS_FLOAT_DICT = [HRTF_FILES_SAME_AS_ROM_DEFAULT, HRTF_FILES_SAME_AS_ROM_CUSTOM]
HRTF_TAGS_FILES_FOR_FX_SAME_AS_FLOAT = dict(zip(HRTF_TAGS_FX_AS_FLOAT, HRTF_FILES_FOR_FX_SAME_AS_FLOAT_DICT))
HRTF_FILE_FOR_TAG = dict(zip(HRTF_TAGS, HRTF_FILES))

SAMPLE_RATE = ["16", "32", "48"]
+248 −0
Original line number Diff line number Diff line
#!/usr/bin/env python3

"""
   (C) 2022-2024 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
   Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
   Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
   Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
   contributors to this repository. All Rights Reserved.

   This software is protected by copyright law and by international treaties.
   The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB,
   Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
   Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
   Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
   contributors to this repository retain full ownership rights in their respective contributions in
   the software. This notice grants no license of any kind, including but not limited to patent
   license, nor is any license granted by implication, estoppel or otherwise.

   Contributors are required to enter into the IVAS codec Public Collaboration agreement before making
   contributions.

   This software is provided "AS IS", without any express or implied warranties. The software is in the
   development stage. It is intended exclusively for experts who have experience with such software and
   solely for the purpose of inspection. All implied warranties of non-infringement, merchantability
   and fitness for a particular purpose are hereby disclaimed and excluded.

   Any dispute, controversy or claim arising under or in relation to providing this software shall be
   submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in
   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

from tests.hrtf_binary_loading.utils import *
from tests.renderer.constants import (
    CUSTOM_LAYOUT_DIR,
    CUSTOM_LS_TO_TEST,
    FRAMING_TO_TEST,
    HR_TRAJECTORY_DIR,
    INPUT_FORMATS_AMBI,
    INPUT_FORMATS_ISM,
    INPUT_FORMATS_MC,
)

from .constants import HRTF_TAGS_FILES_FOR_FX_SAME_AS_FLOAT

""" Ambisonics """


@pytest.mark.parametrize("out_fmt", OUTPUT_FORMATS_BINAURAL)
@pytest.mark.parametrize("in_fmt", INPUT_FORMATS_AMBI)
@pytest.mark.parametrize("frame_size", FRAMING_TO_TEST)
@pytest.mark.parametrize("hrtf_tag", HRTF_TAGS_FILES_FOR_FX_SAME_AS_FLOAT)
def test_ambisonics_binaural_static_with_binary_hrir(
    test_info, in_fmt, out_fmt, frame_size, hrtf_tag
):
    compare_renderer_with_binary_fix_vs_with_binary_float(
        test_info, in_fmt, out_fmt, hrtf_tag, frame_size=frame_size
    )


@pytest.mark.parametrize("trj_file", HR_TRAJECTORIES_TO_TEST_RENDERER)
@pytest.mark.parametrize("out_fmt", OUTPUT_FORMATS_BINAURAL)
@pytest.mark.parametrize("in_fmt", INPUT_FORMATS_AMBI)
@pytest.mark.parametrize("frame_size", FRAMING_TO_TEST)
@pytest.mark.parametrize("hrtf_tag", HRTF_TAGS_FILES_FOR_FX_SAME_AS_FLOAT)
def test_ambisonics_binaural_headrotation_with_binary_hrir(
    test_info, in_fmt, out_fmt, trj_file, frame_size, hrtf_tag
):
    compare_renderer_with_binary_fix_vs_with_binary_float(
        test_info,
        in_fmt,
        out_fmt,
        hrtf_tag,
        trj_file=HR_TRAJECTORY_DIR.joinpath(f"{trj_file}.csv"),
        frame_size=frame_size,
    )


""" Multichannel """


@pytest.mark.parametrize("out_fmt", OUTPUT_FORMATS_BINAURAL)
@pytest.mark.parametrize("in_fmt", INPUT_FORMATS_MC)
@pytest.mark.parametrize("frame_size", FRAMING_TO_TEST)
@pytest.mark.parametrize("hrtf_tag", HRTF_TAGS_FILES_FOR_FX_SAME_AS_FLOAT)
def test_multichannel_binaural_static_with_binary_hrir(
    test_info, in_fmt, out_fmt, frame_size, hrtf_tag
):
    if in_fmt in ["MONO", "STEREO"]:
        pytest.skip("MONO or STEREO to Binaural rendering unsupported")

    compare_renderer_with_binary_fix_vs_with_binary_float(
        test_info, in_fmt, out_fmt, hrtf_tag, frame_size=frame_size
    )


@pytest.mark.parametrize("trj_file", HR_TRAJECTORIES_TO_TEST_RENDERER)
@pytest.mark.parametrize("out_fmt", OUTPUT_FORMATS_BINAURAL)
@pytest.mark.parametrize("in_fmt", INPUT_FORMATS_MC)
@pytest.mark.parametrize("frame_size", FRAMING_TO_TEST)
@pytest.mark.parametrize("hrtf_tag", HRTF_TAGS_FILES_FOR_FX_SAME_AS_FLOAT)
def test_multichannel_binaural_headrotation_with_binary_hrir(
    test_info, in_fmt, out_fmt, trj_file, frame_size, hrtf_tag
):
    if in_fmt in ["MONO", "STEREO"]:
        pytest.skip("MONO or STEREO to Binaural rendering unsupported")

    compare_renderer_with_binary_fix_vs_with_binary_float(
        test_info,
        in_fmt,
        out_fmt,
        hrtf_tag,
        trj_file=HR_TRAJECTORY_DIR.joinpath(f"{trj_file}.csv"),
        frame_size=frame_size,
    )


""" ISM """


@pytest.mark.parametrize("out_fmt", OUTPUT_FORMATS_BINAURAL)
@pytest.mark.parametrize("in_fmt", INPUT_FORMATS_ISM)
@pytest.mark.parametrize("frame_size", FRAMING_TO_TEST)
@pytest.mark.parametrize("hrtf_tag", HRTF_TAGS_FILES_FOR_FX_SAME_AS_FLOAT)
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_with_binary_fix_vs_with_binary_float(
        test_info,
        in_fmt,
        out_fmt,
        hrtf_tag,
        in_meta_files=in_meta_files,
        frame_size=frame_size,
    )


@pytest.mark.parametrize("trj_file", HR_TRAJECTORIES_TO_TEST_RENDERER)
@pytest.mark.parametrize("out_fmt", OUTPUT_FORMATS_BINAURAL)
@pytest.mark.parametrize("in_fmt", INPUT_FORMATS_ISM)
@pytest.mark.parametrize("frame_size", FRAMING_TO_TEST)
@pytest.mark.parametrize("hrtf_tag", HRTF_TAGS_FILES_FOR_FX_SAME_AS_FLOAT)
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_with_binary_fix_vs_with_binary_float(
        test_info,
        in_fmt,
        out_fmt,
        hrtf_tag,
        trj_file=HR_TRAJECTORY_DIR.joinpath(f"{trj_file}.csv"),
        in_meta_files=in_meta_files,
        frame_size=frame_size,
    )


""" MASA """


@pytest.mark.parametrize("out_fmt", OUTPUT_FORMATS_BINAURAL)
@pytest.mark.parametrize("in_fmt", INPUT_FORMATS_MASA_RENDERER)
@pytest.mark.parametrize("frame_size", FRAMING_TO_TEST)
@pytest.mark.parametrize("hrtf_tag", HRTF_TAGS_FILES_FOR_FX_SAME_AS_FLOAT)
def test_masa_binaural_static_with_binary_hrir(
    test_info, in_fmt, out_fmt, frame_size, hrtf_tag
):
    if out_fmt in ["BINAURAL_ROOM_IR", "BINAURAL_ROOM_REVERB"]:
        pytest.skip("Skipping binaural room outputs for MASA as unimplemented.")

    compare_renderer_with_binary_fix_vs_with_binary_float(
        test_info,
        in_fmt,
        out_fmt,
        hrtf_tag,
        in_meta_files=FORMAT_TO_METADATA_FILES_RENDERER[in_fmt],
    )


@pytest.mark.parametrize("trj_file", HR_TRAJECTORIES_TO_TEST_RENDERER)
@pytest.mark.parametrize("out_fmt", OUTPUT_FORMATS_BINAURAL)
@pytest.mark.parametrize("in_fmt", INPUT_FORMATS_MASA_RENDERER)
@pytest.mark.parametrize("frame_size", FRAMING_TO_TEST)
@pytest.mark.parametrize("hrtf_tag", HRTF_TAGS_FILES_FOR_FX_SAME_AS_FLOAT)
def test_masa_binaural_headrotation_with_binary_hrir(
    test_info, in_fmt, out_fmt, trj_file, frame_size, hrtf_tag
):
    if out_fmt in ["BINAURAL_ROOM_IR", "BINAURAL_ROOM_REVERB"]:
        pytest.skip("Skipping binaural room outputs for MASA as unimplemented.")

    compare_renderer_with_binary_fix_vs_with_binary_float(
        test_info,
        in_fmt,
        out_fmt,
        hrtf_tag,
        trj_file=HR_TRAJECTORY_DIR.joinpath(f"{trj_file}.csv"),
        in_meta_files=FORMAT_TO_METADATA_FILES_RENDERER[in_fmt],
    )


""" Custom loudspeaker layouts """


@pytest.mark.parametrize("out_fmt", OUTPUT_FORMATS_BINAURAL)
@pytest.mark.parametrize("in_layout", CUSTOM_LS_TO_TEST)
@pytest.mark.parametrize("frame_size", FRAMING_TO_TEST)
@pytest.mark.parametrize("hrtf_tag", HRTF_TAGS_FILES_FOR_FX_SAME_AS_FLOAT)
def test_custom_ls_input_binaural_with_binary_hrir(
    test_info, in_layout, out_fmt, frame_size, hrtf_tag
):
    compare_renderer_with_binary_fix_vs_with_binary_float(
        test_info,
        CUSTOM_LAYOUT_DIR.joinpath(f"{in_layout}.txt"),
        out_fmt,
        hrtf_tag,
        frame_size=frame_size,
    )


@pytest.mark.parametrize("trj_file", HR_TRAJECTORIES_TO_TEST_RENDERER)
@pytest.mark.parametrize("out_fmt", OUTPUT_FORMATS_BINAURAL)
@pytest.mark.parametrize("in_layout", CUSTOM_LS_TO_TEST)
@pytest.mark.parametrize("frame_size", FRAMING_TO_TEST)
@pytest.mark.parametrize("hrtf_tag", HRTF_TAGS_FILES_FOR_FX_SAME_AS_FLOAT)
def test_custom_ls_input_binaural_headrotation_with_binary_hrir(
    test_info, in_layout, out_fmt, trj_file, frame_size, hrtf_tag
):
    compare_renderer_with_binary_fix_vs_with_binary_float(
        test_info,
        CUSTOM_LAYOUT_DIR.joinpath(f"{in_layout}.txt"),
        out_fmt,
        hrtf_tag,
        trj_file=HR_TRAJECTORY_DIR.joinpath(f"{trj_file}.csv"),
        frame_size=frame_size,
    )
+74 −0
Original line number Diff line number Diff line
@@ -398,3 +398,77 @@ def compare_renderer_vs_renderer_with_binary_hrir(
    if keep_file == False:
        os.remove(ref_out)
        os.remove(cut_out)
        
        
def compare_renderer_with_binary_fix_vs_with_binary_float(
    test_info,
    in_fmt,
    out_fmt,
    hrtf_tag,
    metadata_input: Optional[str] = None,
    in_meta_files: Optional[list] = None,
    trj_file: Optional[str] = None,
    non_diegetic_pan: Optional[str] = None,
    name_extension: Optional[str] = uuid.uuid1(),
    refrot_file: Optional[str] = None,
    refvec_file: Optional[str] = None,
    refveclev_file: Optional[str] = None,
    config_file: Optional[str] = None,
    frame_size: Optional[str] = "20ms",
    keep_file=False,
):
    hrtf_file = HRTF_TAGS_FILES_FOR_FX_SAME_AS_FLOAT[hrtf_tag][0]
    hrtf_file_fx = HRTF_TAGS_FILES_FOR_FX_SAME_AS_FLOAT[hrtf_tag][1]

    hrtf_file_dir = SCRIPTS_DIR.joinpath(
        "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,
        test_info,
        in_fmt,
        out_fmt,
        metadata_input,
        in_meta_files,
        trj_file,
        non_diegetic_pan,
        name_extension,
        refrot_file,
        refvec_file,
        refveclev_file,
        config_file,
        hrtf_file=hrtf_file_path,
        frame_size=frame_size,
    )
    cut_out = run_renderer(
        None,
        test_info,
        in_fmt,
        out_fmt,
        metadata_input,
        in_meta_files,
        trj_file,
        non_diegetic_pan,
        name_extension,
        refrot_file,
        refvec_file,
        refveclev_file,
        config_file,
        hrtf_file=hrtf_file_path_fx,
        frame_size=frame_size,
    )

    ref, ref_fs = pyaudio3dtools.audiofile.readfile(ref_out)
    cut, cut_fs = pyaudio3dtools.audiofile.readfile(cut_out)

    check_BE(test_info, ref, ref_fs, cut, cut_fs, 0)
    if keep_file == False:
        os.remove(ref_out)
        os.remove(cut_out)