- class flamo.processor.dsp.Transform(transform: callable = <function Transform.<lambda>>, device=None)¶
Base class for all transformations.
The transformation is a callable, e.g.,
lambda
expression, function,nn.Module
.- Args:
transform (callable): The transformation function to be applied to the input. Default: lambda x: x
device (str): The device of the constructed tensor, if any. Default: None.
- Attributes:
transform (callable): The transformation function to be applied to the input.
device (str): The device of constructed tensors.
- Methods:
forward(x): Applies the transformation function to the input.
Examples:
>>> pow2 = Transform(lambda x: x**2) >>> input = torch.tensor([1, 2, 3]) >>> pow2(input) tensor([1, 4, 9])
- forward(x)¶
Applies the transformation to the input tensor.
- Args:
x (Tensor): The input tensor.
- Returns:
Tensor: The transformed tensor.
- class flamo.processor.dsp.FFT(nfft=2048, norm='backward')¶
Real Fast Fourier Transform (FFT) class.
The
FFT
class is an instance of theTransform
class. The transformation function is thetorch.fft.rfft()
function. Computes the one dimensional Fourier transform of real-valued input. The input is interpreted as a real-valued signal in time domain. The output contains only the positive frequencies below the Nyquist frequency.- Args:
nfft (int): The number of points to compute the FFT.
norm (str): The normalization mode for the FFT.
- Attributes:
nfft (int): The number of points to compute the FFT.
norm (str): The normalization mode for the FFT.
- Methods:
foward(x): Apply the FFT to the input tensor x and return the one sided FFT.
For details on the FFT function, see torch.fft.rfft documentation.
- class flamo.processor.dsp.iFFT(nfft=2048, norm='backward')¶
Inverse Fast Fourier Transform (iFFT) class.
The
iFFT
class is an instance of theTransform
class. The transformation function is thetorch.fft.irfft()
function. Computes the inverse of the Fourier transform of a real-valued tensor. The input is interpreted as a one-sided Hermitian signal in the Fourier domain. The output is a real-valued signal in the time domain.- Args:
nfft (int): The size of the FFT. Default: 2**11.
norm (str): The normalization mode. Default: “backward”.
- Attributes:
nfft (int): The size of the FFT.
norm (str): The normalization mode.
- Methods:
foward(x): Apply the inverse FFT to the input tensor x and returns its corresponding real valued tensor.
For details on the inverse FFT function, see torch.fft.irfft documentation.
- class flamo.processor.dsp.DSP(size: tuple, nfft: int = 2048, map=<function DSP.<lambda>>, requires_grad: bool = False, alias_decay_db: float = 0.0, device=None)¶
Processor core module consisting of learnable parameters representing a Linear Time-Invariant (LTI) system, which is then convolved with the input signal.
The parameters are stored in
param
tensor whose values at initialization are drawn from the normal distribution \(\mathcal{N}(0, 1)\) and can be modified using theassign_value()
method.The anti aliasing envelope is computed using the
get_gamma()
method from thealias_decay_db
attribute which determines the decay in dB reached by the exponentially decaying envelope \(\gamma(n)\) afternfft
samples. The envelope \(\gamma(n)\) is then applied to the time domain signal before computing the FFT- Args:
size (tuple): The shape of the parameters before mapping.
nfft (int, optional): The number of FFT points required to compute the frequency response. Default: 2 ** 11.
map (function, optional): The mapping function applied to the raw parameters. Default: lambda x: x.
requires_grad (bool, optional): Whether the parameters require gradients. Default: False.
alias_decay_db (float, optional): The decaying factor in dB for the time anti-aliasing envelope. The decay refers to the attenuation after nfft samples. Default: 0.
device (str): The device of the constructed tensor, if any. Default: None.
- Attributes:
size (tuple): The shape of the parameters.
nfft (int): The number of FFT points required to compute the frequency response.
map (function): The mapping function applied to the raw parameters.
requires_grad (bool): Whether the parameters require gradients.
alias_decay_db (float): The decaying factor in dB for the time anti-aliasing envelope.
param (nn.Parameter): The parameters of the DSP module.
fft (function): The FFT function. Calls the
torch.fft.rfft()
function.ifft (function): The Inverse FFT function. Calls the
torch.fft.irfft()
.gamma (torch.Tensor): The gamma value used for time anti-aliasing envelope.
new_value (int): Flag indicating if new values have been assigned.
device (str): The device of the constructed tensors.
- Methods:
forward(x): Applies the processor core module to the input tensor x by multiplication.
init_param(): Initializes the parameters of the DSP module.
get_gamma(): Computes the gamma value used for time anti-aliasing envelope.
assign_value(new_value, indx): Assigns new values to the parameters.
- assign_value(new_value, indx: tuple = (slice(None, None, None),))¶
Assigns new values to the parameters.
- Args:
new_value (torch.Tensor): New values to be assigned.
indx (tuple, optional): Index to specify the subset of values to be assigned. Default: tuple([slice(None)]).
Warning
the gradient calulcation is disable when assigning new values to
param
.
- forward(x)¶
Forward method.
Warning
Forward method not implemented. Input is returned.
- get_gamma()¶
Calculate the gamma value based on the alias decay in dB and the number of FFT points. The gamma value is computed as follows and saved in the attribute
gamma
:\[\gamma = 10^{\frac{-|\alpha_{\text{dB}}|}{20 \cdot \texttt{nfft}}}\; \text{and}\; \gamma(n) = \gamma^{n}\]where \(\alpha_{\textrm{dB}}\) is the alias decay in dB, \(\texttt{nfft}\) is the number of FFT points, and \(n\) is the descrete time index \(0\\leq n < N\), where N is the length of the signal.
- init_param()¶
Initializes the parameters of the model using a normal distribution \(\mathcal{N}(0, 1)\). It uses the
torch.nn.init.normal_()
function to set the values ofparam
.
- class flamo.processor.dsp.Gain(size: tuple = (1, 1), nfft: int = 2048, map=<function Gain.<lambda>>, requires_grad: bool = False, alias_decay_db: float = 0.0, device=None)¶
A class representing a set of gains. Inherits from
DSP
. The input tensor is expected to be a complex-valued tensor representing the frequency response of the input signal. The input tensor is then multiplied with the gain parameters to produce the output tensor.- Shape:
input: \((B, M, N_{in}, ...)\)
param: \((N_{out}, N_{in})\)
output: \((B, M, N_{out}, ...)\)
where \(B\) is the batch size, \(M\) is the number of frequency bins, \(N_{in}\) is the number of input channels, and \(N_{out}\) is the number of output channels. Ellipsis \((...)\) represents additional dimensions.
- Args:
size (tuple): The size of the gain parameters. Default: (1, 1).
nfft (int): The number of FFT points required to compute the frequency response. Default: 2 ** 11.
map (function): A mapping function applied to the raw parameters. Default: lambda x: x.
requires_grad (bool): Whether the parameters requires gradients. Default: False.
alias_decay_db (float): The decaying factor in dB for the time anti-aliasing envelope. The decay refers to the attenuation after nfft samples. Default: 0.
device (str): The device of the constructed tensors. Default: None.
- Attributes:
size (tuple): The size of the gain parameters.
nfft (int): The number of FFT points required to compute the frequency response.
map (function): A mapping function applied to the raw parameters.
requires_grad (bool): Whether the parameters requires gradients.
alias_decay_db (float): The decaying factor in dB for the time anti-aliasing envelope.
param (nn.Parameter): The parameters of the Gain module.
fft (function): The FFT function. Calls the torch.fft.rfft function.
ifft (function): The Inverse FFT function. Calls the torch.fft.irfft.
gamma (torch.Tensor): The gamma value used for time anti-aliasing envelope.
new_value (int): Flag indicating if new values have been assigned.
device (str): The device of the constructed tensors.
- Methods:
forward(x): Applies the Gain module to the input tensor x by multiplication.
check_input_shape(x): Checks if the dimensions of the input tensor x are compatible with the module.
check_param_shape(): Checks if the shape of the gain parameters is valid.
get_freq_convolve(): Computes the frequency convolution function.
initialize_class(): Initializes the Gain module.
- check_input_shape(x)¶
Checks if the dimensions of the input tensor x are compatible with the module.
- Args:
x (torch.Tensor): Input tensor of shape \((B, M, N_{in}, ...)\).
- check_param_shape()¶
Checks if the shape of the gain parameters is valid.
- forward(x)¶
Applies the Gain module to the input tensor x.
- Args:
x (torch.Tensor): Input tensor of shape \((B, M, N_{in}, ...)\).
- Returns:
torch.Tensor: Output tensor of shape \((B, M, N_{out}, ...)\).
- get_freq_convolve()¶
Computes the frequency convolution function.
The frequency convolution is computed using the einsum function.
- Args:
x (torch.Tensor): Input tensor.
- Returns:
torch.Tensor: Output tensor after frequency convolution.
- get_io()¶
Computes the number of input and output channels based on the size parameter.
- initialize_class()¶
Initializes the Gain module.
This method checks the shape of the gain parameters and computes the frequency convolution function.
- class flamo.processor.dsp.Matrix(size: tuple = (1, 1), nfft: int = 2048, map=<function Matrix.<lambda>>, matrix_type: str = 'random', requires_grad=False, alias_decay_db: float = 0.0, device=None)¶
A class representing a matrix. inherits from
Gain
.- Args:
size (tuple, optional): The size of the matrix. Default: (1, 1).
nfft (int, optional): The number of FFT points required to compute the frequency response. Default: 2 ** 11.
map (function, optional): The mapping function to apply to the raw matrix elements. Default: lambda x: x.
matrix_type (str, optional): The type of matrix to generate. Default: “random”.
requires_grad (bool, optional): Whether the matrix requires gradient computation. Default: False.
alias_decay_db (float, optional): The decaying factor in dB for the time anti-aliasing envelope. The decay refers to the attenuation after nfft samples. Default: 0.
device (str, optional): The device of the constructed tensors. Default: None.
- Attributes:
size (tuple): The size of the matrix.
nfft (int): The number of FFT points required to compute the frequency response.
map (function): The mapping function to apply to the raw matrix elements.
matrix_type (str): The type of matrix to generate.
requires_grad (bool): Whether the matrix requires gradient computation.
alias_decay_db (float): The decaying factor in dB for the time anti-aliasing envelope.
param (nn.Parameter): The parameters of the Matrix module.
fft (function): The FFT function. Calls the torch.fft.rfft function.
ifft (function): The Inverse FFT function. Calls the torch.fft.irfft.
gamma (torch.Tensor): The gamma value used for time anti-aliasing envelope.
device (str): The device of the constructed tensors.
- Methods:
forward(x): Applies the Matrix module to the input tensor x by multiplication.
check_input_shape(x): Checks if the dimensions of the input tensor x are compatible with the module.
check_param_shape(): Checks if the shape of the matrix parameters is valid.
get_freq_convolve(): Computes the frequency convolution function.
initialize_class(): Initializes the Matrix module.
matrix_gallery(): Generates the matrix based on the specified matrix type.
- initialize_class()¶
Initializes the Matrix module.
This method checks the shape of the matrix parameters, sets the matrix type, generates the matrix, and computes the frequency convolution function.
- matrix_gallery()¶
Generates the matrix based on the specified matrix type. The
map
attribute will be overwritten based on the matrix type.
- class flamo.processor.dsp.Delay(size: tuple = (1, 1), max_len: int = 2000, isint: bool = False, unit: int = 100, nfft: int = 2048, fs: int = 48000, requires_grad=False, alias_decay_db: float = 0.0, device=None)¶
Delay module that applies in frequency domain a time delay to the input signal. Inherits from
DSP
. To improve update effectiveness, the unit of time can be adjusted via theunit
attribute to use subdivisions or multiples of time. For integer Delays, theisint
attribute can be set to True to round the delay to the nearest integer before computing the frequency response.- Shape:
input: \((B, M, N_{in}, ...)\)
param: \((M, N_{out}, N_{in})\)
output: \((B, M, N_{out}, ...)\)
where \(B\) is the batch size, \(M\) is the number of frequency bins, \(N_{in}\) is the number of input channels, and \(N_{out}\) is the number of output channels. Ellipsis \((...)\) represents additional dimensions.
For a delay of \(d\) seconds, the frequency response of the delay without anti-aliasing is computed as:
\[e^{-j \omega d}\; \text{for}\; \omega = 2\pi \frac{m}{\texttt{nfft}}\]where \(\texttt{nfft}\) is the number of FFT points, and \(m\) is the frequency index \(m=0, 1, \dots, \lfloor\texttt{nfft}/2 +1\rfloor\) .
- Args:
size (tuple, optional): Size of the delay module. Default: (1, 1).
max_len (int, optional): Maximum length of the delay in samples. Default: 2000.
isint (bool, optional): Flag indicating whether the delay length should be rounded to the nearest integer. Default: False.
unit (int, optional): Unit value used for second-to-sample conversion. Default: 100.
nfft (int, optional): Number of FFT points. Default: 2 ** 11.
fs (int, optional): Sampling frequency. Default: 48000.
requires_grad (bool, optional): Flag indicating whether the module parameters require gradients. Default: False.
alias_decay_db (float, optional): The decaying factor in dB for the time anti-aliasing envelope. The decay refers to the attenuation after nfft samples. Defaults to 0.
device (str, optional): The device of the constructed tensors. Default: None.
- Attributes:
fs (int): Sampling frequency.
max_len (int): Maximum length of the delay in samples.
unit (int): Unit value used for second-to-sample conversion.
isint (bool): Flag indicating whether the delay length should be rounded to the nearest integer.
omega (torch.Tensor): The frequency values used for the FFT.
freq_response (torch.Tensor): The frequency response of the delay module.
order (int): The order of the delay.
freq_convolve (function): The frequency convolution function.
alias_decay_db (float): The decaying factor in dB for the time anti-aliasing envelope.
- Methods:
forward(x): Applies the Delay module to the input tensor x.
init_param(): Initializes the delay parameters.
s2sample(delay): Converts a delay value from seconds to samples.
sample2s(delay): Converts a delay value from samples to seconds.
get_freq_response(): Computes the frequency response of the delay module.
check_input_shape(x): Checks if the input dimensions are compatible with the delay parameters.
check_param_shape(): Checks if the shape of the delay parameters is valid.
get_freq_convolve(): Computes the frequency convolution function.
initialize_class(): Initializes the Delay module.
- check_input_shape(x)¶
Checks if the input dimensions are compatible with the delay parameters.
- Args:
x (torch.Tensor): The input signal.
- check_param_shape()¶
Checks if the shape of the delay parameters is valid.
- forward(x)¶
Applies the Delay module to the input tensor x.
- Args:
x (torch.Tensor): Input tensor of shape (B, M, N_in, …).
- Returns:
torch.Tensor: Output tensor of shape (B, M, N_out, …).
- get_delays()¶
Computes the delay values from the raw parameters.
- get_freq_convolve()¶
Computes the frequency convolution function.
- get_freq_response()¶
Computes the frequency response of the delay module.
- get_io()¶
Computes the number of input and output channels based on the size parameter.
- init_param()¶
Initializes the delay parameters.
- initialize_class()¶
Initializes the Delay module.
This method checks the shape of the delay parameters, computes the frequency response, and initializes the frequency convolution function.
- s2sample(delay)¶
Converts a delay value from seconds to samples.
- Args:
delay (float): The delay value in seconds.
- sample2s(delay)¶
Converts a delay value from samples to seconds.
- Args:
delay (torch.Tensor): The delay value in samples.
- class flamo.processor.dsp.parallelDelay(size: tuple = (1,), max_len=2000, unit: int = 100, isint: bool = False, nfft=2048, fs: int = 48000, requires_grad=False, alias_decay_db: float = 0.0, device=None)¶
Parallel counterpart of the
Delay
class. For information about attributes and methods seeDelay
.- Shape:
input: \((B, M, N, ...)\)
param: \((M, N)\)
output: \((B, M, N, ...)\)
where \(B\) is the batch size, \(M\) is the number of frequency bins, and \(N\) is the number of input channels. Ellipsis \((...)\) represents additional dimensions.
- check_param_shape()¶
Checks if the shape of the delay parameters is valid.
- get_freq_convolve()¶
Computes the frequency convolution function.
- get_freq_response()¶
Computes the frequency response of the delay module.
- get_io()¶
Computes the number of input and output channels based on the size parameter.
- class flamo.processor.dsp.Biquad(size: tuple = (1, 1), n_sections: int = 1, filter_type: str = 'lowpass', nfft: int = 2048, fs: int = 48000, requires_grad: bool = True, alias_decay_db: float = 0.0, device=None)¶
Biquad filter class. Inherits from the
Filter
class. It supports class lowpass, highpass, and bandpass filters using RBJ cookbook formulas, which map the cut-off frequency \(f_{c}\) and gain \(g\) parameters to the \(\mathbf{b}\) and \(\mathbf{a}\) coefficients. The transfer function of the filter is given by\[H(z) = \frac{b_0 + b_1 z^{-1} + b_2 z^{-2}}{a_0 + a_1 z^{-1} + a_2 z^{-2}}\]The mapping from learnable parameters \(\mathbf{f_c}\) and \(\mathbf{g}\) are defined by
flamo.functional.lowpass_filter()
,flamo.functional.highpass_filter()
,flamo.functional.bandpass_filter()
.- Shape:
input: \((B, M, N_{\text{in}}, ...)\)
param: \((K, P, N_{\text{out}}, N_{\text{in}})\) # TODO change so (P, K, ..)
freq_response: \((M, N_{\text{out}}, N_{\text{in}})\)
output: \((B, M, N_{\text{out}}, ...)\)
where \(B\) is the batch size, \(M\) is the number of frequency bins, and \(N_{\text{in}}\) is the number of input channels, and \(N_{\text{out}}\) is the number of output channels. The :attr:’param’ attribute represent the biquad filter coefficents. The first dimension of the :attr:’param’ tensor corresponds to the number of filters \(K\), the second dimension corresponds to the number of filter parameters \(P\). Ellipsis \((...)\) represents additional dimensions (not tested).
- Args:
size (tuple, optional): Size of the filter. Default: (1, 1).
n_sections (int, optional): Number of filters. Default: 1.
filter_type (str, optional): Type of the filter. Must be one of “lowpass”, “highpass”, or “bandpass”. Default: “lowpass”.
nfft (int, optional): Number of points for FFT. Default: 2048.
fs (int, optional): Sampling frequency. Default: 48000.
requires_grad (bool, optional): Whether the filter parameters require gradient computation. Default: True.
alias_decay_db (float): The decaying factor in dB for the time anti-aliasing envelope. The decay refers to the attenuation after nfft samples. Default: 0.
device (str, optional): The device of the constructed tensors. Default: None.
- Attributes:
filter_type (str): Type of the filter.
fs (int): Sampling frequency.
freq_response (torch.Tensor): Frequency response of the filter.
param (nn.Parameter): Parameters of the Biquad filter.
- Methods:
get_size(): Get the size of the filter based on the filter type.
get_freq_response(): Compute the frequency response of the filter.
get_map(): Get the mapping function for parameter values based on the filter type.
init_param(): Initialize the filter parameters.
check_param_shape(): Check the shape of the filter parameters.
initialize_class(): Initialize the Biquad class.
- check_param_shape()¶
Check the shape of the filter parameters.
- get_freq_response()¶
Compute the frequency response of the filter. It calls the
flamo.functional.lowpass_filter()
,flamo.functional.highpass_filter()
, orflamo.functional.bandpass_filter()
functions based on the filter type.
- get_io()¶
Computes the number of input and output channels based on the size parameter.
- get_map()¶
Get the mapping function
map
to parameter values that ensure stability. The type of mapping is based on the filter type.
- get_size()¶
Get the leading dimensions of the parameters based on the filter type. These coincide with
2 for lowpass and highpass filters (\(f_\textrm{c}\), gain)
3 for bandpass filters (\(f_\textrm{c1}\), \(f_\textrm{c2}\), gain)
- Returns:
tuple: leading dimensions of the parameters.
- init_param()¶
Initialize the filter parameters.
- class flamo.processor.dsp.parallelBiquad(size: tuple = (1,), n_sections: int = 1, filter_type: str = 'lowpass', nfft: int = 2048, fs: int = 48000, requires_grad=True, alias_decay_db: float = 0.0, device=None)¶
Parallel counterpart of the
Biquad
class. For information about attributes and methods seeflamo.processor.dsp.Biquad
.- Shape:
input: \((B, M, N, ...)\)
param: \((K, P, N, N)\)
freq_response: \((M, N, N)\)
output: \((B, M, N, ...)\)
where \(B\) is the batch size, \(M\) is the number of frequency bins, and \(N\) is the number of input/output channels. The :attr:’param’ attribute represent the biquad filter coefficents. The first dimension of the :attr:’param’ tensor corresponds to the number of filters \(K\), the second dimension corresponds to the number of filter parameters \(P\) (3). Ellipsis \((...)\) represents additional dimensions (not tested).
- check_param_shape()¶
Check the shape of the filter parameters.
- get_freq_convolve()¶
Computes the frequency convolution function.
The frequency convolution is computed using the einsum function.
- Args:
x (torch.Tensor): Input tensor.
- Returns:
torch.Tensor: Output tensor after frequency convolution.
- get_freq_response()¶
Compute the frequency response of the filter. It calls the
flamo.functional.lowpass_filter()
,flamo.functional.highpass_filter()
, orflamo.functional.bandpass_filter()
functions based on the filter type.
- get_io()¶
Computes the number of input and output channels based on the size parameter.
- get_map()¶
Get the mapping function
map
to parameter values that ensure stability. The type of mapping is based on the filter type.
- class flamo.processor.dsp.SVF(size: tuple = (1, 1), n_sections: int = 1, filter_type: str = None, nfft: int = 2048, fs: int = 48000, requires_grad: bool = True, alias_decay_db: float = 0.0, device=None)¶
IIR filter as a serially cascaded state variable filters (SVFs). Inherits from the
Filter
class. Can be used to design a variety of filters such as lowpass, highpass, bandpass, lowshelf, highshelf, peaking, and notch filters. The filter coefficients are parameterized by the cut-off frequency (\(f\)) and resonance (\(R\)) parameters. The mixing coefficients (\(m_{LP}\), \(m_{BP}\), \(m_{HP}\) for lowpass, bandpass, and highpass filters) determine the contribution of each filter type in the cascaded structure.- Shape:
input: \((B, M, N_{in}, ...)\)
param: \((P, K, N_{out}, N_{in})\)
freq_response: \((M, N_{out}, N_{in})\)
output: \((B, M, N_{out}, ...)\)
where \(B\) is the batch size, \(M\) is the number of frequency bins, \(N_{in}\) is the number of input channels, \(N_{out}\) is the number of output channels, The :attr:’param’ attribute represent the biquad filter coefficents. The first dimension of the :attr:’param’ tensor corresponds to the number of SVF parameters (5), the second dimension corresponds to the number of filters \(K\). Ellipsis \((...)\) represents additional dimensions (not tested).
SVF parameters are used to express biquad filters as follows:
\[ \begin{align}\begin{aligned}H(z) = \frac{b_0 + b_1 z^{-1} + b_2 z^{-2}}{a_0 + a_1 z^{-1} + a_2 z^{-2}}\\\begin{split}b_0 = f^2 m_{LP} + f m_{BP} + m_{HP} \\ b_1 = 2 f^2 m_{LP} - 2 m_{HP} \\ b_2 = f^2 m_{LP} - f m_{BP} + m_{HP} \\ a_0 = f^2 + 2 R f + 1 \\ a_1 = 2 f^2 - 2 \\ a_2 = f^2 - 2 R f + 1 \\\end{split}\end{aligned}\end{align} \]For serieally cascaded SVFs, the frequency response is
\[H(z) = \prod_{k=1}^{K} H_k(z)\]where \(K\) is the number of cascaded filters
n_sections
.- Args:
size (tuple, optional): The size of the raw filter parameters. Default: (1, 1).
n_sections (int, optional): The number of cascaded filters. Default: 1.
filter_type (str, optional): The type of filter to use. Options are {“lowpass”,”highpass”,”bandpass”,”lowshelf”,”highshelf”,”peaking”,”notch”,} Default: None.
nfft (int, optional): The number of FFT points required to compute the frequency response. Default: 2 ** 11.
map (function, optional): The mapping function to apply to the raw parameters. Default: lambda x: x.
requires_grad (bool, optional): Whether the filter parameters require gradients. Default: False.
alias_decay_db (float, optional): The decaying factor in dB for the time anti-aliasing envelope. The decay refers to the attenuation after nfft samples. Default: 0.
device (str, optional): The device of the constructed tensors. Default: None.
- Attributes:
fs (int): The sampling frequency.
n_sections (int): The number of cascaded filters.
filter_type (str): The type of filter.
freq_response (torch.Tensor): The frequency response of the filter.
param (nn.Parameter): The parameters of the SVF filter.
- Methods:
check_param_shape(): Check the shape of the filter parameters.
check_input_shape(x): Check if the dimensions of the input tensor x are compatible with the module.
get_freq_response(): Compute the frequency response of the filter.
get_freq_convolve(): Compute the frequency convolution function.
For more details, refer to the paper Differentiable artificial reverberation <https://arxiv.org/abs/2105.13940> by Lee, S. et al.
- check_input_shape(x)¶
Checks if the input dimensions are compatible with the filter parameters.
- Args:
x (torch.Tensor): The input signal.
- check_param_shape()¶
Checks if the shape of the filter parameters is valid.
- get_freq_response()¶
Compute the frequency response of the filter.
- get_io()¶
Computes the number of input and output channels based on the size parameter.
- map_param2svf(param)¶
Mapping function for the raw parameters to the SVF filter coefficients.
- param2R(param)¶
Applies a softplus function to the parameter value and maps it to the range [0, 1], according to the formula:
\[R = \text{softplus}(x) / log(2).\]
- param2freq(param)¶
Applies a sigmoid function to the parameter value and maps it to the range [0, fs/2], where \(f_s\) is the sampling frequency according to the formula:
\[f = \text{tan}\left(\pi \cdot \text{sigmoid}(x) \cdot 0.5\right).\]
- param2mix(param, R=None)¶
Mapping function for the mixing coefficients relative to the filter type.
lowpass: \(m_{LP} = G, m_{BP} = 0, m_{HP} = 0\).
highpass: \(m_{LP} = 0, m_{BP} = 0, m_{HP} = G.\)
bandpass: \(m_{LP} = 0, m_{BP} = G, m_{HP} = 0.\)
lowshelf: \(m_{LP} = 1, m_{BP} = 2 \cdot R \cdot \sqrt{G}, m_{HP} = G.\)
highshelf: \(m_{LP} = G, m_{BP} = 2 \cdot R \cdot \sqrt{G}, m_{HP} = 1.\)
peaking | notch: \(m_{LP} = 1, m_{BP} = 2 \cdot R \cdot \sqrt{G}, m_{HP} = 1.\)
where \(G\) is the gain parameter mapped from the raw parameters as \(G = 10^{-\text{softplus}(x)}\).
- Args:
param (torch.Tensor): The raw parameters.
R (torch.Tensor, optional): The resonance parameter. Default: None.