diff --git a/examples/TEMPLATE.yml b/examples/TEMPLATE.yml index 9252a44df02ffde494929694a26a916e173171ff..37ca8024e498b26ea6dc42bc803ea0bcc7125aa6 100755 --- a/examples/TEMPLATE.yml +++ b/examples/TEMPLATE.yml @@ -49,6 +49,10 @@ output_path: ".../tmp_output" # input_select: # - "48kHz" +### Include the condition number in the item name; default = false +### for e.g. abcxyz.wav --> abcxyz.cXX.wav +# condition_in_output_filename: true + ################################################ ### Input configuration ################################################ diff --git a/ivas_processing_scripts/__init__.py b/ivas_processing_scripts/__init__.py index 62b26ec99e10fb7109de88cc01747a4f4624cda1..1a3fa594476d66917354cd9171e7737687641ce9 100755 --- a/ivas_processing_scripts/__init__.py +++ b/ivas_processing_scripts/__init__.py @@ -48,6 +48,7 @@ from ivas_processing_scripts.processing.processing import ( preprocess_2, preprocess_background_noise, process_item, + rename_generated_conditions, reorder_items_list, reverse_process_2, ) @@ -176,6 +177,9 @@ def main(args): if hasattr(cfg, "preprocessing_2"): reverse_process_2(cfg, logger) + if cfg.condition_in_output_filename: + rename_generated_conditions(cfg.output_path) + # copy configuration to output directory with open(cfg.output_path.joinpath(f"{cfg.name}.yml"), "w") as f: yaml.safe_dump(cfg._yaml_dump, f) diff --git a/ivas_processing_scripts/constants.py b/ivas_processing_scripts/constants.py index 8f260bb16968816c16f936d3c4c2224e068f9a2c..762c11b31802c1ef52c757e1aa6981fce3bdecc4 100755 --- a/ivas_processing_scripts/constants.py +++ b/ivas_processing_scripts/constants.py @@ -67,6 +67,7 @@ DEFAULT_CONFIG = { "mask": None, "limit": False, }, + "condition_in_output_filename": False, } DEFAULT_CONFIG_EVS = { "cod": { diff --git a/ivas_processing_scripts/processing/chains.py b/ivas_processing_scripts/processing/chains.py index 338b4e8ea2999c978bdfb5f7c310130c285110ba..f62c696a406fe019aefbb28e9343152ec51380d7 100755 --- a/ivas_processing_scripts/processing/chains.py +++ b/ivas_processing_scripts/processing/chains.py @@ -57,7 +57,10 @@ def init_processing_chains(cfg: TestConfig) -> None: # TODO we may need to change this to ensure it is only one value for IVAS and a possible list for EVS # condition naming will also need to be checked since we rename to {cond_name}_{bitrate} # this may not be desired - + if bitrates is not None and len(bitrates) > 1: + multiple_bitrates_flag = True + else: + multiple_bitrates_flag = False if bitrates: for bitrate in bitrates: # check if a list was specified @@ -65,14 +68,24 @@ def init_processing_chains(cfg: TestConfig) -> None: # flatten the list of lists for IVAS [ cfg.proc_chains.append( - get_processing_chain(cond_name, cond_cfg, extend_br) + get_processing_chain( + cond_name, + cond_cfg, + extend_br, + multiple_bitrates=multiple_bitrates_flag, + ) ) for extend_br in bitrate ] else: # otherwise pass the list; EVS will interpret as per-channel bitrate cfg.proc_chains.append( - get_processing_chain(cond_name, cfg, bitrate) + get_processing_chain( + cond_name, + cfg, + bitrate, + multiple_bitrates=multiple_bitrates_flag, + ) ) else: # non coding condition @@ -176,7 +189,10 @@ def get_preprocessing_2(cfg: TestConfig) -> dict: def get_processing_chain( - condition: str, cfg: TestConfig, bitrate: Optional[int] = None + condition: str, + cfg: TestConfig, + bitrate: Optional[int] = None, + multiple_bitrates: Optional[bool] = False, ) -> dict: """Mapping from test configuration to condition and postprocessing keyword arguments""" name = f"{condition}" @@ -185,7 +201,8 @@ def get_processing_chain( if isinstance(bitrate, list): name += f"_{sum(bitrate)}" else: - name += f"_{bitrate}" + if multiple_bitrates is True: + name += f"_{bitrate}" chain = { "name": name, diff --git a/ivas_processing_scripts/processing/processing.py b/ivas_processing_scripts/processing/processing.py index d7ed03934bd1b8c5e602c4f416783a2eea453591..5e07afa0e3dc33d7bb8c373bd5db21e17cb627cc 100755 --- a/ivas_processing_scripts/processing/processing.py +++ b/ivas_processing_scripts/processing/processing.py @@ -31,6 +31,7 @@ # import logging +import re from abc import ABC, abstractmethod from itertools import repeat from pathlib import Path @@ -563,3 +564,22 @@ def multiple_of_frame_size( warn( f"The length ({n_samples_x} samples) of audio ({item.name}) is not a multiple of frame length (20 ms)." ) + + +def rename_generated_conditions(output_path: Path): + """ + Rename the output files. Only renames the files in directories that contain "cXX" in thier names. + The "XX" in "cXX" stands for the condition number, for example "c01" + + Parameters + ---------- + output_path: Path + Path to output directory + """ + directory = output_path + pattern = re.compile(r"^c\d{2}") + for subdirectory in directory.iterdir(): + if subdirectory.is_dir() and pattern.match(subdirectory.name): + for file_path in subdirectory.iterdir(): + new_filename = f"{file_path.stem}.{subdirectory.name}{file_path.suffix}" + file_path.rename(subdirectory / new_filename)