Commit c58578d7 authored by Ke Zhao's avatar Ke Zhao
Browse files

Refactor test vector truncation for BE tests, and add truncation for external mode

parent b58f0a07
Loading
Loading
Loading
Loading
+29 −17
Original line number Diff line number Diff line
@@ -37,12 +37,31 @@ from typing import Tuple

import numpy as np

from tests.cut_pcm import cut_samples
from tests.renderer.utils import check_BE, run_cmd, test_info
from tests.split_rendering.constants import *

sys.path.append(SCRIPTS_DIR)
from pyaudio3dtools.audiofile import readfile
from pyaudio3dtools.audiofile import readfile, writefile


def truncate_signal(
    in_file: Path,
    out_file: Path,
) -> None:
    """
    Truncate the signal in in_file to maximum INPUT_DURATION_SEC seconds,
    and write the truncated signal to out_file
    """
    data, fs = readfile(in_file)

    if data.ndim == 1:
        data_out = data[: INPUT_DURATION_SEC * fs]
    elif data.ndim == 2:
        data_out = data[: INPUT_DURATION_SEC * fs, :]
    else:
        raise ValueError(f"Cannot truncate data with dimension of {data.ndim}")

    writefile(out_file, data_out, fs)


def run_full_chain_split_rendering(
@@ -86,21 +105,10 @@ def run_full_chain_split_rendering(
        cmd[0] += binary_suffix
        cmd[1] = bitrate
        if is_comparetest:
            # Cut input if longer than INPUT_DURATION_SEC
            in_file = FORMAT_TO_FILE_COMPARETEST[in_fmt]
            in_data, in_fs = readfile(in_file)
            if len(in_data) > INPUT_DURATION_SEC * in_fs:
                cut_samples(
                    in_file=in_file,
                    out_file=cut_in_file,
                    num_channels=FORMAT_TO_NCHAN[in_fmt],
                    sample_rate=in_fs,
                    start=0,
                    duration=INPUT_DURATION_SEC,
                )
            truncate_signal(in_file, cut_in_file)

            cmd[3] = str(cut_in_file)
            else:
                cmd[3] = str(in_file)
        else:
            cmd[3] = str(FORMAT_TO_FILE_SMOKETEST[in_fmt])
        cmd[4] = str(ivas_bitstream)
@@ -162,6 +170,7 @@ def run_external_split_rendering(

    with TemporaryDirectory() as tmp_dir:
        tmp_dir = Path(tmp_dir)
        cut_in_file = tmp_dir.joinpath("cut_input.wav")
        split_bitstream = tmp_dir.joinpath("split.bit")
        if renderer_fmt == "BINAURAL_SPLIT_PCM":
            split_md_file = tmp_dir.joinpath("split_md.bin")
@@ -184,7 +193,10 @@ def run_external_split_rendering(
        cmd[0] += binary_suffix
        cmd[4] = str(render_config)
        if is_comparetest:
            cmd[6] = str(FORMAT_TO_FILE_COMPARETEST[in_fmt])
            in_file = FORMAT_TO_FILE_COMPARETEST[in_fmt]
            truncate_signal(in_file, cut_in_file)

            cmd[6] = str(cut_in_file)
        else:
            cmd[6] = str(FORMAT_TO_FILE_SMOKETEST[in_fmt])
        cmd[8] = in_fmt