Commit 6f1bb9ec authored by sagnowski's avatar sagnowski
Browse files

Move test_voip_be_splitrend_vs_binaural into a separate file and CI job

parent bd046407
Loading
Loading
Loading
Loading
Loading
+23 −1
Original line number Diff line number Diff line
@@ -680,7 +680,7 @@ split-rendering-smoke-test:
  stage: test
  script:
    - make -j
    - testcase_timeout=30
    - testcase_timeout=10
    - python3 -m pytest -q -n auto -rA --junit-xml=report-junit.xml tests/split_rendering/test_split_rendering.py --testcase_timeout=$testcase_timeout
  artifacts:
    name: "mr-$CI_MERGE_REQUEST_IID--sha-$CI_COMMIT_SHORT_SHA--job-$CI_JOB_NAME--results"
@@ -693,6 +693,28 @@ split-rendering-smoke-test:
      junit:
        - report-junit.xml

# test split rendering in VoIP mode against BINAURAL output
split-rendering-voip-be-to-binaural:
  extends:
    - .test-job-linux
    - .rules-merge-request-to-main
  needs: ["build-codec-linux-make"]
  stage: test
  script:
    - make -j
    - testcase_timeout=30
    - python3 -m pytest -q -n auto -rA --junit-xml=report-junit.xml tests/split_rendering/test_voip_be_splitrend_vs_binaural.py --testcase_timeout=$testcase_timeout
  artifacts:
    name: "mr-$CI_MERGE_REQUEST_IID--sha-$CI_COMMIT_SHORT_SHA--job-$CI_JOB_NAME--results"
    expire_in: 1 week
    when: always
    paths:
      - report-junit.xml
    expose_as: "VoIP split rendering vs BINAURAL make pytest results"
    reports:
      junit:
        - report-junit.xml

lc3-wrapper-unit-test:
  extends:
    - .test-job-linux
+1 −118
Original line number Diff line number Diff line
@@ -32,18 +32,8 @@

import pytest

from tempfile import TemporaryDirectory
from pathlib import Path
import filecmp

from tests.split_rendering.utils import *
from tests.split_rendering.constants import SCRIPTS_DIR, TESTV_DIR
from tests.test_be_for_jbm_neutral_dly_profile import (
    INPUT_FILES,
    get_options_cod,
)
from split_rendering.isar_bstool import IsarBitstream
from pyaudio3dtools import audioarray, audiofile

 
""" Ambisonics """

@@ -595,110 +585,3 @@ def test_framing_combinations_full_chain_split(
        get_odg=get_odg,
        get_odg_bin=get_odg_bin,        
    )


IN_FORMATS = [
    "MC_5_1",
    "ISM4",
    "FOA",
    "MASA2TC",
    # Mixed formats to be finalised in a follow-up issue
    # "OSBA_ISM3_HOA3",
    # "OMASA_ISM4",
]

DELAY_PROFILES = ["dly_error_profile_0.dat", "dly_error_profile_5.dat"]


# Compares PCM output and tracefile from a VoIP BINAURAL_SPLIT_PCM chain with equivalent BINAURAL
# chain to ensure time-scaling and other JBM operations are BE between the two.
@pytest.mark.parametrize("in_format", IN_FORMATS)
@pytest.mark.parametrize("delay_profile", DELAY_PROFILES)
def test_voip_be_splitrend_vs_binaural(
    in_format,
    delay_profile,
    dut_encoder_frontend,
    dut_decoder_frontend,
    bitrate=128000,
):
    with TemporaryDirectory() as tmp_dir:
        tmp_dir = Path(tmp_dir)

        sampling_rate_khz = 48
        delay_profile_path = SCRIPTS_DIR / "dly_error_profiles" / delay_profile
        delay_profile_id = int(delay_profile[-5])

        # run encoder
        bitstream_file = (tmp_dir / f"{in_format}-dly{delay_profile_id}.192").absolute()
        dtx = False
        wav_in = TESTV_DIR / INPUT_FILES[in_format]
        dut_encoder_frontend.run(
            bitrate,
            sampling_rate_khz,
            wav_in,
            bitstream_file,
            add_option_list=get_options_cod(in_format, dtx),
            run_dir=tmp_dir,
        )

        def run_decoder(out_format):
            options = []

            # Head trajectory must be static due to the slight time shift between audio outputs of BINAURAL/SPLIT_PCM
            head_traj = Path(SCRIPTS_DIR /  "trajectories/const000.csv")
            options.extend(["-T", str(head_traj)])

            wav_out = (
                tmp_dir
                / f"{in_format}-{bitrate}-{out_format}-dly{delay_profile_id}.wav"
            ).absolute()

            trace_out = wav_out.with_suffix(".trace")
            options.extend(["-Tracefile", str(trace_out)])

            if out_format == "BINAURAL_SPLIT_PCM":
                isar_md_file = wav_out.with_suffix(".isarmd")
                options.extend(["-om", str(isar_md_file)])
            else:
                isar_md_file = None

            dut_decoder_frontend.run(
                out_format,
                sampling_rate_khz,
                bitstream_file,
                wav_out,
                netsim_profile=delay_profile_path,
                add_option_list=options,
            )

            return wav_out, trace_out, isar_md_file

        wav_out_bin, trace_out_bin, _ = run_decoder("BINAURAL")
        wav_out_sr, trace_out_sr, isar_md_out_sr = run_decoder("BINAURAL_SPLIT_PCM")

        # Delay-align audio
        assert isar_md_out_sr is not None
        sr_delay_samples = IsarBitstream(isar_md_out_sr).delay_samples
        audio_sr, _ = audiofile.readfile(str(wav_out_sr))
        audio_bin, _ = audiofile.readfile(str(wav_out_bin))
        audio_sr = audio_sr[sr_delay_samples:]
        audio_bin = audio_bin[:-sr_delay_samples]

        # Ensure audio and tracefiles are BE
        audio_cmp_result = audioarray.compare(
            audio_bin, audio_sr, fs=sampling_rate_khz * 1000, per_frame=False
        )
        tracefiles_equal = filecmp.cmp(trace_out_bin, trace_out_sr)
        failed = not audio_cmp_result["bitexact"] or not tracefiles_equal
        if failed:
            message = []
            if not audio_cmp_result["bitexact"]:
                message.append(
                    "Difference found between delay-aligned BINAURAL audio and BINAURAL_SPLIT_PCM audio! "
                    f"Max abs diff: {audio_cmp_result['max_abs_diff']}"
                )
            if not tracefiles_equal:
                message.append(
                    "Difference found between BINAURAL tracefile and BINAURAL_SPLIT_PCM tracefile!"
                )
            pytest.fail("; ".join(message))
+152 −0
Original line number Diff line number Diff line
#!/usr/bin/env python3

"""
   (C) 2022-2025 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 tempfile import TemporaryDirectory
from pathlib import Path
import filecmp

from tests.split_rendering.utils import *
from tests.split_rendering.constants import SCRIPTS_DIR, TESTV_DIR
from tests.test_be_for_jbm_neutral_dly_profile import (
    INPUT_FILES,
    get_options_cod,
)
from split_rendering.isar_bstool import IsarBitstream
from pyaudio3dtools import audioarray, audiofile

IN_FORMATS = [
    "MC_5_1",
    "ISM4",
    "FOA",
    "MASA2TC",
    # Mixed formats to be finalised in a follow-up issue
    # "OSBA_ISM3_HOA3",
    # "OMASA_ISM4",
]

DELAY_PROFILES = ["dly_error_profile_0.dat", "dly_error_profile_5.dat"]


# Compares PCM output and tracefile from a VoIP BINAURAL_SPLIT_PCM chain with equivalent BINAURAL
# chain to ensure time-scaling and other JBM operations are BE between the two.
@pytest.mark.parametrize("in_format", IN_FORMATS)
@pytest.mark.parametrize("delay_profile", DELAY_PROFILES)
def test_voip_be_splitrend_vs_binaural(
    in_format,
    delay_profile,
    dut_encoder_frontend,
    dut_decoder_frontend,
    bitrate=128000,
):
    with TemporaryDirectory() as tmp_dir:
        tmp_dir = Path(tmp_dir)

        sampling_rate_khz = 48
        delay_profile_path = SCRIPTS_DIR / "dly_error_profiles" / delay_profile
        delay_profile_id = int(delay_profile[-5])

        # run encoder
        bitstream_file = (tmp_dir / f"{in_format}-dly{delay_profile_id}.192").absolute()
        dtx = False
        wav_in = TESTV_DIR / INPUT_FILES[in_format]
        dut_encoder_frontend.run(
            bitrate,
            sampling_rate_khz,
            wav_in,
            bitstream_file,
            add_option_list=get_options_cod(in_format, dtx),
            run_dir=tmp_dir,
        )

        def run_decoder(out_format):
            options = []

            # Head trajectory must be static due to the slight time shift between audio outputs of BINAURAL/SPLIT_PCM
            head_traj = Path(SCRIPTS_DIR /  "trajectories/const000.csv")
            options.extend(["-T", str(head_traj)])

            wav_out = (
                tmp_dir
                / f"{in_format}-{bitrate}-{out_format}-dly{delay_profile_id}.wav"
            ).absolute()

            trace_out = wav_out.with_suffix(".trace")
            options.extend(["-Tracefile", str(trace_out)])

            if out_format == "BINAURAL_SPLIT_PCM":
                isar_md_file = wav_out.with_suffix(".isarmd")
                options.extend(["-om", str(isar_md_file)])
            else:
                isar_md_file = None

            dut_decoder_frontend.run(
                out_format,
                sampling_rate_khz,
                bitstream_file,
                wav_out,
                netsim_profile=delay_profile_path,
                add_option_list=options,
            )

            return wav_out, trace_out, isar_md_file

        wav_out_bin, trace_out_bin, _ = run_decoder("BINAURAL")
        wav_out_sr, trace_out_sr, isar_md_out_sr = run_decoder("BINAURAL_SPLIT_PCM")

        # Delay-align audio
        assert isar_md_out_sr is not None
        sr_delay_samples = IsarBitstream(isar_md_out_sr).delay_samples
        audio_sr, _ = audiofile.readfile(str(wav_out_sr))
        audio_bin, _ = audiofile.readfile(str(wav_out_bin))
        audio_sr = audio_sr[sr_delay_samples:]
        audio_bin = audio_bin[:-sr_delay_samples]

        # Ensure audio and tracefiles are BE
        audio_cmp_result = audioarray.compare(
            audio_bin, audio_sr, fs=sampling_rate_khz * 1000, per_frame=False
        )
        tracefiles_equal = filecmp.cmp(trace_out_bin, trace_out_sr)
        failed = not audio_cmp_result["bitexact"] or not tracefiles_equal
        if failed:
            message = []
            if not audio_cmp_result["bitexact"]:
                message.append(
                    "Difference found between delay-aligned BINAURAL audio and BINAURAL_SPLIT_PCM audio! "
                    f"Max abs diff: {audio_cmp_result['max_abs_diff']}"
                )
            if not tracefiles_equal:
                message.append(
                    "Difference found between BINAURAL tracefile and BINAURAL_SPLIT_PCM tracefile!"
                )
            pytest.fail("; ".join(message))
+2 −2
Original line number Diff line number Diff line
@@ -101,7 +101,7 @@ def is_split_rend(format) -> bool:


def get_options_cod(in_format, dtx):
    # NOTE: this function is shared with another test in tests/split_rendering/test_split_rendering.py
    # NOTE: this function is shared with another test in tests/split_rendering/test_voip_be_splitrend_vs_binaural.py
    options = list()

    if dtx:
@@ -169,7 +169,7 @@ def get_options_dec(
    return options


# NOTE: this list is shared with another test in tests/split_rendering/test_split_rendering.py
# NOTE: this list is shared with another test in tests/split_rendering/test_voip_be_splitrend_vs_binaural.py
INPUT_FILES = {
    "stereo": "stvST48n.wav",
    "ISM1": "stv1ISM48s.wav",