Skip to content
Commits on Source (7)
...@@ -49,6 +49,10 @@ output_path: ".../tmp_output" ...@@ -49,6 +49,10 @@ output_path: ".../tmp_output"
# input_select: # input_select:
# - "48kHz" # - "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 ### Input configuration
################################################ ################################################
......
...@@ -48,6 +48,7 @@ from ivas_processing_scripts.processing.processing import ( ...@@ -48,6 +48,7 @@ from ivas_processing_scripts.processing.processing import (
preprocess_2, preprocess_2,
preprocess_background_noise, preprocess_background_noise,
process_item, process_item,
rename_generated_conditions,
reorder_items_list, reorder_items_list,
reverse_process_2, reverse_process_2,
) )
...@@ -176,6 +177,9 @@ def main(args): ...@@ -176,6 +177,9 @@ def main(args):
if hasattr(cfg, "preprocessing_2"): if hasattr(cfg, "preprocessing_2"):
reverse_process_2(cfg, logger) reverse_process_2(cfg, logger)
if cfg.condition_in_output_filename:
rename_generated_conditions(cfg.output_path)
# copy configuration to output directory # copy configuration to output directory
with open(cfg.output_path.joinpath(f"{cfg.name}.yml"), "w") as f: with open(cfg.output_path.joinpath(f"{cfg.name}.yml"), "w") as f:
yaml.safe_dump(cfg._yaml_dump, f) yaml.safe_dump(cfg._yaml_dump, f)
...@@ -67,6 +67,7 @@ DEFAULT_CONFIG = { ...@@ -67,6 +67,7 @@ DEFAULT_CONFIG = {
"mask": None, "mask": None,
"limit": False, "limit": False,
}, },
"condition_in_output_filename": False,
} }
DEFAULT_CONFIG_EVS = { DEFAULT_CONFIG_EVS = {
"cod": { "cod": {
......
...@@ -57,7 +57,10 @@ def init_processing_chains(cfg: TestConfig) -> None: ...@@ -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 # 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} # condition naming will also need to be checked since we rename to {cond_name}_{bitrate}
# this may not be desired # 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: if bitrates:
for bitrate in bitrates: for bitrate in bitrates:
# check if a list was specified # check if a list was specified
...@@ -65,14 +68,24 @@ def init_processing_chains(cfg: TestConfig) -> None: ...@@ -65,14 +68,24 @@ def init_processing_chains(cfg: TestConfig) -> None:
# flatten the list of lists for IVAS # flatten the list of lists for IVAS
[ [
cfg.proc_chains.append( 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 for extend_br in bitrate
] ]
else: else:
# otherwise pass the list; EVS will interpret as per-channel bitrate # otherwise pass the list; EVS will interpret as per-channel bitrate
cfg.proc_chains.append( cfg.proc_chains.append(
get_processing_chain(cond_name, cfg, bitrate) get_processing_chain(
cond_name,
cfg,
bitrate,
multiple_bitrates=multiple_bitrates_flag,
)
) )
else: else:
# non coding condition # non coding condition
...@@ -176,7 +189,10 @@ def get_preprocessing_2(cfg: TestConfig) -> dict: ...@@ -176,7 +189,10 @@ def get_preprocessing_2(cfg: TestConfig) -> dict:
def get_processing_chain( 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: ) -> dict:
"""Mapping from test configuration to condition and postprocessing keyword arguments""" """Mapping from test configuration to condition and postprocessing keyword arguments"""
name = f"{condition}" name = f"{condition}"
...@@ -185,6 +201,7 @@ def get_processing_chain( ...@@ -185,6 +201,7 @@ def get_processing_chain(
if isinstance(bitrate, list): if isinstance(bitrate, list):
name += f"_{sum(bitrate)}" name += f"_{sum(bitrate)}"
else: else:
if multiple_bitrates is True:
name += f"_{bitrate}" name += f"_{bitrate}"
chain = { chain = {
......
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
# #
import logging import logging
import re
from abc import ABC, abstractmethod from abc import ABC, abstractmethod
from itertools import repeat from itertools import repeat
from pathlib import Path from pathlib import Path
...@@ -563,3 +564,22 @@ def multiple_of_frame_size( ...@@ -563,3 +564,22 @@ def multiple_of_frame_size(
warn( warn(
f"The length ({n_samples_x} samples) of audio ({item.name}) is not a multiple of frame length (20 ms)." 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)