lupy.filters

class lupy.filters.Coeff(b: ndarray[tuple[int], dtype[float64]], a: ndarray[tuple[int], dtype[float64]], sample_rate: int = 48000, _sos: ndarray[tuple[int, Literal[6]], dtype[float64]] | None = None)[source]

Bases: object

Digital filter coefficients

b: ndarray[tuple[int], dtype[float64]]

Numerator of the filter

a: ndarray[tuple[int], dtype[float64]]

Denominator of the filter

sample_rate: int = 48000

Sample rate of the filter

classmethod from_sos(sos: ndarray[tuple[int, Literal[6]], dtype[float64]], sample_rate: int = 48000) Self[source]

Create a Coeff instance from second-order sections

This is the inverse of sos property.

property sos: ndarray[tuple[int, Literal[6]], dtype[float64]]

Array of second-order sections calculated from the filter’s transfer function form

combine(other: Self) Self[source]

Return a new Coeff instance is a combination of this and another Coeff instance

Raises:

ValueError – If the sample rates of the two Coeff instances do not match

as_sample_rate(sample_rate: int) Self[source]

Return a new Coeff instance with the coefficients converted to the specified sample rate

lupy.filters.HS_COEFF = Coeff(b=array([ 1.53512486, -2.69169619,  1.19839281]), a=array([ 1.        , -1.69065929,  0.73248077]), sample_rate=48000, _sos=None)

Stage 1 (high-shelf) of the pre-filter defined in BS 1770 table 1

lupy.filters.HP_COEFF = Coeff(b=array([ 1., -2.,  1.]), a=array([ 1.        , -1.99004745,  0.99007225]), sample_rate=48000, _sos=None)

Stage 2 (high-pass) of the pre-filter defined in BS 1770 table 2

class lupy.filters.BaseFilter(coeff: T, num_channels: NumChannelsT)[source]

Bases: Generic[T, NumChannelsT], ABC

coeff: T

The filter coefficients

num_channels: NumChannelsT

Number of audio channels to filter

abstractmethod __call__(x: ndarray[tuple[int], dtype[float64]] | ndarray[tuple[int, int], dtype[float64]]) ndarray[tuple[int, int], dtype[float64]][source]

Apply the filter defined by coeff and return the result

Parameters:

x (ndarray[tuple[int], dtype[float64]] | ndarray[tuple[int, int], dtype[float64]]) – The input data with shape (num_channels, n) where n is the length of the input data for each channel

abstractmethod reset() None[source]

Reset any internal filter conditions

class lupy.filters.TruePeakFilter(num_channels: NumChannelsT, upsample_factor: int = 4)[source]

Bases: BaseFilter[ndarray[tuple[int], dtype[float64]], NumChannelsT]

Oversampling filter with interpolating FIR window

An upsample_factor of 4 is recommended for sample rates below 88.2 kHz, while a factor of 2 has proven to be sufficient for sample rates of 88.2 kHz and above.

upsample_factor: int

Upsampling factor

__call__(x: ndarray[tuple[int], dtype[float64]] | ndarray[tuple[int, int], dtype[float64]]) ndarray[tuple[int, int], dtype[float64]][source]

Apply the filter defined by coeff and return the result

Parameters:

x (ndarray[tuple[int], dtype[float64]] | ndarray[tuple[int, int], dtype[float64]]) – The input data with shape (num_channels, n) where n is the length of the input data for each channel

reset() None[source]

Reset any internal filter conditions

class lupy.filters.Filter(coeff: Coeff, num_channels: NumChannelsT)[source]

Bases: BaseFilter[Coeff, NumChannelsT]

Multi-channel filter that tracks the filter conditions between calls

The filter (defined by coeff) is applied by calling a Filter instance directly.

sos_zi: ndarray[tuple[int, int, Literal[2]], dtype[float64]]

The filter conditions

__call__(x: ndarray[tuple[int], dtype[float64]] | ndarray[tuple[int, int], dtype[float64]]) ndarray[tuple[int, int], dtype[float64]][source]

Apply the filter defined by coeff and return the result

Parameters:

x (ndarray[tuple[int], dtype[float64]] | ndarray[tuple[int, int], dtype[float64]]) – The input data with shape (num_channels, n) where n is the length of the input data for each channel

reset() None[source]

Reset any internal filter conditions

class lupy.filters.FilterGroup(*coeff: Coeff, num_channels: NumChannelsT)[source]

Bases: Generic[NumChannelsT]

Apply multiple filters in series

Parameters:
num_channels: NumChannelsT

Number of audio channels to filter

__call__(x: ndarray[tuple[int], dtype[float64]] | ndarray[tuple[int, int], dtype[float64]]) ndarray[tuple[int, int], dtype[float64]][source]

Apply the filters in series and return the result

Parameters:

x (ndarray[tuple[int], dtype[float64]] | ndarray[tuple[int, int], dtype[float64]]) – The input data with shape (num_channels, n) where n is the length of the input data for each channel

reset() None[source]

Reset the filter conditions for each filter in the group