diff --git a/examples/TEMPLATE.yml b/examples/TEMPLATE.yml index 89415ceeb261e2bf0b9def3a20c35d626778f6c0..bab59220e02885565d29df5c25aa71385b6d5d35 100755 --- a/examples/TEMPLATE.yml +++ b/examples/TEMPLATE.yml @@ -65,13 +65,10 @@ input: fmt: "HOA3" ### Input sampling rate in Hz needed for headerless audio files; default = 48000 # fs: 32000 - ### Enable check for input files being aligned to a integer multiple of a given length in ms. - ### If a file is not aligned, a warning will be issued. If the input format has metadata or force is true, an error is raised instead. - # aligned_to: - ### alignment length in ms, is needed if aligned_to is used - # len: 20 - ### default: false - # force: true + ### Treatment of items that are not 20ms aligned + ### options: "padding" (pads with low level noise to frame length), "warning" or "error" (raises a warning or an error when items are not aligned), + ### "ignore" (no special treatment for items that are not aligned); default = "padding" (for ISM: default = "error") + # frame_alignment: "error" ################################################ ### Pre-processing on individual items @@ -119,10 +116,6 @@ input: # preamble: 10000 ### Flag wheter to use noise (amplitude +-4) for the preamble or silence; default = false (silence) # preamble_noise: true - ### Specify postamble duration in ms. Postamble is added after concatenation and possible signal repetition. defaut = 0 - # postamble: 20 - ### Flag wheter to use noise (amplitude +-4) for the postamble or silence; default = false (silence) - # postamble_noise: true ### Additive background noise # background_noise: ### SNR for background noise in dB; REQUIRED for prerecorded background noise and ignored for low level noise diff --git a/experiments/selection/BS1534-1a/config/BS1534-1a.yml b/experiments/selection/BS1534-1a/config/BS1534-1a.yml index ec8a6aab9b3b68d7e32ccfe071a66f6687a89d2e..f82c69871f6fb7c1a68806161b1b83279422e8f2 100644 --- a/experiments/selection/BS1534-1a/config/BS1534-1a.yml +++ b/experiments/selection/BS1534-1a/config/BS1534-1a.yml @@ -35,8 +35,6 @@ preprocessing: preprocessing_2: concatenate_input: false preamble_noise: false - postamble: 20 - postamble_noise: true repeat_signal: true ################################################# diff --git a/experiments/selection/BS1534-1b/config/BS1534-1b.yml b/experiments/selection/BS1534-1b/config/BS1534-1b.yml index 5c06316a6356b5d77eef011e1bdeebaae51dc427..d3c41c05a6c7f4f1a409e2bb015e0c911c60f0e2 100644 --- a/experiments/selection/BS1534-1b/config/BS1534-1b.yml +++ b/experiments/selection/BS1534-1b/config/BS1534-1b.yml @@ -35,8 +35,6 @@ preprocessing: preprocessing_2: concatenate_input: false preamble_noise: false - postamble: 20 - postamble_noise: true repeat_signal: true ################################################# diff --git a/experiments/selection/BS1534-2a/config/BS1534-2a.yml b/experiments/selection/BS1534-2a/config/BS1534-2a.yml index 66e9a41c24bd940f62783928c67a9d75dbeda01f..c4f6799ca50b2d65ac3257f098ea7454db79f04e 100644 --- a/experiments/selection/BS1534-2a/config/BS1534-2a.yml +++ b/experiments/selection/BS1534-2a/config/BS1534-2a.yml @@ -35,8 +35,6 @@ preprocessing: preprocessing_2: concatenate_input: false preamble_noise: false - postamble: 20 - postamble_noise: true repeat_signal: true ################################################# diff --git a/experiments/selection/BS1534-2b/config/BS1534-2b.yml b/experiments/selection/BS1534-2b/config/BS1534-2b.yml index 1728956963ee383ade685be1ce5b78a2c50f85ff..a228d7bc90f6a1e9077aeb551ad2491aa52981a5 100644 --- a/experiments/selection/BS1534-2b/config/BS1534-2b.yml +++ b/experiments/selection/BS1534-2b/config/BS1534-2b.yml @@ -35,8 +35,6 @@ preprocessing: preprocessing_2: concatenate_input: false preamble_noise: false - postamble: 20 - postamble_noise: true repeat_signal: true ################################################# diff --git a/experiments/selection/BS1534-3a/config/BS1534-3a.yml b/experiments/selection/BS1534-3a/config/BS1534-3a.yml index c7e384d7f43f259d4e88a89e54f0f729c7aa253c..558379cb5246f5f137f3beb946547b88644fe8af 100644 --- a/experiments/selection/BS1534-3a/config/BS1534-3a.yml +++ b/experiments/selection/BS1534-3a/config/BS1534-3a.yml @@ -35,8 +35,6 @@ preprocessing: preprocessing_2: concatenate_input: false preamble_noise: false - postamble: 20 - postamble_noise: true repeat_signal: true ################################################# diff --git a/experiments/selection/BS1534-3b/config/BS1534-3b.yml b/experiments/selection/BS1534-3b/config/BS1534-3b.yml index 889c06d64dc07abe5b35c0520b507ac81b156741..6c0bc99f0367920685d437b494e1471a3be863ca 100644 --- a/experiments/selection/BS1534-3b/config/BS1534-3b.yml +++ b/experiments/selection/BS1534-3b/config/BS1534-3b.yml @@ -35,8 +35,6 @@ preprocessing: preprocessing_2: concatenate_input: false preamble_noise: false - postamble: 20 - postamble_noise: true repeat_signal: true ################################################# diff --git a/experiments/selection/BS1534-4a/config/BS1534-4a.yml b/experiments/selection/BS1534-4a/config/BS1534-4a.yml index a1901c1d8443a388451b05481bc9ce168c69d943..98f16df11fdf0346164653e1c707be5cde602c0b 100644 --- a/experiments/selection/BS1534-4a/config/BS1534-4a.yml +++ b/experiments/selection/BS1534-4a/config/BS1534-4a.yml @@ -35,8 +35,6 @@ preprocessing: preprocessing_2: concatenate_input: false preamble_noise: false - postamble: 20 - postamble_noise: true repeat_signal: true ################################################# diff --git a/experiments/selection/BS1534-4b/config/BS1534-4b.yml b/experiments/selection/BS1534-4b/config/BS1534-4b.yml index 619fa75b4c1bf83b99f6fd177ba3f6e0cf66e2e9..20dc8b699021a6b92ada85e960dfdd6709ea04d6 100644 --- a/experiments/selection/BS1534-4b/config/BS1534-4b.yml +++ b/experiments/selection/BS1534-4b/config/BS1534-4b.yml @@ -35,8 +35,6 @@ preprocessing: preprocessing_2: concatenate_input: false preamble_noise: false - postamble: 20 - postamble_noise: true repeat_signal: true ################################################# diff --git a/experiments/selection/BS1534-5a/config/BS1534-5a.yml b/experiments/selection/BS1534-5a/config/BS1534-5a.yml index 5186df641d2878fb29cb9933e6887e1e74d408c5..9e769941ad930150f6f3e892c5be190867b93f99 100644 --- a/experiments/selection/BS1534-5a/config/BS1534-5a.yml +++ b/experiments/selection/BS1534-5a/config/BS1534-5a.yml @@ -35,8 +35,6 @@ preprocessing: preprocessing_2: concatenate_input: false preamble_noise: false - postamble: 20 - postamble_noise: true repeat_signal: true ################################################# diff --git a/experiments/selection/BS1534-5b/config/BS1534-5b.yml b/experiments/selection/BS1534-5b/config/BS1534-5b.yml index 49eaa813f0c754a4f48f0cedfc2a0ad8811bf70d..f6b9f9e808110af7f9a2b0572e308b7309846aa6 100644 --- a/experiments/selection/BS1534-5b/config/BS1534-5b.yml +++ b/experiments/selection/BS1534-5b/config/BS1534-5b.yml @@ -35,8 +35,6 @@ preprocessing: preprocessing_2: concatenate_input: false preamble_noise: false - postamble: 20 - postamble_noise: true repeat_signal: true ################################################# diff --git a/experiments/selection/BS1534-7a/config/BS1534-7a.yml b/experiments/selection/BS1534-7a/config/BS1534-7a.yml index 69574c294b55020321f3989df2303c13090c5bc5..e9c2a1cb8b7472feb91d42050f79957fedf9a110 100644 --- a/experiments/selection/BS1534-7a/config/BS1534-7a.yml +++ b/experiments/selection/BS1534-7a/config/BS1534-7a.yml @@ -35,8 +35,6 @@ preprocessing: preprocessing_2: concatenate_input: false preamble_noise: false - postamble: 20 - postamble_noise: true repeat_signal: true ################################################# diff --git a/experiments/selection/BS1534-7b/config/BS1534-7b.yml b/experiments/selection/BS1534-7b/config/BS1534-7b.yml index 5aea94738dcdb767269a99afaa386ee0ef813fb2..46be3389e50076d0cf2a58253d02ee10e0053a97 100644 --- a/experiments/selection/BS1534-7b/config/BS1534-7b.yml +++ b/experiments/selection/BS1534-7b/config/BS1534-7b.yml @@ -35,8 +35,6 @@ preprocessing: preprocessing_2: concatenate_input: false preamble_noise: false - postamble: 20 - postamble_noise: true repeat_signal: true ################################################# diff --git a/experiments/selection/P800-1/config/P800-1.yml b/experiments/selection/P800-1/config/P800-1.yml index 238484b99a06590b7eef6c3c0008cfe8072cb53a..0a0f977eb4a83ddae78d29ba7b22beb6fd5cbb75 100644 --- a/experiments/selection/P800-1/config/P800-1.yml +++ b/experiments/selection/P800-1/config/P800-1.yml @@ -37,8 +37,6 @@ preprocessing_2: # concatenation_order: [] preamble: 10000 preamble_noise: true - postamble: 20 - postamble_noise: true repeat_signal: true background_noise: ### REQUIRED: SNR for background noise in dB diff --git a/experiments/selection/P800-2/config/P800-2.yml b/experiments/selection/P800-2/config/P800-2.yml index 97e3d19632c195eebab5820495c14f498e9ddb31..9153ce28cbad5c5cbabc323b19af153d6a687e16 100644 --- a/experiments/selection/P800-2/config/P800-2.yml +++ b/experiments/selection/P800-2/config/P800-2.yml @@ -37,8 +37,6 @@ preprocessing_2: # concatenation_order: [] preamble: 10000 preamble_noise: true - postamble: 20 - postamble_noise: true ### Additive background noise background_noise: ### REQUIRED: SNR for background noise in dB diff --git a/experiments/selection/P800-3/config/P800-3.yml b/experiments/selection/P800-3/config/P800-3.yml index 762831f2caff5829d90ffc8a496db992c548d5c0..36ec2905f11bf5d78596a7851d53c65d9ca5e781 100644 --- a/experiments/selection/P800-3/config/P800-3.yml +++ b/experiments/selection/P800-3/config/P800-3.yml @@ -37,8 +37,6 @@ preprocessing_2: # concatenation_order: [] preamble: 10000 preamble_noise: true - postamble: 20 - postamble_noise: true repeat_signal: true ################################################# diff --git a/experiments/selection/P800-4/config/P800-4.yml b/experiments/selection/P800-4/config/P800-4.yml index 9a760d9903a72be347f1e6c33d07a68ba0654c43..4a8885b38c9e4cee9993eb41271ee9b85e8179fd 100644 --- a/experiments/selection/P800-4/config/P800-4.yml +++ b/experiments/selection/P800-4/config/P800-4.yml @@ -38,8 +38,6 @@ preprocessing_2: # concatenation_order: [] preamble: 10000 preamble_noise: true - postamble: 20 - postamble_noise: true repeat_signal: true background_noise: ### REQUIRED: SNR for background noise in dB diff --git a/experiments/selection/P800-5/config/P800-5.yml b/experiments/selection/P800-5/config/P800-5.yml index 96c39191f27e2b3b8feb7844cf896389f17a29b5..16c2536ba262c630542bc2bf0d2c4a9b9d150979 100644 --- a/experiments/selection/P800-5/config/P800-5.yml +++ b/experiments/selection/P800-5/config/P800-5.yml @@ -38,8 +38,6 @@ preprocessing_2: # concatenation_order: [] preamble: 10000 preamble_noise: true - postamble: 20 - postamble_noise: true repeat_signal: true background_noise: ### REQUIRED: SNR for background noise in dB diff --git a/experiments/selection/P800-8/config/P800-8.yml b/experiments/selection/P800-8/config/P800-8.yml index c4eb1d52585547d37a9d4ac6c036b0c5c653de47..49a08e9b0683807422c11fc0fd8564347f374298 100644 --- a/experiments/selection/P800-8/config/P800-8.yml +++ b/experiments/selection/P800-8/config/P800-8.yml @@ -37,8 +37,6 @@ preprocessing_2: # concatenation_order: [] preamble: 10000 preamble_noise: true - postamble: 20 - postamble_noise: true background_noise: ### REQUIRED: SNR for background noise in dB snr: 45 diff --git a/experiments/selection/P800-9/config/P800-9.yml b/experiments/selection/P800-9/config/P800-9.yml index 8cfb2b37806fb5541d327f4a8dde419f43d2e139..016b4ae2550c4037d4e70d3d3e343a82ee263d57 100644 --- a/experiments/selection/P800-9/config/P800-9.yml +++ b/experiments/selection/P800-9/config/P800-9.yml @@ -37,8 +37,6 @@ preprocessing_2: # concatenation_order: [] preamble: 10000 preamble_noise: true - postamble: 20 - postamble_noise: true background_noise: ### REQUIRED: SNR for background noise in dB snr: 10 diff --git a/ivas_processing_scripts/audiotools/metadata.py b/ivas_processing_scripts/audiotools/metadata.py index af87fe3feda6464166e537dc61f6e9e255d8126d..6c87809782ef0b78961c1b189a5b1848fda1ce7f 100755 --- a/ivas_processing_scripts/audiotools/metadata.py +++ b/ivas_processing_scripts/audiotools/metadata.py @@ -44,7 +44,6 @@ from ivas_processing_scripts.audiotools.constants import ( DEFAULT_ISM_METADATA, FORMAT_ISM_METADATA_CSV, IVAS_FRAME_LEN_MS, - NUMBER_COLUMNS_ISM_METADATA, ) @@ -378,7 +377,7 @@ def concat_meta_from_file( # add preamble if preamble: - concat_meta_all_obj = add_remove_preamble(concat_meta_all_obj, preamble, 0) + concat_meta_all_obj = add_remove_preamble(concat_meta_all_obj, preamble) write_ISM_metadata_in_file(concat_meta_all_obj, out_file) @@ -548,7 +547,6 @@ def metadata_search( def add_remove_preamble( metadata, preamble, - postamble, add: Optional[bool] = True, ): # preamble @@ -579,32 +577,4 @@ def add_remove_preamble( samples=True, ) - # postamble - postamble_frames = postamble / IVAS_FRAME_LEN_MS - if not postamble_frames.is_integer(): - raise ValueError( - f"Application of postamble for ISM metadata is only possible if postamble length is multiple of frame length. " - f"Frame length: {IVAS_FRAME_LEN_MS}ms" - ) - for obj_idx in range(len(metadata)): - if metadata is not None and metadata[obj_idx] is not None: - if add: - num_columns = metadata[obj_idx].shape[1] - metadata[obj_idx] = np.vstack( - [ - metadata[obj_idx], - np.repeat( - np.array(DEFAULT_ISM_METADATA)[None, :num_columns], - postamble_frames, - 0, - ), - ] - ) - else: - metadata[obj_idx] = trim( - metadata[obj_idx], - limits=(0, int(postamble_frames)), - samples=True, - ) - return metadata diff --git a/ivas_processing_scripts/audiotools/wrappers/reverb.py b/ivas_processing_scripts/audiotools/wrappers/reverb.py index 62c6dfdc8e5eb656f8c80e99738b79ea48dda0a4..1ce334ac993cc0269219cb3f630141dfc0bdeef7 100644 --- a/ivas_processing_scripts/audiotools/wrappers/reverb.py +++ b/ivas_processing_scripts/audiotools/wrappers/reverb.py @@ -90,7 +90,9 @@ def reverb( tmp_input.fs = IR.fs # add trailing zeros - tmp_input.audio = np.concatenate([tmp_input.audio, np.zeros((IR.audio.shape[0]-1, 1))]) + tmp_input.audio = np.concatenate( + [tmp_input.audio, np.zeros((IR.audio.shape[0] - 1, 1))] + ) # write input audio signal to temporary file in .pcm format tmp_input_file = tmp_dir.joinpath("tmp_reverbIn.pcm") diff --git a/ivas_processing_scripts/constants.py b/ivas_processing_scripts/constants.py index 5cc4760948bee91dc956d5b99ef03bda7b01d3ef..b4cf5a280a1396a4cf39cdd974325cdc645c52aa 100755 --- a/ivas_processing_scripts/constants.py +++ b/ivas_processing_scripts/constants.py @@ -63,6 +63,9 @@ DEFAULT_CONFIG = { "master_seed": 0, "prerun_seed": 0, "metadata_path": None, + "input": { + "frame_alignment": "padding", + }, # postprocessing "postprocessing": { "mask": None, diff --git a/ivas_processing_scripts/processing/chains.py b/ivas_processing_scripts/processing/chains.py index 3d7e04912a97edd6461579883ef580f43a603c12..f9ec2c7928fe7570f379b24f2b4e799b299ab47e 100755 --- a/ivas_processing_scripts/processing/chains.py +++ b/ivas_processing_scripts/processing/chains.py @@ -30,11 +30,13 @@ # the United Nations Convention on Contracts on the International Sales of Goods. # +from shutil import copyfile from typing import Optional from warnings import warn from ivas_processing_scripts.audiotools import audio -from ivas_processing_scripts.audiotools.audiofile import read +from ivas_processing_scripts.audiotools.audioarray import trim +from ivas_processing_scripts.audiotools.audiofile import read, write from ivas_processing_scripts.processing.config import TestConfig from ivas_processing_scripts.processing.evs import EVS from ivas_processing_scripts.processing.ivas import IVAS @@ -189,8 +191,6 @@ def get_preprocessing_2(cfg: TestConfig) -> dict: "concatenation_order": pre2_cfg.get("concatenation_order", None), "preamble": pre2_cfg.get("preamble", 0), "pad_noise_preamble": pre2_cfg.get("preamble_noise", False), - "postamble": pre2_cfg.get("postamble", 0), - "pad_noise_postamble": pre2_cfg.get("preamble_noise", False), "background_noise": background, "in_mask": pre2_cfg.get("mask", None), "multiprocessing": cfg.multiprocessing, @@ -502,7 +502,6 @@ def get_processing_chain( "out_fmt": post_fmt, # no rendering here "concatenate_input": pre2_cfg.get("concatenate_input", False), "preamble": pre2_cfg.get("preamble", 0), - "postamble": pre2_cfg.get("postamble", 0), "repeat_signal": pre2_cfg.get("repeat_signal", False), "loudness": post_cfg.get("loudness", None), "loudness_fmt": post_cfg.get("loudness_fmt", None), @@ -524,7 +523,23 @@ def validate_input_files(cfg: TestConfig): input_format = cfg.input["fmt"] num_chan_expected = audio.fromtype(input_format).num_channels - for item in cfg.items_list: + frame_alignment = cfg.input["frame_alignment"] + + # always throw an error for ISM (and MASA) input + if input_format.startswith("ISM") or input_format.startswith("MASA"): + frame_alignment = "error" + + if cfg.input["frame_alignment"] == "padding": + # Create new input directory for padded files + output_dir = cfg.output_path / "20ms_aligned_files" + try: + output_dir.mkdir(exist_ok=False, parents=True) + except FileExistsError: + raise ValueError( + "Folder for 20ms aligned files already exists. Please move or delete folder" + ) + + for i, item in enumerate(cfg.items_list): if "fs" in cfg.input: sampling_rate = cfg.input["fs"] x, fs = read(item, nchannels=num_chan_expected, fs=sampling_rate) @@ -547,18 +562,51 @@ def validate_input_files(cfg: TestConfig): f"The number of channels in the file ({n_chan_x}) do NOT match with those of format ({num_chan_expected}, {input_format}) specified in the config yaml." ) - if (input_aligned_cfg := cfg.input.get("aligned_to", None)) is not None: - input_fmt_has_metadata = input_format.startswith( - "ISM" - ) or input_format.startswith("MASA") - force_alignment = ( - input_aligned_cfg.get("force", False) or input_fmt_has_metadata - ) + # check frame alignment of items + if cfg.input["frame_alignment"] != "ignore": + alignment_len_samples = (20 / 1000) * fs - alignment_len_samples = (input_aligned_cfg["len"] / 1000) * fs if n_samples_x % alignment_len_samples != 0: - msg = f"The length ({n_samples_x} samples) of audio ({item.name}) is not a multiple of given alignment length ({input_aligned_cfg['len']} ms)." - if force_alignment: - raise ValueError(msg) + if frame_alignment == "warning": + warn( + f"The length ({n_samples_x} samples) of audio ({item.name}) is not a multiple of the frame length." + ) + elif frame_alignment == "error": + raise ValueError( + f"The length ({n_samples_x} samples) of audio ({item.name}) is not a multiple of the frame length." + ) + elif frame_alignment == "padding": + warn( + f"The length ({n_samples_x} samples) of audio ({item.name}) is not a multiple of frame length (20 ms). Padding to the nearest integer multiple." + ) + # Calculate number of samples needed for padding + padding_samples = int( + alignment_len_samples - (n_samples_x % alignment_len_samples) + ) + # Create and append zeros + padded_data = trim( + x, + fs, + (0, -padding_samples), + pad_noise=True, + samples=True, + ) + # Write padded data to output directory + write(output_dir / item.name, padded_data, fs) + # Update audio file path in list + cfg.items_list[i] = output_dir / item.name else: - warn(msg) + raise ValueError( + f"Value of key frame_alignment does not match possible options. Value: {frame_alignment}. Options: 'padding', 'ignore', 'warning', 'error'" + ) + else: + if frame_alignment == "padding": + copyfile(item, output_dir / item.name) + # Update audio file path in list + cfg.items_list[i] = output_dir / item.name + else: + pass + + if frame_alignment == "padding": + # Make the output path as the new input path + cfg.input_path = output_dir diff --git a/ivas_processing_scripts/processing/preprocessing_2.py b/ivas_processing_scripts/processing/preprocessing_2.py index 83dc0097865b5f3a423051c250706bd853d06e89..912ef6d13fa16f233dfc12a3843bf21db163b53d 100644 --- a/ivas_processing_scripts/processing/preprocessing_2.py +++ b/ivas_processing_scripts/processing/preprocessing_2.py @@ -75,16 +75,12 @@ class Preprocessing2(Processing): metadata = audio_object.object_pos # add preamble - metadata = add_remove_preamble(metadata, preamble, 0) + metadata = add_remove_preamble(metadata, preamble) # repeat signal if self.repeat_signal: metadata = [np.concatenate((m, m), axis=0) for m in metadata] - # add postable - if self.postamble: - metadata = add_remove_preamble(metadata, 0, self.postamble) - meta_files = write_ISM_metadata_in_file(metadata, [out_file], True) # modify audio object @@ -118,16 +114,6 @@ class Preprocessing2(Processing): (audio_object.audio, audio_object.audio), axis=0 ) - # add postamble - do alter signal repetition as this is just for ensuring equal lengths between in- and output signals - if self.postamble > 0: - logger.debug(f"Add postamble of length {self.postamble}ms") - audio_object.audio = trim( - audio_object.audio, - audio_object.fs, - (0, -self.postamble), - self.pad_noise_postamble, - ) - # save file write(out_file, audio_object.audio, fs=audio_object.fs) diff --git a/ivas_processing_scripts/processing/processing.py b/ivas_processing_scripts/processing/processing.py index bcc8330fdeb0d2b120748ad612f65290a8eed404..299ca4c30104597a9d55d4a5c3e672efce89cf3e 100755 --- a/ivas_processing_scripts/processing/processing.py +++ b/ivas_processing_scripts/processing/processing.py @@ -162,9 +162,7 @@ def concat_setup(cfg: TestConfig, chain, logger: logging.Logger): logger.info(f"Splits written to file {splits_info_file}") -def concat_teardown( - x, splits, out_fmt, fs, in_fs, meta, len_postamble_ms, logger: logging.Logger -): +def concat_teardown(x, splits, out_fmt, fs, in_fs, meta, logger: logging.Logger): if not splits: raise ValueError("Splitting not possible without split marker") @@ -185,14 +183,9 @@ def concat_teardown( raise ValueError( f"Last split index {splits[-1]} is larger than the signal length {len(x)}" ) - elif splits[-1] < len(x) - ( - postamble_len_samples := (len_postamble_ms * fs_old) // 1000 - ): - msg_file_len = len(x) - if len_postamble_ms > 0: - msg_file_len = f"(minus postamble length of {postamble_len_samples}): {len(x) - postamble_len_samples}" + elif splits[-1] < len(x): warn( - f"Last split index {splits[-1]} is smaller than the signal length {msg_file_len}" + f"Last split index {splits[-1]} is smaller than the signal length {len(x)}" ) split_old = 0 @@ -439,29 +432,16 @@ def process_item( copyfile(ppm, out_meta[idx]) -def remove_pre_and_postamble( - x, out_fmt, fs, repeat_signal, preamble_len_ms, postamble_len_ms, meta, logger -): +def remove_preamble(x, out_fmt, fs, repeat_signal, preamble_len_ms, meta, logger): # remove preamble for ISM metadata if out_fmt.startswith("ISM"): - # remove postamble - if postamble_len_ms: - meta = add_remove_preamble(meta, 0, postamble_len_ms, add=False) - # cut first half of the metadata if repeat_signal: meta = [m[int(len(m) / 2) :, :] for m in meta] # remove preamble if preamble_len_ms > 0: - meta = add_remove_preamble(meta, preamble_len_ms, 0, add=False) - - # remove postamble - if postamble_len_ms: - if logger: - logger.debug("Remove postamble") - postamble_len_samples = (postamble_len_ms * fs) // 1000 - x = trim(x, fs, (0, postamble_len_samples), samples=True) + meta = add_remove_preamble(meta, preamble_len_ms, add=False) # cut first half of signal if repeat_signal: diff --git a/ivas_processing_scripts/processing/processing_splitting_scaling.py b/ivas_processing_scripts/processing/processing_splitting_scaling.py index 69a77e61857c6ada4f2df704bc9388d51e9b0911..4b162f68ffc84593d68a2daa0990339371f8ad7b 100644 --- a/ivas_processing_scripts/processing/processing_splitting_scaling.py +++ b/ivas_processing_scripts/processing/processing_splitting_scaling.py @@ -13,7 +13,7 @@ from ivas_processing_scripts.audiotools.wrappers.bs1770 import loudness_norm from ivas_processing_scripts.processing.processing import ( Processing, concat_teardown, - remove_pre_and_postamble, + remove_preamble, ) # @@ -190,14 +190,13 @@ class Processing_splitting_scaling(Processing): self, x, fs, in_file, out_file, in_meta, noerror=False, logger=None ): # remove preamble and first half of signal due to repetition - if self.preamble or self.postamble or self.repeat_signal: - x, in_meta = remove_pre_and_postamble( + if self.preamble or self.repeat_signal: + x, in_meta = remove_preamble( x, self.out_fmt, self.fs, self.repeat_signal, self.preamble, - self.postamble, in_meta, logger, ) @@ -214,7 +213,7 @@ class Processing_splitting_scaling(Processing): # split file file_splits, meta_splits = concat_teardown( - x, splits, self.out_fmt, fs, split_fs, in_meta, self.postamble, logger + x, splits, self.out_fmt, fs, split_fs, in_meta, logger ) # set new out_files