From 04d03d3aa6783ebca2a348c3e1ea93ddf3ecc9d0 Mon Sep 17 00:00:00 2001 From: Treffehn Date: Wed, 14 Jun 2023 14:01:04 +0200 Subject: [PATCH 1/5] removed postamble from processing --- examples/TEMPLATE.yml | 4 --- .../selection/BS1534-1a/config/BS1534-1a.yml | 2 -- .../selection/BS1534-1b/config/BS1534-1b.yml | 2 -- .../selection/BS1534-2a/config/BS1534-2a.yml | 2 -- .../selection/BS1534-2b/config/BS1534-2b.yml | 2 -- .../selection/BS1534-3a/config/BS1534-3a.yml | 2 -- .../selection/BS1534-3b/config/BS1534-3b.yml | 2 -- .../selection/BS1534-4a/config/BS1534-4a.yml | 2 -- .../selection/BS1534-4b/config/BS1534-4b.yml | 2 -- .../selection/BS1534-5a/config/BS1534-5a.yml | 2 -- .../selection/BS1534-5b/config/BS1534-5b.yml | 2 -- .../selection/BS1534-7a/config/BS1534-7a.yml | 2 -- .../selection/BS1534-7b/config/BS1534-7b.yml | 2 -- .../selection/P800-1/config/P800-1.yml | 2 -- .../selection/P800-2/config/P800-2.yml | 2 -- .../selection/P800-3/config/P800-3.yml | 2 -- .../selection/P800-4/config/P800-4.yml | 2 -- .../selection/P800-5/config/P800-5.yml | 2 -- .../selection/P800-8/config/P800-8.yml | 2 -- .../selection/P800-9/config/P800-9.yml | 2 -- .../audiotools/metadata.py | 31 +------------------ ivas_processing_scripts/processing/chains.py | 3 -- .../processing/preprocessing_2.py | 16 +--------- .../processing/processing.py | 27 ++++------------ .../processing_splitting_scaling.py | 9 +++--- 25 files changed, 12 insertions(+), 116 deletions(-) diff --git a/examples/TEMPLATE.yml b/examples/TEMPLATE.yml index 89415cee..0af8b3d7 100755 --- a/examples/TEMPLATE.yml +++ b/examples/TEMPLATE.yml @@ -119,10 +119,6 @@ input: # preamble: 10000 ### Flag wheter to use noise (amplitude +-4) for the preamble or silence; default = false (silence) # preamble_noise: true - ### Specify postamble duration in ms. Postamble is added after concatenation and possible signal repetition. defaut = 0 - # postamble: 20 - ### Flag wheter to use noise (amplitude +-4) for the postamble or silence; default = false (silence) - # postamble_noise: true ### Additive background noise # background_noise: ### SNR for background noise in dB; REQUIRED for prerecorded background noise and ignored for low level noise diff --git a/experiments/selection/BS1534-1a/config/BS1534-1a.yml b/experiments/selection/BS1534-1a/config/BS1534-1a.yml index ec8a6aab..f82c6987 100644 --- a/experiments/selection/BS1534-1a/config/BS1534-1a.yml +++ b/experiments/selection/BS1534-1a/config/BS1534-1a.yml @@ -35,8 +35,6 @@ preprocessing: preprocessing_2: concatenate_input: false preamble_noise: false - postamble: 20 - postamble_noise: true repeat_signal: true ################################################# diff --git a/experiments/selection/BS1534-1b/config/BS1534-1b.yml b/experiments/selection/BS1534-1b/config/BS1534-1b.yml index 5c06316a..d3c41c05 100644 --- a/experiments/selection/BS1534-1b/config/BS1534-1b.yml +++ b/experiments/selection/BS1534-1b/config/BS1534-1b.yml @@ -35,8 +35,6 @@ preprocessing: preprocessing_2: concatenate_input: false preamble_noise: false - postamble: 20 - postamble_noise: true repeat_signal: true ################################################# diff --git a/experiments/selection/BS1534-2a/config/BS1534-2a.yml b/experiments/selection/BS1534-2a/config/BS1534-2a.yml index 66e9a41c..c4f6799c 100644 --- a/experiments/selection/BS1534-2a/config/BS1534-2a.yml +++ b/experiments/selection/BS1534-2a/config/BS1534-2a.yml @@ -35,8 +35,6 @@ preprocessing: preprocessing_2: concatenate_input: false preamble_noise: false - postamble: 20 - postamble_noise: true repeat_signal: true ################################################# diff --git a/experiments/selection/BS1534-2b/config/BS1534-2b.yml b/experiments/selection/BS1534-2b/config/BS1534-2b.yml index 17289569..a228d7bc 100644 --- a/experiments/selection/BS1534-2b/config/BS1534-2b.yml +++ b/experiments/selection/BS1534-2b/config/BS1534-2b.yml @@ -35,8 +35,6 @@ preprocessing: preprocessing_2: concatenate_input: false preamble_noise: false - postamble: 20 - postamble_noise: true repeat_signal: true ################################################# diff --git a/experiments/selection/BS1534-3a/config/BS1534-3a.yml b/experiments/selection/BS1534-3a/config/BS1534-3a.yml index c7e384d7..558379cb 100644 --- a/experiments/selection/BS1534-3a/config/BS1534-3a.yml +++ b/experiments/selection/BS1534-3a/config/BS1534-3a.yml @@ -35,8 +35,6 @@ preprocessing: preprocessing_2: concatenate_input: false preamble_noise: false - postamble: 20 - postamble_noise: true repeat_signal: true ################################################# diff --git a/experiments/selection/BS1534-3b/config/BS1534-3b.yml b/experiments/selection/BS1534-3b/config/BS1534-3b.yml index 889c06d6..6c0bc99f 100644 --- a/experiments/selection/BS1534-3b/config/BS1534-3b.yml +++ b/experiments/selection/BS1534-3b/config/BS1534-3b.yml @@ -35,8 +35,6 @@ preprocessing: preprocessing_2: concatenate_input: false preamble_noise: false - postamble: 20 - postamble_noise: true repeat_signal: true ################################################# diff --git a/experiments/selection/BS1534-4a/config/BS1534-4a.yml b/experiments/selection/BS1534-4a/config/BS1534-4a.yml index a1901c1d..98f16df1 100644 --- a/experiments/selection/BS1534-4a/config/BS1534-4a.yml +++ b/experiments/selection/BS1534-4a/config/BS1534-4a.yml @@ -35,8 +35,6 @@ preprocessing: preprocessing_2: concatenate_input: false preamble_noise: false - postamble: 20 - postamble_noise: true repeat_signal: true ################################################# diff --git a/experiments/selection/BS1534-4b/config/BS1534-4b.yml b/experiments/selection/BS1534-4b/config/BS1534-4b.yml index 619fa75b..20dc8b69 100644 --- a/experiments/selection/BS1534-4b/config/BS1534-4b.yml +++ b/experiments/selection/BS1534-4b/config/BS1534-4b.yml @@ -35,8 +35,6 @@ preprocessing: preprocessing_2: concatenate_input: false preamble_noise: false - postamble: 20 - postamble_noise: true repeat_signal: true ################################################# diff --git a/experiments/selection/BS1534-5a/config/BS1534-5a.yml b/experiments/selection/BS1534-5a/config/BS1534-5a.yml index 5186df64..9e769941 100644 --- a/experiments/selection/BS1534-5a/config/BS1534-5a.yml +++ b/experiments/selection/BS1534-5a/config/BS1534-5a.yml @@ -35,8 +35,6 @@ preprocessing: preprocessing_2: concatenate_input: false preamble_noise: false - postamble: 20 - postamble_noise: true repeat_signal: true ################################################# diff --git a/experiments/selection/BS1534-5b/config/BS1534-5b.yml b/experiments/selection/BS1534-5b/config/BS1534-5b.yml index 49eaa813..f6b9f9e8 100644 --- a/experiments/selection/BS1534-5b/config/BS1534-5b.yml +++ b/experiments/selection/BS1534-5b/config/BS1534-5b.yml @@ -35,8 +35,6 @@ preprocessing: preprocessing_2: concatenate_input: false preamble_noise: false - postamble: 20 - postamble_noise: true repeat_signal: true ################################################# diff --git a/experiments/selection/BS1534-7a/config/BS1534-7a.yml b/experiments/selection/BS1534-7a/config/BS1534-7a.yml index 69574c29..e9c2a1cb 100644 --- a/experiments/selection/BS1534-7a/config/BS1534-7a.yml +++ b/experiments/selection/BS1534-7a/config/BS1534-7a.yml @@ -35,8 +35,6 @@ preprocessing: preprocessing_2: concatenate_input: false preamble_noise: false - postamble: 20 - postamble_noise: true repeat_signal: true ################################################# diff --git a/experiments/selection/BS1534-7b/config/BS1534-7b.yml b/experiments/selection/BS1534-7b/config/BS1534-7b.yml index 5aea9473..46be3389 100644 --- a/experiments/selection/BS1534-7b/config/BS1534-7b.yml +++ b/experiments/selection/BS1534-7b/config/BS1534-7b.yml @@ -35,8 +35,6 @@ preprocessing: preprocessing_2: concatenate_input: false preamble_noise: false - postamble: 20 - postamble_noise: true repeat_signal: true ################################################# diff --git a/experiments/selection/P800-1/config/P800-1.yml b/experiments/selection/P800-1/config/P800-1.yml index 238484b9..0a0f977e 100644 --- a/experiments/selection/P800-1/config/P800-1.yml +++ b/experiments/selection/P800-1/config/P800-1.yml @@ -37,8 +37,6 @@ preprocessing_2: # concatenation_order: [] preamble: 10000 preamble_noise: true - postamble: 20 - postamble_noise: true repeat_signal: true background_noise: ### REQUIRED: SNR for background noise in dB diff --git a/experiments/selection/P800-2/config/P800-2.yml b/experiments/selection/P800-2/config/P800-2.yml index 97e3d196..9153ce28 100644 --- a/experiments/selection/P800-2/config/P800-2.yml +++ b/experiments/selection/P800-2/config/P800-2.yml @@ -37,8 +37,6 @@ preprocessing_2: # concatenation_order: [] preamble: 10000 preamble_noise: true - postamble: 20 - postamble_noise: true ### Additive background noise background_noise: ### REQUIRED: SNR for background noise in dB diff --git a/experiments/selection/P800-3/config/P800-3.yml b/experiments/selection/P800-3/config/P800-3.yml index 762831f2..36ec2905 100644 --- a/experiments/selection/P800-3/config/P800-3.yml +++ b/experiments/selection/P800-3/config/P800-3.yml @@ -37,8 +37,6 @@ preprocessing_2: # concatenation_order: [] preamble: 10000 preamble_noise: true - postamble: 20 - postamble_noise: true repeat_signal: true ################################################# diff --git a/experiments/selection/P800-4/config/P800-4.yml b/experiments/selection/P800-4/config/P800-4.yml index 9a760d99..4a8885b3 100644 --- a/experiments/selection/P800-4/config/P800-4.yml +++ b/experiments/selection/P800-4/config/P800-4.yml @@ -38,8 +38,6 @@ preprocessing_2: # concatenation_order: [] preamble: 10000 preamble_noise: true - postamble: 20 - postamble_noise: true repeat_signal: true background_noise: ### REQUIRED: SNR for background noise in dB diff --git a/experiments/selection/P800-5/config/P800-5.yml b/experiments/selection/P800-5/config/P800-5.yml index 96c39191..16c2536b 100644 --- a/experiments/selection/P800-5/config/P800-5.yml +++ b/experiments/selection/P800-5/config/P800-5.yml @@ -38,8 +38,6 @@ preprocessing_2: # concatenation_order: [] preamble: 10000 preamble_noise: true - postamble: 20 - postamble_noise: true repeat_signal: true background_noise: ### REQUIRED: SNR for background noise in dB diff --git a/experiments/selection/P800-8/config/P800-8.yml b/experiments/selection/P800-8/config/P800-8.yml index c4eb1d52..49a08e9b 100644 --- a/experiments/selection/P800-8/config/P800-8.yml +++ b/experiments/selection/P800-8/config/P800-8.yml @@ -37,8 +37,6 @@ preprocessing_2: # concatenation_order: [] preamble: 10000 preamble_noise: true - postamble: 20 - postamble_noise: true background_noise: ### REQUIRED: SNR for background noise in dB snr: 45 diff --git a/experiments/selection/P800-9/config/P800-9.yml b/experiments/selection/P800-9/config/P800-9.yml index 8cfb2b37..016b4ae2 100644 --- a/experiments/selection/P800-9/config/P800-9.yml +++ b/experiments/selection/P800-9/config/P800-9.yml @@ -37,8 +37,6 @@ preprocessing_2: # concatenation_order: [] preamble: 10000 preamble_noise: true - postamble: 20 - postamble_noise: true background_noise: ### REQUIRED: SNR for background noise in dB snr: 10 diff --git a/ivas_processing_scripts/audiotools/metadata.py b/ivas_processing_scripts/audiotools/metadata.py index af87fe3f..2f7a1473 100755 --- a/ivas_processing_scripts/audiotools/metadata.py +++ b/ivas_processing_scripts/audiotools/metadata.py @@ -378,7 +378,7 @@ def concat_meta_from_file( # add preamble if preamble: - concat_meta_all_obj = add_remove_preamble(concat_meta_all_obj, preamble, 0) + concat_meta_all_obj = add_remove_preamble(concat_meta_all_obj, preamble) write_ISM_metadata_in_file(concat_meta_all_obj, out_file) @@ -548,7 +548,6 @@ def metadata_search( def add_remove_preamble( metadata, preamble, - postamble, add: Optional[bool] = True, ): # preamble @@ -579,32 +578,4 @@ def add_remove_preamble( samples=True, ) - # postamble - postamble_frames = postamble / IVAS_FRAME_LEN_MS - if not postamble_frames.is_integer(): - raise ValueError( - f"Application of postamble for ISM metadata is only possible if postamble length is multiple of frame length. " - f"Frame length: {IVAS_FRAME_LEN_MS}ms" - ) - for obj_idx in range(len(metadata)): - if metadata is not None and metadata[obj_idx] is not None: - if add: - num_columns = metadata[obj_idx].shape[1] - metadata[obj_idx] = np.vstack( - [ - metadata[obj_idx], - np.repeat( - np.array(DEFAULT_ISM_METADATA)[None, :num_columns], - postamble_frames, - 0, - ), - ] - ) - else: - metadata[obj_idx] = trim( - metadata[obj_idx], - limits=(0, int(postamble_frames)), - samples=True, - ) - return metadata diff --git a/ivas_processing_scripts/processing/chains.py b/ivas_processing_scripts/processing/chains.py index 3d7e0491..3f944518 100755 --- a/ivas_processing_scripts/processing/chains.py +++ b/ivas_processing_scripts/processing/chains.py @@ -189,8 +189,6 @@ def get_preprocessing_2(cfg: TestConfig) -> dict: "concatenation_order": pre2_cfg.get("concatenation_order", None), "preamble": pre2_cfg.get("preamble", 0), "pad_noise_preamble": pre2_cfg.get("preamble_noise", False), - "postamble": pre2_cfg.get("postamble", 0), - "pad_noise_postamble": pre2_cfg.get("preamble_noise", False), "background_noise": background, "in_mask": pre2_cfg.get("mask", None), "multiprocessing": cfg.multiprocessing, @@ -502,7 +500,6 @@ def get_processing_chain( "out_fmt": post_fmt, # no rendering here "concatenate_input": pre2_cfg.get("concatenate_input", False), "preamble": pre2_cfg.get("preamble", 0), - "postamble": pre2_cfg.get("postamble", 0), "repeat_signal": pre2_cfg.get("repeat_signal", False), "loudness": post_cfg.get("loudness", None), "loudness_fmt": post_cfg.get("loudness_fmt", None), diff --git a/ivas_processing_scripts/processing/preprocessing_2.py b/ivas_processing_scripts/processing/preprocessing_2.py index 83dc0097..912ef6d1 100644 --- a/ivas_processing_scripts/processing/preprocessing_2.py +++ b/ivas_processing_scripts/processing/preprocessing_2.py @@ -75,16 +75,12 @@ class Preprocessing2(Processing): metadata = audio_object.object_pos # add preamble - metadata = add_remove_preamble(metadata, preamble, 0) + metadata = add_remove_preamble(metadata, preamble) # repeat signal if self.repeat_signal: metadata = [np.concatenate((m, m), axis=0) for m in metadata] - # add postable - if self.postamble: - metadata = add_remove_preamble(metadata, 0, self.postamble) - meta_files = write_ISM_metadata_in_file(metadata, [out_file], True) # modify audio object @@ -118,16 +114,6 @@ class Preprocessing2(Processing): (audio_object.audio, audio_object.audio), axis=0 ) - # add postamble - do alter signal repetition as this is just for ensuring equal lengths between in- and output signals - if self.postamble > 0: - logger.debug(f"Add postamble of length {self.postamble}ms") - audio_object.audio = trim( - audio_object.audio, - audio_object.fs, - (0, -self.postamble), - self.pad_noise_postamble, - ) - # save file write(out_file, audio_object.audio, fs=audio_object.fs) diff --git a/ivas_processing_scripts/processing/processing.py b/ivas_processing_scripts/processing/processing.py index 71674283..9dd11b37 100755 --- a/ivas_processing_scripts/processing/processing.py +++ b/ivas_processing_scripts/processing/processing.py @@ -160,7 +160,7 @@ def concat_setup(cfg: TestConfig, chain, logger: logging.Logger): def concat_teardown( - x, splits, out_fmt, fs, in_fs, meta, len_postamble_ms, logger: logging.Logger + x, splits, out_fmt, fs, in_fs, meta, logger: logging.Logger ): if not splits: raise ValueError("Splitting not possible without split marker") @@ -182,14 +182,9 @@ def concat_teardown( raise ValueError( f"Last split index {splits[-1]} is larger than the signal length {len(x)}" ) - elif splits[-1] < len(x) - ( - postamble_len_samples := (len_postamble_ms * fs_old) // 1000 - ): - msg_file_len = len(x) - if len_postamble_ms > 0: - msg_file_len = f"(minus postamble length of {postamble_len_samples}): {len(x) - postamble_len_samples}" + elif splits[-1] < len(x): warn( - f"Last split index {splits[-1]} is smaller than the signal length {msg_file_len}" + f"Last split index {splits[-1]} is smaller than the signal length {len(x)}" ) split_old = 0 @@ -402,14 +397,11 @@ def process_item( copyfile(ppm, out_meta[idx]) -def remove_pre_and_postamble( - x, out_fmt, fs, repeat_signal, preamble_len_ms, postamble_len_ms, meta, logger +def remove_preamble( + x, out_fmt, fs, repeat_signal, preamble_len_ms, meta, logger ): # remove preamble for ISM metadata if out_fmt.startswith("ISM"): - # remove postamble - if postamble_len_ms: - meta = add_remove_preamble(meta, 0, postamble_len_ms, add=False) # cut first half of the metadata if repeat_signal: @@ -417,14 +409,7 @@ def remove_pre_and_postamble( # remove preamble if preamble_len_ms > 0: - meta = add_remove_preamble(meta, preamble_len_ms, 0, add=False) - - # remove postamble - if postamble_len_ms: - if logger: - logger.debug("Remove postamble") - postamble_len_samples = (postamble_len_ms * fs) // 1000 - x = trim(x, fs, (0, postamble_len_samples), samples=True) + meta = add_remove_preamble(meta, preamble_len_ms, add=False) # cut first half of signal if repeat_signal: diff --git a/ivas_processing_scripts/processing/processing_splitting_scaling.py b/ivas_processing_scripts/processing/processing_splitting_scaling.py index 69a77e61..4b162f68 100644 --- a/ivas_processing_scripts/processing/processing_splitting_scaling.py +++ b/ivas_processing_scripts/processing/processing_splitting_scaling.py @@ -13,7 +13,7 @@ from ivas_processing_scripts.audiotools.wrappers.bs1770 import loudness_norm from ivas_processing_scripts.processing.processing import ( Processing, concat_teardown, - remove_pre_and_postamble, + remove_preamble, ) # @@ -190,14 +190,13 @@ class Processing_splitting_scaling(Processing): self, x, fs, in_file, out_file, in_meta, noerror=False, logger=None ): # remove preamble and first half of signal due to repetition - if self.preamble or self.postamble or self.repeat_signal: - x, in_meta = remove_pre_and_postamble( + if self.preamble or self.repeat_signal: + x, in_meta = remove_preamble( x, self.out_fmt, self.fs, self.repeat_signal, self.preamble, - self.postamble, in_meta, logger, ) @@ -214,7 +213,7 @@ class Processing_splitting_scaling(Processing): # split file file_splits, meta_splits = concat_teardown( - x, splits, self.out_fmt, fs, split_fs, in_meta, self.postamble, logger + x, splits, self.out_fmt, fs, split_fs, in_meta, logger ) # set new out_files -- GitLab From fcf3171a4a89dd0d7c97377a6e5b7e3ba7a06ca7 Mon Sep 17 00:00:00 2001 From: Treffehn Date: Wed, 14 Jun 2023 16:25:27 +0200 Subject: [PATCH 2/5] added optional key for padding the input signals --- examples/TEMPLATE.yml | 11 ++- ivas_processing_scripts/constants.py | 3 + ivas_processing_scripts/processing/chains.py | 70 ++++++++++++++++---- 3 files changed, 63 insertions(+), 21 deletions(-) diff --git a/examples/TEMPLATE.yml b/examples/TEMPLATE.yml index 0af8b3d7..bab59220 100755 --- a/examples/TEMPLATE.yml +++ b/examples/TEMPLATE.yml @@ -65,13 +65,10 @@ input: fmt: "HOA3" ### Input sampling rate in Hz needed for headerless audio files; default = 48000 # fs: 32000 - ### Enable check for input files being aligned to a integer multiple of a given length in ms. - ### If a file is not aligned, a warning will be issued. If the input format has metadata or force is true, an error is raised instead. - # aligned_to: - ### alignment length in ms, is needed if aligned_to is used - # len: 20 - ### default: false - # force: true + ### Treatment of items that are not 20ms aligned + ### options: "padding" (pads with low level noise to frame length), "warning" or "error" (raises a warning or an error when items are not aligned), + ### "ignore" (no special treatment for items that are not aligned); default = "padding" (for ISM: default = "error") + # frame_alignment: "error" ################################################ ### Pre-processing on individual items diff --git a/ivas_processing_scripts/constants.py b/ivas_processing_scripts/constants.py index 5cc47609..b4cf5a28 100755 --- a/ivas_processing_scripts/constants.py +++ b/ivas_processing_scripts/constants.py @@ -63,6 +63,9 @@ DEFAULT_CONFIG = { "master_seed": 0, "prerun_seed": 0, "metadata_path": None, + "input": { + "frame_alignment": "padding", + }, # postprocessing "postprocessing": { "mask": None, diff --git a/ivas_processing_scripts/processing/chains.py b/ivas_processing_scripts/processing/chains.py index 3f944518..2e8c9b77 100755 --- a/ivas_processing_scripts/processing/chains.py +++ b/ivas_processing_scripts/processing/chains.py @@ -32,9 +32,10 @@ from typing import Optional from warnings import warn +from shutil import copyfile from ivas_processing_scripts.audiotools import audio -from ivas_processing_scripts.audiotools.audiofile import read +from ivas_processing_scripts.audiotools.audiofile import read, write from ivas_processing_scripts.processing.config import TestConfig from ivas_processing_scripts.processing.evs import EVS from ivas_processing_scripts.processing.ivas import IVAS @@ -44,6 +45,7 @@ from ivas_processing_scripts.processing.preprocessing_2 import Preprocessing2 from ivas_processing_scripts.processing.processing_splitting_scaling import ( Processing_splitting_scaling, ) +from ivas_processing_scripts.audiotools.audioarray import trim from ivas_processing_scripts.utils import get_abs_path, list_audio @@ -521,7 +523,23 @@ def validate_input_files(cfg: TestConfig): input_format = cfg.input["fmt"] num_chan_expected = audio.fromtype(input_format).num_channels - for item in cfg.items_list: + frame_alignment = cfg.input["frame_alignment"] + + # always throw an error for ISM (and MASA) input + if input_format.startswith("ISM") or input_format.startswith("MASA"): + frame_alignment = "error" + + if cfg.input["frame_alignment"] == "padding": + # Create new input directory for padded files + output_dir = cfg.output_path / "20ms_aligned_files" + try: + output_dir.mkdir(exist_ok=False) + except FileExistsError: + raise ValueError( + "Folder for 20ms aligned files already exists. Please move or delete folder" + ) + + for i, item in enumerate(cfg.items_list): if "fs" in cfg.input: sampling_rate = cfg.input["fs"] x, fs = read(item, nchannels=num_chan_expected, fs=sampling_rate) @@ -544,18 +562,42 @@ def validate_input_files(cfg: TestConfig): f"The number of channels in the file ({n_chan_x}) do NOT match with those of format ({num_chan_expected}, {input_format}) specified in the config yaml." ) - if (input_aligned_cfg := cfg.input.get("aligned_to", None)) is not None: - input_fmt_has_metadata = input_format.startswith( - "ISM" - ) or input_format.startswith("MASA") - force_alignment = ( - input_aligned_cfg.get("force", False) or input_fmt_has_metadata - ) + # check frame alignment of items + if cfg.input["frame_alignment"] != "ignore": + + alignment_len_samples = (20 / 1000) * fs - alignment_len_samples = (input_aligned_cfg["len"] / 1000) * fs if n_samples_x % alignment_len_samples != 0: - msg = f"The length ({n_samples_x} samples) of audio ({item.name}) is not a multiple of given alignment length ({input_aligned_cfg['len']} ms)." - if force_alignment: - raise ValueError(msg) + if frame_alignment == "warning": + warn(f"The length ({n_samples_x} samples) of audio ({item.name}) is not a multiple of the frame length.") + elif frame_alignment == "error": + raise ValueError(f"The length ({n_samples_x} samples) of audio ({item.name}) is not a multiple of the frame length.") + elif frame_alignment == "padding": + warn(f"The length ({n_samples_x} samples) of audio ({item.name}) is not a multiple of frame length (20 ms). Padding to the nearest integer multiple.") + # Calculate number of samples needed for padding + padding_samples = int(alignment_len_samples - (n_samples_x % alignment_len_samples)) + # Create and append zeros + padded_data = trim( + x, + fs, + (0, -padding_samples), + pad_noise=True, + samples=True, + ) + # Write padded data to output directory + write(output_dir / item.name, padded_data, fs) + # Update audio file path in list + cfg.items_list[i] = output_dir / item.name else: - warn(msg) + raise ValueError(f"Value of key frame_alignment does not match possible options. Value: {frame_alignment}. Options: 'padding', 'ignore', 'warning', 'error'") + else: + if frame_alignment == "padding": + copyfile(item, output_dir / item.name) + # Update audio file path in list + cfg.items_list[i] = output_dir / item.name + else: + pass + + if frame_alignment == "padding": + # Make the output path as the new input path + cfg.input_path = output_dir -- GitLab From baf4c9b563f14818b4476180ff31b8da5350652d Mon Sep 17 00:00:00 2001 From: Treffehn Date: Wed, 14 Jun 2023 17:07:34 +0200 Subject: [PATCH 3/5] also added subfolders to mkdir --- ivas_processing_scripts/processing/chains.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ivas_processing_scripts/processing/chains.py b/ivas_processing_scripts/processing/chains.py index 2e8c9b77..b21048f6 100755 --- a/ivas_processing_scripts/processing/chains.py +++ b/ivas_processing_scripts/processing/chains.py @@ -533,7 +533,7 @@ def validate_input_files(cfg: TestConfig): # Create new input directory for padded files output_dir = cfg.output_path / "20ms_aligned_files" try: - output_dir.mkdir(exist_ok=False) + output_dir.mkdir(exist_ok=False, parents=True) except FileExistsError: raise ValueError( "Folder for 20ms aligned files already exists. Please move or delete folder" -- GitLab From 2260c49923a72c4be4435812308c2f9252995b6e Mon Sep 17 00:00:00 2001 From: Treffehn Date: Wed, 14 Jun 2023 17:11:37 +0200 Subject: [PATCH 4/5] formatting --- .../audiotools/wrappers/reverb.py | 4 +++- ivas_processing_scripts/processing/chains.py | 24 +++++++++++++------ .../processing/processing.py | 8 ++----- 3 files changed, 22 insertions(+), 14 deletions(-) diff --git a/ivas_processing_scripts/audiotools/wrappers/reverb.py b/ivas_processing_scripts/audiotools/wrappers/reverb.py index 62c6dfdc..1ce334ac 100644 --- a/ivas_processing_scripts/audiotools/wrappers/reverb.py +++ b/ivas_processing_scripts/audiotools/wrappers/reverb.py @@ -90,7 +90,9 @@ def reverb( tmp_input.fs = IR.fs # add trailing zeros - tmp_input.audio = np.concatenate([tmp_input.audio, np.zeros((IR.audio.shape[0]-1, 1))]) + tmp_input.audio = np.concatenate( + [tmp_input.audio, np.zeros((IR.audio.shape[0] - 1, 1))] + ) # write input audio signal to temporary file in .pcm format tmp_input_file = tmp_dir.joinpath("tmp_reverbIn.pcm") diff --git a/ivas_processing_scripts/processing/chains.py b/ivas_processing_scripts/processing/chains.py index b21048f6..d0f4f283 100755 --- a/ivas_processing_scripts/processing/chains.py +++ b/ivas_processing_scripts/processing/chains.py @@ -30,11 +30,12 @@ # the United Nations Convention on Contracts on the International Sales of Goods. # +from shutil import copyfile from typing import Optional from warnings import warn -from shutil import copyfile from ivas_processing_scripts.audiotools import audio +from ivas_processing_scripts.audiotools.audioarray import trim from ivas_processing_scripts.audiotools.audiofile import read, write from ivas_processing_scripts.processing.config import TestConfig from ivas_processing_scripts.processing.evs import EVS @@ -45,7 +46,6 @@ from ivas_processing_scripts.processing.preprocessing_2 import Preprocessing2 from ivas_processing_scripts.processing.processing_splitting_scaling import ( Processing_splitting_scaling, ) -from ivas_processing_scripts.audiotools.audioarray import trim from ivas_processing_scripts.utils import get_abs_path, list_audio @@ -569,13 +569,21 @@ def validate_input_files(cfg: TestConfig): if n_samples_x % alignment_len_samples != 0: if frame_alignment == "warning": - warn(f"The length ({n_samples_x} samples) of audio ({item.name}) is not a multiple of the frame length.") + warn( + f"The length ({n_samples_x} samples) of audio ({item.name}) is not a multiple of the frame length." + ) elif frame_alignment == "error": - raise ValueError(f"The length ({n_samples_x} samples) of audio ({item.name}) is not a multiple of the frame length.") + raise ValueError( + f"The length ({n_samples_x} samples) of audio ({item.name}) is not a multiple of the frame length." + ) elif frame_alignment == "padding": - warn(f"The length ({n_samples_x} samples) of audio ({item.name}) is not a multiple of frame length (20 ms). Padding to the nearest integer multiple.") + warn( + f"The length ({n_samples_x} samples) of audio ({item.name}) is not a multiple of frame length (20 ms). Padding to the nearest integer multiple." + ) # Calculate number of samples needed for padding - padding_samples = int(alignment_len_samples - (n_samples_x % alignment_len_samples)) + padding_samples = int( + alignment_len_samples - (n_samples_x % alignment_len_samples) + ) # Create and append zeros padded_data = trim( x, @@ -589,7 +597,9 @@ def validate_input_files(cfg: TestConfig): # Update audio file path in list cfg.items_list[i] = output_dir / item.name else: - raise ValueError(f"Value of key frame_alignment does not match possible options. Value: {frame_alignment}. Options: 'padding', 'ignore', 'warning', 'error'") + raise ValueError( + f"Value of key frame_alignment does not match possible options. Value: {frame_alignment}. Options: 'padding', 'ignore', 'warning', 'error'" + ) else: if frame_alignment == "padding": copyfile(item, output_dir / item.name) diff --git a/ivas_processing_scripts/processing/processing.py b/ivas_processing_scripts/processing/processing.py index 445f6e79..f1d689eb 100755 --- a/ivas_processing_scripts/processing/processing.py +++ b/ivas_processing_scripts/processing/processing.py @@ -162,9 +162,7 @@ def concat_setup(cfg: TestConfig, chain, logger: logging.Logger): logger.info(f"Splits written to file {splits_info_file}") -def concat_teardown( - x, splits, out_fmt, fs, in_fs, meta, logger: logging.Logger -): +def concat_teardown(x, splits, out_fmt, fs, in_fs, meta, logger: logging.Logger): if not splits: raise ValueError("Splitting not possible without split marker") @@ -434,9 +432,7 @@ def process_item( copyfile(ppm, out_meta[idx]) -def remove_preamble( - x, out_fmt, fs, repeat_signal, preamble_len_ms, meta, logger -): +def remove_preamble(x, out_fmt, fs, repeat_signal, preamble_len_ms, meta, logger): # remove preamble for ISM metadata if out_fmt.startswith("ISM"): -- GitLab From 0ab1f82417fbb5895ee84a866fc6ea2158e26fcf Mon Sep 17 00:00:00 2001 From: Treffehn Date: Wed, 14 Jun 2023 17:25:06 +0200 Subject: [PATCH 5/5] format --- ivas_processing_scripts/audiotools/metadata.py | 1 - ivas_processing_scripts/processing/chains.py | 1 - ivas_processing_scripts/processing/processing.py | 1 - 3 files changed, 3 deletions(-) diff --git a/ivas_processing_scripts/audiotools/metadata.py b/ivas_processing_scripts/audiotools/metadata.py index 2f7a1473..6c878097 100755 --- a/ivas_processing_scripts/audiotools/metadata.py +++ b/ivas_processing_scripts/audiotools/metadata.py @@ -44,7 +44,6 @@ from ivas_processing_scripts.audiotools.constants import ( DEFAULT_ISM_METADATA, FORMAT_ISM_METADATA_CSV, IVAS_FRAME_LEN_MS, - NUMBER_COLUMNS_ISM_METADATA, ) diff --git a/ivas_processing_scripts/processing/chains.py b/ivas_processing_scripts/processing/chains.py index d0f4f283..f9ec2c79 100755 --- a/ivas_processing_scripts/processing/chains.py +++ b/ivas_processing_scripts/processing/chains.py @@ -564,7 +564,6 @@ def validate_input_files(cfg: TestConfig): # check frame alignment of items if cfg.input["frame_alignment"] != "ignore": - alignment_len_samples = (20 / 1000) * fs if n_samples_x % alignment_len_samples != 0: diff --git a/ivas_processing_scripts/processing/processing.py b/ivas_processing_scripts/processing/processing.py index f1d689eb..299ca4c3 100755 --- a/ivas_processing_scripts/processing/processing.py +++ b/ivas_processing_scripts/processing/processing.py @@ -435,7 +435,6 @@ def process_item( def remove_preamble(x, out_fmt, fs, repeat_signal, preamble_len_ms, meta, logger): # remove preamble for ISM metadata if out_fmt.startswith("ISM"): - # cut first half of the metadata if repeat_signal: meta = [m[int(len(m) / 2) :, :] for m in meta] -- GitLab