Commit ce1d51a8 authored by janssontoftg's avatar janssontoftg
Browse files

Clean-up and formatting.

parent 39d17173
Loading
Loading
Loading
Loading
Loading
+122 −135
Original line number Diff line number Diff line
@@ -32,15 +32,16 @@

import logging
import os
from math import floor
from itertools import repeat
from math import floor

import numpy as np

from ivas_processing_scripts.audiotools import audio, audiofile
from ivas_processing_scripts.audiotools.wrappers.bs1770 import get_loudness
from ivas_processing_scripts.audiotools.wrappers.reverb import reverb_stereo
from ivas_processing_scripts.generation import config
from ivas_processing_scripts.utils import apply_func_parallel, list_audio, pairwise
from ivas_processing_scripts.utils import apply_func_parallel

SEED_RANDOM_NOISE = 0

@@ -57,9 +58,6 @@ def generate_stereo_items(
):
    """Generate STEREO items from mono items based on scene description"""

    # get the number of scenes
    N_scenes = len(cfg.scenes)

    # set the target level
    if "loudness" not in cfg.__dict__:
        cfg.loudness = -26
@@ -93,22 +91,15 @@ def generate_stereo_items(

    apply_func_parallel(
        generate_stereo_scene,
        zip(
            cfg.scenes.keys(),
            cfg.scenes.values(),
            repeat(cfg),
            repeat(logger)
        ),
        zip(cfg.scenes.keys(), cfg.scenes.values(), repeat(cfg), repeat(logger)),
        None,
        "mp" if cfg.multiprocessing else None,
    )
    return


def generate_stereo_scene(
    scene_name: str,
    scene: dict,
    cfg: config.TestConfig,
    logger: logging.Logger
    scene_name: str, scene: dict, cfg: config.TestConfig, logger: logging.Logger
):
    logger.info(
        f"Processing scene: {scene_name} out of {len(cfg.scenes)} scenes, name: {scene['name']}"
@@ -136,14 +127,10 @@ def generate_stereo_scene(
        logger.info(f"Convolving {source_file} with {source_IR}")

        # read source file
            x = audio.fromfile(
                "MONO", os.path.join(cfg.input_path, source_file), fs=cfg.fs
            )
        x = audio.fromfile("MONO", os.path.join(cfg.input_path, source_file), fs=cfg.fs)

        # read the IR file
            IR = audio.fromfile(
                "STEREO", os.path.join(cfg.IR_path, IR_file), fs=cfg.IR_fs
            )
        IR = audio.fromfile("STEREO", os.path.join(cfg.IR_path, IR_file), fs=cfg.IR_fs)

        # convolve with stereo IR
        x = reverb_stereo(x, IR)
@@ -228,9 +215,7 @@ def generate_stereo_scene(
    if cfg.add_low_level_random_noise:
        # create uniformly distributed noise between -4 and 4
        np.random.seed(SEED_RANDOM_NOISE)
            noise = np.random.randint(low=-4, high=5, size=y.audio.shape).astype(
                "float"
            )
        noise = np.random.randint(low=-4, high=5, size=y.audio.shape).astype("float")

        # superimpose
        y.audio += noise
@@ -238,5 +223,7 @@ def generate_stereo_scene(
    # write the reverberated audio into output file
    output_filename = cfg.listening_lab + cfg.exp + scene["name"] + ".wav"
    audiofile.write(
            os.path.join(cfg.output_path, scene_name.split('_')[0], output_filename), y.audio, y.fs
        os.path.join(cfg.output_path, scene_name.split("_")[0], output_filename),
        y.audio,
        y.fs,
    )  # !!!! TBD: replace all os.path.xxx operations with the Path object