From f7799d39a31a71e93cd38b417aeab7750523c0a3 Mon Sep 17 00:00:00 2001 From: Treffehn Date: Mon, 19 Jun 2023 12:43:35 +0200 Subject: [PATCH 1/2] small fix in 16kHz lp filtering --- other/lp16k.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/other/lp16k.py b/other/lp16k.py index 975356aa..4876ae60 100755 --- a/other/lp16k.py +++ b/other/lp16k.py @@ -10,6 +10,7 @@ from ivas_processing_scripts.audiotools.audio import fromfile 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 +from ivas_processing_scripts.audiotools.audioarray import trim def lp16k(in_file, out_file): @@ -19,21 +20,22 @@ 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) -- GitLab From 2f18a6b3cc3834cc6d6a12a0f52f2f26db374e74 Mon Sep 17 00:00:00 2001 From: Treffehn Date: Mon, 19 Jun 2023 13:05:37 +0200 Subject: [PATCH 2/2] formatting --- ivas_processing_scripts/audiotools/__init__.py | 5 ++++- other/lp16k.py | 6 ++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/ivas_processing_scripts/audiotools/__init__.py b/ivas_processing_scripts/audiotools/__init__.py index f392771d..7d835d16 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 4876ae60..9f078881 100755 --- a/other/lp16k.py +++ b/other/lp16k.py @@ -7,10 +7,10 @@ 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 -from ivas_processing_scripts.audiotools.audioarray import trim def lp16k(in_file, out_file): @@ -34,7 +34,9 @@ def lp16k(in_file, out_file): 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) + 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) -- GitLab