diff --git a/ivas_processing_scripts/audiotools/wrappers/masaRenderer.py b/ivas_processing_scripts/audiotools/wrappers/masaRenderer.py index 198db6f4c73cc53618ae1a2755486554a415da48..b0f6f85336cbc5f30345ef4351632b6e1a8af0bb 100755 --- a/ivas_processing_scripts/audiotools/wrappers/masaRenderer.py +++ b/ivas_processing_scripts/audiotools/wrappers/masaRenderer.py @@ -41,7 +41,7 @@ from ivas_processing_scripts.audiotools import audio from ivas_processing_scripts.audiotools.audiofile import read, write from ivas_processing_scripts.audiotools.wrappers.filter import resample_itu from ivas_processing_scripts.constants import DEFAULT_CONFIG_BINARIES -from ivas_processing_scripts.utils import find_binary, run +from ivas_processing_scripts.utils import find_binary, get_binary_path, run def ivasRendMasa( @@ -51,7 +51,7 @@ def ivasRendMasa( logger: Optional[logging.Logger] = None, ) -> np.ndarray: """ - Wrapper for IVAS_Rend MASA Rendering + Wrapper for IVAS_rend MASA Rendering Parameters ---------- @@ -78,6 +78,8 @@ def ivasRendMasa( else: binary = find_binary("IVAS_rend") + binary = get_binary_path(binary, False) + rend = IVAS_rend( { "bin": binary, diff --git a/ivas_processing_scripts/processing/evs.py b/ivas_processing_scripts/processing/evs.py index d2aec6755a8cf46930df473ca0f7eeaa3bd5df6d..ea0a4a52710b3705e921106cee2cce06128eb5cc 100755 --- a/ivas_processing_scripts/processing/evs.py +++ b/ivas_processing_scripts/processing/evs.py @@ -32,7 +32,6 @@ import logging import os.path -import platform from itertools import repeat from pathlib import Path from shutil import copyfile @@ -55,7 +54,12 @@ from ivas_processing_scripts.audiotools.wrappers.eid_xor import ( validate_error_pattern_application, ) from ivas_processing_scripts.processing.processing import Processing -from ivas_processing_scripts.utils import apply_func_parallel, run, use_wine +from ivas_processing_scripts.utils import ( + apply_func_parallel, + get_binary_path, + run, + use_wine, +) class EVS(Processing): @@ -69,27 +73,8 @@ class EVS(Processing): def _validate( self, ): - need_exe_suffix = ( - platform.system() == "Windows" or self.use_windows_codec_binaries - ) - if not self.cod_bin or not Path(self.cod_bin).exists(): - if need_exe_suffix and ( - self.cod_bin and Path(self.cod_bin).with_suffix(".exe").exists() - ): - self.cod_bin = Path(self.cod_bin).with_suffix(".exe") - else: - raise FileNotFoundError( - "The EVS encoder binary was not found! Please check the configuration." - ) - if not self.dec_bin or not Path(self.dec_bin).exists(): - if need_exe_suffix and ( - self.dec_bin and Path(self.dec_bin).with_suffix(".exe").exists() - ): - self.dec_bin = Path(self.dec_bin).with_suffix(".exe") - else: - raise FileNotFoundError( - "The EVS decoder binary was not found! Please check the configuration." - ) + self.cod_bin = get_binary_path(self.cod_bin, self.use_windows_codec_binaries) + self.dec_bin = get_binary_path(self.dec_bin, self.use_windows_codec_binaries) # configure per-channel bitrate if specified, otherwise simply repeat if not isinstance(self.bitrate, list): diff --git a/ivas_processing_scripts/processing/ivas.py b/ivas_processing_scripts/processing/ivas.py index 9ee079a3412c38effc64b9be8bcaa65c9aa7f0ee..f427d2e2be09b8bca8006ace6f5a6f810658069a 100755 --- a/ivas_processing_scripts/processing/ivas.py +++ b/ivas_processing_scripts/processing/ivas.py @@ -53,7 +53,7 @@ from ivas_processing_scripts.audiotools.wrappers.networkSimulator import ( ) from ivas_processing_scripts.audiotools.wrappers.random_seed import random_seed from ivas_processing_scripts.processing.processing import Processing -from ivas_processing_scripts.utils import run, use_wine +from ivas_processing_scripts.utils import get_binary_path, run, use_wine class IVAS(Processing): @@ -68,27 +68,8 @@ class IVAS(Processing): self._validate() def _validate(self): - need_exe_suffix = ( - platform.system() == "Windows" or self.use_windows_codec_binaries - ) - if not self.cod_bin or not Path(self.cod_bin).exists(): - if need_exe_suffix and ( - self.cod_bin and Path(self.cod_bin).with_suffix(".exe").exists() - ): - self.cod_bin = Path(self.cod_bin).with_suffix(".exe") - else: - raise FileNotFoundError( - "The IVAS encoder binary was not found! Please check the configuration." - ) - if not self.dec_bin or not Path(self.dec_bin).exists(): - if need_exe_suffix and ( - self.dec_bin and Path(self.dec_bin).with_suffix(".exe").exists() - ): - self.dec_bin = Path(self.dec_bin).with_suffix(".exe") - else: - raise FileNotFoundError( - "The IVAS decoder binary was not found! Please check the configuration." - ) + self.cod_bin = get_binary_path(self.cod_bin, self.use_windows_codec_binaries) + self.dec_bin = get_binary_path(self.dec_bin, self.use_windows_codec_binaries) # existence of error pattern files (if given) already here if self.tx is not None: @@ -497,18 +478,7 @@ class IVAS_rend(Processing): ) def _validate(self): - need_exe_suffix = ( - platform.system() == "Windows" or self.use_windows_codec_binaries - ) - if not Path(self.bin).exists(): - if need_exe_suffix and ( - self.bin and Path(self.bin).with_suffix(".exe").exists() - ): - self.bin = Path(self.bin).with_suffix(".exe") - else: - raise FileNotFoundError( - "The IVAS renderer binary was not found! Please check the configuration." - ) + self.bin = get_binary_path(self.bin, self.use_windows_codec_binaries) def process( self, diff --git a/ivas_processing_scripts/processing/ivas_combined.py b/ivas_processing_scripts/processing/ivas_combined.py index b737490759338111ec7e2ba420fb2b7e90192061..f1b9c84bab652c7730372d417be8d8ca87ba7665 100755 --- a/ivas_processing_scripts/processing/ivas_combined.py +++ b/ivas_processing_scripts/processing/ivas_combined.py @@ -31,7 +31,6 @@ # import logging -import platform from pathlib import Path from warnings import warn @@ -45,7 +44,7 @@ from ivas_processing_scripts.audiotools.wrappers.networkSimulator import ( ) from ivas_processing_scripts.processing.ivas import IVAS from ivas_processing_scripts.processing.processing import Processing -from ivas_processing_scripts.utils import use_wine +from ivas_processing_scripts.utils import get_binary_path, use_wine class IVASCombined(Processing): @@ -68,27 +67,8 @@ class IVASCombined(Processing): ) def _validate(self): - need_exe_suffix = ( - platform.system() == "Windows" or self.use_windows_codec_binaries - ) - if not self.cod_bin or not Path(self.cod_bin).exists(): - if need_exe_suffix and ( - self.cod_bin and Path(self.cod_bin).with_suffix(".exe").exists() - ): - self.cod_bin = Path(self.cod_bin).with_suffix(".exe") - else: - raise FileNotFoundError( - "The IVAS encoder binary was not found! Please check the configuration." - ) - if not self.dec_bin or not Path(self.dec_bin).exists(): - if need_exe_suffix and ( - self.dec_bin and Path(self.dec_bin).with_suffix(".exe").exists() - ): - self.dec_bin = Path(self.dec_bin).with_suffix(".exe") - else: - raise FileNotFoundError( - "The IVAS decoder binary was not found! Please check the configuration." - ) + self.cod_bin = get_binary_path(self.cod_bin, self.use_windows_codec_binaries) + self.dec_bin = get_binary_path(self.dec_bin, self.use_windows_codec_binaries) # existence of error pattern files (if given) already here if self.tx is not None: diff --git a/ivas_processing_scripts/utils.py b/ivas_processing_scripts/utils.py index af55590a830bf3d398ffd64e9eb2d2da1c337a43..08c7bbe205e879a4553a7ec284c5d4157c0d5284 100755 --- a/ivas_processing_scripts/utils.py +++ b/ivas_processing_scripts/utils.py @@ -152,6 +152,22 @@ def use_wine(use_windows_codec_binaries: bool): return linux_system and not wsl and use_windows_codec_binaries +def get_binary_path(binary: str, use_windows_codec_binaries: bool) -> Path: + need_exe_suffix = platform.system() == "Windows" or use_windows_codec_binaries + + if need_exe_suffix and binary: + binary = Path(binary).with_suffix(".exe") + + if not binary or not binary.exists(): + raise FileNotFoundError( + f"The binary {binary.name} was not found!" + f"\nProvided path was '{binary}'." + "\nPlease check the configuration." + ) + + return binary + + def find_binary( binary: str, raise_error: Optional[bool] = True,