diff --git a/ivas_processing_scripts/audiotools/audio.py b/ivas_processing_scripts/audiotools/audio.py index b727454624ed3a1dd01e25e351616d9e3ce30e6e..3df2de94632843c6a09080904f41dffd3c49dfd3 100755 --- a/ivas_processing_scripts/audiotools/audio.py +++ b/ivas_processing_scripts/audiotools/audio.py @@ -283,7 +283,9 @@ class ObjectBasedAudio(Audio): if file_name_meta.is_file(): obj.metadata_files.append(file_name_meta) else: - raise ValueError(f"Metadata file {file_name_meta} not found.") + raise FileNotFoundError( + f"Metadata file {file_name_meta} not found." + ) warn( f"No metadata files specified: The following files were found and used: \n {*obj.metadata_files,}" ) @@ -422,7 +424,9 @@ class OMASAAudio(Audio): if file_name_meta.is_file(): obj.metadata_files.append(file_name_meta) else: - raise ValueError(f"Metadata file {file_name_meta} not found.") + raise FileNotFoundError( + f"Metadata file {file_name_meta} not found." + ) warn( f"No metadata files specified: The following files were found and used: \n {*obj.metadata_files,}" ) @@ -527,7 +531,9 @@ class OSBAAudio(Audio): if file_name_meta.is_file(): obj.metadata_files.append(file_name_meta) else: - raise ValueError(f"Metadata file {file_name_meta} not found.") + raise FileNotFoundError( + f"Metadata file {file_name_meta} not found." + ) warn( f"No metadata files specified: The following files were found and used: \n {*obj.metadata_files,}" ) diff --git a/ivas_processing_scripts/audiotools/convert/masa.py b/ivas_processing_scripts/audiotools/convert/masa.py index b4e099c89b70666d93052cb4f019aa2e7ee77732..6f872f5eb5a7772d6beee636d5d7ac19e2a4bafe 100755 --- a/ivas_processing_scripts/audiotools/convert/masa.py +++ b/ivas_processing_scripts/audiotools/convert/masa.py @@ -35,8 +35,7 @@ from typing import Optional, Union from warnings import warn from ivas_processing_scripts.audiotools import audio -from ivas_processing_scripts.audiotools.convert import channelbased -from ivas_processing_scripts.audiotools.wrappers.masaRenderer import masaRenderer +from ivas_processing_scripts.audiotools.wrappers.masaRenderer import ivasRendMasa """ MetadataAssistedSpatialAudio functions """ @@ -90,6 +89,8 @@ def render_masa_to_binaural( Name of binaural dataset without prefix or suffix """ + # Needed if using masaRenderer (deprecated) + """ if "ROOM" in bin.name: cba_tmp = audio.fromtype("7_1_4") cba_tmp.fs = masa.fs @@ -108,6 +109,19 @@ def render_masa_to_binaural( ) bin.audio = masaRenderer(masa, "BINAURAL") + """ + + if bin_dataset is not None: + warn( + "Binaural dataset selection not supported by IVAS_rend - please render manually" + ) + if bin.name == "BINAURAL_ROOM": + warn( + "BINAURAL_ROOM is not a valid output format for IVAS_rend. Defaulting to BINAURAL_ROOM_IR." + ) + bin.name += "_IR" + + bin.audio = ivasRendMasa(masa, bin.name, trajectory) def render_masa_to_cba( @@ -125,6 +139,8 @@ def render_masa_to_cba( Channel-based output audio """ + # Needed if using masaRenderer (deprecated) + """ if cba.name not in ["5_1", "7_1_4"]: warn( f"MasaRenderer does not support {cba.name} natively. Using 7_1_4 as an intermediate format." @@ -137,6 +153,8 @@ def render_masa_to_cba( channelbased.render_cba_to_cba(cba_tmp, cba) else: cba.audio = masaRenderer(masa, cba.name) + """ + cba.audio = ivasRendMasa(masa, cba.name) def render_masa_to_sba( @@ -154,6 +172,8 @@ def render_masa_to_sba( SBA output audio """ + # Needed if using masaRenderer (deprecated) + """ warn( f"MasaRenderer does not support {sba.name} natively. Using 7_1_4 as an intermediate format." ) @@ -163,3 +183,5 @@ def render_masa_to_sba( cba_tmp.audio = masaRenderer(masa, cba_tmp.name) channelbased.render_cba_to_sba(cba_tmp, sba) + """ + sba.audio = ivasRendMasa(masa, sba.name) diff --git a/ivas_processing_scripts/audiotools/metadata.py b/ivas_processing_scripts/audiotools/metadata.py index 8bcd466224e01d3bc2855a69a5a44b6ee580b88f..ec1b6166fa640d18dca16a419ae4b6823ae31511 100755 --- a/ivas_processing_scripts/audiotools/metadata.py +++ b/ivas_processing_scripts/audiotools/metadata.py @@ -586,7 +586,7 @@ def metadata_search_ISM( if file_name_meta.is_file(): list_item.append(Path(file_name_meta).resolve()) else: - raise ValueError(f"Metadata file {file_name_meta} not found.") + raise FileNotFoundError(f"Metadata file {file_name_meta} not found.") if len(item_names) == 1: list_meta = list_item else: @@ -614,7 +614,7 @@ def metadata_search_MASA( if file_name_meta.is_file(): list_item.append(Path(file_name_meta).resolve()) else: - raise ValueError(f"Metadata file {file_name_meta} not found.") + raise FileNotFoundError(f"Metadata file {file_name_meta} not found.") if len(item_names) == 1: list_meta = list_item else: diff --git a/ivas_processing_scripts/audiotools/wrappers/masaRenderer.py b/ivas_processing_scripts/audiotools/wrappers/masaRenderer.py index 47ec8c6edc1c2a6abb572051baedc3b54b7974ea..b6aa1c9ee4840947989f3fa2e8a40584216146ff 100755 --- a/ivas_processing_scripts/audiotools/wrappers/masaRenderer.py +++ b/ivas_processing_scripts/audiotools/wrappers/masaRenderer.py @@ -32,6 +32,7 @@ from pathlib import Path from tempfile import TemporaryDirectory +from warnings import warn import numpy as np @@ -42,6 +43,65 @@ from ivas_processing_scripts.constants import DEFAULT_CONFIG_BINARIES from ivas_processing_scripts.utils import find_binary, run +def ivasRendMasa( + masa: audio.MetadataAssistedSpatialAudio, + out_fmt: str, + trajectory: Path = None, +) -> np.ndarray: + """ + Wrapper for IVAS_Rend MASA Rendering + + Parameters + ---------- + masa : MetadataAssistedSpatialAudio + Input MASA audio + out_fmt: str + Desired output format (only 5_1, 7_1_4 and BINAURAL supported) + + Returns + ------- + output : np.ndarray + MASA rendered to out_fmt + """ + # This import is needed here and not at the top of the file to avoid a circular dependency with imports! + from ivas_processing_scripts.processing.ivas import IVAS_rend + + if "IVAS_rend" in DEFAULT_CONFIG_BINARIES["binary_paths"]: + binary = find_binary( + DEFAULT_CONFIG_BINARIES["binary_paths"]["IVAS_rend"].name, + binary_path=DEFAULT_CONFIG_BINARIES["binary_paths"]["IVAS_rend"].parent, + ) + else: + binary = find_binary("IVAS_rend") + + rend = IVAS_rend( + { + "bin": binary, + "in_fmt": masa.name, + "in_fs": masa.fs, + "out_fmt": out_fmt, + "trajectory": trajectory, + "use_windows_codec_binaries": False, + } + ) + + with TemporaryDirectory() as tmp_dir: + tmp_dir = Path(tmp_dir) + tmp_in = tmp_dir.joinpath("tmp_masaRendIn.wav") + tmp_out = tmp_dir.joinpath("tmp_masaRendOut.wav") + + write(tmp_in, masa.audio, masa.fs) + + masa_metadata_file = masa.metadata_file + if masa_metadata_file is not None and not isinstance(masa_metadata_file, Path): + masa_metadata_file = Path(masa_metadata_file) + + rend.process(tmp_in, tmp_out, in_meta=[masa_metadata_file]) + + output, _ = read(tmp_out) + return output + + def masaRenderer( masa: audio.MetadataAssistedSpatialAudio, out_fmt: str, @@ -61,6 +121,9 @@ def masaRenderer( output : np.ndarray MASA rendered to out_fmt """ + warn( + "This function (masaRenderer) has been replaced by ivasRendMasa, please switch code to use that instead" + ) if "masaRenderer" in DEFAULT_CONFIG_BINARIES["binary_paths"]: binary = find_binary( diff --git a/ivas_processing_scripts/binary_paths.yml b/ivas_processing_scripts/binary_paths.yml index 1c810062322df01caa1290e74f810d103dfc43d9..00de00dda1e6054e6591f637fe73f9cb3412285b 100644 --- a/ivas_processing_scripts/binary_paths.yml +++ b/ivas_processing_scripts/binary_paths.yml @@ -22,6 +22,8 @@ # eid-xor: "path/to/binary/eid-xor" # ### Binary for error pattern generation # gen-patt: "path/to/binary/gen-patt" +# ### Binary for IVAS Renderer +# IVAS_rend: "path/to/binary/IVAS_rend" # ### Binary for random offset/seed generation # random: "path/to/binary/random" # ### Binary for JBM network similulator diff --git a/ivas_processing_scripts/processing/ivas.py b/ivas_processing_scripts/processing/ivas.py index 28c207182819494c8796e0507b3d3763f742f1ca..bab205a845c538cfb6591142539ceb064b5b5c1b 100755 --- a/ivas_processing_scripts/processing/ivas.py +++ b/ivas_processing_scripts/processing/ivas.py @@ -494,8 +494,9 @@ class IVAS_rend(Processing): in_meta, logger: Optional[logging.Logger] = None, ) -> None: - logger.debug(f"IVAS rend configuration : {self.__dict__}") - logger.debug(f"IVAS rend {in_file.absolute()} -> {out_file.absolute()}") + if logger: + logger.debug(f"IVAS rend configuration : {self.__dict__}") + logger.debug(f"IVAS rend {in_file.absolute()} -> {out_file.absolute()}") # set defaults in case input sampling rate is not specified if not self.in_fs: @@ -556,7 +557,7 @@ class IVAS_rend(Processing): cmd.append("-im") cmd.extend([str(f) for f in in_meta]) - if self.opts: + if getattr(self, "opts", None): cmd.extend(self.opts) run(cmd, logger=logger) diff --git a/ivas_processing_scripts/processing/processing_splitting_scaling.py b/ivas_processing_scripts/processing/processing_splitting_scaling.py index e6edc173403019b2365dbdd556b9a8bb721f2a73..5f9ac34fe210d9a49d4c76966fcebad2b64d30e6 100644 --- a/ivas_processing_scripts/processing/processing_splitting_scaling.py +++ b/ivas_processing_scripts/processing/processing_splitting_scaling.py @@ -236,13 +236,6 @@ class Processing_splitting_scaling(Processing): ) splits, split_names, split_fs = read_splits_file(splits_info_file) - # split file - if self.ivas_jbm and not noerror: - # only use flag if IVAS JBM condition but not the loudness reference without error is processed - ivas_jbm_splitting_flag = True - else: - ivas_jbm_splitting_flag = False - file_splits, meta_splits, new_splits = concat_teardown( x, splits, diff --git a/tests/test_binaries_present.py b/tests/test_binaries_present.py index 4567afa49e9f8279e48683f6e263f61cbbea67f9..05045fe477b13c283c1cf98e1ad1da08c747ae55 100755 --- a/tests/test_binaries_present.py +++ b/tests/test_binaries_present.py @@ -41,9 +41,10 @@ BINARIES = [ "eid-xor", "gen-patt", "filter", + "IVAS_rend", "random", "networkSimulator_g192", - "masaRenderer", + # "masaRenderer", "masaAnalyzer", ]