diff --git a/ivas_processing_scripts/audiotools/__init__.py b/ivas_processing_scripts/audiotools/__init__.py index f392771dc5b43206c0aac7d4fb08e0d90ce42e9c..7d835d1663a6ed3754f1743ad499f9d9ec5d52be 100755 --- a/ivas_processing_scripts/audiotools/__init__.py +++ b/ivas_processing_scripts/audiotools/__init__.py @@ -34,7 +34,10 @@ import argparse from itertools import repeat from pathlib import Path -from ivas_processing_scripts.audiotools.constants import AUDIO_FORMATS, BINAURAL_LFE_GAIN +from ivas_processing_scripts.audiotools.constants import ( + AUDIO_FORMATS, + BINAURAL_LFE_GAIN, +) from ivas_processing_scripts.audiotools.convert import convert_file from ivas_processing_scripts.utils import apply_func_parallel diff --git a/other/lp16k.py b/other/lp16k.py index 975356aa07538a9ba5aacba837ecc55f3d101cb7..9f078881bbbecaef5a2623de4329457625bdb176 100755 --- a/other/lp16k.py +++ b/other/lp16k.py @@ -7,6 +7,7 @@ from time import sleep sys.path.append(str(Path(__file__).parent.parent)) from ivas_processing_scripts.audiotools.audio import fromfile +from ivas_processing_scripts.audiotools.audioarray import trim from ivas_processing_scripts.audiotools.audiofile import write from ivas_processing_scripts.audiotools.wrappers.filter import resample_itu from ivas_processing_scripts.utils import progressbar_update, spinner @@ -19,21 +20,24 @@ def lp16k(in_file, out_file): f"Unsupported sampling rate {x.fs//1000} kHz for input file {in_file} - only 48 kHz is supported!" ) + # save length of audio since resampling can alter the length by one sample due to rounding + len_signal = len(x.audio) + # resample ITU only returns the audio array # but uses the sampling rate stored in the audio object # so we need to correctly set it after each call - x.audio = resample_itu(x, 96000) - x.fs = 96000 - x.audio = resample_itu(x, 32000) x.fs = 32000 - x.audio = resample_itu(x, 96000) - x.fs = 96000 - x.audio = resample_itu(x, 48000) x.fs = 48000 + if len_signal != len(x.audio): + # padding should usually not happen since the resampling only rounds up + x.audio = trim( + x.audio, x.fs, (0, len(x.audio) - len_signal), samples=True, pad_noise=True + ) + write(out_file, x.audio, x.fs)