Commit e15eb5ad authored by Vladimir Malenovsky's avatar Vladimir Malenovsky
Browse files

formatting

parent 800d5656
Loading
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -73,7 +73,9 @@ def masaAnalyzer(
        binary = find_binary("masaAnalyzer")

    # enforce metadata_out_filename to be a Path object
    if metadata_out_filename is not None and not isinstance(metadata_out_filename, Path):
    if metadata_out_filename is not None and not isinstance(
        metadata_out_filename, Path
    ):
        metadata_out_filename = Path(metadata_out_filename)

    if num_tcs not in [1, 2]:
+6 −5
Original line number Diff line number Diff line
@@ -186,7 +186,7 @@ def reverb_stereo(
    y_right = reverb(input, IR_right, align=align)

    # combine into stereo output
    y = audio.fromtype('STEREO')
    y = audio.fromtype("STEREO")
    y.fs = input.fs
    y.audio = np.column_stack([y_left.audio, y_right.audio])

@@ -252,7 +252,7 @@ def reverb_foa(
    y_z = reverb(input, IR_z, align=align)

    # combine into FOA output
    y = audio.fromtype('FOA')
    y = audio.fromtype("FOA")
    y.fs = input.fs
    y.audio = np.column_stack([y_w.audio, y_x.audio, y_y.audio, y_z.audio])

@@ -303,7 +303,7 @@ def reverb_hoa2(
        ych.append(reverb(input, IR, align=align))

    # combine into HOA2 output
    y = audio.fromtype('HOA2')
    y = audio.fromtype("HOA2")
    y.fs = input.fs
    y.audio = np.column_stack(
        [
@@ -321,6 +321,7 @@ def reverb_hoa2(

    return y


def reverb_hoa3(
    input: Audio,
    hoa3_IR: Audio,
@@ -365,7 +366,7 @@ def reverb_hoa3(
        ych.append(reverb(input, IR, align=align))

    # combine into HOA3 output
    y = audio.fromtype('HOA3')
    y = audio.fromtype("HOA3")
    y.fs = input.fs
    y.audio = np.column_stack(
        [
+3 −2
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@
#

import logging

import yaml

from ivas_processing_scripts.constants import (
@@ -41,10 +42,10 @@ from ivas_processing_scripts.constants import (
from ivas_processing_scripts.generation import (
    config,
    generate_ambi_items,
    generate_stereo_items,
    generate_ismN_items,
    generate_omasa_items,
    generate_osba_items,
    generate_stereo_items,
)
from ivas_processing_scripts.utils import create_dir

+29 −15
Original line number Diff line number Diff line
@@ -41,8 +41,15 @@ import numpy as np
from ivas_processing_scripts.audiotools import audio, audioarray, audiofile, convert
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 get_loudness, loudness_norm
from ivas_processing_scripts.audiotools.wrappers.reverb import reverb_foa, reverb_hoa2, reverb_hoa3
from ivas_processing_scripts.audiotools.wrappers.bs1770 import (
    get_loudness,
    loudness_norm,
)
from ivas_processing_scripts.audiotools.wrappers.reverb import (
    reverb_foa,
    reverb_hoa2,
    reverb_hoa3,
)
from ivas_processing_scripts.generation import config
from ivas_processing_scripts.utils import apply_func_parallel

@@ -201,7 +208,9 @@ def generate_ambi_scene(
    N_inputs = len(np.atleast_1d(scene["input"]))

    # initialize output dirs
    output_filename = Path(scene["output"]).parent / (cfg.use_output_prefix + Path(scene["output"]).name)
    output_filename = Path(scene["output"]).parent / (
        cfg.use_output_prefix + Path(scene["output"]).name
    )

    dir_path = output_filename.parent
    if dir_path and not dir_path.exists():
@@ -211,7 +220,6 @@ def generate_ambi_scene(
    y = audio.SceneBasedAudio(cfg.format)

    for i in range(N_inputs):

        # parse parameters from the scene description
        source_file = np.atleast_1d(scene["input"])[i]
        IR_file = np.atleast_1d(scene["IR"])[i]
@@ -239,7 +247,9 @@ def generate_ambi_scene(
        logger.info(f"Convolving {source_file} with {IR_file}")

        # get input filename and IR filename
        input_filename = Path(source_file).parent / (cfg.use_input_prefix + Path(source_file).name)
        input_filename = Path(source_file).parent / (
            cfg.use_input_prefix + Path(source_file).name
        )
        IR_filename = Path(IR_file).parent / (cfg.use_IR_prefix + Path(IR_file).name)

        # read source file
@@ -280,7 +290,9 @@ def generate_ambi_scene(
            # adjust the signal length (trim from the end or pad with zeros) to align its length with the previous signal(s)
            N_pad = y.audio.shape[0] - x.audio.shape[0]
            if N_pad != 0:
                x.audio = audioarray.trim(x.audio, x.fs, limits=[0, -N_pad], samples=True)
                x.audio = audioarray.trim(
                    x.audio, x.fs, limits=[0, -N_pad], samples=True
                )

            # superimpose
            y.audio += x.audio
@@ -305,7 +317,9 @@ def generate_ambi_scene(
        binaudio = audio.fromtype("BINAURAL")
        binaudio.fs = y.fs
        convert_scenebased(y, binaudio)
        binaural_output_filename = output_filename.with_name(output_filename.stem + "_BINAURAL" + output_filename.suffix)
        binaural_output_filename = output_filename.with_name(
            output_filename.stem + "_BINAURAL" + output_filename.suffix
        )
        audiofile.write(
            binaural_output_filename,
            binaudio.audio,
+32 −22
Original line number Diff line number Diff line
@@ -33,12 +33,16 @@ import csv
import logging
from itertools import groupby, repeat
from math import floor
import numpy as np
from pathlib import Path

import numpy as np

from ivas_processing_scripts.audiotools import audio, audioarray, audiofile
from ivas_processing_scripts.audiotools.convert.objectbased import convert_objectbased
from ivas_processing_scripts.audiotools.wrappers.bs1770 import get_loudness, loudness_norm
from ivas_processing_scripts.audiotools.wrappers.bs1770 import (
    get_loudness,
    loudness_norm,
)
from ivas_processing_scripts.generation import config
from ivas_processing_scripts.utils import apply_func_parallel

@@ -186,7 +190,9 @@ def generate_ismN_scene(

    # initialize output dirs
    ism_format = f"ISM{N_inputs}"
    output_filename = Path(scene["output"]).parent / (cfg.use_output_prefix + Path(scene["output"]).name)
    output_filename = Path(scene["output"]).parent / (
        cfg.use_output_prefix + Path(scene["output"]).name
    )

    dir_path = output_filename.parent
    if dir_path and not dir_path.exists():
@@ -197,7 +203,6 @@ def generate_ismN_scene(

    # repeat for all source files
    for i in range(N_inputs):

        # parse parameters from the scene description
        source_file = (
            scene["input"][i] if isinstance(scene["input"], list) else scene["input"]
@@ -236,7 +241,9 @@ def generate_ismN_scene(
        logger.info(f"Encoding {source_file} at position(s) {source_azi},{source_ele}")

        # get input filename
        input_filename = Path(source_file).parent / (cfg.use_input_prefix + Path(source_file).name)
        input_filename = Path(source_file).parent / (
            cfg.use_input_prefix + Path(source_file).name
        )

        # generate ISM metadata .csv filename (should end with .wav..0.csv, .wav.1.csv, ...)
        y.metadata_files.insert(i, str(output_filename.with_suffix(f".{i}.csv")))
@@ -268,7 +275,9 @@ def generate_ismN_scene(
            # pad ISM signal with zeros to have the same length as the MASA signal
            N_pad = y.audio.shape[0] - x.audio.shape[0]
            if N_pad != 0:
                x.audio = audioarray.trim(x.audio, x.fs, limits=[0, -N_pad], samples=True)
                x.audio = audioarray.trim(
                    x.audio, x.fs, limits=[0, -N_pad], samples=True
                )

            # append ISM signal to the ISM object
            y.audio = np.append(y.audio, x.audio, axis=1)
@@ -309,7 +318,7 @@ def generate_ismN_scene(
                azi = np.arange(
                    float(eval(source_azi[0])),
                    float(eval(source_azi[0])) + N_frames * float(eval(source_azi[1])),
                    float(eval(source_azi[1]))
                    float(eval(source_azi[1])),
                )
            else:
                # replicate static azimuth value N_frames times
@@ -336,7 +345,7 @@ def generate_ismN_scene(
                ele = np.arange(
                    float(eval(source_ele[0])),
                    np.sign(float(eval(source_ele[1]))) * 90,
                    float(eval(source_ele[1]))
                    float(eval(source_ele[1])),
                )[:N_frames]

                # repeat the last elevation value, if array is shorter than N_frames
@@ -381,10 +390,11 @@ def generate_ismN_scene(
        binaudio = audio.fromtype("BINAURAL")
        binaudio.fs = y.fs
        convert_objectbased(y, binaudio)
        binaural_output_filename = output_filename.with_name(output_filename.stem + "_BINAURAL" + output_filename.suffix)
        binaural_output_filename = output_filename.with_name(
            output_filename.stem + "_BINAURAL" + output_filename.suffix
        )
        audiofile.write(
            binaural_output_filename,
            binaudio.audio,
            binaudio.fs,
        )
Loading