Commit c94eac1f authored by Anika Treffehn's avatar Anika Treffehn
Browse files

Merge branch 'fix_support_lp_filter_condition' into 'main'

Fix support lp filter condition

See merge request !145
parents 17644dd4 ce38eeb8
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -118,9 +118,10 @@ def load_ir(
    dataset_suffix = None

    if out_fmt.startswith("BINAURAL") and "ROOM" in out_fmt:

        if "_IR" in out_fmt or "_REVERB" in out_fmt:
            warn("For reference rendering _IR and _REVERB extensions of BINAURAL_ROOM are ignored")
            warn(
                "For reference rendering _IR and _REVERB extensions of BINAURAL_ROOM are ignored"
            )

        dataset_prefix = "BRIR"
        if dataset is None:
+18 −1
Original line number Diff line number Diff line
@@ -44,7 +44,7 @@ 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.esdru import esdru, spatial_distortion
from ivas_processing_scripts.audiotools.wrappers.filter import (
    lpfilter_itu,
    maskfilter_itu,
@@ -169,6 +169,8 @@ def convert(
    limit: Optional[bool] = False,
    mnru_q: Optional[float] = None,
    esdru_alpha: Optional[float] = None,
    spatial_distortion_amplitude: Optional[float] = None,
    spatial_distortion_frequency: Optional[float] = None,
    logger: Optional[logging.Logger] = None,
    **kwargs,
) -> None:
@@ -186,6 +188,8 @@ def convert(
        window=in_window,
        loudness=in_loudness,
        loudness_fmt=in_loudness_fmt,
        spatial_distortion_amplitude=spatial_distortion_amplitude,
        spatial_distortion_frequency=spatial_distortion_frequency,
        logger=logger,
    )

@@ -225,6 +229,8 @@ def process_audio(
    limit: Optional[bool] = False,
    mnru_q: Optional[float] = None,
    esdru_alpha: Optional[float] = None,
    spatial_distortion_amplitude: Optional[float] = None,
    spatial_distortion_frequency: Optional[float] = None,
    logger: Optional[logging.Logger] = None,
) -> None:
    """Perform (pre-/pos-) processing of audio"""
@@ -287,6 +293,17 @@ def process_audio(
            logger.debug("Applying ESDRU Recommendation ITU-T P.811")
        x.audio = esdru(x, esdru_alpha)

    """Spatial distortion"""
    if (
        spatial_distortion_frequency is not None
        and spatial_distortion_amplitude is not None
    ):
        if logger:
            logger.debug("Applying spatial distortion")
        x.audio = spatial_distortion(
            x, spatial_distortion_amplitude, spatial_distortion_frequency
        )

    """loudness normalization"""
    if loudness is not None:
        if logger:
+30 −12
Original line number Diff line number Diff line
@@ -30,17 +30,19 @@
#  the United Nations Convention on Contracts on the International Sales of Goods.
#

import os.path
from pathlib import Path
from typing import Optional, Union
from warnings import warn

from ivas_processing_scripts.audiotools.wrappers.networkSimulator import LIST_JBM_PROFILES, ERROR_PATTERNS_DIR
from ivas_processing_scripts.constants import DEFAULT_CONFIG_BINARIES
from ivas_processing_scripts.utils import find_binary, run
from ivas_processing_scripts.audiotools.wrappers.eid_xor import eid_xor
from ivas_processing_scripts.audiotools.wrappers.networkSimulator import (
    ERROR_PATTERNS_DIR,
    LIST_JBM_PROFILES,
    length_pattern,
)
from ivas_processing_scripts.audiotools.wrappers.random_seed import random_seed
from ivas_processing_scripts.audiotools.wrappers.networkSimulator import length_pattern
from ivas_processing_scripts.constants import DEFAULT_CONFIG_BINARIES
from ivas_processing_scripts.utils import find_binary, run


def dlyerr_2_errpat(
@@ -87,7 +89,9 @@ def dlyerr_2_errpat(
    if "dlyerr_2_errpat" in DEFAULT_CONFIG_BINARIES["binary_paths"]:
        binary = find_binary(
            DEFAULT_CONFIG_BINARIES["binary_paths"]["dlyerr_2_errpat"].name,
            binary_path=DEFAULT_CONFIG_BINARIES["binary_paths"]["dlyerr_2_errpat"].parent,
            binary_path=DEFAULT_CONFIG_BINARIES["binary_paths"][
                "dlyerr_2_errpat"
            ].parent,
        )
    else:
        binary = find_binary("dlyerr_2_errpat")
@@ -98,7 +102,9 @@ def dlyerr_2_errpat(
            f"Delay and error pattern file {dlyerr_pattern} for bitstream processing does not exist"
        )
    if delay is not None and late_loss_rate is not None:
        raise ValueError("Can't scpecify delay and late loss rate for dlyerr_2_err tool but only one of them")
        raise ValueError(
            "Can't scpecify delay and late loss rate for dlyerr_2_err tool but only one of them"
        )

    # set up command line
    cmd = [
@@ -132,8 +138,17 @@ def dlyerr_2_errpat(
    return


def evs_jbm(bitstream, bitstream_processed, error_profile, error_pattern, errpatt_late_loss_rate, errpatt_delay, errpatt_seed, errpatt_frames_packet, master_seed):

def evs_jbm(
    bitstream,
    bitstream_processed,
    error_profile,
    error_pattern,
    errpatt_late_loss_rate,
    errpatt_delay,
    errpatt_seed,
    errpatt_frames_packet,
    master_seed,
):
    # convert delay and error profile
    delay = None
    num_frames_packet = None
@@ -257,9 +272,13 @@ def validate_evs_jbm(
                "JBM pattern and JBM profile number are specified for bitstream processing. Can't use both! Please check the configuration."
            )
        if errpatt_late_loss_rate is not None and errpatt_delay is not None:
            raise ValueError("For EVS JBM conditions with error pattern only late loss rate OR delay has to be specified, not both!")
            raise ValueError(
                "For EVS JBM conditions with error pattern only late loss rate OR delay has to be specified, not both!"
            )
        if errpatt_late_loss_rate is None and errpatt_delay is None:
            raise ValueError("For EVS JBM conditions with error pattern either late loss rate or delay has to be specified!")
            raise ValueError(
                "For EVS JBM conditions with error pattern either late loss rate or delay has to be specified!"
            )
        if errpatt_seed is None:
            warn("No seed was specified for EVS JBM offset -> Use 0")
    elif error_profile is not None:
@@ -272,4 +291,3 @@ def validate_evs_jbm(
            f"n_frames_per_paket is {n_frames_per_packet}. Should be 1 or 2. Please check your configuration."
        )
    return
+30 −0
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@
#  the United Nations Convention on Contracts on the International Sales of Goods.
#

from copy import deepcopy
from pathlib import Path
from tempfile import TemporaryDirectory
from typing import Optional
@@ -126,3 +127,32 @@ def esdru(
        tmp_output_signal, out_fs = read(tmp_output_file, 2, sf)

    return tmp_output_signal


def spatial_distortion(
    input: audio.Audio,
    amplitude,
    frequency,
) -> np.ndarray:
    if not isinstance(input, audio.SceneBasedAudio):
        raise ValueError("Spatial distortion currently only implemented for SBA.")

    input_copy = deepcopy(input)

    # order channels WYZX
    y = input_copy.audio[:, 1]
    x = input_copy.audio[:, 3]

    # angle changes over time
    amplitude = np.deg2rad(amplitude)
    angle = amplitude * np.sin(np.arange(len(y)) * 2 * np.pi * frequency)

    # Y channel left-right
    y_new = y * np.cos(angle) + x * np.sin(angle)
    input_copy.audio[:, 1] = y_new

    # X channel front-back
    x_new = -y * np.sin(angle) + x * np.cos(angle)
    input_copy.audio[:, 3] = x_new

    return input_copy.audio
+2 −5
Original line number Diff line number Diff line
@@ -33,11 +33,10 @@
import logging
from pathlib import Path
from typing import Optional, Union
from warnings import warn

from ivas_processing_scripts.audiotools.wrappers.random_seed import random_seed
from ivas_processing_scripts.constants import DEFAULT_CONFIG_BINARIES
from ivas_processing_scripts.utils import find_binary, run
from ivas_processing_scripts.audiotools.wrappers.random_seed import random_seed

LIST_JBM_PROFILES = range(11)
ERROR_PATTERNS_DIR = Path(__file__).parent.parent.parent.joinpath("dly_error_profiles")
@@ -84,8 +83,6 @@ def validate_network_simulator(
            raise ValueError(
                "JBM pattern and JBM profile number are specified for bitstream processing. Can't use both! Please check the configuration."
            )
        if errpatt_seed is None:
            raise warn("No error pattern seed specified for JBM offset -> use 0")
    elif error_profile is not None:
        if error_profile not in LIST_JBM_PROFILES:
            raise ValueError(
@@ -238,7 +235,7 @@ def apply_network_simulator(


def length_pattern(path_pattern):
    with open(path_pattern, 'r') as f:
    with open(path_pattern, "r") as f:
        p = f.readlines()
        length = len(p)
    return length
Loading