Commit 5d3c7976 authored by Jan Kiene's avatar Jan Kiene
Browse files

Merge branch 'ci/mld-playback-level-instead-of-rescaling' into 'main'

[CI] mld playback level instead of rescaling

See merge request !2527
parents b98b20b2 5cfe2025
Loading
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -248,7 +248,8 @@ def compare(
    test_start_offset_ms: int = 0,
    ref_jbm_tf: Optional[Union[Path, str]] = None,
    test_jbm_tf: Optional[Union[Path, str]] = None,
    handle_differing_lengths: HandleDifferingLengths = "fail",
    handle_differing_lengths: HandleDifferingLengths = HandleDifferingLengths.FAIL,
    mld_playback_level: float = 92.0,
) -> dict:
    """Compare two audio arrays

@@ -390,6 +391,8 @@ def compare(
                # wav-diff return code is 1 if differences are found which
                # would cause parse_wav_diff to raise an Exception on these cases
                "--no-fail",
                "--mld-playback-level",
                f"{mld_playback_level}",
                str(tmpfile_ref),
                str(tmpfile_test),
            ]
+21 −4
Original line number Diff line number Diff line
@@ -42,6 +42,7 @@ def cmp_pcm(
    cut_jbm_tf: Optional[Path] = None,
    quiet: Optional[bool] = False,
    scalefac: int = 1,
    mld_playback_level: float = 92.0,
    split_idx: np.ndarray = np.empty(0),
) -> tuple[List[int], List[str]]:
    """
@@ -111,6 +112,7 @@ def cmp_pcm(
            ref_jbm_tf=ref_jbm_tf,
            test_jbm_tf=cut_jbm_tf,
            handle_differing_lengths=handle_differing_lengths,
            mld_playback_level=mld_playback_level,
        )

        output_differs = 0
@@ -146,7 +148,9 @@ def cmp_pcm(

        if get_odg:
            for n in range(nchannels):
                pqeval_output = pqevalaudio_wrapper(s1[:, n], s2[:, n], fs)
                pqeval_output = pqevalaudio_wrapper(
                    s1[:, n], s2[:, n], fs, mld_playback_level
                )

                match_odg = re.search(ODG_PATTERN_PQEVALAUDIO, pqeval_output)
                odg = float(match_odg.groups()[0])
@@ -168,7 +172,7 @@ def cmp_pcm(
                ).astype(np.int16)

            pqeval_output = pqevalaudio_wrapper(
                odg_files[odg_input], odg_files[odg_ref], 48000
                odg_files[odg_input], odg_files[odg_ref], 48000, mld_playback_level
            )
            match_odg = re.search(ODG_PATTERN_PQEVALAUDIO, pqeval_output)
            try:
@@ -177,7 +181,7 @@ def cmp_pcm(
                raise OdgParsingFailed("Could not get Odg for ref signal")

            pqeval_output = pqevalaudio_wrapper(
                odg_files[odg_input], odg_files[odg_test], 48000
                odg_files[odg_input], odg_files[odg_test], 48000, mld_playback_level
            )
            match_odg = re.search(ODG_PATTERN_PQEVALAUDIO, pqeval_output)
            try:
@@ -208,6 +212,7 @@ def pqevalaudio_wrapper(
    ref_sig: np.ndarray,
    eval_sig: np.ndarray,
    fs: int,
    playback_level: float = 92.0,
) -> str:
    with tempfile.TemporaryDirectory() as tmp_dir:
        tmp_dir = Path(tmp_dir)
@@ -229,7 +234,13 @@ def pqevalaudio_wrapper(
        pyaudio3dtools.audiofile.writefile(tmp_file_ref, r48, 48000)
        pyaudio3dtools.audiofile.writefile(tmp_file_eval, t48, 48000)

        cmd = ["PQevalAudio", tmp_file_ref, tmp_file_eval]
        cmd = [
            "PQevalAudio",
            "--levelSPL",
            f"{playback_level}",
            tmp_file_ref,
            tmp_file_eval,
        ]

        result = subprocess.run(cmd, capture_output=True)
        if result.returncode != 0:
@@ -277,6 +288,12 @@ if __name__ == "__main__":
        dest="scalefac",
        help="Scale factor to be applied before comparing the output. Useful when input scaling has been applied.",
    )
    parser.add_argument(
        "--mld-playback-level",
        type=float,
        help="Playback level arg for MLD in wav-diff",
        default=92.0,
    )
    parser.add_argument("--quiet", action="store_true")
    args = vars(parser.parse_args())

+10 −6
Original line number Diff line number Diff line
@@ -545,7 +545,12 @@ def run_test(
                str(f).replace(dut_base_path, reference_path) for f in dut_dmx_files
            ]

            prop_results = compare_dmx_signals(ref_dmx_files, dut_dmx_files, in_sr)
            prop_results = compare_dmx_signals(
                ref_dmx_files,
                dut_dmx_files,
                in_sr,
                test_info.config.options.mld_playback_level,
            )
            for prop, val in prop_results.items():
                dut_decoder_frontend.record_property(prop, val)

@@ -639,7 +644,7 @@ def run_test(
            odg_ref=odg_ref,
            ref_jbm_tf=ref_tracefile_dec,
            cut_jbm_tf=dut_tracefile_dec,
            scalefac=test_info.config.option.scalefac,
            mld_playback_level=test_info.config.option.mld_playback_level,
            split_idx=split_idx,
        )

@@ -669,7 +674,7 @@ def run_test(
                odg_ref=odg_ref,
                ref_jbm_tf=ref_tracefile_dec,
                cut_jbm_tf=dut_tracefile_dec,
                scalefac=test_info.config.option.scalefac,
                mld_playback_level=test_info.config.option.mld_playback_level,
                split_idx=split_idx,
            )
            output_differs_parts += output_differs_splits
@@ -725,9 +730,8 @@ def run_test(
            if this_meta_differs == False:
                if dut_metadata_file.suffix == ".met":
                    this_meta_differs = check_masa_meta_diff(
                        ref=ref_metadata_file,
                        dut=dut_metadata_file,
                        print_stdout=True)
                        ref=ref_metadata_file, dut=dut_metadata_file, print_stdout=True
                    )
                else:
                    if not filecmp.cmp(dut_metadata_file, ref_metadata_file):
                        print("Output metadata differs for file: " + md_file)
+13 −3
Original line number Diff line number Diff line
@@ -180,6 +180,7 @@ def test_pca_enc(
            plc_pattern=plc_pattern,
            get_enc_stats=get_enc_stats,
            compare_enc_dmx=compare_enc_dmx,
            mld_playback_level=test_info.config.option.mld_playback_level,
        )

    if not encoder_only:
@@ -337,6 +338,7 @@ def test_sba_enc_system(
            plc_pattern=plc_pattern,
            get_enc_stats=get_enc_stats,
            compare_enc_dmx=compare_enc_dmx,
            mld_playback_level=test_info.config.option.mld_playback_level,
        )

        if update_ref == 0 and get_enc_stats:
@@ -490,6 +492,7 @@ def test_spar_hoa2_enc_system(
            plc_pattern=plc_pattern,
            get_enc_stats=get_enc_stats,
            compare_enc_dmx=compare_enc_dmx,
            mld_playback_level=test_info.config.option.mld_playback_level,
        )

        if update_ref == 0 and get_enc_stats:
@@ -643,6 +646,7 @@ def test_spar_hoa3_enc_system(
            plc_pattern=plc_pattern,
            get_enc_stats=get_enc_stats,
            compare_enc_dmx=compare_enc_dmx,
            mld_playback_level=test_info.config.option.mld_playback_level,
        )

        if get_enc_stats:
@@ -811,6 +815,7 @@ def test_sba_enc_BWforce_system(
            plc_pattern=plc_pattern,
            get_enc_stats=get_enc_stats,
            compare_enc_dmx=compare_enc_dmx,
            mld_playback_level=test_info.config.option.mld_playback_level,
        )

        if update_ref == 0 and get_enc_stats:
@@ -1003,6 +1008,7 @@ def test_sba_plc_system(
            plc_pattern=plc_pattern,
            get_enc_stats=get_enc_stats,
            compare_enc_dmx=compare_enc_dmx,
            mld_playback_level=test_info.config.option.mld_playback_level,
        )

    if not encoder_only:
@@ -1067,6 +1073,7 @@ def sba_enc(
    plc_pattern=None,
    get_enc_stats=False,
    compare_enc_dmx=False,
    mld_playback_level=92.0,
):
    input_path = f"{test_vector_path}/{tag}.wav"
    dtx_mode = dtx == "1"
@@ -1157,7 +1164,10 @@ def sba_enc(
        ]

        prop_results = compare_dmx_signals(
            ref_dmx_files, dut_dmx_files, int(sampling_rate)
            ref_dmx_files,
            dut_dmx_files,
            int(sampling_rate),
            mld_playback_level,
        )
        for prop, val in prop_results.items():
            dut_encoder_frontend.record_property(prop, val)
@@ -1348,7 +1358,7 @@ def sba_dec(
            odg_input=odg_input,
            odg_test=odg_test,
            odg_ref=odg_ref,
            scalefac=test_info.config.option.scalefac,
            mld_playback_level=test_info.config.option.mld_playback_level,
            split_idx=split_idx,
        )

@@ -1376,7 +1386,7 @@ def sba_dec(
                odg_input=odg_input,
                odg_test=odg_test,
                odg_ref=odg_ref,
                scalefac=test_info.config.option.scalefac,
                mld_playback_level=test_info.config.option.mld_playback_level,
                split_idx=split_idx,
            )
            output_differs_parts += output_differs_splits
+12 −1
Original line number Diff line number Diff line
@@ -317,6 +317,14 @@ def pytest_addoption(parser):
        default=1,
    )

    parser.addoption(
        "--mld-playback-level",
        action="store",
        help="Playback level arg for MLD calulcation.",
        type=float,
        default=92.0,
    )

    parser.addoption(
        "--split-comparison",
        action="store_true",
@@ -449,6 +457,7 @@ def test_info(request):
    if hasattr(request, "error"):
        pytest.fail(request.error)


@pytest.hookimpl(hookwrapper=True)
def pytest_runtest_makereport(item, call):
    # Use hook to catch exceptions
@@ -464,6 +473,7 @@ def pytest_runtest_makereport(item, call):
            # Capture exception in test_info
            test_info.error = str(call.excinfo.value)


@pytest.fixture(scope="session")
def split_comparison(request):
    return request.config.option.split_comparison
@@ -1248,7 +1258,7 @@ class MaxDiffPatternNotFound(Exception):
    pass


def compare_dmx_signals(ref_dmx_files, dut_dmx_files, fs) -> dict:
def compare_dmx_signals(ref_dmx_files, dut_dmx_files, fs, mld_playback_level) -> dict:
    nchannels = len(dut_dmx_files)
    with NamedTemporaryFile(suffix=".ref_dmx.pcm") as dmx_file_ref_tmp:
        with NamedTemporaryFile(suffix=".dut_dmx.pcm") as dmx_file_dut_tmp:
@@ -1265,6 +1275,7 @@ def compare_dmx_signals(ref_dmx_files, dut_dmx_files, fs) -> dict:
                in_fs=fs * 1000,
            )

            # TODO: needs mld-playback-level
            dmx_differs, reason = cmp_pcm(
                dmx_file_ref_tmp.name,
                dmx_file_dut_tmp.name,
Loading