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

Merge branch '20-low-level-background-noise-option-missing' into 'main'

added low level background noise

See merge request !51
parents 534dba3e 1ad6d804
Loading
Loading
Loading
Loading
Loading
+5 −2
Original line number Diff line number Diff line
@@ -239,10 +239,13 @@ input:
    # preamble_noise: true
    ### Additive background noise
    # background_noise:
        ### REQUIRED: SNR for background noise in dB
        ### SNR for background noise in dB; REQUIRED for prerecorded background noise and ignored for low level noise
        # snr: 10
        ### REQUIRED: Path to background noise, must have same format and sampling rate as input signal(s)
        ### REQUIRED: Either background noise path or low level noise flag
        ### Path to background noise, must have same format and sampling rate as input signal(s); default = null
        # background_noise_path: ".../noise.wav"
        ### Flag for using low level [-4,+4] background noise; default = false
        # low_level_noise: true
```

</details>
+5 −2
Original line number Diff line number Diff line
@@ -106,10 +106,13 @@ input:
    # preamble_noise: true
    ### Additive background noise
    # background_noise:
        ### REQUIRED: SNR for background noise in dB
        ### SNR for background noise in dB; REQUIRED for prerecorded background noise and ignored for low level noise
        # snr: 10
        ### REQUIRED: Path to background noise, must have same format and sampling rate as input signal(s)
        ### REQUIRED: Either background noise path or low level noise flag
        ### Path to background noise, must have same format and sampling rate as input signal(s); default = null
        # background_noise_path: ".../noise.wav"
        ### Flag for using low level [-4,+4] background noise; default = false
        # low_level_noise: true

#################################################
### Bitstream processing
+1 −0
Original line number Diff line number Diff line
@@ -145,6 +145,7 @@ def main(args):
                hasattr(cfg, "preprocessing")
                and hasattr(cfg.pre2, "background_noise")
                and cfg.pre2.background_noise is not None
                and cfg.pre2.background_noise.get("background_noise_path")
            ):
                preprocess_background_noise(cfg)
            # preprocess 2
+9 −2
Original line number Diff line number Diff line
@@ -52,6 +52,7 @@ def trim(
    limits: Optional[Tuple[int, int]] = None,
    pad_noise: Optional[bool] = False,
    samples: Optional[bool] = False,
    seed: Optional[int] = None,
) -> np.ndarray:
    """
    Trim an audio array
@@ -88,6 +89,9 @@ def trim(
    if pre_trim < 0:
        if pad_noise:
            # pad with uniformly distributed noise between -4 and 4
            if seed:
                np.random.seed(seed)
            else:
                np.random.seed(SEED_PADDING)
            noise = np.random.randint(
                low=-4, high=5, size=(np.abs(pre_trim), np.shape(x)[1])
@@ -101,6 +105,9 @@ def trim(
    if post_trim < 0:
        if pad_noise:
            # pad with uniformly distributed noise between -4 and 4
            if seed:
                np.random.seed(seed)
            else:
                np.random.seed(SEED_PADDING)
            noise = np.random.randint(
                low=-4, high=5, size=(np.abs(post_trim), np.shape(x)[1])
+4 −10
Original line number Diff line number Diff line
@@ -30,7 +30,6 @@
#  the United Nations Convention on Contracts on the International Sales of Goods.
#

from pathlib import Path
from typing import Optional
from warnings import warn

@@ -40,7 +39,7 @@ from ivas_processing_scripts.processing.ivas import IVAS
from ivas_processing_scripts.processing.postprocessing import Postprocessing
from ivas_processing_scripts.processing.preprocessing import Preprocessing
from ivas_processing_scripts.processing.preprocessing_2 import Preprocessing2
from ivas_processing_scripts.utils import list_audio
from ivas_processing_scripts.utils import get_abs_path, list_audio


def init_processing_chains(cfg: TestConfig) -> None:
@@ -133,6 +132,8 @@ def get_preprocessing_2(cfg: TestConfig) -> dict:
    }

    pre2_cfg = cfg.preprocessing_2

    # set up background noise
    background_cfg = pre2_cfg.get("background_noise", None)
    if background_cfg:
        background = {
@@ -140,6 +141,7 @@ def get_preprocessing_2(cfg: TestConfig) -> dict:
            "background_noise_path": get_abs_path(
                background_cfg.get("background_noise_path", None)
            ),
            "low_level_noise": background_cfg.get("low_level_noise", False),
            "seed_delay": cfg.prerun_seed,
            "master_seed": cfg.master_seed,
            "output_fmt": cfg.postprocessing["fmt"],
@@ -414,11 +416,3 @@ def get_processing_chain(
    )

    return chain


def get_abs_path(rel_path):
    if rel_path is not None:
        abs_path = Path(rel_path).resolve().absolute()
    else:
        abs_path = None
    return abs_path
Loading