diff --git a/ivas_processing_scripts/audiotools/audiofile.py b/ivas_processing_scripts/audiotools/audiofile.py index 7ec547895611eca8d988b2e41e6247a4b843e219..2d6ee25a63b8b933d14f3bedf9a542eee7c59dca 100755 --- a/ivas_processing_scripts/audiotools/audiofile.py +++ b/ivas_processing_scripts/audiotools/audiofile.py @@ -34,11 +34,13 @@ import logging import struct from pathlib import Path from typing import Optional, Tuple, Union +from warnings import warn import numpy as np import scipy.io.wavfile as wav from .audioarray import trim, window +from .constants import VERT_HOA_CHANNELS_ACN logger = logging.getLogger("__main__") logger.setLevel(logging.DEBUG) @@ -326,6 +328,8 @@ def split_channels( in_file: str, out_filenames: list, in_nchans: int, + out_nchans: int, + is_planar: Optional[bool] = False, in_fs: Optional[int] = 48000, ) -> None: """ @@ -339,6 +343,10 @@ def split_channels( List of output file names (.pcm, .raw or .wav) in_nchans: int Input number of channels + out_nchans: int + Number of channels to be split + is_planar: Optional[bool] + If true vertical SBA channels are set to zero in_fs: Optional[int] = 48000 Input sampling rate, default 48000 Hz @@ -350,14 +358,17 @@ def split_channels( # validation if in_nchans is None: raise ValueError("Number of channels to split must be specified!") - if in_nchans != len(out_filenames): - print( + if out_nchans != len(out_filenames): + warn( "Split: Mismatch between number of channels and output filenames length. Truncating output filenames list." ) - out_filenames = out_filenames[:in_nchans] + out_filenames = out_filenames[:out_nchans] x, in_fs = read(in_file, nchannels=in_nchans, fs=in_fs) + if is_planar: + x[:, VERT_HOA_CHANNELS_ACN[VERT_HOA_CHANNELS_ACN < in_nchans]] = 0 + # Write output files for idx, out_file in enumerate(out_filenames): # extract correct channel diff --git a/ivas_processing_scripts/processing/chains.py b/ivas_processing_scripts/processing/chains.py index accf1014728e8ae05c1075e3cc06e86bacf58b2c..bfa8045130d79067bb5ea8e83652e2954bc98f7c 100755 --- a/ivas_processing_scripts/processing/chains.py +++ b/ivas_processing_scripts/processing/chains.py @@ -300,11 +300,13 @@ def get_processing_chain( "tx": tx_cfg, "preamble": preamble, "evs_lfe_9k6bps_nb": evs_lfe_9k6bps_nb, + "sba_format": cond_cfg.get("sba_format", tmp_in_fmt), } ) ) # update values to reflect decoder output tmp_in_fs = dec_cfg.get("fs", tmp_in_fs) + tmp_in_fmt = cond_cfg.get("sba_format", cfg.input["fmt"]) elif cond_cfg["type"] == "ivas": cod_cfg = cond_cfg["cod"] diff --git a/ivas_processing_scripts/processing/evs.py b/ivas_processing_scripts/processing/evs.py index 7c52eaabe42846925dab651736d77d8901ffa82d..605e61df869564f85aab6141ef9b6b60a35daad5 100755 --- a/ivas_processing_scripts/processing/evs.py +++ b/ivas_processing_scripts/processing/evs.py @@ -167,16 +167,33 @@ class EVS(Processing): if not self.out_fs: self.out_fs = self.in_fs + # consider SBA format for condition + condition_fmt = audio.fromtype(self.sba_format) + if isinstance(self.in_fmt, audio.SceneBasedAudio): + if not isinstance(condition_fmt, audio.SceneBasedAudio) or ( + condition_fmt.num_channels > self.in_fmt.num_channels + ): + raise ValueError( + "SBA format has to be SBA with lower order than input signal" + ) + is_planar = condition_fmt.is_planar + else: + if self.in_fmt.name != condition_fmt.name: + raise ValueError("Cannot specify SBA format for non SBA input formats") + is_planar = False + # Split the channels to prepare for multi-mono coding split_chan_files = [ - out_file.with_suffix(f".{i}.pcm") for i in range(self.in_fmt.num_channels) + out_file.with_suffix(f".{i}.pcm") for i in range(condition_fmt.num_channels) ] split_channels( in_file, split_chan_files, - self.in_fmt.num_channels, - self.in_fs, + in_nchans=self.in_fmt.num_channels, + out_nchans=condition_fmt.num_channels, + in_fs=self.in_fs, + is_planar=is_planar, ) # run processing diff --git a/tests/data/test_SBA.yml b/tests/data/test_SBA.yml index aa20a5fdc520fd5002fa6d2ae53ed1195c2046bd..679e57c4d988efff4ebbd88eb48080e25a3bda4e 100644 --- a/tests/data/test_SBA.yml +++ b/tests/data/test_SBA.yml @@ -265,6 +265,7 @@ conditions_to_generate: ### For possible arguments see overall bitstream modification type: "JBM" error_profile: 3 + sba_format: "PLANARFOA" ################################################ ### Post-processing