From 74016ebcfa91a68de555d851b3701062fc658ca9 Mon Sep 17 00:00:00 2001 From: knj Date: Wed, 7 Jun 2023 10:15:13 +0200 Subject: [PATCH 01/16] add postamble to be added after concatenation --- ivas_processing_scripts/processing/chains.py | 3 ++ .../processing/preprocessing_2.py | 14 ++++++-- .../processing/processing.py | 34 +++++++++++-------- .../processing_splitting_scaling.py | 3 +- 4 files changed, 37 insertions(+), 17 deletions(-) diff --git a/ivas_processing_scripts/processing/chains.py b/ivas_processing_scripts/processing/chains.py index cf7f43b6..7f86b652 100755 --- a/ivas_processing_scripts/processing/chains.py +++ b/ivas_processing_scripts/processing/chains.py @@ -184,6 +184,8 @@ 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, @@ -495,6 +497,7 @@ 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 2d2fd500..b894dd96 100644 --- a/ivas_processing_scripts/processing/preprocessing_2.py +++ b/ivas_processing_scripts/processing/preprocessing_2.py @@ -85,9 +85,9 @@ class Preprocessing2(Processing): audio_object.metadata_files = meta_files audio_object.obect_pos = metadata - if self.preamble: + # add preamble + if self.preamble > 0: logger.debug(f"Add preamble of length {self.preamble}ms") - # add preamble to actual signal audio_object.audio = trim( audio_object.audio, audio_object.fs, @@ -111,6 +111,16 @@ class Preprocessing2(Processing): (audio_object.audio, audio_object.audio), axis=0 ) + # add postamble - do ater 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 093fa91b..22555771 100755 --- a/ivas_processing_scripts/processing/processing.py +++ b/ivas_processing_scripts/processing/processing.py @@ -161,7 +161,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, len_postamble_ms, logger: logging.Logger): if not splits: raise ValueError("Splitting not possible without split marker") @@ -182,9 +182,12 @@ def concat_teardown(x, splits, out_fmt, fs, in_fs, meta, logger: logging.Logger) raise ValueError( f"Last split index {splits[-1]} is larger than the signal length {len(x)}" ) - elif splits[-1] < 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}" warn( - f"Last split index {splits[-1]} is smaller that the signal length {len(x)}" + f"Last split index {splits[-1]} is smaller than the signal length {msg_file_len}" ) split_old = 0 @@ -397,7 +400,7 @@ def process_item( copyfile(ppm, out_meta[idx]) -def remove_preamble(x, out_fmt, fs, repeat_signal, preamble, meta, logger): +def remove_preamble(x, out_fmt, fs, repeat_signal, preamble_len_ms, postamble_len_ms, meta, logger): # remove preamble for ISM metadata if out_fmt.startswith("ISM"): # cut first half of the metadata @@ -405,20 +408,23 @@ def remove_preamble(x, out_fmt, fs, repeat_signal, preamble, meta, logger): meta = [m[int(len(m) / 2) :, :] for m in meta] # remove preamble - if preamble: - meta = add_remove_preamble(meta, preamble, add=False) + if preamble_len_ms > 0: + meta = add_remove_preamble(meta, preamble_len_ms, add=False) - # remove first half of signal + # get number of samples to cut from start + trim_len_samples = (preamble_len_ms * fs) // 1000 if repeat_signal: if logger: logger.debug("Remove first half of signal") - x = x[int(len(x) / 2) :, :] - - # remove preamble - if preamble: - if logger: - logger.debug("Remove preamble") - x = trim(x, fs, (preamble, 0)) + + # need to subtract the postamble length before getting half of signal length - it was added after concatenation + postamble_len_samples = (postamble_len_ms * fs) // 1000 + trim_len_samples += (len(x) - postamble_len_samples) // 2 + + if trim_len_samples > 0 and logger: + logger.debug("Remove preamble") + + x = trim(x, fs, (trim_len_samples, 0), samples=True) return x, meta diff --git a/ivas_processing_scripts/processing/processing_splitting_scaling.py b/ivas_processing_scripts/processing/processing_splitting_scaling.py index b49454ff..1c2f916c 100644 --- a/ivas_processing_scripts/processing/processing_splitting_scaling.py +++ b/ivas_processing_scripts/processing/processing_splitting_scaling.py @@ -198,6 +198,7 @@ class Processing_splitting_scaling(Processing): self.fs, self.repeat_signal, self.preamble, + self.postamble, in_meta, logger, ) @@ -214,7 +215,7 @@ class Processing_splitting_scaling(Processing): # split file file_splits, meta_splits = concat_teardown( - x, splits, self.out_fmt, fs, split_fs, in_meta, logger + x, splits, self.out_fmt, fs, split_fs, in_meta, self.postamble, logger ) # set new out_files -- GitLab From 989053fa28ca6da88fb45f41fde54692d40f4bf5 Mon Sep 17 00:00:00 2001 From: knj Date: Wed, 7 Jun 2023 11:34:15 +0200 Subject: [PATCH 02/16] remove input file padding and move validation after file collection --- ivas_processing_scripts/__init__.py | 4 - ivas_processing_scripts/processing/chains.py | 52 ++++++++- .../processing/processing.py | 103 +----------------- 3 files changed, 52 insertions(+), 107 deletions(-) diff --git a/ivas_processing_scripts/__init__.py b/ivas_processing_scripts/__init__.py index 1b7eed97..15424a3a 100755 --- a/ivas_processing_scripts/__init__.py +++ b/ivas_processing_scripts/__init__.py @@ -41,7 +41,6 @@ from ivas_processing_scripts.constants import ( ) from ivas_processing_scripts.processing import chains, config from ivas_processing_scripts.processing.processing import ( - multiple_of_frame_size, preprocess, preprocess_2, preprocess_background_noise, @@ -127,9 +126,6 @@ def main(args): cfg.metadata_path = metadata - # checking if audio is a multiple of frame size - multiple_of_frame_size(cfg) - # run preprocessing only once if hasattr(cfg, "preprocessing"): # save process info for background noise diff --git a/ivas_processing_scripts/processing/chains.py b/ivas_processing_scripts/processing/chains.py index 7f86b652..1b7ee788 100755 --- a/ivas_processing_scripts/processing/chains.py +++ b/ivas_processing_scripts/processing/chains.py @@ -43,6 +43,8 @@ from ivas_processing_scripts.processing.processing_splitting_scaling import ( Processing_splitting_scaling, ) from ivas_processing_scripts.utils import get_abs_path, list_audio +from ivas_processing_scripts.audiotools import audio +from ivas_processing_scripts.audiotools.audiofile import read def init_processing_chains(cfg: TestConfig) -> None: @@ -95,11 +97,14 @@ def init_processing_chains(cfg: TestConfig) -> None: cfg.items_list = list_audio( cfg.input_path, select_list=getattr(cfg, "input_select", None) ) - if not cfg.items_list: + if len(cfg.items_list) == 0: raise SystemExit( f"Directory {cfg.input_path} does not exist, contains no audio files or all files were filtered out." ) + # validate input files for correct format and sampling rate + validate_input_files(cfg) + # assemble a list of output and temporary directories to create for chain in cfg.proc_chains: cfg.out_dirs.append(cfg.output_path.joinpath(chain["name"])) @@ -508,3 +513,48 @@ def get_processing_chain( ) return chain + + +def validate_input_files(cfg: TestConfig): + """ + Go through list of input files and check whether they match the sampling rate and format + (by checking number of channels) specified in the config and are aligned to the given + input block size. + """ + input_format = cfg.input["fmt"] + num_chan_expected = audio.fromtype(input_format).num_channels + check_block_aligned_to = 20 + for item in cfg.items_list: + if "fs" in cfg.input: + sampling_rate = cfg.input["fs"] + x, fs = read(item, nchannels=num_chan_expected, fs=sampling_rate) + elif item.suffix == ".pcm" or item.suffix == ".raw": + raise ValueError("Sampling rate must be specified for headerless files!") + elif item.suffix == ".wav": + x, fs = read(item) + sampling_rate = fs + else: + raise ValueError(f"Unsupported input file type {item.suffix}") + n_samples_x, n_chan_x = x.shape + + # check for number of channels and sampling rate + if fs != sampling_rate: + raise ValueError( + f"Sampling rate of the file ({fs}) does NOT match with that ({sampling_rate}) specified in the config yaml." + ) + if n_chan_x != num_chan_expected: + raise ValueError( + 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 check_block_aligned_to > 0: + frame_length_samples = (check_block_aligned_to / 1000) * fs + if n_samples_x % frame_length_samples != 0: + if input_format.startswith("ISM") or input_format.startswith("MASA"): + raise ValueError( + f"The length ({n_samples_x} samples) of audio ({item.name}) is not a multiple of frame length (20 ms) - not allowed for input formats with metadata." + ) + else: + warn( + f"The length ({n_samples_x} samples) of audio ({item.name}) is not a multiple of frame length (20 ms)." + ) \ No newline at end of file diff --git a/ivas_processing_scripts/processing/processing.py b/ivas_processing_scripts/processing/processing.py index 22555771..99fa872a 100755 --- a/ivas_processing_scripts/processing/processing.py +++ b/ivas_processing_scripts/processing/processing.py @@ -459,105 +459,4 @@ def preprocess_background_noise(cfg): "background_object" ] = output_audio - return - - -def multiple_of_frame_size( - cfg: TestConfig, - frame_size_in_ms: Optional[int] = 20, -) -> np.ndarray: - """ - This function checks if the list of multi channel audio files is a multiple of frame size. - If the file isn't a multiple then the function pads it to the next integer of frame size and writes the file to an output directory. - It also copies the already aligned files to the output directory. - - Parameters - ---------- - cfg: TestConfig - Input configuration - frame_size_in_ms: Optional[int] - Frame size in milliseconds; default = 20 - """ - # get the number of channels from the input format - input_format = cfg.input["fmt"] - num_channels = audio.fromtype(input_format).num_channels - - # Create output directory - 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" - ) - - # iterate over input files - for i, item in enumerate(cfg.items_list): - # read the audio file - if "fs" in cfg.input: - sampling_rate = cfg.input["fs"] - x, fs = read(item, nchannels=num_channels, fs=sampling_rate) - elif item.suffix == ".pcm" or item.suffix == ".raw": - raise ValueError("Sampling rate must be specified for headerless files!") - elif item.suffix == ".wav": - x, fs = read(item) - sampling_rate = fs - else: - raise ValueError(f"Unsupported input file type {item.suffix}") - n_samples_x, n_chan_x = x.shape - - # check for number of channels and sampling rate - if fs != sampling_rate: - raise ValueError( - f"Sampling rate of the file ({fs}) does NOT match with that ({sampling_rate}) specified in the config yaml." - ) - if n_chan_x != num_channels: - raise ValueError( - f"The number of channels in the file ({n_chan_x}) do NOT match with those of format ({num_channels}, {input_format}) specified in the config yaml." - ) - - # warn if audio length not a multiple of frame length - frame_length_samples = (frame_size_in_ms / 1000) * fs - remainder = n_samples_x % frame_length_samples - if remainder != 0: - # Calculate number of samples needed for padding - padding_samples = int(frame_length_samples - remainder) - - if input_format.startswith("ISM") or input_format.startswith("MASA"): - raise ValueError( - f"The length ({n_samples_x} samples) of audio ({item.name}) is not a multiple of frame length (20 ms)." - ) - else: - 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." - ) - - # Create and append zeros - padded_data = trim(x, sampling_rate, (0, -padding_samples), pad_noise=True, samples=True) - # Write padded data to output directory - write(output_dir / item.name, padded_data, fs) - else: - copyfile(item, output_dir / item.name) - - # Update audio file path in list - cfg.items_list[i] = output_dir / item.name - - # Copy metadata and update path - if input_format.startswith("ISM"): - for j in range(int(cfg.input["fmt"][3])): - copyfile( - cfg.metadata_path[i][j], output_dir / cfg.metadata_path[i][j].name - ) - cfg.metadata_path[i][j] = output_dir / cfg.metadata_path[i][j].name - elif input_format.startswith("MASA"): - raise ValueError("MASA as input format not implemented yet") - - # Check if all files are present in output directory - all_files_present = all( - [(output_dir / audio_file.name).exists() for audio_file in cfg.items_list] - ) - if not all_files_present: - raise Exception("Not all files are present in the output directory") - - # Make the output path as the new input path - cfg.input_path = output_dir + return \ No newline at end of file -- GitLab From 1b63ada4306ee40326cf828bdb5d6a4812e9ae45 Mon Sep 17 00:00:00 2001 From: knj Date: Wed, 7 Jun 2023 11:36:44 +0200 Subject: [PATCH 03/16] run formatter --- ivas_processing_scripts/processing/chains.py | 6 ++--- .../processing/processing.py | 24 +++++++++++-------- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/ivas_processing_scripts/processing/chains.py b/ivas_processing_scripts/processing/chains.py index 1b7ee788..948eb926 100755 --- a/ivas_processing_scripts/processing/chains.py +++ b/ivas_processing_scripts/processing/chains.py @@ -33,6 +33,8 @@ from typing import Optional from warnings import warn +from ivas_processing_scripts.audiotools import audio +from ivas_processing_scripts.audiotools.audiofile import read from ivas_processing_scripts.processing.config import TestConfig from ivas_processing_scripts.processing.evs import EVS from ivas_processing_scripts.processing.ivas import IVAS @@ -43,8 +45,6 @@ from ivas_processing_scripts.processing.processing_splitting_scaling import ( Processing_splitting_scaling, ) from ivas_processing_scripts.utils import get_abs_path, list_audio -from ivas_processing_scripts.audiotools import audio -from ivas_processing_scripts.audiotools.audiofile import read def init_processing_chains(cfg: TestConfig) -> None: @@ -557,4 +557,4 @@ def validate_input_files(cfg: TestConfig): else: warn( f"The length ({n_samples_x} samples) of audio ({item.name}) is not a multiple of frame length (20 ms)." - ) \ No newline at end of file + ) diff --git a/ivas_processing_scripts/processing/processing.py b/ivas_processing_scripts/processing/processing.py index 99fa872a..d97fdc59 100755 --- a/ivas_processing_scripts/processing/processing.py +++ b/ivas_processing_scripts/processing/processing.py @@ -35,14 +35,12 @@ from abc import ABC, abstractmethod from itertools import repeat from pathlib import Path from shutil import copyfile -from typing import Iterable, Optional, Union +from typing import Iterable, Union from warnings import warn -import numpy as np - from ivas_processing_scripts.audiotools import audio from ivas_processing_scripts.audiotools.audioarray import window -from ivas_processing_scripts.audiotools.audiofile import concat, read, trim, write +from ivas_processing_scripts.audiotools.audiofile import concat, trim from ivas_processing_scripts.audiotools.constants import IVAS_FRAME_LEN_MS from ivas_processing_scripts.audiotools.convert.__init__ import convert from ivas_processing_scripts.audiotools.metadata import ( @@ -161,7 +159,9 @@ 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, len_postamble_ms, logger: logging.Logger): +def concat_teardown( + x, splits, out_fmt, fs, in_fs, meta, len_postamble_ms, logger: logging.Logger +): if not splits: raise ValueError("Splitting not possible without split marker") @@ -182,7 +182,9 @@ def concat_teardown(x, splits, out_fmt, fs, in_fs, meta, len_postamble_ms, logge 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): + 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}" @@ -400,7 +402,9 @@ def process_item( copyfile(ppm, out_meta[idx]) -def remove_preamble(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, postamble_len_ms, meta, logger +): # remove preamble for ISM metadata if out_fmt.startswith("ISM"): # cut first half of the metadata @@ -416,14 +420,14 @@ def remove_preamble(x, out_fmt, fs, repeat_signal, preamble_len_ms, postamble_le if repeat_signal: if logger: logger.debug("Remove first half of signal") - + # need to subtract the postamble length before getting half of signal length - it was added after concatenation postamble_len_samples = (postamble_len_ms * fs) // 1000 trim_len_samples += (len(x) - postamble_len_samples) // 2 if trim_len_samples > 0 and logger: logger.debug("Remove preamble") - + x = trim(x, fs, (trim_len_samples, 0), samples=True) return x, meta @@ -459,4 +463,4 @@ def preprocess_background_noise(cfg): "background_object" ] = output_audio - return \ No newline at end of file + return -- GitLab From 28a127e334bed2a3870a903033c795dde3f54964 Mon Sep 17 00:00:00 2001 From: knj Date: Wed, 7 Jun 2023 12:08:41 +0200 Subject: [PATCH 04/16] make alignment check user-configurable in config --- .../selection/P800-1/config/P800-1.yml | 4 ++++ ivas_processing_scripts/processing/chains.py | 22 +++++++++---------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/experiments/selection/P800-1/config/P800-1.yml b/experiments/selection/P800-1/config/P800-1.yml index 92ac83b2..50f799bd 100644 --- a/experiments/selection/P800-1/config/P800-1.yml +++ b/experiments/selection/P800-1/config/P800-1.yml @@ -19,6 +19,8 @@ input: fmt: "STEREO" # TODO: to be clarified in Test Plan fs: 48000 + aligned_to: + len: 20 ################################################ ### Pre-processing on individual items @@ -36,6 +38,8 @@ preprocessing_2: # concatenation_order: [] preamble: 10000 preamble_noise: true + postamble: 10000 + postamble_noise: true repeat_signal: true background_noise: ### REQUIRED: SNR for background noise in dB diff --git a/ivas_processing_scripts/processing/chains.py b/ivas_processing_scripts/processing/chains.py index 948eb926..97967ab2 100755 --- a/ivas_processing_scripts/processing/chains.py +++ b/ivas_processing_scripts/processing/chains.py @@ -523,7 +523,7 @@ def validate_input_files(cfg: TestConfig): """ input_format = cfg.input["fmt"] num_chan_expected = audio.fromtype(input_format).num_channels - check_block_aligned_to = 20 + for item in cfg.items_list: if "fs" in cfg.input: sampling_rate = cfg.input["fs"] @@ -547,14 +547,14 @@ 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 check_block_aligned_to > 0: - frame_length_samples = (check_block_aligned_to / 1000) * fs - if n_samples_x % frame_length_samples != 0: - if input_format.startswith("ISM") or input_format.startswith("MASA"): - raise ValueError( - f"The length ({n_samples_x} samples) of audio ({item.name}) is not a multiple of frame length (20 ms) - not allowed for input formats with metadata." - ) + 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 + + 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) else: - warn( - f"The length ({n_samples_x} samples) of audio ({item.name}) is not a multiple of frame length (20 ms)." - ) + warn(msg) -- GitLab From a78f30b2404ca95f4cd7b2af46dbd610d303c5a8 Mon Sep 17 00:00:00 2001 From: knj Date: Wed, 7 Jun 2023 12:25:41 +0200 Subject: [PATCH 05/16] add postamble to configs --- experiments/selection/BS1534-1a/config/BS1534-1a.yml | 4 ++++ experiments/selection/BS1534-1b/config/BS1534-1b.yml | 4 ++++ experiments/selection/BS1534-2a/config/BS1534-2a.yml | 4 ++++ experiments/selection/BS1534-2b/config/BS1534-2b.yml | 4 ++++ experiments/selection/BS1534-3a/config/BS1534-3a.yml | 4 ++++ experiments/selection/BS1534-3b/config/BS1534-3b.yml | 4 ++++ experiments/selection/BS1534-4a/config/BS1534-4a.yml | 4 ++++ experiments/selection/BS1534-4b/config/BS1534-4b.yml | 4 ++++ experiments/selection/BS1534-5a/config/BS1534-5a.yml | 4 ++++ experiments/selection/BS1534-5b/config/BS1534-5b.yml | 4 ++++ experiments/selection/BS1534-6a/config/BS1534-6a.yml | 6 ++++++ experiments/selection/BS1534-6b/config/BS1534-6b.yml | 4 ++++ experiments/selection/BS1534-7a/config/BS1534-7a.yml | 4 ++++ experiments/selection/BS1534-7b/config/BS1534-7b.yml | 4 ++++ experiments/selection/P800-1/config/P800-1.yml | 2 +- experiments/selection/P800-2/config/P800-2.yml | 4 ++++ experiments/selection/P800-3/config/P800-3.yml | 7 ++++++- experiments/selection/P800-4/config/P800-4.yml | 4 ++++ experiments/selection/P800-5/config/P800-5.yml | 4 ++++ experiments/selection/P800-6/config/P800-6.yml | 4 ++++ experiments/selection/P800-7/config/P800-7.yml | 4 ++++ experiments/selection/P800-8/config/P800-8.yml | 4 ++++ experiments/selection/P800-9/config/P800-9.yml | 4 ++++ 23 files changed, 93 insertions(+), 2 deletions(-) diff --git a/experiments/selection/BS1534-1a/config/BS1534-1a.yml b/experiments/selection/BS1534-1a/config/BS1534-1a.yml index 4ed1bf73..ec8a6aab 100644 --- a/experiments/selection/BS1534-1a/config/BS1534-1a.yml +++ b/experiments/selection/BS1534-1a/config/BS1534-1a.yml @@ -18,6 +18,8 @@ condition_in_output_filename: true input: fmt: "STEREO" fs: 48000 + aligned_to: + len: 20 ################################################ ### Pre-processing on individual items @@ -33,6 +35,8 @@ 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 742b61e4..5c06316a 100644 --- a/experiments/selection/BS1534-1b/config/BS1534-1b.yml +++ b/experiments/selection/BS1534-1b/config/BS1534-1b.yml @@ -18,6 +18,8 @@ condition_in_output_filename: true input: fmt: "STEREO" fs: 48000 + aligned_to: + len: 20 ################################################ ### Pre-processing on individual items @@ -33,6 +35,8 @@ 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 543adb69..66e9a41c 100644 --- a/experiments/selection/BS1534-2a/config/BS1534-2a.yml +++ b/experiments/selection/BS1534-2a/config/BS1534-2a.yml @@ -18,6 +18,8 @@ condition_in_output_filename: true input: fmt: "5_1" fs: 48000 + aligned_to: + len: 20 ################################################ ### Pre-processing on individual items @@ -33,6 +35,8 @@ 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 fcaf4dfa..17289569 100644 --- a/experiments/selection/BS1534-2b/config/BS1534-2b.yml +++ b/experiments/selection/BS1534-2b/config/BS1534-2b.yml @@ -18,6 +18,8 @@ condition_in_output_filename: true input: fmt: "5_1" fs: 48000 + aligned_to: + len: 20 ################################################ ### Pre-processing on individual items @@ -33,6 +35,8 @@ 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 dfaf1808..c7e384d7 100644 --- a/experiments/selection/BS1534-3a/config/BS1534-3a.yml +++ b/experiments/selection/BS1534-3a/config/BS1534-3a.yml @@ -18,6 +18,8 @@ condition_in_output_filename: true input: fmt: "7_1_4" fs: 48000 + aligned_to: + len: 20 ################################################ ### Pre-processing on individual items @@ -33,6 +35,8 @@ 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 7c15efd7..889c06d6 100644 --- a/experiments/selection/BS1534-3b/config/BS1534-3b.yml +++ b/experiments/selection/BS1534-3b/config/BS1534-3b.yml @@ -18,6 +18,8 @@ condition_in_output_filename: true input: fmt: "7_1_4" fs: 48000 + aligned_to: + len: 20 ################################################ ### Pre-processing on individual items @@ -33,6 +35,8 @@ 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 917482b6..a1901c1d 100644 --- a/experiments/selection/BS1534-4a/config/BS1534-4a.yml +++ b/experiments/selection/BS1534-4a/config/BS1534-4a.yml @@ -18,6 +18,8 @@ condition_in_output_filename: true input: fmt: "HOA3" fs: 48000 + aligned_to: + len: 20 ################################################ ### Pre-processing on individual items @@ -33,6 +35,8 @@ 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 a549c07d..619fa75b 100644 --- a/experiments/selection/BS1534-4b/config/BS1534-4b.yml +++ b/experiments/selection/BS1534-4b/config/BS1534-4b.yml @@ -18,6 +18,8 @@ condition_in_output_filename: true input: fmt: "HOA3" fs: 48000 + aligned_to: + len: 20 ################################################ ### Pre-processing on individual items @@ -33,6 +35,8 @@ 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 8ac50c05..5186df64 100644 --- a/experiments/selection/BS1534-5a/config/BS1534-5a.yml +++ b/experiments/selection/BS1534-5a/config/BS1534-5a.yml @@ -18,6 +18,8 @@ condition_in_output_filename: true input: fmt: "HOA3" fs: 48000 + aligned_to: + len: 20 ################################################ ### Pre-processing on individual items @@ -33,6 +35,8 @@ 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 50ca2553..49eaa813 100644 --- a/experiments/selection/BS1534-5b/config/BS1534-5b.yml +++ b/experiments/selection/BS1534-5b/config/BS1534-5b.yml @@ -18,6 +18,8 @@ condition_in_output_filename: true input: fmt: "HOA3" fs: 48000 + aligned_to: + len: 20 ################################################ ### Pre-processing on individual items @@ -33,6 +35,8 @@ preprocessing: preprocessing_2: concatenate_input: false preamble_noise: false + postamble: 20 + postamble_noise: true repeat_signal: true ################################################# diff --git a/experiments/selection/BS1534-6a/config/BS1534-6a.yml b/experiments/selection/BS1534-6a/config/BS1534-6a.yml index 8d69f1f7..7073ab70 100644 --- a/experiments/selection/BS1534-6a/config/BS1534-6a.yml +++ b/experiments/selection/BS1534-6a/config/BS1534-6a.yml @@ -18,6 +18,8 @@ condition_in_output_filename: true input: fmt: "ISM3" fs: 48000 + aligned_to: + len: 20 ################################################ ### Pre-processing on individual items @@ -33,6 +35,10 @@ preprocessing: preprocessing_2: concatenate_input: false preamble_noise: false + postamble: 20 + postamble_noise: true + postamble: 20 + postamble_noise: true repeat_signal: true ################################################# diff --git a/experiments/selection/BS1534-6b/config/BS1534-6b.yml b/experiments/selection/BS1534-6b/config/BS1534-6b.yml index d7d5763a..eb1fba71 100644 --- a/experiments/selection/BS1534-6b/config/BS1534-6b.yml +++ b/experiments/selection/BS1534-6b/config/BS1534-6b.yml @@ -18,6 +18,8 @@ condition_in_output_filename: true input: fmt: "ISM4" fs: 48000 + aligned_to: + len: 20 ################################################ ### Pre-processing on individual items @@ -33,6 +35,8 @@ 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 89da64b0..5232f47f 100644 --- a/experiments/selection/BS1534-7a/config/BS1534-7a.yml +++ b/experiments/selection/BS1534-7a/config/BS1534-7a.yml @@ -18,6 +18,8 @@ condition_in_output_filename: true input: fmt: "FOA" fs: 48000 + aligned_to: + len: 20 ################################################ ### Pre-processing on individual items @@ -33,6 +35,8 @@ 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 e9a3075b..f89704b0 100644 --- a/experiments/selection/BS1534-7b/config/BS1534-7b.yml +++ b/experiments/selection/BS1534-7b/config/BS1534-7b.yml @@ -18,6 +18,8 @@ condition_in_output_filename: true input: fmt: "FOA" fs: 48000 + aligned_to: + len: 20 ################################################ ### Pre-processing on individual items @@ -33,6 +35,8 @@ 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 50f799bd..36e790d1 100644 --- a/experiments/selection/P800-1/config/P800-1.yml +++ b/experiments/selection/P800-1/config/P800-1.yml @@ -38,7 +38,7 @@ preprocessing_2: # concatenation_order: [] preamble: 10000 preamble_noise: true - postamble: 10000 + postamble: 20 postamble_noise: true repeat_signal: true background_noise: diff --git a/experiments/selection/P800-2/config/P800-2.yml b/experiments/selection/P800-2/config/P800-2.yml index 740eb3b0..8d18b0d5 100644 --- a/experiments/selection/P800-2/config/P800-2.yml +++ b/experiments/selection/P800-2/config/P800-2.yml @@ -19,6 +19,8 @@ input: fmt: "STEREO" # TODO: to be clarified in Test Plan fs: 48000 + aligned_to: + len: 20 ################################################ ### Pre-processing on individual items @@ -36,6 +38,8 @@ 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 0b454c00..762831f2 100644 --- a/experiments/selection/P800-3/config/P800-3.yml +++ b/experiments/selection/P800-3/config/P800-3.yml @@ -17,7 +17,10 @@ condition_in_output_filename: true ################################################ input: fmt: "STEREO" - + fs: 48000 + aligned_to: + len: 20 + ################################################ ### Pre-processing on individual items ################################################ @@ -34,6 +37,8 @@ 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 98aa56da..ef52a833 100644 --- a/experiments/selection/P800-4/config/P800-4.yml +++ b/experiments/selection/P800-4/config/P800-4.yml @@ -19,6 +19,8 @@ input: fmt: "FOA" # TODO: to be clarified in Test Plan fs: 48000 + aligned_to: + len: 20 ################################################ ### Pre-processing on individual items @@ -37,6 +39,8 @@ 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 d15fc7e0..ea9ec407 100644 --- a/experiments/selection/P800-5/config/P800-5.yml +++ b/experiments/selection/P800-5/config/P800-5.yml @@ -19,6 +19,8 @@ input: fmt: "FOA" # TODO: to be clarified in Test Plan fs: 48000 + aligned_to: + len: 20 ################################################ ### Pre-processing on individual items @@ -37,6 +39,8 @@ 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-6/config/P800-6.yml b/experiments/selection/P800-6/config/P800-6.yml index 2dd0f1c2..e4ea1242 100644 --- a/experiments/selection/P800-6/config/P800-6.yml +++ b/experiments/selection/P800-6/config/P800-6.yml @@ -19,6 +19,8 @@ input: fmt: "ISM1" # TODO: to be clarified in Test Plan fs: 48000 + aligned_to: + len: 20 ################################################ ### Pre-processing on individual items @@ -36,6 +38,8 @@ preprocessing_2: # concatenation_order: [] preamble: 10000 preamble_noise: true + postamble: 20 + postamble_noise: true repeat_signal: true ################################################# diff --git a/experiments/selection/P800-7/config/P800-7.yml b/experiments/selection/P800-7/config/P800-7.yml index b584a724..6d9f468a 100644 --- a/experiments/selection/P800-7/config/P800-7.yml +++ b/experiments/selection/P800-7/config/P800-7.yml @@ -19,6 +19,8 @@ input: fmt: "ISM2" # TODO: to be clarified in Test Plan fs: 48000 + aligned_to: + len: 20 ################################################ ### Pre-processing on individual items @@ -36,6 +38,8 @@ preprocessing_2: # concatenation_order: [] preamble: 10000 preamble_noise: true + postamble: 20 + postamble_noise: true repeat_signal: true ################################################# diff --git a/experiments/selection/P800-8/config/P800-8.yml b/experiments/selection/P800-8/config/P800-8.yml index 2dbf23d2..69b84d02 100644 --- a/experiments/selection/P800-8/config/P800-8.yml +++ b/experiments/selection/P800-8/config/P800-8.yml @@ -18,6 +18,8 @@ condition_in_output_filename: true input: fmt: "FOA" fs: 48000 + aligned_to: + len: 20 ################################################ ### Pre-processing on individual items @@ -35,6 +37,8 @@ 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 fe941a8a..8cfb2b37 100644 --- a/experiments/selection/P800-9/config/P800-9.yml +++ b/experiments/selection/P800-9/config/P800-9.yml @@ -18,6 +18,8 @@ condition_in_output_filename: true input: fmt: "FOA" fs: 48000 + aligned_to: + len: 20 ################################################ ### Pre-processing on individual items @@ -35,6 +37,8 @@ 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 -- GitLab From 065b41daa4628824fbc0e5aaf8e65f3906a8065c Mon Sep 17 00:00:00 2001 From: knj Date: Wed, 7 Jun 2023 12:32:36 +0200 Subject: [PATCH 06/16] update template config with new keys --- examples/TEMPLATE.yml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/examples/TEMPLATE.yml b/examples/TEMPLATE.yml index 0dcd1ae8..89415cee 100755 --- a/examples/TEMPLATE.yml +++ b/examples/TEMPLATE.yml @@ -65,6 +65,13 @@ 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 ################################################ ### Pre-processing on individual items @@ -112,6 +119,10 @@ 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 -- GitLab From eec016ffbf48ade857279d215d2b657e4bd678d3 Mon Sep 17 00:00:00 2001 From: knj Date: Wed, 7 Jun 2023 12:57:53 +0200 Subject: [PATCH 07/16] fix length check --- tests/test_experiments.py | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/tests/test_experiments.py b/tests/test_experiments.py index a073b2e9..5693f9be 100644 --- a/tests/test_experiments.py +++ b/tests/test_experiments.py @@ -39,7 +39,7 @@ from numpy.random import random, seed from ivas_processing_scripts import main as generate_test from ivas_processing_scripts.audiotools import audio -from ivas_processing_scripts.audiotools.audiofile import concat, write +from ivas_processing_scripts.audiotools.audiofile import concat, write, read from ivas_processing_scripts.processing.config import TestConfig from tests.constants import ( FORMAT_TO_METADATA_FILES, @@ -98,6 +98,25 @@ def setup_input_files_for_config(config): write(bg_noise_path, noise) +def all_lengths_equal(cfg): + input_files = cfg.items_list + output_folder = cfg.output_path + + all_lengths_equal = True + for condition in cfg.conditions_to_generate.keys(): + output_condition_folder = output_folder.joinpath(condition) + for input_file in input_files: + output_file = output_condition_folder.joinpath(input_file.name) + in_signal = read(input_file) + out_signal = read(output_file) + shapes_equal = in_signal.shape == out_signal.shape + if not shapes_equal: + print("Unequal file length for {input_file.name} in condition {condition}") + all_lengths_equal = False + + return all_lengths_equal + + @pytest.mark.parametrize( "exp_lab_pair", zip(INPUT_EXPERIMENT_NAMES, LAB_IDS_FOR_EXPERIMENTS) ) @@ -106,7 +125,13 @@ def test_generate_test_items(exp_lab_pair): cfgs = create_experiment_setup(exp_name, lab_id) cfg = cfgs[0] + # patch key to make checking for same input and output file length easier + cfg.condition_in_output_filename = False + args = Arguments(str(cfg)) config = TestConfig(cfg) setup_input_files_for_config(config) generate_test(args) + + if not all_lengths_equal(cfg): + raise RuntimeError("Unequal lengths between input and output files detected") -- GitLab From 74231ca7cb6a7112595bb1cb884e772295a009c9 Mon Sep 17 00:00:00 2001 From: knj Date: Wed, 7 Jun 2023 13:04:12 +0200 Subject: [PATCH 08/16] fix test code --- tests/test_experiments.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/test_experiments.py b/tests/test_experiments.py index 5693f9be..d43ae296 100644 --- a/tests/test_experiments.py +++ b/tests/test_experiments.py @@ -125,11 +125,12 @@ def test_generate_test_items(exp_lab_pair): cfgs = create_experiment_setup(exp_name, lab_id) cfg = cfgs[0] - # patch key to make checking for same input and output file length easier - cfg.condition_in_output_filename = False - args = Arguments(str(cfg)) config = TestConfig(cfg) + + # patch key to make checking for same input and output file length easier + config.condition_in_output_filename = False + setup_input_files_for_config(config) generate_test(args) -- GitLab From 8623616d63f082089c729696f30c13c706d40144 Mon Sep 17 00:00:00 2001 From: knj Date: Wed, 7 Jun 2023 13:29:49 +0200 Subject: [PATCH 09/16] fix path in internal length check --- .../processing/processing_splitting_scaling.py | 1 - 1 file changed, 1 deletion(-) diff --git a/ivas_processing_scripts/processing/processing_splitting_scaling.py b/ivas_processing_scripts/processing/processing_splitting_scaling.py index 1c2f916c..94214ad1 100644 --- a/ivas_processing_scripts/processing/processing_splitting_scaling.py +++ b/ivas_processing_scripts/processing/processing_splitting_scaling.py @@ -244,7 +244,6 @@ class Processing_splitting_scaling(Processing): # check length of output signals input_aligned_file = ( in_file.parent.parent - / "20ms_aligned_files" / f"{Path(in_file.stem).stem}.wav" ) input_aligned_array, _ = read(input_aligned_file) -- GitLab From 36b2ae50fd2b08d7da7bda829bba5afa963f977b Mon Sep 17 00:00:00 2001 From: knj Date: Wed, 7 Jun 2023 13:32:19 +0200 Subject: [PATCH 10/16] disable some tests temporarily for quicker testing --- .gitlab-ci.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index d5a2b1b5..0a3248f5 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -65,7 +65,7 @@ check_for_binaries: # ------------------------------------ # test the format conversion only -test_audiotools_convert: +.test_audiotools_convert: stage: test tags: - linux @@ -81,7 +81,7 @@ experiments: script: - *print-common-info - *get-codec-binaries - - python3 -m pytest tests/test_experiments.py::test_generate_test_items -n auto | tee log.txt + - python3 -m pytest tests/test_experiments.py::test_generate_test_items -n auto -x | tee log.txt artifacts: paths: - experiments/selection/*/proc_output/*.log @@ -90,7 +90,7 @@ experiments: expire_in: 1 week # run some test configs for item creation -test_processing: +.test_processing: stage: test rules: - if: $CI_PIPELINE_SOURCE == 'merge_request_event' -- GitLab From b337605f8dfb51abcbf54f0f009d4b62694c3949 Mon Sep 17 00:00:00 2001 From: knj Date: Wed, 7 Jun 2023 13:57:26 +0200 Subject: [PATCH 11/16] fix base path in config creation script --- generate_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/generate_test.py b/generate_test.py index c393dd73..c187dbc2 100644 --- a/generate_test.py +++ b/generate_test.py @@ -96,7 +96,7 @@ def create_experiment_setup(experiment, lab) -> list[Path]: experiments = EXPERIMENTS_P800 + EXPERIMENTS_BS1534 seed = 101 + experiments.index(experiment) * 4 + LAB_IDS.index(lab) - base_path = Path(HERE.name).joinpath(f"experiments/selection/{experiment}") + base_path = HERE.joinpath(f"experiments/selection/{experiment}") cfgs = list() for cat in categories: -- GitLab From e747b1a2bcca77081deda7d96be36e522a237a9a Mon Sep 17 00:00:00 2001 From: knj Date: Wed, 7 Jun 2023 14:12:01 +0200 Subject: [PATCH 12/16] disable length check for no concatenation for now --- .../processing/processing_splitting_scaling.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/ivas_processing_scripts/processing/processing_splitting_scaling.py b/ivas_processing_scripts/processing/processing_splitting_scaling.py index 94214ad1..8c3ef2dc 100644 --- a/ivas_processing_scripts/processing/processing_splitting_scaling.py +++ b/ivas_processing_scripts/processing/processing_splitting_scaling.py @@ -242,15 +242,15 @@ class Processing_splitting_scaling(Processing): else: # check length of output signals - input_aligned_file = ( - in_file.parent.parent - / f"{Path(in_file.stem).stem}.wav" - ) - input_aligned_array, _ = read(input_aligned_file) - if (len_inp := len(input_aligned_array)) != (len_out := len(x)): - warn( - f"For file {out_file} the length is {len_out} and does not match the (frame aligned) input length {len_inp}." - ) + # input_aligned_file = ( + # in_file.parent.parent + # / f"{Path(in_file.stem).stem}.wav" + # ) + # input_aligned_array, _ = read(input_aligned_file) + # if (len_inp := len(input_aligned_array)) != (len_out := len(x)): + # warn( + # f"For file {out_file} the length is {len_out} and does not match the (frame aligned) input length {len_inp}." + # ) # set output values out_files = [out_file] -- GitLab From 8290f26defdf303712237a29a6a28bcde59e4c72 Mon Sep 17 00:00:00 2001 From: knj Date: Wed, 7 Jun 2023 15:04:30 +0200 Subject: [PATCH 13/16] fix test and postamble trimming for tests without concatenation --- .../processing/processing.py | 6 +++--- .../processing/processing_splitting_scaling.py | 6 +++--- tests/test_experiments.py | 17 +++++++---------- 3 files changed, 13 insertions(+), 16 deletions(-) diff --git a/ivas_processing_scripts/processing/processing.py b/ivas_processing_scripts/processing/processing.py index d97fdc59..219d9bb3 100755 --- a/ivas_processing_scripts/processing/processing.py +++ b/ivas_processing_scripts/processing/processing.py @@ -402,7 +402,7 @@ def process_item( copyfile(ppm, out_meta[idx]) -def remove_preamble( +def remove_pre_and_postamble( x, out_fmt, fs, repeat_signal, preamble_len_ms, postamble_len_ms, meta, logger ): # remove preamble for ISM metadata @@ -417,18 +417,18 @@ def remove_preamble( # get number of samples to cut from start trim_len_samples = (preamble_len_ms * fs) // 1000 + postamble_len_samples = (postamble_len_ms * fs) // 1000 if repeat_signal: if logger: logger.debug("Remove first half of signal") # need to subtract the postamble length before getting half of signal length - it was added after concatenation - postamble_len_samples = (postamble_len_ms * fs) // 1000 trim_len_samples += (len(x) - postamble_len_samples) // 2 if trim_len_samples > 0 and logger: logger.debug("Remove preamble") - x = trim(x, fs, (trim_len_samples, 0), samples=True) + x = trim(x, fs, (trim_len_samples, postamble_len_samples), samples=True) return x, meta diff --git a/ivas_processing_scripts/processing/processing_splitting_scaling.py b/ivas_processing_scripts/processing/processing_splitting_scaling.py index 8c3ef2dc..3fdbb87c 100644 --- a/ivas_processing_scripts/processing/processing_splitting_scaling.py +++ b/ivas_processing_scripts/processing/processing_splitting_scaling.py @@ -14,7 +14,7 @@ from ivas_processing_scripts.audiotools.wrappers.bs1770 import loudness_norm from ivas_processing_scripts.processing.processing import ( Processing, concat_teardown, - remove_preamble, + remove_pre_and_postamble, ) # @@ -191,8 +191,8 @@ 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.repeat_signal: - x, in_meta = remove_preamble( + if self.preamble or self.postamble or self.repeat_signal: + x, in_meta = remove_pre_and_postamble( x, self.out_fmt, self.fs, diff --git a/tests/test_experiments.py b/tests/test_experiments.py index d43ae296..4671a123 100644 --- a/tests/test_experiments.py +++ b/tests/test_experiments.py @@ -39,6 +39,7 @@ from numpy.random import random, seed from ivas_processing_scripts import main as generate_test from ivas_processing_scripts.audiotools import audio +from ivas_processing_scripts.utils import list_audio from ivas_processing_scripts.audiotools.audiofile import concat, write, read from ivas_processing_scripts.processing.config import TestConfig from tests.constants import ( @@ -99,19 +100,18 @@ def setup_input_files_for_config(config): def all_lengths_equal(cfg): - input_files = cfg.items_list output_folder = cfg.output_path all_lengths_equal = True for condition in cfg.conditions_to_generate.keys(): output_condition_folder = output_folder.joinpath(condition) - for input_file in input_files: - output_file = output_condition_folder.joinpath(input_file.name) - in_signal = read(input_file) - out_signal = read(output_file) + for input_file in list_audio(cfg.input_path): + output_file = output_condition_folder.joinpath(input_file.name).with_suffix(f".{condition}.wav") + in_signal, _ = read(input_file) + out_signal, _ = read(output_file) shapes_equal = in_signal.shape == out_signal.shape if not shapes_equal: - print("Unequal file length for {input_file.name} in condition {condition}") + print(f"Unequal file length for {input_file.name} in condition {condition}") all_lengths_equal = False return all_lengths_equal @@ -128,11 +128,8 @@ def test_generate_test_items(exp_lab_pair): args = Arguments(str(cfg)) config = TestConfig(cfg) - # patch key to make checking for same input and output file length easier - config.condition_in_output_filename = False - setup_input_files_for_config(config) generate_test(args) - if not all_lengths_equal(cfg): + if not all_lengths_equal(config): raise RuntimeError("Unequal lengths between input and output files detected") -- GitLab From 88a36ddf16adddd24df6dafda9bbb5caee0a787a Mon Sep 17 00:00:00 2001 From: knj Date: Wed, 7 Jun 2023 15:43:18 +0200 Subject: [PATCH 14/16] correct configs for object tests + length check in test --- experiments/selection/BS1534-6a/config/BS1534-6a.yml | 5 +---- experiments/selection/BS1534-6b/config/BS1534-6b.yml | 3 +-- experiments/selection/P800-6/config/P800-6.yml | 3 +-- experiments/selection/P800-7/config/P800-7.yml | 3 +-- tests/test_experiments.py | 6 +++--- 5 files changed, 7 insertions(+), 13 deletions(-) diff --git a/experiments/selection/BS1534-6a/config/BS1534-6a.yml b/experiments/selection/BS1534-6a/config/BS1534-6a.yml index 7073ab70..d3363f81 100644 --- a/experiments/selection/BS1534-6a/config/BS1534-6a.yml +++ b/experiments/selection/BS1534-6a/config/BS1534-6a.yml @@ -20,6 +20,7 @@ input: fs: 48000 aligned_to: len: 20 + force: true ################################################ ### Pre-processing on individual items @@ -35,10 +36,6 @@ preprocessing: preprocessing_2: concatenate_input: false preamble_noise: false - postamble: 20 - postamble_noise: true - postamble: 20 - postamble_noise: true repeat_signal: true ################################################# diff --git a/experiments/selection/BS1534-6b/config/BS1534-6b.yml b/experiments/selection/BS1534-6b/config/BS1534-6b.yml index eb1fba71..63d00c7b 100644 --- a/experiments/selection/BS1534-6b/config/BS1534-6b.yml +++ b/experiments/selection/BS1534-6b/config/BS1534-6b.yml @@ -20,6 +20,7 @@ input: fs: 48000 aligned_to: len: 20 + force: true ################################################ ### Pre-processing on individual items @@ -35,8 +36,6 @@ preprocessing: preprocessing_2: concatenate_input: false preamble_noise: false - postamble: 20 - postamble_noise: true repeat_signal: true ################################################# diff --git a/experiments/selection/P800-6/config/P800-6.yml b/experiments/selection/P800-6/config/P800-6.yml index e4ea1242..467345ec 100644 --- a/experiments/selection/P800-6/config/P800-6.yml +++ b/experiments/selection/P800-6/config/P800-6.yml @@ -21,6 +21,7 @@ input: fs: 48000 aligned_to: len: 20 + force: true ################################################ ### Pre-processing on individual items @@ -38,8 +39,6 @@ preprocessing_2: # concatenation_order: [] preamble: 10000 preamble_noise: true - postamble: 20 - postamble_noise: true repeat_signal: true ################################################# diff --git a/experiments/selection/P800-7/config/P800-7.yml b/experiments/selection/P800-7/config/P800-7.yml index 6d9f468a..43798520 100644 --- a/experiments/selection/P800-7/config/P800-7.yml +++ b/experiments/selection/P800-7/config/P800-7.yml @@ -21,6 +21,7 @@ input: fs: 48000 aligned_to: len: 20 + force: true ################################################ ### Pre-processing on individual items @@ -38,8 +39,6 @@ preprocessing_2: # concatenation_order: [] preamble: 10000 preamble_noise: true - postamble: 20 - postamble_noise: true repeat_signal: true ################################################# diff --git a/tests/test_experiments.py b/tests/test_experiments.py index 4671a123..4a2dbde0 100644 --- a/tests/test_experiments.py +++ b/tests/test_experiments.py @@ -109,9 +109,9 @@ def all_lengths_equal(cfg): output_file = output_condition_folder.joinpath(input_file.name).with_suffix(f".{condition}.wav") in_signal, _ = read(input_file) out_signal, _ = read(output_file) - shapes_equal = in_signal.shape == out_signal.shape - if not shapes_equal: - print(f"Unequal file length for {input_file.name} in condition {condition}") + lengths_equal = in_signal.shape[0] == out_signal.shape[0] + if not lengths_equal: + print(f"Unequal file length for {input_file.name} in condition {condition} - in len {in_signal.shape[0]} vs. out len {out_signal.shape[0]}") all_lengths_equal = False return all_lengths_equal -- GitLab From 0221275018198629ee69c60f40fe095232ba7cc0 Mon Sep 17 00:00:00 2001 From: knj Date: Wed, 7 Jun 2023 15:47:46 +0200 Subject: [PATCH 15/16] run linter and formatter --- ivas_processing_scripts/processing/chains.py | 8 ++++++-- .../processing/processing_splitting_scaling.py | 1 - tests/test_experiments.py | 12 ++++++++---- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/ivas_processing_scripts/processing/chains.py b/ivas_processing_scripts/processing/chains.py index 97967ab2..3d7e0491 100755 --- a/ivas_processing_scripts/processing/chains.py +++ b/ivas_processing_scripts/processing/chains.py @@ -548,8 +548,12 @@ def validate_input_files(cfg: TestConfig): ) 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 + 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 + ) alignment_len_samples = (input_aligned_cfg["len"] / 1000) * fs if n_samples_x % alignment_len_samples != 0: diff --git a/ivas_processing_scripts/processing/processing_splitting_scaling.py b/ivas_processing_scripts/processing/processing_splitting_scaling.py index 3fdbb87c..86b893b2 100644 --- a/ivas_processing_scripts/processing/processing_splitting_scaling.py +++ b/ivas_processing_scripts/processing/processing_splitting_scaling.py @@ -3,7 +3,6 @@ import logging import re from itertools import repeat from pathlib import Path -from warnings import warn import numpy as np diff --git a/tests/test_experiments.py b/tests/test_experiments.py index 4a2dbde0..b8e62114 100644 --- a/tests/test_experiments.py +++ b/tests/test_experiments.py @@ -39,9 +39,9 @@ from numpy.random import random, seed from ivas_processing_scripts import main as generate_test from ivas_processing_scripts.audiotools import audio -from ivas_processing_scripts.utils import list_audio -from ivas_processing_scripts.audiotools.audiofile import concat, write, read +from ivas_processing_scripts.audiotools.audiofile import concat, read, write from ivas_processing_scripts.processing.config import TestConfig +from ivas_processing_scripts.utils import list_audio from tests.constants import ( FORMAT_TO_METADATA_FILES, INPUT_EXPERIMENT_NAMES, @@ -106,12 +106,16 @@ def all_lengths_equal(cfg): for condition in cfg.conditions_to_generate.keys(): output_condition_folder = output_folder.joinpath(condition) for input_file in list_audio(cfg.input_path): - output_file = output_condition_folder.joinpath(input_file.name).with_suffix(f".{condition}.wav") + output_file = output_condition_folder.joinpath(input_file.name).with_suffix( + f".{condition}.wav" + ) in_signal, _ = read(input_file) out_signal, _ = read(output_file) lengths_equal = in_signal.shape[0] == out_signal.shape[0] if not lengths_equal: - print(f"Unequal file length for {input_file.name} in condition {condition} - in len {in_signal.shape[0]} vs. out len {out_signal.shape[0]}") + print( + f"Unequal file length for {input_file.name} in condition {condition} - in len {in_signal.shape[0]} vs. out len {out_signal.shape[0]}" + ) all_lengths_equal = False return all_lengths_equal -- GitLab From 4409f5f389220111c4e81868493971dea10e8b1a Mon Sep 17 00:00:00 2001 From: knj Date: Wed, 7 Jun 2023 16:10:31 +0200 Subject: [PATCH 16/16] activate all tests again --- .gitlab-ci.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 0a3248f5..d5a2b1b5 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -65,7 +65,7 @@ check_for_binaries: # ------------------------------------ # test the format conversion only -.test_audiotools_convert: +test_audiotools_convert: stage: test tags: - linux @@ -81,7 +81,7 @@ experiments: script: - *print-common-info - *get-codec-binaries - - python3 -m pytest tests/test_experiments.py::test_generate_test_items -n auto -x | tee log.txt + - python3 -m pytest tests/test_experiments.py::test_generate_test_items -n auto | tee log.txt artifacts: paths: - experiments/selection/*/proc_output/*.log @@ -90,7 +90,7 @@ experiments: expire_in: 1 week # run some test configs for item creation -.test_processing: +test_processing: stage: test rules: - if: $CI_PIPELINE_SOURCE == 'merge_request_event' -- GitLab