From 7576a86051d32c71cd555d3aff1447cd7da1b4e9 Mon Sep 17 00:00:00 2001 From: Treffehn Date: Tue, 11 Apr 2023 14:21:12 +0200 Subject: [PATCH 1/2] Changed supported formats for mono rendering --- .../binaural_datasets/binaural_dataset.py | 4 +--- .../audiotools/convert/channelbased.py | 16 ++++++++++++++++ .../audiotools/convert/masa.py | 2 -- .../audiotools/convert/objectbased.py | 2 -- .../audiotools/convert/scenebased.py | 2 -- ivas_processing_scripts/processing/chains.py | 2 -- ivas_processing_scripts/processing/evs.py | 19 +++++++++++++------ ivas_processing_scripts/processing/ivas.py | 19 +++++++++++++------ 8 files changed, 43 insertions(+), 23 deletions(-) diff --git a/ivas_processing_scripts/audiotools/binaural_datasets/binaural_dataset.py b/ivas_processing_scripts/audiotools/binaural_datasets/binaural_dataset.py index 12ee1018..e2341a8a 100755 --- a/ivas_processing_scripts/audiotools/binaural_datasets/binaural_dataset.py +++ b/ivas_processing_scripts/audiotools/binaural_datasets/binaural_dataset.py @@ -154,9 +154,7 @@ def load_ir( f"No latency of HRTF dataset specified in .mat file -> computed latency: {latency_smp}" ) - if in_fmt.startswith("MONO"): - IR = IR[:, :, :1] # use omni/W from SBA - elif in_fmt.startswith("STEREO"): + if in_fmt.startswith("STEREO"): IR = IR[:, :, :2] # use L and R channels. elif ( in_fmt in CHANNEL_BASED_AUDIO_FORMATS.keys() diff --git a/ivas_processing_scripts/audiotools/convert/channelbased.py b/ivas_processing_scripts/audiotools/convert/channelbased.py index 94acef8e..7b16653d 100755 --- a/ivas_processing_scripts/audiotools/convert/channelbased.py +++ b/ivas_processing_scripts/audiotools/convert/channelbased.py @@ -104,6 +104,15 @@ def render_cba_to_binaural( bin_lfe_gain: Optional[float] LFE gain for binaural rendering """ + + if cba.name == "MONO": + # no binauralization possible for mono -> render to stereo and assume binaural signal + cba_stereo = audio.fromtype("STEREO") + cba_stereo.fs = bin.fs + render_cba_to_cba(cba, cba_stereo) + bin.audio = cba_stereo.audio + return + # TODO this will change if we have resampled HRTFs cba.audio = resample_itu(cba, 48000) old_fs = cba.fs @@ -199,6 +208,9 @@ def render_cba_to_binaural( def render_cba_to_cba( cba_in: audio.ChannelBasedAudio, cba_out: audio.ChannelBasedAudio ) -> None: + if cba_in.name == "MONO" and cba_out.name != "STEREO": + raise ValueError(f"Rendering from MONO to {cba_out.name} is not supported.") + # Stereo to Mono if cba_in.name == "STEREO" and cba_out.name == "MONO": render_mtx = np.vstack([[0.5], [0.5]]) @@ -234,6 +246,10 @@ def render_cba_to_cba( def render_cba_to_sba(cba: audio.ChannelBasedAudio, sba: audio.SceneBasedAudio) -> None: + + if cba.name == "MONO": + raise ValueError(f"Rendering from MONO to {sba.name} is not supported.") + # SH response for loudspeaker positions render_mtx = np.hstack( [ diff --git a/ivas_processing_scripts/audiotools/convert/masa.py b/ivas_processing_scripts/audiotools/convert/masa.py index 0014ef80..c03977ab 100755 --- a/ivas_processing_scripts/audiotools/convert/masa.py +++ b/ivas_processing_scripts/audiotools/convert/masa.py @@ -78,8 +78,6 @@ def render_masa_to_binaural( **kwargs, ): if "ROOM" in bin.name: - # TODO decide between MOZART or 7_1_4 for BRIRs - # cba_tmp = audio.fromtype("MOZART") cba_tmp = audio.fromtype("7_1_4") cba_tmp.fs = masa.fs diff --git a/ivas_processing_scripts/audiotools/convert/objectbased.py b/ivas_processing_scripts/audiotools/convert/objectbased.py index 9c8fcde3..4111face 100755 --- a/ivas_processing_scripts/audiotools/convert/objectbased.py +++ b/ivas_processing_scripts/audiotools/convert/objectbased.py @@ -108,8 +108,6 @@ def render_oba_to_binaural( # bin.audio = np.zeros([oba.audio.shape[0], bin.num_channels]) if "ROOM" in bin.name: - # TODO decide between MOZART or 7_1_4 for BRIRs - # cba_tmp = audio.fromtype("MOZART") cba_tmp = audio.fromtype("7_1_4") cba_tmp.fs = oba.fs diff --git a/ivas_processing_scripts/audiotools/convert/scenebased.py b/ivas_processing_scripts/audiotools/convert/scenebased.py index 393f2a32..10a91522 100755 --- a/ivas_processing_scripts/audiotools/convert/scenebased.py +++ b/ivas_processing_scripts/audiotools/convert/scenebased.py @@ -113,8 +113,6 @@ def render_sba_to_binaural( sba.audio = rotate_sba(sba, trajectory) if "ROOM" in bin.name: - # TODO decide between MOZART or 7_1_4 for BRIRs - # cba_tmp = audio.fromtype("MOZART") cba_tmp = audio.fromtype("7_1_4") cba_tmp.fs = sba.fs diff --git a/ivas_processing_scripts/processing/chains.py b/ivas_processing_scripts/processing/chains.py index 2786bc20..e495f531 100755 --- a/ivas_processing_scripts/processing/chains.py +++ b/ivas_processing_scripts/processing/chains.py @@ -163,8 +163,6 @@ def get_processing_chain( elif cond_cfg["type"] == "esdru": tmp_esdru_alpha = cond_cfg["alpha"] elif cond_cfg["type"] == "mono_dmx": - # TODO: mono dmx - # raise NotImplementedError("Mono downmix support WIP") chain["processes"].append( Postprocessing( { diff --git a/ivas_processing_scripts/processing/evs.py b/ivas_processing_scripts/processing/evs.py index 52133877..0e9c3e44 100755 --- a/ivas_processing_scripts/processing/evs.py +++ b/ivas_processing_scripts/processing/evs.py @@ -35,6 +35,7 @@ from itertools import repeat from pathlib import Path from shutil import copyfile from typing import Optional +import platform from ivas_processing_scripts.audiotools import audio from ivas_processing_scripts.audiotools.audiofile import ( @@ -57,13 +58,19 @@ class EVS(Processing): self, ): if not self.cod_bin or not Path(self.cod_bin).exists(): - raise FileNotFoundError( - "The EVS encoder binary was not found! Please check the configuration." - ) + if platform.system() == "Windows" 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(): - raise FileNotFoundError( - "The EVS decoder binary was not found! Please check the configuration." - ) + if platform.system() == "Windows" 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." + ) # 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 886eb267..18199f9b 100755 --- a/ivas_processing_scripts/processing/ivas.py +++ b/ivas_processing_scripts/processing/ivas.py @@ -35,6 +35,7 @@ import os.path from copy import deepcopy from pathlib import Path from typing import Optional +import platform from ivas_processing_scripts.audiotools import audio from ivas_processing_scripts.audiotools.audiofile import parse_wave_header @@ -52,13 +53,19 @@ class IVAS(Processing): def _validate(self): if not self.cod_bin or not Path(self.cod_bin).exists(): - raise FileNotFoundError( - "The IVAS encoder binary was not found! Please check the configuration." - ) + if platform.system() == "Windows" 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(): - raise FileNotFoundError( - "The IVAS decoder binary was not found! Please check the configuration." - ) + if platform.system() == "Windows" 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." + ) if self.tx is not None: if not self.tx["bin"] or not Path(self.tx["bin"]).exists(): bin = self.tx["bin"] -- GitLab From f3853584bc20e313efc773702c0036a919cab6ee Mon Sep 17 00:00:00 2001 From: Treffehn Date: Tue, 11 Apr 2023 16:38:51 +0200 Subject: [PATCH 2/2] enabled mono to channelbased again --- ivas_processing_scripts/audiotools/convert/channelbased.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/ivas_processing_scripts/audiotools/convert/channelbased.py b/ivas_processing_scripts/audiotools/convert/channelbased.py index 7b16653d..b0fadf99 100755 --- a/ivas_processing_scripts/audiotools/convert/channelbased.py +++ b/ivas_processing_scripts/audiotools/convert/channelbased.py @@ -208,8 +208,6 @@ def render_cba_to_binaural( def render_cba_to_cba( cba_in: audio.ChannelBasedAudio, cba_out: audio.ChannelBasedAudio ) -> None: - if cba_in.name == "MONO" and cba_out.name != "STEREO": - raise ValueError(f"Rendering from MONO to {cba_out.name} is not supported.") # Stereo to Mono if cba_in.name == "STEREO" and cba_out.name == "MONO": -- GitLab