Commit 143afb2d authored by Lauros Pajunen's avatar Lauros Pajunen
Browse files

Use the new fmtsw encoder in test

parent 8d19d964
Loading
Loading
Loading
Loading
Loading
+12 −6
Original line number Diff line number Diff line
@@ -570,6 +570,7 @@ class EncoderFrontend:
        run_dir: Optional[Path] = None,
        stats_file: Optional[Path] = None,
        compare_enc_dmx: Optional[bool] = False,
        fmtsw_command: Optional[bool] = False,
    ) -> None:
        command = [str(self._path)]

@@ -593,6 +594,11 @@ class EncoderFrontend:
            command.extend(add_option_list)

        # add mandatory parameters
        if fmtsw_command:
            command += [
                str(input_path),
            ]
        else:
            command += [
                str(bitrate),
                str(input_sampling_rate),
+73 −0
Original line number Diff line number Diff line
@@ -55,6 +55,9 @@ from tests.renderer.constants import (
    FORMAT_TO_METADATA_FILES,
)
from ivasrtp import *
import platform

BIN_EXT = ".exe" if platform.system() == "Windows" else ""

FORMAT_ARGUMENT_MAPPING = {
    "MONO": [],
@@ -200,3 +203,73 @@ def test_format_switching (
                add_option_list= ["-VOIP_HF_ONLY=1"]
            )


def test_format_switching_new_encoder (
    record_property,
    dut_decoder_frontend: DecoderFrontend
):
    bitrate = 48000
    fs = 48
    bandwidth = "FB"
    outMode = "MONO"

    dut_encoder_path = Path(ROOT_DIR).joinpath(f"IVAS_cod{BIN_EXT}")
    dut_encoder_fmtsw_path = Path(ROOT_DIR).joinpath(f"IVAS_cod_fmtsw{BIN_EXT}")
    dut_encoder_fmtsw_frontend = EncoderFrontend(
        dut_encoder_fmtsw_path, "DUT", record_property
    )

    # Create 1s test files
    cut_suffix = "_cut.wav"
    test_file = Path( str(FORMAT_TO_FILE_COMPARETEST["MONO"]).replace(".wav", cut_suffix) )
    if not test_file.exists():
        create_short_testvectors(1.0, False, None)

    with TemporaryDirectory() as tmp_dir:

        # Create file for encoding commands
        temp_format_switching_file = Path(tmp_dir).joinpath("format_switching_input.txt").absolute()
        temp_rtpdump = Path(tmp_dir).joinpath("output_concatenated.rtpdump").absolute()
        with open (temp_format_switching_file, mode="a") as outFile:
            for key, audioFile in FORMAT_TO_FILE_COMPARETEST.items():
                if key in ["META", "16ch_8+4+4", "4d4", "t_design_4"]:
                    break

                encoder_args = []
                encoder_args += [str(dut_encoder_path)]
                encoder_args += ["-rtpdump", "1"]
                encoder_args += FORMAT_ARGUMENT_MAPPING[key]
                if key in FORMAT_TO_METADATA_FILES:
                    encoder_args += FORMAT_TO_METADATA_FILES[key]
                elif "SBA" in key:
                    # ISM metadata files for OSBA
                    encoder_args += FORMAT_TO_METADATA_FILES[key[:4]]
                encoder_args += [str(bitrate)]
                encoder_args += [str(fs)]
                cutFile = Path( str(audioFile).replace(".wav", cut_suffix) )
                encoder_args += [str(cutFile)]
                encoder_args += [str(temp_rtpdump)]

                outFile.write(' '.join(encoder_args))
                outFile.write("\n")

        # Encode with the format switch encoder
        dut_encoder_fmtsw_frontend.run(
            bitrate='',
            input_sampling_rate='',
            input_path=temp_format_switching_file,
            output_bitstream_path='',
            quiet_mode=False,
            fmtsw_command=True
        )

        # Decode the combined bitstreams
        cat_output_rtpdump = Path(tmp_dir).joinpath(f"output_concatenated.wav").absolute()

        dut_decoder_frontend.run(
            output_config=outMode,
            output_sampling_rate=48,
            input_bitstream_path=temp_rtpdump,
            output_path=cat_output_rtpdump,
            add_option_list= ["-VOIP_HF_ONLY=1"]
        )