Commit 1babf7f9 authored by Anika Treffehn's avatar Anika Treffehn
Browse files

formatting

parent dd4ca712
Loading
Loading
Loading
Loading
+8 −2
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@ from itertools import repeat
import yaml

from ivas_processing_scripts.audiotools.metadata import check_ISM_metadata
from ivas_processing_scripts.audiotools.wrappers.bs1770 import scale_files
from ivas_processing_scripts.constants import (
    LOGGER_DATEFMT,
    LOGGER_FORMAT,
@@ -49,7 +50,6 @@ from ivas_processing_scripts.processing.processing import (
    process_item,
)
from ivas_processing_scripts.utils import DirManager, apply_func_parallel
from ivas_processing_scripts.audiotools.wrappers.bs1770 import scale_files


def logging_init(args, cfg):
@@ -150,7 +150,13 @@ def main(args):
            # scale individual files
            if cfg.postprocessing.get("loudness", False):
                # TODO: take care of samplingrate
                scale_files(out_paths_splits, cfg.postprocessing["fmt"], cfg.postprocessing["loudness"], cfg.postprocessing.get("fs", None), out_meta_splits)
                scale_files(
                    out_paths_splits,
                    cfg.postprocessing["fmt"],
                    cfg.postprocessing["loudness"],
                    cfg.postprocessing.get("fs", None),
                    out_meta_splits,
                )

    # copy configuration to output directory
    with open(cfg.output_path.joinpath(f"{cfg.name}.yml"), "w") as f:
+10 −6
Original line number Diff line number Diff line
@@ -42,7 +42,9 @@ logger = logging.getLogger("__main__")
logger.setLevel(logging.DEBUG)


### Functions used in this module
"""Functions used in this module"""


def trim(
    x: np.ndarray,
    fs: Optional[int] = 48000,
@@ -183,13 +185,13 @@ def delay_compensation(
    """

    # Get the delay in number of samples
    if flt_type == "SHQ2" and up == True:
    if flt_type == "SHQ2" and up:
        d_samples = DELAY_COMPENSATION_FOR_FILTERING["SHQ2"]["up"]
    elif flt_type == "SHQ2" and down == True:
    elif flt_type == "SHQ2" and down:
        d_samples = DELAY_COMPENSATION_FOR_FILTERING["SHQ2"]["down"]
    elif flt_type == "SHQ3" and up == True:
    elif flt_type == "SHQ3" and up:
        d_samples = DELAY_COMPENSATION_FOR_FILTERING["SHQ3"]["up"]
    elif flt_type == "SHQ3" and down == True:
    elif flt_type == "SHQ3" and down:
        d_samples = DELAY_COMPENSATION_FOR_FILTERING["SHQ3"]["down"]
    else:
        d_samples = DELAY_COMPENSATION_FOR_FILTERING[flt_type]
@@ -405,7 +407,9 @@ def framewise_io(
    )


### Deprecated functions (partly replaced by ITU binaries)
"""Deprecated functions (partly replaced by ITU binaries)"""


def resample(
    x: np.ndarray,
    in_freq: int,
+12 −5
Original line number Diff line number Diff line
@@ -30,7 +30,6 @@
#  the United Nations Convention on Contracts on the International Sales of Goods.
#

import logging
import warnings
from pathlib import Path
from typing import Optional, Tuple, Union
@@ -142,15 +141,23 @@ def load_ir(
            if in_fmt == "SBA1" or in_fmt == "FOA":
                dataset_suffix = "SBA1"
                # Use truncated SBA3 dataset if no SBA1 or 2 dataset exists
                if not (Path(__file__).parent.joinpath(f"{dataset_prefix}_{dataset}_{dataset_suffix}.mat")).is_file():
                if not (
                    Path(__file__).parent.joinpath(
                        f"{dataset_prefix}_{dataset}_{dataset_suffix}.mat"
                    )
                ).is_file():
                    dataset_suffix = "SBA3"
                    warnings.warn(f"No SBA1 dataset found -> use truncated SBA3 dataset")
                    warnings.warn("No SBA1 dataset found -> use truncated SBA3 dataset")
            elif in_fmt.endswith("2"):
                dataset_suffix = "SBA2"
                # Use truncated SBA3 dataset if no SBA1 or 2 dataset exists
                if not (Path(__file__).parent.joinpath(f"{dataset_prefix}_{dataset}_{dataset_suffix}.mat")).is_file():
                if not (
                    Path(__file__).parent.joinpath(
                        f"{dataset_prefix}_{dataset}_{dataset_suffix}.mat"
                    )
                ).is_file():
                    dataset_suffix = "SBA3"
                    warnings.warn(f"No SBA2 dataset found -> use truncated SBA3 dataset")
                    warnings.warn("No SBA2 dataset found -> use truncated SBA3 dataset")
            else:
                dataset_suffix = "SBA3"

+8 −6
Original line number Diff line number Diff line
@@ -41,12 +41,12 @@ from ivas_processing_scripts.audiotools.convert.masa import convert_masa
from ivas_processing_scripts.audiotools.convert.objectbased import convert_objectbased
from ivas_processing_scripts.audiotools.convert.scenebased import convert_scenebased
from ivas_processing_scripts.audiotools.wrappers.bs1770 import loudness_norm
from ivas_processing_scripts.audiotools.wrappers.esdru import esdru
from ivas_processing_scripts.audiotools.wrappers.filter import (
    hp50filter_itu,
    lpfilter_itu,
    resample_itu,
)
from ivas_processing_scripts.audiotools.wrappers.esdru import esdru
from ivas_processing_scripts.audiotools.wrappers.p50fbmnru import p50fbmnru

from ..metadata import write_ISM_metadata_in_file
@@ -258,13 +258,13 @@ def process_audio(
    """MNRU"""
    if mnru_q is not None:
        if logger:
            logger.debug(f"Applying P.50 Fullband MNRU")
            logger.debug("Applying P.50 Fullband MNRU")
        x.audio = p50fbmnru(x, mnru_q)

    """ESDRU"""
    if esdru_alpha is not None:
        if logger:
            logger.debug(f"Applying ESDRU Recommendation ITU-T P.811")
            logger.debug("Applying ESDRU Recommendation ITU-T P.811")
        x.audio = esdru(x, esdru_alpha)

    """limiting"""
@@ -284,17 +284,19 @@ def format_conversion(

    # validation
    if isinstance(output, audio.MetadataAssistedSpatialAudio):
        raise NotImplementedError(f"MASA is not supported as an output for rendering!")
        raise NotImplementedError("MASA is not supported as an output for rendering!")

    if isinstance(output, audio.ObjectBasedAudio) and input.name != output.name:
        raise NotImplementedError(
            f"ISM is not supported as an output for rendering! Only usable as pass-through"
            "ISM is not supported as an output for rendering! Only usable as pass-through"
        )

    if logger:
        logger.debug(f"Format conversion: {input.name} -> {output.name}")

    if input.name == output.name or (input.name.startswith("BINAURAL") and output.name.startswith("BINAURAL")):
    if input.name == output.name or (
        input.name.startswith("BINAURAL") and output.name.startswith("BINAURAL")
    ):
        output.audio = input.audio
    else:
        if isinstance(input, audio.BinauralAudio):
+9 −4
Original line number Diff line number Diff line
@@ -413,7 +413,12 @@ def split_meta_in_file(
            # remove preamble
            if preamble:
                preamble_frames = int(preamble / IVAS_FRAME_LEN_MS)
                y = trim(audio_object.object_pos[obj], audio_object.fs, (preamble_frames, 0), samples=True)
                y = trim(
                    audio_object.object_pos[obj],
                    audio_object.fs,
                    (preamble_frames, 0),
                    samples=True,
                )
            else:
                y = audio_object.object_pos[obj]

@@ -448,7 +453,7 @@ def check_ISM_metadata(
                path_meta = in_meta["all_items"]
            except KeyError:
                raise ValueError(
                    f'Only one metadata path is given but not with key "all_items".'
                    'Only one metadata path is given but not with key "all_items".'
                )

            list_meta = metadata_search(path_meta, item_names, num_objects)
@@ -475,7 +480,7 @@ def check_ISM_metadata(
                    # just read out
                    list_item = current_item
                else:
                    raise ValueError(f"Number of objects and metadata does not match.")
                    raise ValueError("Number of objects and metadata does not match.")
                list_meta.append(list_item)
        else:
            raise ValueError("Number of metadata inputs does not match number of items")
@@ -492,7 +497,7 @@ def metadata_search(
    """Search for ISM metadata with structure item_name.{0-3}.csv in in_meta folder"""

    if not item_names:
        raise ValueError(f"Item names not provided, can't search for metadata")
        raise ValueError("Item names not provided, can't search for metadata")

    list_meta = []
    for item in item_names:
Loading