Modulation Effects

This section covers various modulation effects including chorus, flanger, and phaser variations.

Chorus

class diffFx_pytorch.processors.modulation.Chorus(*args: Any, **kwargs: Any)[source]

Bases: ProcessorsBase

Differentiable implementation of a chorus audio effect.

Implementation is based on:

This processor implements a modulated delay line to create the chorus effect, generating multiple detuned copies of the input signal using LFO-controlled delay modulation.

Processing Chain:
  1. Generate LFO for delay modulation

  2. Calculate delay phases

  3. Apply variable delay

  4. Mix with original signal

The transfer function is:

\[y(t) = mix * (x(t) + LFO_{delay}(t)) + (1 - mix) * x(t)\]
where coefficients are functions of:
  • x(t): Input signal

  • LFO_{delay}(t): Delay modulated by sine wave

  • mix: Wet/dry balance parameter

Parameters:

sample_rate (int) – Audio sample rate in Hz. Defaults to 44100.

sample_rate

Audio sample rate in Hz

Type:

int

Parameters Details:
delay_ms: Base delay time
  • Range: 5.0 to 40.0 ms

  • Controls center delay time

  • Typical chorus uses 20-30ms

rate: LFO modulation frequency
  • Range: 0.1 to 10.0 Hz

  • Controls modulation speed

  • Lower values create gentle chorusing

  • Higher values for vibrato effects

depth: Modulation intensity
  • Range: 0.0 to 0.25

  • Controls amount of pitch variation

  • Affects richness of chorus effect

mix: Wet/dry balance
  • Range: 0.0 to 1.0

  • 0.0: Only clean signal

  • 1.0: Only chorused signal

Warning

When using with neural networks:
  • norm_params must be in range [0, 1]

  • Parameters will be automatically mapped to their ranges

  • Ensure your network output is properly normalized (e.g., using sigmoid)

  • Parameter order must match _register_default_parameters()

Examples

Basic DSP Usage:
>>> # Create a chorus effect
>>> chorus = Chorus(
...     sample_rate=44100
... )
>>> # Process with musical settings
>>> output = chorus(input_audio, dsp_params={
...     'delay_ms': 20.0,  # 20ms base delay
...     'rate': 2.0,       # 2 Hz modulation
...     'depth': 0.15,     # Moderate intensity
...     'mix': 0.5         # Equal mix
... })
Neural Network Control:
>>> # Simple parameter prediction
>>> class ChorusController(nn.Module):
...     def __init__(self, input_size, num_params):
...         super().__init__()
...         self.net = nn.Sequential(
...             nn.Linear(input_size, 32),
...             nn.ReLU(),
...             nn.Linear(32, num_params),
...             nn.Sigmoid()  # Ensures output is in [0,1] range
...         )
...
...     def forward(self, x):
...         return self.net(x)
>>>
>>> # Initialize controller
>>> chorus = Chorus(sample_rate=44100)
>>> num_params = chorus.count_num_parameters()  # 4 parameters
>>> controller = ChorusController(input_size=16, num_params=num_params)
>>>
>>> # Process with features
>>> features = torch.randn(batch_size, 16)  # Audio features
>>> norm_params = controller(features)
>>> output = chorus(input_audio, norm_params=norm_params)

A chorus effect that creates a shimmering, thickening sound by adding slightly detuned and delayed copies of the original signal. This processor adds depth and width to the original sound by simulating multiple slightly out-of-tune instruments playing together.

_register_default_parameters()[source]

Register default parameters for the chorus effect.

Sets up:

delay_ms: Base delay time (5.0 to 40.0 ms) rate: LFO modulation rate (0.1 to 10.0 Hz) depth: Modulation intensity (0.0 to 0.25) mix: Wet/dry balance (0.0 to 1.0)

__init__(sample_rate=44100, param_range=None)[source]

Initialize the processor base.

Parameters:
  • sample_rate – Audio sample rate in Hz

  • param_range – Optional parameter definitions to override defaults

process(x, norm_params=None, dsp_params=None)[source]

Process input signal through the chorus effect.

Parameters:
  • x (torch.Tensor) – Input audio tensor. Shape: (batch, channels, samples)

  • norm_params (Dict[str, torch.Tensor]) –

    Normalized parameters (0 to 1) Must contain the following keys:

    • ’delay_ms’: Base delay time (0 to 1)

    • ’rate’: LFO frequency (0 to 1)

    • ’depth’: Modulation intensity (0 to 1)

    • ’mix’: Wet/dry balance (0 to 1)

    Each value should be a tensor of shape (batch_size,)

  • dsp_params (Dict[str, Union[float, torch.Tensor]], optional) – Direct DSP parameters. Can specify chorus parameters as: - float/int: Single value applied to entire batch - 0D tensor: Single value applied to entire batch - 1D tensor: Batch of values matching input batch size Parameters will be automatically expanded to match batch size and moved to input device if necessary. If provided, norm_params must be None.

Returns:

Processed audio tensor of same shape as input

Return type:

torch.Tensor

MultiVoiceChorus

class diffFx_pytorch.processors.modulation.MultiVoiceChorus(*args: Any, **kwargs: Any)[source]

Bases: ProcessorsBase

Differentiable implementation of a multi-voice chorus effect with independent voice control.

Implementation is based on:

This processor implements a chorus effect with multiple independently controlled voices, each featuring phase-shifted modulation and individual gain control. The implementation uses multiple LFO-modulated delay lines with evenly distributed phase offsets to create rich ensemble effects.

The transfer function for the multi-voice chorus is:

\[ \begin{align}\begin{aligned}y(t) = (1-mix)x(t) + mix\sum_{i=0}^{N-1} g_i x(t - d_i(t))\\d_i(t) = depth * sin(2πf_rt + \frac{2πi}{N}) + delay_{base}\end{aligned}\end{align} \]
where coefficients are functions of:
  • N: Number of chorus voices

  • g_i: Gain of voice i

  • f_r: LFO rate in Hz

  • depth: Modulation depth

  • delay_base: Base delay time

Parameters:
  • sample_rate (int) – Audio sample rate in Hz. Defaults to 44100.

  • num_voices (int) – Number of chorus voices. Defaults to 2.

num_voices

Number of active chorus voices

Type:

int

sample_rate

Audio sample rate in Hz

Type:

int

Parameters Details:
delay_ms: Base delay time
  • Range: 1.0 to 10.0 ms

  • Controls center delay time

  • Shorter than single chorus for tighter effect

rate: LFO modulation frequency
  • Range: 0.1 to 10.0 Hz

  • Controls modulation speed

  • Affects movement of ensemble effect

depth: Modulation intensity
  • Range: 0.0 to 0.25

  • Controls amount of detuning

  • Higher values create wider ensemble

mix: Wet/dry balance
  • Range: 0.0 to 1.0

  • 0.0: Only clean signal

  • 1.0: Only processed signal

For each voice i:
gi: Voice gain
  • Range: 0.0 to 1.0

  • Controls level of each voice

  • Allows voice balancing

Warning

When using with neural networks:
  • norm_params must be in range [0, 1]

  • Parameters will be automatically mapped to ranges

  • Ensure network output is properly normalized (e.g., using sigmoid)

  • Parameter order must match _register_default_parameters()

Examples

Basic DSP Usage:
>>> # Create a 3-voice chorus
>>> chorus = MultiVoiceChorus(
...     sample_rate=44100,
...     num_voices=3
... )
>>> # Process with musical settings
>>> output = chorus(input_audio, dsp_params={
...     'delay_ms': 5.0,    # Base delay
...     'rate': 1.5,        # Modulation rate
...     'depth': 0.15,      # Moderate detuning
...     'mix': 0.7,         # Mostly wet
...     'g0': 1.0,          # Full level voice 1
...     'g1': 0.8,          # Reduced voice 2
...     'g2': 0.6           # Quiet voice 3
... })
Neural Network Control:
>>> # Simple parameter prediction
>>> class MultiChorusController(nn.Module):
...     def __init__(self, input_size, num_params):
...         super().__init__()
...         self.net = nn.Sequential(
...             nn.Linear(input_size, 32),
...             nn.ReLU(),
...             nn.Linear(32, num_params),
...             nn.Sigmoid()  # Ensures output is in [0,1] range
...         )
...
...     def forward(self, x):
...         return self.net(x)
>>>
>>> # Initialize controller
>>> chorus = MultiVoiceChorus(sample_rate=44100, num_voices=3)
>>> num_params = chorus.count_num_parameters()  # 7 parameters (4 base + 3 gains)
>>> controller = MultiChorusController(input_size=16, num_params=num_params)
>>>
>>> # Process with features
>>> features = torch.randn(batch_size, 16)  # Audio features
>>> norm_params = controller(features)
>>> output = chorus(input_audio, norm_params=norm_params)

An advanced chorus effect that generates multiple detuned and delayed voices from the original signal. This effect provides more complex and rich spatial modulation compared to traditional single-voice chorus effects, allowing for more intricate sound design and spatial enhancement.

_register_default_parameters()[source]

Register default parameters for the multi-voice chorus.

Sets up:

delay_ms: Base delay time (1.0 to 10.0 ms) rate: LFO modulation rate (0.1 to 10.0 Hz) depth: Modulation intensity (0.0 to 0.25) mix: Wet/dry balance (0.0 to 1.0) gi: Gain for each voice i (0.0 to 1.0)

__init__(sample_rate=44100, param_range=None, num_voices=2)[source]

Initialize the processor base.

Parameters:
  • sample_rate – Audio sample rate in Hz

  • param_range – Optional parameter definitions to override defaults

process(x, norm_params=None, dsp_params=None)[source]

Process input signal through the multi-voice chorus.

Parameters:
  • x (torch.Tensor) – Input audio tensor. Shape: (batch, channels, samples)

  • norm_params (Dict[str, torch.Tensor]) –

    Normalized parameters (0 to 1) Must contain the following keys:

    • ’delay_ms’: Base delay time (0 to 1)

    • ’rate’: LFO frequency (0 to 1)

    • ’depth’: Modulation intensity (0 to 1)

    • ’mix’: Wet/dry balance (0 to 1)

    • ’g0’ to ‘g{num_voices-1}’: Voice gains (0 to 1)

    Each value should be a tensor of shape (batch_size,)

  • dsp_params (Dict[str, Union[float, torch.Tensor]], optional) – Direct DSP parameters. Can specify chorus parameters as: - float/int: Single value applied to entire batch - 0D tensor: Single value applied to entire batch - 1D tensor: Batch of values matching input batch size Parameters will be automatically expanded to match batch size and moved to input device if necessary. If provided, norm_params must be None.

Returns:

Processed audio tensor of same shape as input

Return type:

torch.Tensor

StereoChorus

class diffFx_pytorch.processors.modulation.StereoChorus(*args: Any, **kwargs: Any)[source]

Bases: ProcessorsBase

Differentiable implementation of a stereo chorus effect with configurable voices.

Implementation is based on:

This processor implements a stereo chorus effect with multiple independently controlled voices, each featuring phase-shifted modulation, individual gain control, and stereo panning. The implementation combines multi-voice modulated delays with constant-power stereo positioning to create rich, spatially distributed chorus effects.

Processing Chain: 1. Generate phase-offset LFOs for each voice 2. Calculate individual voice delays 3. Apply stereo panning per voice 4. Mix delayed and panned voices 5. Combine with dry signal

The transfer function for each voice i is:

\[ \begin{align}\begin{aligned}y_L(t) = mix * \sum_{i=0}^{N-1} g_i\sqrt{\frac{1-pan_i}{2}}x(t - d_i(t))\\y_R(t) = mix * \sum_{i=0}^{N-1} g_i\sqrt{\frac{1+pan_i}{2}}x(t - d_i(t))\\d_i(t) = depth * sin(2πf_rt + \frac{πi}{2}) + delay_{base}\end{aligned}\end{align} \]

where coefficients are functions of: - N: Number of chorus voices - g_i: Gain of voice i - pan_i: Stereo position of voice i (-1 to 1) - f_r: LFO rate in Hz - depth: Modulation depth - delay_base: Base delay time

Args: sample_rate (int): Audio sample rate in Hz. Defaults to 44100. num_voices (int): Number of chorus voices. Defaults to 2.

Attributes: num_voices (int): Number of active chorus voices sample_rate (int): Audio sample rate in Hz

Parameters Details: delay_ms: Base delay time

  • Range: 1.0 to 10.0 ms

  • Controls center delay time

  • Shorter delays for tighter effect

rate: LFO modulation frequency
  • Range: 0.1 to 10.0 Hz

  • Controls modulation speed

  • Lower values for gentle chorusing

depth: Modulation intensity
  • Range: 0.0 to 0.25

  • Controls amount of detuning

  • Affects richness of chorus

mix: Wet/dry balance
  • Range: 0.0 to 1.0

  • 0.0: Only clean signal

  • 1.0: Only processed signal

For each voice i:
gi: Voice gain
  • Range: 0.0 to 1.0

  • Controls level of each voice

pani: Voice stereo position
  • Range: -1.0 to 1.0

  • -1.0: Full left

  • 0.0: Center

  • 1.0: Full right

Warning: When using with neural networks:

  • norm_params must be in range [0, 1]

  • Parameters will be automatically mapped to ranges

  • Ensure network output is properly normalized (e.g., using sigmoid)

  • Parameter order must match _register_default_parameters()

  • Total parameters = 4 + 2*num_voices (base params + gain/pan per voice)

Examples: Basic DSP Usage:

>>> # Create a stereo chorus with 2 voices
>>> chorus = StereoChorus(
...     sample_rate=44100,
...     num_voices=2
... )
>>> # Process with musical settings
>>> output = chorus(input_audio, dsp_params={
...     'delay_ms': 5.0,    # Base delay
...     'rate': 1.5,        # Modulation rate
...     'depth': 0.15,      # Moderate detuning
...     'mix': 0.7,         # Mostly wet
...     'g0': 1.0,          # Full voice 1
...     'pan0': -0.7,       # Voice 1 left
...     'g1': 0.8,          # Reduced voice 2
...     'pan1': 0.7         # Voice 2 right
... })
Neural Network Control:
>>> # Simple parameter prediction
>>> class StereoChorusController(nn.Module):
...     def __init__(self, input_size, num_params):
...         super().__init__()
...         self.net = nn.Sequential(
...             nn.Linear(input_size, 32),
...             nn.ReLU(),
...             nn.Linear(32, num_params),
...             nn.Sigmoid()  # Ensures output is in [0,1] range
...         )
...
...     def forward(self, x):
...         return self.net(x)
>>>
>>> # Initialize controller
>>> chorus = StereoChorus(sample_rate=44100, num_voices=2)
>>> num_params = chorus.count_num_parameters()  # 8 parameters (4 base + 2*2 voice params)
>>> controller = StereoChorusController(input_size=16, num_params=num_params)
>>>
>>> # Process with features
>>> features = torch.randn(batch_size, 16)  # Audio features
>>> norm_params = controller(features)
>>> output = chorus(input_audio, norm_params=norm_params)

A stereo-specific chorus effect that creates a wide, immersive modulation by applying independent chorus processing to left and right channels. This approach enhances the stereo image and provides a more expansive sound stage compared to mono chorus effects.

_register_default_parameters()[source]

Register default parameters for the stereo chorus.

Sets up:

delay_ms: Base delay time (1.0 to 10.0 ms) rate: LFO modulation rate (0.1 to 10.0 Hz) depth: Modulation intensity (0.0 to 0.25) mix: Wet/dry balance (0.0 to 1.0)

For each voice i:

gi: Voice gain (0.0 to 1.0) pani: Voice stereo position (-1.0 to 1.0)

__init__(sample_rate=44100, param_range=None, num_voices=2)[source]

Initialize the stereo chorus processor.

Parameters:
  • sample_rate (int) – Audio sample rate in Hz. Defaults to 44100.

  • num_voices (int) – Number of chorus voices. Defaults to 2.

process(x, norm_params=None, dsp_params=None)[source]

Process input signal through the stereo chorus.

Parameters:
  • x (torch.Tensor) – Input audio tensor. Shape: (batch, channels, samples) Accepts both mono (channels=1) and stereo (channels=2) input. Mono input will be automatically converted to stereo.

  • norm_params (Dict[str, torch.Tensor]) –

    Normalized parameters (0 to 1) Must contain the following keys:

    • ’delay_ms’: Base delay time (0 to 1)

    • ’rate’: LFO frequency (0 to 1)

    • ’depth’: Modulation intensity (0 to 1)

    • ’mix’: Wet/dry balance (0 to 1)

    For each voice i:
    • f’g{i}’: Voice gain (0 to 1)

    • f’pan{i}’: Voice position (0 to 1)

    Each value should be a tensor of shape (batch_size,)

  • dsp_params (Dict[str, Union[float, torch.Tensor]], optional) – Direct DSP parameters. Can specify chorus parameters as: - float/int: Single value applied to entire batch - 0D tensor: Single value applied to entire batch - 1D tensor: Batch of values matching input batch size Parameters will be automatically expanded to match batch size and moved to input device if necessary. If provided, norm_params must be None.

Returns:

Processed stereo audio tensor. Shape: (batch, 2, samples)

Return type:

torch.Tensor

Flanger

class diffFx_pytorch.processors.modulation.Flanger(*args: Any, **kwargs: Any)[source]

Bases: ProcessorsBase

Differentiable implementation of a flanger audio effect.

Implementation is based on:

This processor implements a modulated delay line to create the flanger effect, using a low-frequency oscillator (LFO) to modulate a very short delay time. The implementation creates the characteristic “swooshing” sound through phase cancellation and reinforcement.

Processing Chain:
  1. Generate LFO for delay modulation

  2. Calculate delay phases

  3. Apply variable delay

  4. Mix with original signal

The transfer function is:

\[ \begin{align}\begin{aligned}y(t) = mix * x(t - d(t)) + (1 - mix) * x(t)\\d(t) = depth * sin(2πf_rt) + delay_{base}\end{aligned}\end{align} \]
where coefficients are functions of:
  • x(t): Input signal

  • f_r: LFO rate in Hz

  • depth: Modulation depth

  • delay_base: Base delay time

  • mix: Wet/dry balance

Parameters:

sample_rate (int) – Audio sample rate in Hz. Defaults to 44100.

sample_rate

Audio sample rate in Hz

Type:

int

Parameters Details:
delay_ms: Base delay time
  • Range: 1.0 to 10.0 ms

  • Controls center delay time

  • Very short delays for flanger effect

rate: LFO modulation frequency
  • Range: 0.1 to 2.0 Hz

  • Controls modulation speed

  • Lower values create slow sweeps

  • Higher values for faster effects

depth: Modulation intensity
  • Range: 0.0 to 1.0

  • Controls sweep width

  • Affects intensity of effect

mix: Wet/dry balance
  • Range: 0.0 to 1.0

  • 0.0: Only clean signal

  • 1.0: Only flanged signal

Note

The processor supports the following features:
  • Variable delay implementation

  • Smooth LFO modulation

  • Phase-coherent processing

  • Automatic buffer size handling

  • Efficient batch processing

Warning

When using with neural networks:
  • norm_params must be in range [0, 1]

  • Parameters will be automatically mapped to ranges

  • Ensure network output is properly normalized (e.g., using sigmoid)

  • Parameter order must match _register_default_parameters()

Examples

Basic DSP Usage:
>>> # Create a flanger effect
>>> flanger = Flanger(
...     sample_rate=44100
... )
>>> # Process with musical settings
>>> output = flanger(input_audio, dsp_params={
...     'delay_ms': 5.0,    # 5ms base delay
...     'rate': 0.5,        # 0.5 Hz modulation
...     'depth': 0.7,       # Strong sweep
...     'mix': 0.6          # 60% wet
... })
Neural Network Control:
>>> # Simple parameter prediction
>>> class FlangerController(nn.Module):
...     def __init__(self, input_size, num_params):
...         super().__init__()
...         self.net = nn.Sequential(
...             nn.Linear(input_size, 32),
...             nn.ReLU(),
...             nn.Linear(32, num_params),
...             nn.Sigmoid()  # Ensures output is in [0,1] range
...         )
...
...     def forward(self, x):
...         return self.net(x)
>>>
>>> # Initialize controller
>>> flanger = Flanger(sample_rate=44100)
>>> num_params = flanger.count_num_parameters()  # 4 parameters
>>> controller = FlangerController(input_size=16, num_params=num_params)
>>>
>>> # Process with features
>>> features = torch.randn(batch_size, 16)  # Audio features
>>> norm_params = controller(features)
>>> output = flanger(input_audio, norm_params=norm_params)

A classic modulation effect that creates a sweeping, metallic sound by mixing the original signal with a slightly delayed, time-modulated copy of itself. The effect produces a characteristic whooshing or airplane-like sound through controlled signal delay and feedback.

_register_default_parameters()[source]

Register default parameters for the flanger effect.

Sets up:

delay_ms: Base delay time (1.0 to 10.0 ms) rate: LFO modulation rate (0.1 to 2.0 Hz) depth: Modulation intensity (0.0 to 1.0) mix: Wet/dry balance (0.0 to 1.0)

__init__(sample_rate=44100, param_range=None)[source]

Initialize the processor base.

Parameters:
  • sample_rate – Audio sample rate in Hz

  • param_range – Optional parameter definitions to override defaults

process(x, norm_params=None, dsp_params=None)[source]

Process input signal through the flanger effect.

Parameters:
  • x (torch.Tensor) – Input audio tensor. Shape: (batch, channels, samples)

  • norm_params (Dict[str, torch.Tensor]) –

    Normalized parameters (0 to 1) Must contain the following keys:

    • ’delay_ms’: Base delay time (0 to 1)

    • ’rate’: LFO frequency (0 to 1)

    • ’depth’: Modulation intensity (0 to 1)

    • ’mix’: Wet/dry balance (0 to 1)

    Each value should be a tensor of shape (batch_size,)

  • dsp_params (Dict[str, Union[float, torch.Tensor]], optional) – Direct DSP parameters. Can specify flanger parameters as: - float/int: Single value applied to entire batch - 0D tensor: Single value applied to entire batch - 1D tensor: Batch of values matching input batch size Parameters will be automatically expanded to match batch size and moved to input device if necessary. If provided, norm_params must be None.

Returns:

Processed audio tensor of same shape as input

Return type:

torch.Tensor

StereoFlanger

class diffFx_pytorch.processors.modulation.StereoFlanger(*args: Any, **kwargs: Any)[source]

Bases: ProcessorsBase

Differentiable implementation of a stereo flanger effect with quadrature LFOs.

Implementation is based on:

This processor implements a stereo flanger that uses quadrature (90° phase-shifted) LFOs for the left and right channels, creating a wide stereo image through independent modulation. The implementation provides smooth phase differences between channels while maintaining the characteristic flanger sound.

Processing Chain: 1. Generate quadrature LFOs for stereo modulation 2. Calculate independent channel delays 3. Apply stereo variable delay 4. Mix with original signal

The transfer function for each channel is:

\[ \begin{align}\begin{aligned}y_L(t) = mix * x_L(t - d_L(t)) + (1 - mix) * x_L(t)\\y_R(t) = mix * x_R(t - d_R(t)) + (1 - mix) * x_R(t)\\d_L(t) = depth * sin(2πf_rt) + delay_{base}\\d_R(t) = depth * sin(2πf_rt + π/2) + delay_{base}\end{aligned}\end{align} \]

where coefficients are functions of: - x_L, x_R: Left and right input signals - f_r: LFO rate in Hz - depth: Modulation depth - delay_base: Base delay time - mix: Wet/dry balance

Args: sample_rate (int): Audio sample rate in Hz. Defaults to 44100.

Attributes: sample_rate (int): Audio sample rate in Hz

Parameters Details: delay_ms: Base delay time

  • Range: 1.0 to 10.0 ms

  • Controls center delay time

  • Very short delays for flanger effect

rate: LFO modulation frequency
  • Range: 0.1 to 2.0 Hz

  • Controls modulation speed

  • Lower values create slow stereo sweeps

depth: Modulation intensity
  • Range: 0.0 to 1.0

  • Controls stereo sweep width

  • Affects intensity of effect

mix: Wet/dry balance
  • Range: 0.0 to 1.0

  • 0.0: Only clean signal

  • 1.0: Only flanged signal

Note: The processor supports the following features:

  • Quadrature LFOs for true stereo

  • Independent channel processing

  • Phase-coherent stereo field

  • Automatic buffer size handling

  • Efficient batch processing

Warning: When using with neural networks:

  • norm_params must be in range [0, 1]

  • Parameters will be automatically mapped to ranges

  • Ensure network output is properly normalized (e.g., using sigmoid)

  • Parameter order must match _register_default_parameters()

  • Input must be stereo (2 channels)

Examples: Basic DSP Usage:

>>> # Create a stereo flanger
>>> flanger = StereoFlanger(
...     sample_rate=44100
... )
>>> # Process with musical settings
>>> output = flanger(input_audio, dsp_params={
...     'delay_ms': 5.0,    # 5ms base delay
...     'rate': 0.5,        # 0.5 Hz modulation
...     'depth': 0.7,       # Strong sweep
...     'mix': 0.6          # 60% wet
... })
Neural Network Control:
>>> # Simple parameter prediction
>>> class StereoFlangerController(nn.Module):
...     def __init__(self, input_size, num_params):
...         super().__init__()
...         self.net = nn.Sequential(
...             nn.Linear(input_size, 32),
...             nn.ReLU(),
...             nn.Linear(32, num_params),
...             nn.Sigmoid()  # Ensures output is in [0,1] range
...         )
...
...     def forward(self, x):
...         return self.net(x)
>>>
>>> # Initialize controller
>>> flanger = StereoFlanger(sample_rate=44100)
>>> num_params = flanger.count_num_parameters()  # 4 parameters
>>> controller = StereoFlangerController(input_size=16, num_params=num_params)
>>>
>>> # Process with features
>>> features = torch.randn(batch_size, 16)  # Audio features
>>> norm_params = controller(features)
>>> output = flanger(input_audio, norm_params=norm_params)

A stereo implementation of the flanger effect that applies independent flanger processing to left and right channels. This approach creates a more complex and spatially interesting modulation effect compared to mono flanger implementations.

_register_default_parameters()[source]

Register default parameters for the stereo flanger effect.

Sets up:

delay_ms: Base delay time (1.0 to 10.0 ms) rate: LFO modulation rate (0.1 to 2.0 Hz) depth: Modulation intensity (0.0 to 1.0) mix: Wet/dry balance (0.0 to 1.0)

__init__(sample_rate=44100, param_range=None)[source]

Initialize the processor base.

Parameters:
  • sample_rate – Audio sample rate in Hz

  • param_range – Optional parameter definitions to override defaults

process(x, norm_params=None, dsp_params=None)[source]

Process input signal through the stereo flanger effect.

Parameters:
  • x (torch.Tensor) – Input audio tensor. Shape: (batch, 2, samples) Must be stereo input (2 channels).

  • norm_params (Dict[str, torch.Tensor]) –

    Normalized parameters (0 to 1) Must contain the following keys:

    • ’delay_ms’: Base delay time (0 to 1)

    • ’rate’: LFO frequency (0 to 1)

    • ’depth’: Modulation intensity (0 to 1)

    • ’mix’: Wet/dry balance (0 to 1)

    Each value should be a tensor of shape (batch_size,)

  • dsp_params (Dict[str, Union[float, torch.Tensor]], optional) – Direct DSP parameters. Can specify flanger parameters as: - float/int: Single value applied to entire batch - 0D tensor: Single value applied to entire batch - 1D tensor: Batch of values matching input batch size Parameters will be automatically expanded to match batch size and moved to input device if necessary. If provided, norm_params must be None.

Returns:

Processed stereo audio tensor. Shape: (batch, 2, samples)

Return type:

torch.Tensor

Raises:

AssertionError – If input is not stereo (2 channels)

FeedbackFlanger

class diffFx_pytorch.processors.modulation.FeedbackFlanger(*args: Any, **kwargs: Any)[source]

Bases: ProcessorsBase

Differentiable implementation of a feedback flanger effect.

Implementation is based on:

This processor implements a flanger with feedback path, allowing the delayed signal to be fed back into the input. The feedback creates resonant peaks in the frequency response, resulting in a more pronounced and characteristically “metallic” flanger sound.

Processing Chain: 1. Generate LFO for delay modulation 2. Sum input with feedback signal 3. Apply modulated delay 4. Feed delayed signal back 5. Mix with original signal

The transfer function with feedback is:

\[ \begin{align}\begin{aligned}y(t) = mix * (x(t) + fb * y(t - d(t))) + (1 - mix) * x(t)\\d(t) = depth * sin(2πf_rt) + delay_{base}\end{aligned}\end{align} \]

where coefficients are functions of: - x(t): Input signal - f_r: LFO rate in Hz - depth: Modulation depth - delay_base: Base delay time - fb: Feedback amount - mix: Wet/dry balance

Args: sample_rate (int): Audio sample rate in Hz. Defaults to 44100.

Attributes: sample_rate (int): Audio sample rate in Hz

Parameters Details: delay_ms: Base delay time

  • Range: 1.0 to 10.0 ms

  • Controls center delay time

  • Very short delays for flanger effect

rate: LFO modulation frequency
  • Range: 0.1 to 10.0 Hz

  • Controls modulation speed

  • Lower values create slow sweeps

depth: Modulation intensity
  • Range: 0.0 to 0.25

  • Controls sweep width

  • Affects intensity of effect

feedback: Feedback amount
  • Range: 0.0 to 0.7

  • Controls resonance intensity

  • Higher values create metallic sound

mix: Wet/dry balance
  • Range: 0.0 to 1.0

  • 0.0: Only clean signal

  • 1.0: Only flanged signal

Note: The processor supports the following features:

  • Variable delay implementation

  • Feedback path processing

  • Resonant frequency peaks

  • Automatic stability control

  • Efficient batch processing

Warning: When using with neural networks:

  • norm_params must be in range [0, 1]

  • Parameters will be automatically mapped to ranges

  • Ensure network output is properly normalized (e.g., using sigmoid)

  • Parameter order must match _register_default_parameters()

  • High feedback can create intense resonance

Examples: Basic DSP Usage:

>>> # Create a feedback flanger
>>> flanger = FeedbackFlanger(
...     sample_rate=44100
... )
>>> # Process with musical settings
>>> output = flanger(input_audio, dsp_params={
...     'delay_ms': 5.0,     # 5ms base delay
...     'rate': 0.5,         # 0.5 Hz modulation
...     'depth': 0.15,       # Moderate sweep
...     'feedback': 0.4,     # Medium resonance
...     'mix': 0.6           # 60% wet
... })
Neural Network Control:
>>> # Simple parameter prediction
>>> class FlangerController(nn.Module):
...     def __init__(self, input_size, num_params):
...         super().__init__()
...         self.net = nn.Sequential(
...             nn.Linear(input_size, 32),
...             nn.ReLU(),
...             nn.Linear(32, num_params),
...             nn.Sigmoid()  # Ensures output is in [0,1] range
...         )
...
...     def forward(self, x):
...         return self.net(x)
>>>
>>> # Initialize controller
>>> flanger = FeedbackFlanger(sample_rate=44100)
>>> num_params = flanger.count_num_parameters()  # 5 parameters
>>> controller = FlangerController(input_size=16, num_params=num_params)
>>>
>>> # Process with features
>>> features = torch.randn(batch_size, 16)  # Audio features
>>> norm_params = controller(features)
>>> output = flanger(input_audio, norm_params=norm_params)

An extended flanger effect that incorporates feedback to create more pronounced and resonant modulation. The feedback mechanism allows for more intense and distinctive sweeping sounds, adding additional harmonic complexity to the original signal.

_register_default_parameters()[source]

Register default parameters for the feedback flanger effect.

Sets up:

delay_ms: Base delay time (1.0 to 10.0 ms) rate: LFO modulation rate (0.1 to 10.0 Hz) depth: Modulation intensity (0.0 to 0.25) feedback: Feedback amount (0.0 to 0.7) mix: Wet/dry balance (0.0 to 1.0)

__init__(sample_rate=44100, param_range=None)[source]

Initialize the processor base.

Parameters:
  • sample_rate – Audio sample rate in Hz

  • param_range – Optional parameter definitions to override defaults

process(x, norm_params=None, dsp_params=None)[source]

Process input signal through the feedback flanger effect.

Parameters:
  • x (torch.Tensor) – Input audio tensor. Shape: (batch, channels, samples)

  • norm_params (Dict[str, torch.Tensor]) –

    Normalized parameters (0 to 1) Must contain the following keys:

    • ’delay_ms’: Base delay time (0 to 1)

    • ’rate’: LFO frequency (0 to 1)

    • ’depth’: Modulation intensity (0 to 1)

    • ’feedback’: Feedback amount (0 to 1)

    • ’mix’: Wet/dry balance (0 to 1)

    Each value should be a tensor of shape (batch_size,)

  • dsp_params (Dict[str, Union[float, torch.Tensor]], optional) – Direct DSP parameters. Can specify flanger parameters as: - float/int: Single value applied to entire batch - 0D tensor: Single value applied to entire batch - 1D tensor: Batch of values matching input batch size Parameters will be automatically expanded to match batch size and moved to input device if necessary. If provided, norm_params must be None.

Returns:

Processed audio tensor of same shape as input

Return type:

torch.Tensor

Phaser

class diffFx_pytorch.processors.modulation.Phaser(*args: Any, **kwargs: Any)[source]

Bases: ProcessorsBase

Differentiable implementation of a high-order allpass phaser effect.

Implementation is based on:

This processor implements a sophisticated phaser effect using allpass filters with time-varying coefficients, creating complex phase-shifting modulations in the audio signal. The implementation provides precise control over the phasing effect through multiple parameters.

Processing Chain: 1. Generate low-frequency oscillator (LFO) modulation 2. Create time-varying allpass filter coefficients 3. Apply fourth-order allpass filtering 4. Mix processed and original signals

The phaser effect works by creating phase shifts across different frequency bands, resulting in a sweeping, swirling sound characteristic of classic analog phasers. Unlike simple single-stage phasers, this implementation uses a fourth-order allpass filter for richer, more complex modulations.

Mathematical Concept: The core of the phaser is a time-varying allpass filter where the transfer function is dynamically modified by a low-frequency oscillator (LFO). The phase shift is controlled by the allpass coefficient p(t), which is derived from the LFO and frequency range parameters.

Parameters:

sample_rate (int) – Audio sample rate in Hz. Defaults to 44100.

sample_rate

Audio sample rate in Hz

Type:

int

prev_states

Previous filter states for stateful processing

Type:

torch.Tensor, optional

osc

Oscillator function (defaults to torch.sin)

Type:

callable

lpc_func

Linear prediction coding function for filtering

Type:

callable

Parameters Details: f0: LFO Frequency

  • Range: 0.1 to 5.0 Hz

  • Controls speed of phase modulation

  • Determines sweeping rate of the effect

f_min: Minimum Cutoff Frequency
  • Range: 100.0 to 2000.0 Hz

  • Lower bound of frequency modulation

  • Defines the start of the phase-shifting range

f_max: Maximum Cutoff Frequency
  • Range: 2000.0 to 10000.0 Hz

  • Upper bound of frequency modulation

  • Defines the end of the phase-shifting range

feedback: Feedback Amount
  • Range: 0.0 to 0.9

  • Controls resonance and intensity of the phasing effect

  • Higher values create more pronounced peaks and notches

wet_mix: Wet/Dry Mix
  • Range: 0.0 to 1.0

  • 0.0: Only clean (dry) signal

  • 1.0: Only processed (wet) signal

Note: The processor supports the following features:

  • Fourth-order allpass filtering

  • Dynamic frequency range modulation

  • Precise feedback control

  • Efficient batch processing

  • Neural network compatible

Warning: When using with neural networks:

  • Ensure norm_params are in range [0, 1]

  • Parameters will be automatically mapped to ranges

  • Network output should be properly normalized

  • Input must be mono or stereo

  • Parameter order must match _register_default_parameters()

Examples: Basic DSP Usage:

>>> # Create a phaser
>>> phaser = Phaser(sample_rate=44100)
>>> # Process with musical settings
>>> output = phaser(input_audio, dsp_params={
...     'f0': 0.5,          # 0.5 Hz LFO
...     'f_min': 500.0,     # Start at 500 Hz
...     'f_max': 5000.0,    # End at 5000 Hz
...     'feedback': 0.6,    # Moderate feedback
...     'wet_mix': 0.7      # 70% processed signal
... })
Neural Network Control:
>>> # Simple parameter prediction network
>>> class PhaserController(nn.Module):
...     def __init__(self, input_size, num_params):
...         super().__init__()
...         self.net = nn.Sequential(
...             nn.Linear(input_size, 32),
...             nn.ReLU(),
...             nn.Linear(32, num_params),
...             nn.Sigmoid()  # Ensures output is in [0,1] range
...         )
...
...     def forward(self, x):
...         return self.net(x)

A phase-shifting modulation effect that creates a sweeping, swirling sound by splitting the signal into multiple all-pass filtered paths and recombining them. This results in a distinctive, swooping modulation that adds movement and depth to the original sound.

__init__(sample_rate, param_range=None)[source]

Initialize the processor base.

Parameters:
  • sample_rate – Audio sample rate in Hz

  • param_range – Optional parameter definitions to override defaults

_register_default_parameters()[source]

Register default parameters for the phaser effect.

Sets up:

f0: LFO frequency (0.1 to 5.0 Hz) f_min: Minimum cutoff frequency (100.0 to 2000.0 Hz) f_max: Maximum cutoff frequency (2000.0 to 10000.0 Hz) feedback: Feedback amount (0.0 to 0.9) wet_mix: Wet/dry balance (0.0 to 1.0)

process(x, norm_params=None, dsp_params=None)[source]

Process input signal through the phaser effect.

Parameters:
  • x (torch.Tensor) – Input audio tensor. Shape: (batch, channels, samples) Supports mono or stereo inputs

  • norm_params (Dict[str, torch.Tensor]) –

    Normalized parameters (0 to 1) Must contain keys:

    • ’f0’: LFO frequency

    • ’f_min’: Minimum cutoff frequency

    • ’f_max’: Maximum cutoff frequency

    • ’feedback’: Feedback amount

    • ’wet_mix’: Wet/dry mix

    Each value should be a tensor of shape (batch_size,)

  • dsp_params (Dict[str, Union[float, torch.Tensor]], optional) –

    Direct DSP parameters. Can specify as:
    • float/int: Single value applied to entire batch

    • 0D tensor: Single value applied to entire batch

    • 1D tensor: Batch of values matching input batch size

    If provided, norm_params must be None.

Returns:

Processed audio tensor Shape: (batch, channels, samples)

Return type:

torch.Tensor

Raises:

AssertionError – If input tensor dimensions are incorrect