Commit 83e6d3f6 authored by norvell's avatar norvell
Browse files

Truncate IVAS_rend metadata in PEAQ tests, if IVAS_dec does not include extended metadata

parent 6256c1da
Loading
Loading
Loading
Loading
Loading
+32 −6
Original line number Diff line number Diff line
@@ -406,9 +406,29 @@ def binauralize_input_and_output(

        # Identify metadata
        in_meta_files = [
            str(SCRIPTS_DIR.joinpath(m)) if m != "NULL" else m for m in re.findall(r"\b\S+\.csv|NULL\b", enc_opts)
            str(SCRIPTS_DIR.joinpath(m)) if m != "NULL" else m
            for m in re.findall(r"\b\S+\.csv|NULL\b", enc_opts)
        ]  # All .csv or NULL files in enc_opts are ISM metadata files.
        n_obj = len(in_meta_files)

        # If extended metadata is not used, strip the metadata for the external renderer
        extended_md_used = (
            re.search(r"-ism\s?\+[1-4]", enc_opts)
            and not "OMASA" in in_fmt
            and not "OSBA" in in_fmt
        )
        if not extended_md_used and n_obj > 0:
            truncated_meta_files = []
            for md in in_meta_files:
                md_out_file = str(tmp_dir.joinpath(os.path.basename(md)))
                with open(md_out_file, "w") as fp_out, open(md, "r") as fp_in:
                    for line in fp_in:
                        fp_out.write(
                            ",".join(line.split(",")[:2]) + "\n"
                        )  # Keep only first two elements: azim, elev
                truncated_meta_files.append(md_out_file)
            in_meta_files = truncated_meta_files

        in_meta_files = in_meta_files + [
            str(SCRIPTS_DIR.joinpath(m)) for m in re.findall(r"\b\S+\.met\b", enc_opts)
        ]  # All .met files in enc_opts are MASA metadata files.
@@ -564,13 +584,19 @@ def scene_description_file(in_fmt, metadata_tmp, n_obj, input_file, in_meta_file
                md_file = "1\n1,0,0"  # NULL metadata position: azim=0,elev=0 for 1 frame, looped throughout all frames.
            else:
                md_file = os.path.relpath(in_meta_files[n], currdir)
            fp_meta.write(f"ISM\n{n+1}\n{md_file}\n")  # ISM metadata
            if "OSBA" in in_fmt:
                fp_meta.write(
                f"ISM\n{n+1}\n{md_file}\n"
            )  # ISM metadata
                    "gain_dB:-6\n"
                )  # Set -6 dB on all components for OSBA to match IVAS_dec
        fp_meta.write(f"{in_fmt.split('_')[0][1:]}\n")  # SBA or MASA
        fp_meta.write(f"{n_obj+1}\n")
        fp_meta.write(f"{in_fmt.split('_')[-1]}\n")  # SBA or MASA parameter
        if "MASA" in in_fmt:
        if "OMASA" in in_fmt:
            fp_meta.write(
                f"{os.path.relpath(in_meta_files[n_obj], currdir)}\n"
            )  # MASA metadata
        if "OSBA" in in_fmt:
            fp_meta.write(
                "gain_dB:-6\n"
            )  # Set -6 dB on all components for OSBA to match IVAS_dec