Commit 4a264779 authored by Archit Tamarapu's avatar Archit Tamarapu
Browse files

allow python fallback for arbitrary low-pass filter cutoff frequencies

if ITU filter does not support them
parent a3ddf1ab
Loading
Loading
Loading
Loading
Loading
+1 −3
Original line number Diff line number Diff line
@@ -522,9 +522,7 @@ def lpfilter(
        N, Wn = sig.cheb2ord(fc / (fs / 2), (fc + 500) / (fs / 2), 3, 60)
        b, a = sig.cheby2(N, 60, Wn, "low")

        # Apply the Butterworth filter for each channels, across time axis
        # y = sig.lfilter(b, a, axis=0) # non zero-phase filter
        y = sig.filtfilt(b, a, x, axis=0)  # zero-phase filer, batch processing
        y = sig.filtfilt(b, a, x, axis=0)  # zero-phase filter, batch processing
    else:
        y = x

+13 −5
Original line number Diff line number Diff line
@@ -35,9 +35,11 @@ from copy import copy
from pathlib import Path, PurePath
from shutil import copyfile
from typing import Optional, Union
from warnings import warn

from ivas_processing_scripts.audiotools import audio, audioarray, metadata
from ivas_processing_scripts.audiotools.audiofile import write
from ivas_processing_scripts.audiotools.audioarray import lpfilter
from ivas_processing_scripts.audiotools.convert.channelbased import convert_channelbased
from ivas_processing_scripts.audiotools.convert.masa import convert_masa
from ivas_processing_scripts.audiotools.convert.objectbased import convert_objectbased
@@ -335,11 +337,17 @@ def process_audio(

    """low-pass filtering"""
    if fc is not None:
        try:
            if logger:
                logger.debug(
                    f"Applying low-pass filter with cutoff {fc}Hz using ITU STL filter"
                )
            x.audio = lpfilter_itu(x, fc)
        except NotImplementedError:
            warn(f"Low-pass filter cutoff {fc}Hz not supported by ITU filter. Falling back to python implementation.")
            if logger:
                logger.debug(f" Applying low-pass filter with cutoff {fc}Hz using python")
            x.audio = lpfilter(x.audio, fc, x.fs)

    """MNRU"""
    if mnru_q is not None:
+2 −2
Original line number Diff line number Diff line
@@ -231,8 +231,8 @@ def lpfilter_itu(
    flt_vals = [1500, 3500, 7000, 10000, 12000, 14000, 20000]
    try:
        flt_type = flt_types[flt_vals.index(fc)]
    except Exception:
        raise ValueError(f"LP cut-off frequency {fc}Hz not supported.")
    except ValueError as e:
        raise NotImplementedError(f"LP cut-off frequency {fc}Hz not supported by ITU filter.") from e

    # resample if samplingrate is not supported
    old_fs = None