Commit 88bd93b6 authored by Lauros Pajunen's avatar Lauros Pajunen
Browse files

Remove combined orientation test file and trajectories

parent 99d7755b
Loading
Loading
Loading
Loading
+0 −4
Original line number Diff line number Diff line
0.965926,0.00,0.00,0.258819,1,0,0,0
0.965926,0.00,0.00,0.258819,1,0,0,0
0.965926,0.00,0.00,0.258819,1,0,0,0
0.965926,0.00,0.00,0.258819,1,0,0,0
 No newline at end of file
+0 −4
Original line number Diff line number Diff line
0.965926,0.00,0.00,0.258819,0,1,0,0
0.965926,0.00,0.00,0.258819,0,1,0,0
0.965926,0.00,0.00,0.258819,0,1,0,0
0.965926,0.00,0.00,0.258819,0,1,0,0
 No newline at end of file
+0 −4
Original line number Diff line number Diff line
0.965926,0.00,0.00,0.258819,0,0,0,0
0.965926,0.00,0.00,0.258819,0,0,0,0
0.965926,0.00,0.00,0.258819,0,0,0,0
0.965926,0.00,0.00,0.258819,0,0,0,0
 No newline at end of file
+0 −4
Original line number Diff line number Diff line
-0.965926,-0.00,0.00,0.258819
-0.965926,-0.00,0.00,0.258819
-0.965926,-0.00,0.00,0.258819
-0.965926,-0.00,0.00,0.258819
 No newline at end of file
+0 −181
Original line number Diff line number Diff line
__copyright__ = \
    """
    (C) 2022-2023 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.
    """

__doc__ = \
    """
    Test file to run C encoder and decoder code.
    The outputs are compared with C generated references.
    """

import os
import errno
import pytest

from cmp_pcm import cmp_pcm
from conftest import EncoderFrontend, DecoderFrontend

# params
input_mode_list = ['ism', 'sba', 'masa', 'mc']
output_mode_list = ['BINAURAL', 'BINAURAL_ROOM']
ivas_br_list = [13200, 16400, 24400, 32000, 48000, 64000, 80000,
                96000, 128000, 160000, 192000, 256000, 384000, 512000]

head_ext_reference_list = [# Head rotation disabled, constant 30 degree external orientation --> output should be flipped external orientation, constant -30 degrees
                           ('full-circle-4s.csv', 'const030_noHead_enableExt.csv', 'const_minus030.csv'),
                           # Constant 240 degree head rotation, ext orientation disabled --> output should be same as head rotation, constant 240 degrees
                           ('const240.csv', 'const030_enableHead_noExt.csv', 'const240.csv'),
                           # Head rotation disabled, external orientation disabled --> output should be same as no rotation applied
                           ('full-circle-4s.csv', 'const030_noHead_noExt.csv', None, 'const000.csv'),
                           # Constant 30 degrees head rotation, constant 30 degrees external orientation --> rotations counter each other, output should be zero rotations (due to numerical errors the output is not exactly BE)
                           ('const030.csv', 'const030.csv', 'const000.csv')]


def check_and_makedir(dir_path):
    if not os.path.exists(dir_path):
        try:
            os.makedirs(dir_path)
        except OSError as e:
            if e.errno != errno.EEXIST:
                raise  # raises the error again


@pytest.mark.parametrize("input_mode", input_mode_list)
@pytest.mark.parametrize("output_mode", output_mode_list)
@pytest.mark.parametrize("ivas_br", ivas_br_list)
@pytest.mark.parametrize("head_ext_reference", head_ext_reference_list)
def test_combined_orientations(
    dut_encoder_frontend: EncoderFrontend,
    dut_decoder_frontend: DecoderFrontend,
    ref_encoder_path,
    ref_decoder_path,
    reference_path,
    dut_base_path,
    ivas_br,
    head_ext_reference,
    test_vector_path,
    input_mode,
    output_mode,
):
    if input_mode == "ism" and ivas_br < 24400:
        pytest.skip("ISM4 supported for bitrates above and including 24.4kbps")

    # Input parameters
    in_fs = 48
    out_fs = 48
    out_fs_hz = 48000
    head_rotation_file = head_ext_reference[0]
    ext_orientation_file = head_ext_reference[1]
    reference_rotation_file = head_ext_reference[2]
    head_rotation_file_path = f"{test_vector_path}/../trajectories/{head_rotation_file}"
    ext_orientation_file_path = f"{test_vector_path}/../trajectories/{ext_orientation_file}"

    # Set reference encoder and decoder
    if ref_encoder_path is None and ref_decoder_path is None:
        ref_encoder_frontend = dut_encoder_frontend
        ref_decoder_frontend = dut_decoder_frontend
    else:
        ref_encoder_frontend = EncoderFrontend(ref_encoder_path, "REF")
        ref_decoder_frontend = DecoderFrontend(ref_decoder_path, "REF")

    # Set output paths
    out_dir_bs_ref = f"{reference_path}/combined_orientations"
    out_dir_bs_dut = f"{dut_base_path}/combined_orientations"
    check_and_makedir(out_dir_bs_ref)
    check_and_makedir(out_dir_bs_dut)
    output_bitstream_ref = f"{out_dir_bs_ref}/inputmode{input_mode}_outputmode{output_mode}_ivasbr{ivas_br}k_head{head_rotation_file}_ext{ext_orientation_file}_ref{reference_rotation_file}_ref.bts"
    output_bitstream_dut = f"{out_dir_bs_dut}/inputmode{input_mode}_outputmode{output_mode}_ivasbr{ivas_br}k_head{head_rotation_file}_ext{ext_orientation_file}_ref{reference_rotation_file}.bts"
    dec_output_ref = f"{out_dir_bs_ref}/inputmode{input_mode}_outputmode{output_mode}_ivasbr{ivas_br}k_head{head_rotation_file}_ext{ext_orientation_file}_ref{reference_rotation_file}_ref.wav"
    dec_output_dut = f"{out_dir_bs_dut}/inputmode{input_mode}_outputmode{output_mode}_ivasbr{ivas_br}k_head{head_rotation_file}_ext{ext_orientation_file}_ref{reference_rotation_file}_test.wav"

    # Set options
    if input_mode == "ism":
        input_options = ['-ism', '4', f"{test_vector_path}/stvISM1.csv", f"{test_vector_path}/stvISM2.csv", f"{test_vector_path}/stvISM3.csv", f"{test_vector_path}/stvISM4.csv"]
        input_audio_path = f"{test_vector_path}/stv4ISM48s.wav"
    elif input_mode == "sba":
        input_options = ['-sba', '1']
        input_audio_path = f"{test_vector_path}/stvFOA48c.wav"
    elif input_mode == "masa":
        input_options = ['-masa', '2', f"{test_vector_path}/stv1MASA2TC48c.met"]
        input_audio_path = f"{test_vector_path}/stv1MASA2TC48c.wav"
    elif input_mode == "mc":
        input_options = ['-mc', '5_1']
        input_audio_path = f"{test_vector_path}/stv51MC48c.wav"

        # In MC binaural output, a different renderer is used if head rotation or external orientation file is detected
        # in the input. Instead of not using a head rotation file, use zero head rotation for reference so that the same
        # renderer is used in both cases (test head + ext, reference head).
        if reference_rotation_file is None and output_mode == "BINAURAL":
            reference_rotation_file = head_ext_reference[3]

    test_output_options = ['-T', f"{head_rotation_file_path}", '-EXOF', f"{ext_orientation_file_path}"]
    ref_output_options = []
    if reference_rotation_file is not None:
        reference_rotation_file_path = f"{test_vector_path}/../trajectories/{reference_rotation_file}"
        ref_output_options = ['-T', f"{reference_rotation_file_path}"]

    # Encode
    dut_encoder_frontend.run(
        ivas_br,
        in_fs,
        input_audio_path,
        output_bitstream_dut,
        add_option_list=input_options,
    )
    ref_encoder_frontend.run(
        ivas_br,
        in_fs,
        input_audio_path,
        output_bitstream_ref,
        add_option_list=input_options,
    )

    # Decode head + ext
    dut_decoder_frontend.run(
        output_mode,
        out_fs,
        output_bitstream_dut,
        dec_output_dut,
        add_option_list=test_output_options
    )

    # Decode reference
    ref_decoder_frontend.run(
        output_mode,
        out_fs,
        output_bitstream_ref,
        dec_output_ref,
        add_option_list=ref_output_options
    )

    # Compare audio outputs
    cmp_result, reason = cmp_pcm(dec_output_ref, dec_output_dut, output_mode, out_fs_hz)
    # Report compare result
    assert cmp_result == 0, reason