Distortion
This section covers several types of distortion including various waveshaping functions and bit-crushing effects.
TanHDist
- class diffFx_pytorch.processors.distortion.TanHDist(*args: Any, **kwargs: Any)[source]
Bases:
BaseDistortionDifferentiable implementation of hyperbolic tangent distortion.
This processor implements smooth distortion using the hyperbolic tangent (tanh) function for waveshaping. It provides analog-style saturation with natural compression characteristics and gradual onset of distortion.
The transfer function is:
\[y = tanh(x)\]where x is the input signal (optionally pre-gained and DC biased in shaping mode).
- Parameters:
Parameters Details:
- Basic Mode (shaping_mode=False):
- mix: Wet/dry mix ratio
Range: 0.0 to 1.0
0.0: Only clean signal
1.0: Only distorted signal
- Shaping Mode (shaping_mode=True):
- pre_gain_db: Input gain before distortion
Range: -24.0 to 24.0 dB
Controls amount of drive into saturation
- post_gain_db: Output gain after distortion
Range: -24.0 to 0.0 dB
Compensates for level changes
- dc_bias: DC offset before distortion
Range: -0.2 to 0.2
Affects harmonic content
Examples
- Basic DSP Usage:
>>> # Create a tanh distortion >>> dist = TanHDist(sample_rate=44100) >>> # Process with basic settings >>> output = dist(input_audio, dsp_params={ ... 'mix': 0.7 # 70% wet signal ... })
- Advanced Usage (shaping_mode=True):
>>> # Create with waveshaping controls >>> dist = TanHDist(sample_rate=44100, shaping_mode=True) >>> # Process with detailed control >>> output = dist(input_audio, dsp_params={ ... 'pre_gain_db': 12.0, # Drive into distortion ... 'post_gain_db': -6.0, # Compensate output ... 'dc_bias': 0.1, # Add asymmetry ... 'mix': 0.8 # 80% wet ... })
A smooth distortion effect using the hyperbolic tangent (tanh) function for waveshaping. Provides a musical, analog-style saturation with gradual onset and natural compression characteristics. The drive parameter controls the intensity of the distortion.
- _apply_distortion(x, params)[source]
Apply hyperbolic tangent distortion to the input signal.
- Parameters:
x (torch.Tensor) – Input audio tensor. Shape: (batch, channels, samples)
params (dict) – Processing parameters (not used in this implementation)
- Returns:
Distorted audio tensor of same shape as input
- Return type:
SoftDist
- class diffFx_pytorch.processors.distortion.SoftDist(*args: Any, **kwargs: Any)[source]
Bases:
BaseDistortionDifferentiable implementation of soft-clipping distortion.
This processor implements a soft-clipping distortion using a piecewise polynomial transfer function. It provides smooth transitions between clean and distorted signals, creating a warm overdrive characteristic similar to analog tube saturation.
The transfer function is piecewise:
\[\begin{split}y = \begin{cases} 1.0 & x ≥ 1 \\ 1.5(x - x^3/3) & -1 < x < 1 \\ -1.0 & x ≤ -1 \end{cases}\end{split}\]where x is the input signal (optionally pre-gained and DC biased in shaping mode).
- Parameters:
- Parameters Details:
- Basic Mode (shaping_mode=False):
- mix: Wet/dry mix ratio
Range: 0.0 to 1.0
0.0: Only clean signal
1.0: Only distorted signal
- Shaping Mode (shaping_mode=True):
- pre_gain_db: Input gain before distortion
Range: -24.0 to 24.0 dB
Controls amount of drive into clipping
- post_gain_db: Output gain after distortion
Range: -24.0 to 0.0 dB
Compensates for level changes
- dc_bias: DC offset before distortion
Range: -0.2 to 0.2
Affects asymmetric clipping
Examples
- Basic DSP Usage:
>>> # Create a soft clipper >>> dist = SoftDist(sample_rate=44100) >>> # Process with basic settings >>> output = dist(input_audio, dsp_params={ ... 'mix': 0.6 # 60% wet signal ... })
- Advanced Usage (shaping_mode=True):
>>> # Create with waveshaping controls >>> dist = SoftDist(sample_rate=44100, shaping_mode=True) >>> # Process with detailed control >>> output = dist(input_audio, dsp_params={ ... 'pre_gain_db': 18.0, # Drive into clipping ... 'post_gain_db': -9.0, # Compensate output ... 'dc_bias': 0.05, # Slight asymmetry ... 'mix': 0.7 # 70% wet ... })
A soft-clipping distortion that provides a smooth transition between clean and distorted signals. Uses a polynomial transfer function to create warm overdrive characteristics similar to tube amplifier saturation. Features drive and tone controls for versatile sound shaping.
- _apply_distortion(x, params)[source]
Apply soft-clipping distortion to the input signal.
- Parameters:
x (torch.Tensor) – Input audio tensor. Shape: (batch, channels, samples)
params (dict) – Processing parameters (not used in this implementation)
- Returns:
Distorted audio tensor of same shape as input
- Return type:
Note
Uses a piecewise function: - Linear clipping for \(|x| \geq 1\) - Cubic polynomial for \(|x| < 1\)
HardDist
- class diffFx_pytorch.processors.distortion.HardDist(*args: Any, **kwargs: Any)[source]
Bases:
BaseDistortionDifferentiable implementation of hard-clipping distortion.
This processor implements a hard-clipping distortion that abruptly limits signals above a specified threshold. It creates aggressive distortion with rich harmonic content, similar to extreme transistor or diode clipping circuits.
The transfer function is:
\[\begin{split}y = \begin{cases} threshold & x > threshold \\ x & -threshold ≤ x ≤ threshold \\ -threshold & x < -threshold \end{cases}\end{split}\]where x is the input signal (optionally pre-gained and DC biased in shaping mode).
- Parameters:
- Parameters Details:
- Basic Mode (shaping_mode=False):
- threshold: Clipping threshold level
Range: 0.1 to 1.0
Lower values create more aggressive clipping
Higher values preserve more dynamics
- mix: Wet/dry mix ratio
Range: 0.0 to 1.0
0.0: Only clean signal
1.0: Only distorted signal
- Shaping Mode (shaping_mode=True):
- pre_gain_db: Input gain before distortion
Range: -24.0 to 24.0 dB
Controls amount of drive into clipping
- post_gain_db: Output gain after distortion
Range: -24.0 to 0.0 dB
Compensates for level changes
- dc_bias: DC offset before distortion
Range: -0.2 to 0.2
Affects asymmetric clipping
Examples
- Basic DSP Usage:
>>> # Create a hard clipper >>> dist = HardDist(sample_rate=44100) >>> # Process with basic settings >>> output = dist(input_audio, dsp_params={ ... 'threshold': 0.3, # Aggressive clipping ... 'mix': 0.8 # 80% wet signal ... })
- Advanced Usage (shaping_mode=True):
>>> # Create with waveshaping controls >>> dist = HardDist(sample_rate=44100, shaping_mode=True) >>> # Process with detailed control >>> output = dist(input_audio, dsp_params={ ... 'threshold': 0.5, # Moderate clipping ... 'pre_gain_db': 15.0, # Drive into clipping ... 'post_gain_db': -12.0, # Compensate output ... 'dc_bias': 0.1, # Add asymmetry ... 'mix': 0.7 # 70% wet ... })
A hard-clipping distortion that abruptly limits signal peaks above a threshold, creating aggressive distortion with rich harmonic content. Useful for creating intense distortion effects typical of high-gain guitar amplifiers and fuzz pedals.
- _add_specific_parameters()[source]
Register additional parameters specific to hard clipping.
- Adds:
threshold: Clipping threshold level (0.1 to 1.0)
- _apply_distortion(x, params)[source]
Apply hard-clipping distortion to the input signal.
- Parameters:
x (torch.Tensor) – Input audio tensor. Shape: (batch, channels, samples)
params (dict) – Must contain: - threshold: Clipping threshold level
- Returns:
Distorted audio tensor of same shape as input
- Return type:
DoubleSoftDist
- class diffFx_pytorch.processors.distortion.DoubleSoftDist(*args: Any, **kwargs: Any)[source]
Bases:
BaseDistortionDifferentiable implementation of double soft-clipping distortion with asymmetric controls.
Implementation is based on:
This processor implements a sophisticated dual-stage soft-clipping distortion with independent control over positive and negative waveform shaping. It provides precise control over clipping characteristics, allowing creation of asymmetric distortion with variable slopes and limits.
The transfer function is piecewise and applies separately to positive and negative regions:
Positive region (x > 0):
\[\begin{split}y = \begin{cases} upper\_lim & x ≥ \frac{1}{slope} \\ \frac{3}{2}upper\_lim(slope⋅x - \frac{(slope⋅x)^3}{3}) + \frac{upper\_lim}{2} & -\frac{1}{slope} < x < \frac{1}{slope} \\ 0 & x ≤ -\frac{1}{slope} \end{cases}\end{split}\]Negative region (x ≤ 0):
\[\begin{split}y = \begin{cases} 0 & x ≥ \frac{1}{slope} \\ \frac{3}{2}lower\_lim(slope⋅x - \frac{(slope⋅x)^3}{3}) + \frac{lower\_lim}{2} & -\frac{1}{slope} < x < \frac{1}{slope} \\ lower\_lim & x ≤ -\frac{1}{slope} \end{cases}\end{split}\]- Parameters:
- Parameters Details:
- Basic Mode (shaping_mode=False):
- upper_lim: Positive clipping limit
Range: 0.1 to 1.0
Controls maximum positive output
- lower_lim: Negative clipping limit
Range: -1.0 to -0.1
Controls maximum negative output
- slope: Transfer function steepness
Range: 1.0 to 10.0
Higher values create sharper transitions
- x_off_factor: Offset control
Range: 0.0 to 1.0
Affects symmetry of clipping curve
- upper_skew: Positive region shaping
Range: 0.1 to 2.0
Controls shape of positive overdrive
- lower_skew: Negative region shaping
Range: 0.1 to 2.0
Controls shape of negative overdrive
- mix: Wet/dry mix ratio
Range: 0.0 to 1.0
0.0: Only clean signal
1.0: Only distorted signal
- Shaping Mode (shaping_mode=True):
- pre_gain_db: Input gain before distortion
Range: -24.0 to 24.0 dB
- post_gain_db: Output gain after distortion
Range: -24.0 to 0.0 dB
- dc_bias: DC offset before distortion
Range: -0.2 to 0.2
Examples
- Basic Usage:
>>> # Create a double soft clipper >>> dist = DoubleSoftDist(sample_rate=44100) >>> # Process with asymmetric settings >>> output = dist(input_audio, dsp_params={ ... 'upper_lim': 0.8, ... 'lower_lim': -0.6, ... 'slope': 3.0, ... 'x_off_factor': 0.2, ... 'upper_skew': 1.5, ... 'lower_skew': 1.2, ... 'mix': 0.7 ... })
- Advanced Usage (shaping_mode=True):
>>> # Create with waveshaping controls >>> dist = DoubleSoftDist(sample_rate=44100, shaping_mode=True) >>> output = dist(input_audio, dsp_params={ ... 'upper_lim': 0.8, ... 'lower_lim': -0.6, ... 'slope': 3.0, ... 'x_off_factor': 0.2, ... 'upper_skew': 1.5, ... 'lower_skew': 1.2, ... 'pre_gain_db': 12.0, ... 'post_gain_db': -6.0, ... 'dc_bias': 0.1, ... 'mix': 0.7 ... })
A dual-stage soft clipping distortion that cascades two soft-clipping stages for more complex harmonic generation. Provides additional harmonic richness while maintaining musical qualities of soft-clipping. Features independent drive controls for each stage.
- _add_specific_parameters()[source]
Register additional parameters specific to double soft clipping.
- Adds:
upper_lim: Positive clipping limit (0.1 to 1.0) lower_lim: Negative clipping limit (-1.0 to -0.1) slope: Transfer function steepness (1.0 to 10.0) x_off_factor: Offset control (0.0 to 1.0) upper_skew: Positive region shaping (0.1 to 2.0) lower_skew: Negative region shaping (0.1 to 2.0)
- _apply_distortion(x, params)[source]
Apply double soft-clipping distortion to the input signal.
- Parameters:
x (torch.Tensor) – Input audio tensor. Shape: (batch, channels, samples)
params (dict) – Must contain: - upper_lim: Positive clipping limit - lower_lim: Negative clipping limit - slope: Transfer function steepness - x_off_factor: Offset control - upper_skew: Positive region shaping - lower_skew: Negative region shaping
- Returns:
Distorted audio tensor of same shape as input
- Return type:
Note
Processes positive and negative regions independently using different shaping parameters for each region.
CubicDist
- class diffFx_pytorch.processors.distortion.CubicDist(*args: Any, **kwargs: Any)[source]
Bases:
BaseDistortionDifferentiable implementation of cubic distortion.
This processor implements distortion using a cubic polynomial transfer function, creating asymmetric clipping characteristics by adding a scaled cubic term to the input signal. This approach generates both even and odd harmonics, providing a rich timbral modification.
The transfer function is:
\[y = x + drive * x^3\]where: - x is the input signal - drive is the intensity control (derived from drive_db) - drive = 10^{drive_db/20}
- Parameters:
- Parameters Details:
- Basic Mode (shaping_mode=False):
- drive_db: Distortion intensity
Range: -24.0 to 24.0 dB
Controls amplitude of cubic term
Higher values create more distortion
Negative values reduce distortion
- mix: Wet/dry mix ratio
Range: 0.0 to 1.0
0.0: Only clean signal
1.0: Only distorted signal
- Shaping Mode (shaping_mode=True):
- pre_gain_db: Input gain before distortion
Range: -24.0 to 24.0 dB
Controls overall drive level
- post_gain_db: Output gain after distortion
Range: -24.0 to 0.0 dB
Compensates for level changes
- dc_bias: DC offset before distortion
Range: -0.2 to 0.2
Affects harmonic balance
Examples
- Basic DSP Usage:
>>> # Create a cubic distortion >>> dist = CubicDist(sample_rate=44100) >>> # Process with moderate drive >>> output = dist(input_audio, dsp_params={ ... 'drive_db': 12.0, # 12dB of drive ... 'mix': 0.7 # 70% wet signal ... })
- Advanced Usage (shaping_mode=True):
>>> # Create with waveshaping controls >>> dist = CubicDist(sample_rate=44100, shaping_mode=True) >>> # Process with detailed control >>> output = dist(input_audio, dsp_params={ ... 'drive_db': 18.0, # Heavy distortion ... 'pre_gain_db': 6.0, # Additional input drive ... 'post_gain_db': -12.0, # Output compensation ... 'dc_bias': 0.05, # Slight asymmetry ... 'mix': 0.8 # 80% wet ... })
A distortion effect based on a cubic polynomial transfer function. Creates asymmetric clipping characteristics that add even and odd harmonics to the signal. Provides a distinctive sound quality useful for bass and guitar processing.
- _add_specific_parameters()[source]
Register additional parameters specific to cubic distortion.
- Adds:
drive_db: Distortion intensity (-24.0 to 24.0 dB)
- _apply_distortion(x, params)[source]
Apply cubic distortion to the input signal.
- Parameters:
x (torch.Tensor) – Input audio tensor. Shape: (batch, channels, samples)
params (dict) – Must contain: - drive_db: Distortion intensity in dB
- Returns:
Distorted audio tensor of same shape as input
- Return type:
Note
Drive is converted from dB to linear scaling before application
RectifierDist
- class diffFx_pytorch.processors.distortion.RectifierDist(*args: Any, **kwargs: Any)[source]
Bases:
BaseDistortionDifferentiable implementation of rectifier distortion.
This processor implements half-wave and full-wave rectification with variable threshold, allowing smooth interpolation between rectification modes. The effect is similar to diode clipping circuits, creating characteristic asymmetric distortion with rich harmonic content.
The transfer function interpolates between:
Half-wave (mode = 0):
\[\begin{split}y = \begin{cases} x & x > threshold \\ 0 & |x| ≤ threshold \\ 0 & x < -threshold \end{cases}\end{split}\]Full-wave (mode = 1):
\[\begin{split}y = \begin{cases} |x| & |x| > threshold \\ 0 & |x| ≤ threshold \end{cases}\end{split}\]- Parameters:
- Parameters Details:
- Basic Mode (shaping_mode=False):
- mode: Rectification type
Range: 0.0 to 1.0
0.0: Half-wave rectification
1.0: Full-wave rectification
Intermediate values blend between modes
- threshold: Signal threshold for rectification
Range: 0.0 to 1.0
Signals below threshold are set to zero
Higher values create gating effects
- mix: Wet/dry mix ratio
Range: 0.0 to 1.0
0.0: Only clean signal
1.0: Only rectified signal
- Shaping Mode (shaping_mode=True):
- pre_gain_db: Input gain before rectification
Range: -24.0 to 24.0 dB
Controls amount of signal above threshold
- post_gain_db: Output gain after rectification
Range: -24.0 to 0.0 dB
Compensates for level changes
- dc_bias: DC offset before rectification
Range: -0.2 to 0.2
Affects rectification symmetry
Note: - Half-wave creates strong asymmetric distortion - Full-wave doubles frequency content - Threshold creates gating effects - Useful for extreme timbral modification - Can generate octave-up effects (full-wave)
Examples
- Basic DSP Usage:
>>> # Create a rectifier distortion >>> dist = RectifierDist(sample_rate=44100) >>> # Process with half-wave rectification >>> output = dist(input_audio, dsp_params={ ... 'mode': 0.0, # Half-wave mode ... 'threshold': 0.2, # Low threshold ... 'mix': 0.6 # 60% wet signal ... })
- Advanced Usage (shaping_mode=True):
>>> # Create with waveshaping controls >>> dist = RectifierDist(sample_rate=44100, shaping_mode=True) >>> # Process with detailed control >>> output = dist(input_audio, dsp_params={ ... 'mode': 0.7, # Blend of half/full wave ... 'threshold': 0.3, # Moderate threshold ... 'pre_gain_db': 12.0, # Drive into rectification ... 'post_gain_db': -6.0, # Compensate output ... 'dc_bias': 0.1, # Add asymmetry ... 'mix': 0.8 # 80% wet ... })
A distortion effect that implements half or full-wave rectification, similar to diode clipping circuits. Creates characteristic asymmetric distortion with rich harmonic content, particularly useful for aggressive sound design.
- _add_specific_parameters()[source]
Register additional parameters specific to rectifier distortion.
- Adds:
mode: Rectification type (0.0 to 1.0) threshold: Signal threshold (0.0 to 1.0)
- _apply_distortion(x, params)[source]
Apply rectification distortion to the input signal.
- Parameters:
x (torch.Tensor) – Input audio tensor. Shape: (batch, channels, samples)
params (dict) – Must contain: - mode: Rectification type (0: half-wave, 1: full-wave) - threshold: Signal threshold for rectification
- Returns:
Rectified audio tensor of same shape as input
- Return type:
Note
Interpolates smoothly between half-wave and full-wave rectification using the mode parameter.
BitCrusher
- class diffFx_pytorch.processors.distortion.BitCrusher(sample_rate, param_range=None)[source]
Bases:
ProcessorsBaseDifferentiable implementation of a bit depth reduction effect.
This processor implements bit crushing by reducing the number of available amplitude levels in the signal, creating characteristic digital distortion and quantization effects. The implementation uses rounding to integer steps determined by the bit depth.
The bit reduction process follows:
\[y = round(x * 2^{bits}) / 2^{bits}\]- where:
x is the input signal (assumed to be in [-1, 1] range)
bits is the target bit depth
round() quantizes to nearest integer step
- Parameters:
sample_rate (int) – Audio sample rate in Hz
- Parameters Details:
- bit_depth:
Range: 1.0 to 32.0 bits
Lower values create more extreme effects
Higher values preserve more detail
Examples
- Basic DSP Usage:
>>> # Create a bit crusher >>> crusher = BitCrusher(sample_rate=44100) >>> # Process with moderate bit reduction >>> output = crusher(input_audio, dsp_params={ ... 'bit_depth': 8.0 # 8-bit quality ... })
- Neural Network Control:
>>> # Create a simple bit depth controller >>> class BitCrushController(nn.Module): ... def __init__(self, input_size): ... super().__init__() ... self.net = nn.Sequential( ... nn.Linear(input_size, 32), ... nn.ReLU(), ... nn.Linear(32, 1), ... nn.Sigmoid() # Ensures output is in [0,1] range ... ) ... ... def forward(self, x): ... return self.net(x) >>> >>> # Process with predicted bit depth >>> controller = BitCrushController(input_size=16) >>> bit_depth = controller(features) >>> output = crusher(input_audio, norm_params={'bit_depth': bit_depth})
- Parameters:
param_range (
Optional[Dict[str,EffectParam]]) –
A digital distortion effect that reduces the bit depth and sample rate of the input signal, creating characteristic “lo-fi” artifacts. Features controls for bit depth reduction and sample rate decimation, enabling various retro digital effects.
- __init__(sample_rate, param_range=None)[source]
Initialize the processor base.
- Parameters:
sample_rate – Audio sample rate in Hz
param_range (
Optional[Dict[str,EffectParam]]) – Optional parameter definitions to override defaults
- _register_default_parameters()[source]
Register bit depth parameter.
- Sets up:
bit_depth: Target bit depth (1.0 to 32.0)
- _bit_crush(x, bit_depth)[source]
Apply bit depth reduction to the input signal.
- Parameters:
x (torch.Tensor) – Input audio tensor. Shape: (batch, channels, samples)
bit_depth (torch.Tensor) – Target bit depth. Shape: (batch,)
- Returns:
Bit-crushed audio tensor of same shape as input
- Return type:
- process(x, norm_params=None, dsp_params=None)[source]
Process input signal through the bit crusher.
- Parameters:
x (torch.Tensor) – Input audio tensor. Shape: (batch, channels, samples)
norm_params (Dict[str, torch.Tensor]) –
Normalized parameters (0 to 1) Must contain:
bit_depth: Target bit depth (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 bit depth 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:
Bit-crushed audio tensor of same shape as input
- Return type:
ExponentialDist
- class diffFx_pytorch.processors.distortion.ExponentialDist(*args: Any, **kwargs: Any)[source]
Bases:
BaseDistortionDifferentiable implementation of exponential distortion with asymmetry control.
This processor implements distortion using exponential curves, featuring independent control over positive and negative regions. It creates dynamic saturation characteristics with natural compression and adjustable asymmetry for rich harmonic content.
The transfer function is:
\[y = sign(x) * (1 - e^{-|x| * drive * A(x)})\]- where:
x is the input signal
drive controls overall distortion intensity
- A(x) is the asymmetry function:
A(x) = 1 for x ≥ 0
A(x) = asymmetry for x < 0
- Parameters:
- Parameters Details:
- Basic Mode (shaping_mode=False):
- drive: Distortion intensity
Range: 0.1 to 10.0
Controls steepness of exponential curve
Higher values create more saturation
Affects both positive and negative regions
- asymmetry: Positive/negative balance
Range: 0.1 to 2.0
1.0: Symmetric distortion
<1.0: More negative distortion
>1.0: More positive distortion
- mix: Wet/dry mix ratio
Range: 0.0 to 1.0
0.0: Only clean signal
1.0: Only distorted signal
- Shaping Mode (shaping_mode=True):
- pre_gain_db: Input gain before distortion
Range: -24.0 to 24.0 dB
Controls signal level into exponential curve
- post_gain_db: Output gain after distortion
Range: -24.0 to 0.0 dB
Compensates for level changes
- dc_bias: DC offset before distortion
Range: -0.2 to 0.2
Affects harmonic balance
Examples
- Basic DSP Usage:
>>> # Create an exponential distortion >>> dist = ExponentialDist(sample_rate=44100) >>> # Process with asymmetric settings >>> output = dist(input_audio, dsp_params={ ... 'drive': 3.0, # Moderate drive ... 'asymmetry': 1.5, # More positive distortion ... 'mix': 0.7 # 70% wet signal ... })
- Advanced Usage (shaping_mode=True):
>>> # Create with waveshaping controls >>> dist = ExponentialDist(sample_rate=44100, shaping_mode=True) >>> # Process with detailed control >>> output = dist(input_audio, dsp_params={ ... 'drive': 5.0, # Strong drive ... 'asymmetry': 0.8, # More negative distortion ... 'pre_gain_db': 6.0, # Additional input drive ... 'post_gain_db': -6.0, # Output attenuation ... 'dc_bias': 0.1, # Slight positive offset ... 'mix': 0.8 # 80% wet ... })
A distortion effect using exponential transfer functions to create extreme saturation characteristics. Provides unique timbral shaping with aggressive harmonic generation, suitable for special effects and sound design.
- _add_specific_parameters()[source]
Register additional parameters specific to exponential distortion.
- Adds:
drive: Distortion intensity (0.1 to 10.0) asymmetry: Positive/negative balance (0.1 to 2.0)
- _apply_distortion(x, params)[source]
Apply exponential distortion to the input signal.
- Parameters:
x (torch.Tensor) – Input audio tensor. Shape: (batch, channels, samples)
params (dict) – Must contain: - drive: Distortion intensity - asymmetry: Positive/negative balance
- Returns:
Distorted audio tensor of same shape as input
- Return type:
Note
Processes positive and negative regions independently using the asymmetry parameter to control their relative intensity.
ArcTanDist
- class diffFx_pytorch.processors.distortion.ArcTanDist(*args: Any, **kwargs: Any)[source]
Bases:
BaseDistortionDifferentiable implementation of arctangent distortion.
This processor implements smooth distortion using the arctangent function for waveshaping. Similar to tanh distortion but with slightly different harmonic characteristics, providing musical saturation with natural compression and rich overtones.
The transfer function is:
\[y = \frac{2}{\pi} \arctan(x * drive)\]where: - x is the input signal - drive controls distortion intensity - 2/π factor normalizes output to [-1, 1] range
- Parameters:
- Parameters Details:
- Basic Mode (shaping_mode=False):
- drive: Distortion intensity
Range: 0.1 to 10.0
Controls slope of arctangent curve
Higher values create more saturation
Lower values provide subtle warming
- mix: Wet/dry mix ratio
Range: 0.0 to 1.0
0.0: Only clean signal
1.0: Only distorted signal
- Shaping Mode (shaping_mode=True):
- pre_gain_db: Input gain before distortion
Range: -24.0 to 24.0 dB
Controls signal level into arctangent
- post_gain_db: Output gain after distortion
Range: -24.0 to 0.0 dB
Compensates for level changes
- dc_bias: DC offset before distortion
Range: -0.2 to 0.2
Affects harmonic content
Examples
- Basic DSP Usage:
>>> # Create an arctangent distortion >>> dist = ArcTanDist(sample_rate=44100) >>> # Process with moderate drive >>> output = dist(input_audio, dsp_params={ ... 'drive': 4.0, # Moderate saturation ... 'mix': 0.7 # 70% wet signal ... })
- Advanced Usage (shaping_mode=True):
>>> # Create with waveshaping controls >>> dist = ArcTanDist(sample_rate=44100, shaping_mode=True) >>> # Process with detailed control >>> output = dist(input_audio, dsp_params={ ... 'drive': 6.0, # Strong saturation ... 'pre_gain_db': 6.0, # Additional drive ... 'post_gain_db': -3.0, # Slight attenuation ... 'dc_bias': 0.05, # Slight asymmetry ... 'mix': 0.8 # 80% wet ... })
A smooth distortion effect using the arctangent function for waveshaping. Similar to tanh distortion but with slightly different harmonic characteristics. Provides musical saturation with natural compression and harmonically rich overtones.
- _add_specific_parameters()[source]
Register additional parameters specific to arctangent distortion.
- Adds:
drive: Distortion intensity (0.1 to 10.0)
- _apply_distortion(x, params)[source]
Apply arctangent distortion to the input signal.
- Parameters:
x (torch.Tensor) – Input audio tensor. Shape: (batch, channels, samples)
params (dict) – Must contain: - drive: Distortion intensity
- Returns:
Distorted audio tensor of same shape as input
- Return type:
Note
Output is automatically normalized to [-1, 1] range using the (2/π) scaling factor.