From cbfbd5b1478472a82e187966a722bd3ab3dd30e5 Mon Sep 17 00:00:00 2001 From: Treffehn Date: Wed, 24 May 2023 15:25:31 +0200 Subject: [PATCH 1/3] added key for repeating signal --- README.md | 2 ++ examples/TEMPLATE.yml | 2 ++ .../audiotools/convert/channelbased.py | 4 +++ .../generation/process_ism_items.py | 20 ++++++++++--- ivas_processing_scripts/processing/chains.py | 1 + .../processing/preprocessing_2.py | 9 ++++++ .../processing/processing.py | 30 +++++++++++++------ 7 files changed, 55 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index b0a09124..3106bcbd 100755 --- a/README.md +++ b/README.md @@ -253,6 +253,8 @@ input: # background_noise_path: ".../noise.wav" ### Flag for using low level [-4,+4] background noise; default = false # low_level_noise: true + ### Flag for repeating the whole signal once and discarding the first half after processing + # repeat_signal: true ``` diff --git a/examples/TEMPLATE.yml b/examples/TEMPLATE.yml index a5039d4d..270be375 100755 --- a/examples/TEMPLATE.yml +++ b/examples/TEMPLATE.yml @@ -117,6 +117,8 @@ input: # background_noise_path: ".../noise.wav" ### Flag for using low level [-4,+4] background noise; default = false # low_level_noise: true + ### Flag for repeating the whole signal once and discarding the first half after processing + # repeat_signal: true ################################################# ### Bitstream processing diff --git a/ivas_processing_scripts/audiotools/convert/channelbased.py b/ivas_processing_scripts/audiotools/convert/channelbased.py index 480d635e..5b9874a2 100755 --- a/ivas_processing_scripts/audiotools/convert/channelbased.py +++ b/ivas_processing_scripts/audiotools/convert/channelbased.py @@ -112,6 +112,10 @@ def render_cba_to_binaural( render_cba_to_cba(cba, cba_stereo) bin.audio = cba_stereo.audio return + elif cba.name == "STEREO": + # no binauralization possible for stereo -> assume binaural signal + bin.audio = cba.audio + return cba.audio = resample_itu(cba, 48000) old_fs = cba.fs diff --git a/ivas_processing_scripts/generation/process_ism_items.py b/ivas_processing_scripts/generation/process_ism_items.py index cb8a46b8..ff123663 100644 --- a/ivas_processing_scripts/generation/process_ism_items.py +++ b/ivas_processing_scripts/generation/process_ism_items.py @@ -102,10 +102,22 @@ def generate_ism_items( # repeat for all source files for i in range(N_sources): # parse parameters from the scene description - source_file = scene["source"][i] if isinstance(scene["source"], list) else scene["source"] - source_azi = scene["azimuth"][i] if isinstance(scene["azimuth"], list) else scene["azimuth"] - source_ele = scene["elevation"][i] if isinstance(scene["elevation"], list) else scene["elevation"] - + source_file = ( + scene["source"][i] + if isinstance(scene["source"], list) + else scene["source"] + ) + source_azi = ( + scene["azimuth"][i] + if isinstance(scene["azimuth"], list) + else scene["azimuth"] + ) + source_ele = ( + scene["elevation"][i] + if isinstance(scene["elevation"], list) + else scene["elevation"] + ) + logger.info( f"Encoding {source_file} at position(s) {source_azi},{source_ele}" ) diff --git a/ivas_processing_scripts/processing/chains.py b/ivas_processing_scripts/processing/chains.py index c11be9a1..9e368f06 100755 --- a/ivas_processing_scripts/processing/chains.py +++ b/ivas_processing_scripts/processing/chains.py @@ -182,6 +182,7 @@ def get_preprocessing_2(cfg: TestConfig) -> dict: "background_noise": background, "in_mask": pre2_cfg.get("mask", None), "multiprocessing": cfg.multiprocessing, + "repeat_signal": pre2_cfg.get("repeat_signal", False), } ) ) diff --git a/ivas_processing_scripts/processing/preprocessing_2.py b/ivas_processing_scripts/processing/preprocessing_2.py index 0e84c447..b5f4e9b6 100644 --- a/ivas_processing_scripts/processing/preprocessing_2.py +++ b/ivas_processing_scripts/processing/preprocessing_2.py @@ -81,6 +81,8 @@ class Preprocessing2(Processing): # modify metadata metadata = add_remove_preamble(metadata, preamble) + if self.repeat_signal: + metadata = [np.concatenate((m, m), axis=0) for m in metadata] meta_files = write_ISM_metadata_in_file(metadata, [out_file], True) # modify audio object @@ -106,6 +108,13 @@ class Preprocessing2(Processing): audio_object, in_meta, logger ) + # repeat whole signal as part of preamble + if self.repeat_signal: + logger.debug("Repeat signal") + audio_object.audio = np.concatenate( + (audio_object.audio, audio_object.audio), axis=0 + ) + # 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 cfc5a381..1f8e8712 100755 --- a/ivas_processing_scripts/processing/processing.py +++ b/ivas_processing_scripts/processing/processing.py @@ -323,10 +323,10 @@ def preprocess_2(cfg, logger): def reverse_process_2(cfg, logger): - # remove preamble - if cfg.pre2.preamble: - logger.info("Remove preamble") - remove_preamble(cfg) + + # remove preamble and first half of signal due to repetition + if cfg.pre2.preamble or cfg.pre2.repeat_signal: + remove_preamble(cfg, logger) # reverse concatenation if cfg.pre2.concatenate_input: @@ -443,7 +443,7 @@ def process_item( copyfile(ppm, out_meta[idx]) -def remove_preamble(cfg): +def remove_preamble(cfg, logger): # get number of channels from output format num_channels = audio.fromtype(cfg.postprocessing["fmt"]).num_channels for odir in cfg.out_dirs: @@ -460,10 +460,15 @@ def remove_preamble(cfg): for meta_i in meta_item: metadata_array.append(np.genfromtxt(meta_i, delimiter=",")) + # cut first half of the metadata + if cfg.pre2.repeat_signal: + metadata_array = [m[int(len(m) / 2) :, :] for m in metadata_array] + # remove preamble - metadata_array = add_remove_preamble( - metadata_array, cfg.pre2.preamble, add=False - ) + if cfg.pre2.preamble: + metadata_array = add_remove_preamble( + metadata_array, cfg.pre2.preamble, add=False + ) # write csv files write_ISM_metadata_in_file( @@ -475,8 +480,15 @@ def remove_preamble(cfg): path_input, nchannels=num_channels, fs=cfg.postprocessing["fs"] ) + # remove first half of signal + if cfg.pre2.repeat_signal: + logger.info("Remove first half of signal") + x = x[int(len(x) / 2) :, :] + # remove preamble - x = trim(x, fs, (cfg.pre2.preamble, 0)) + if cfg.pre2.preamble: + logger.info("Remove preamble") + x = trim(x, fs, (cfg.pre2.preamble, 0)) # write file write(path_input, x, fs) -- GitLab From 9166da4284048fbc65024aab1a7461dcbd3e579e Mon Sep 17 00:00:00 2001 From: Treffehn Date: Wed, 24 May 2023 16:06:21 +0200 Subject: [PATCH 2/3] formatting --- ivas_processing_scripts/processing/processing.py | 1 - 1 file changed, 1 deletion(-) diff --git a/ivas_processing_scripts/processing/processing.py b/ivas_processing_scripts/processing/processing.py index 1f8e8712..ac12784b 100755 --- a/ivas_processing_scripts/processing/processing.py +++ b/ivas_processing_scripts/processing/processing.py @@ -323,7 +323,6 @@ def preprocess_2(cfg, logger): def reverse_process_2(cfg, logger): - # remove preamble and first half of signal due to repetition if cfg.pre2.preamble or cfg.pre2.repeat_signal: remove_preamble(cfg, logger) -- GitLab From e9f247aef17b66cc545af2f9524881530563efbc Mon Sep 17 00:00:00 2001 From: Treffehn Date: Thu, 25 May 2023 10:40:50 +0200 Subject: [PATCH 3/3] added key to tests P800 2, 4 and 5 --- experiments/selection/P800-2/config/P800-2.yml | 1 + experiments/selection/P800-4/config/P800-4.yml | 1 + experiments/selection/P800-5/config/P800-5.yml | 1 + 3 files changed, 3 insertions(+) diff --git a/experiments/selection/P800-2/config/P800-2.yml b/experiments/selection/P800-2/config/P800-2.yml index af6d38cc..86f71789 100644 --- a/experiments/selection/P800-2/config/P800-2.yml +++ b/experiments/selection/P800-2/config/P800-2.yml @@ -40,6 +40,7 @@ preprocessing_2: snr: 15 ### REQUIRED: Path to background noise, must have same format and sampling rate as input signal(s) background_noise_path: "experiments/selection/P800-2/background_noise/background_noise.wav" + repeat_signal: true ################################################# ### Bitstream processing diff --git a/experiments/selection/P800-4/config/P800-4.yml b/experiments/selection/P800-4/config/P800-4.yml index d48a900e..6c3a53ac 100644 --- a/experiments/selection/P800-4/config/P800-4.yml +++ b/experiments/selection/P800-4/config/P800-4.yml @@ -35,6 +35,7 @@ preprocessing_2: # concatenation_order: [] preamble: 10000 preamble_noise: true + repeat_signal: true ################################################# ### Bitstream processing diff --git a/experiments/selection/P800-5/config/P800-5.yml b/experiments/selection/P800-5/config/P800-5.yml index de93f64d..1b7d50a9 100644 --- a/experiments/selection/P800-5/config/P800-5.yml +++ b/experiments/selection/P800-5/config/P800-5.yml @@ -40,6 +40,7 @@ preprocessing_2: snr: 15 ### REQUIRED: Path to background noise, must have same format and sampling rate as input signal(s) background_noise_path: "experiments/selection/P800-5/background_noise/background_noise.wav" + repeat_signal: true ################################################# ### Bitstream processing -- GitLab