AudioEffectDistortion
Inherits: AudioEffect < Resource < Shared < Object
Adds a distortion audio effect to an audio bus.
Remaps audio samples using a nonlinear function to achieve a distorted sound.
Description
Section titled “Description”A “distortion” effect modifies the waveform via a nonlinear mathematical function (see available ones in Mode), based on the amplitude of the waveform’s samples.
Note: In a nonlinear function, an input sample at x amplitude value, will either have its amplitude increased or decreased to a y value, based on the function value at x, which is why even at the same drive, the output sound will vary depending on the input’s volume. To change the volume while maintaining the output waveform, use post_gain.
In this effect, each type is a different nonlinear function. The different types available are: clip, atan, lofi (bitcrush), overdrive, and waveshape. Every distortion type available here is symmetric: negative amplitude values are affected the same way as positive ones.
Although distortion will always change frequency content, usually by introducing high harmonics, different distortion types offer a range of sound qualities; from “soft” and “warm”, to “crunchy” and “abrasive”.
For games, it can help simulate sound coming from some saturated device or speaker very efficiently. It can also help the audio stand out in a mix, by introducing higher frequencies and increasing the volume.
Note: Although usually imperceptible, an enabled distortion effect still changes the sound even when drive is set to 0. This is not a bug. If this behavior is undesirable, consider disabling the effect using Audio.set_bus_effect_enabled().
Properties
Section titled “Properties”| Type | Name | Default |
|---|---|---|
| float | drive | 0.0 |
| float | keep_hf_hz | 16000.0 |
| AudioEffectDistortion.Mode | mode | 0 |
| float | post_gain | 0.0 |
| float | pre_gain | 0.0 |
Enumerations and constants
Section titled “Enumerations and constants”enum Mode
Section titled “enum Mode”- MODE_CLIP =
0— Flattens the waveform at 0 dB in a sharp manner.driveincreases amplitude of samples exponentially. This mode functions as a hard clipper ifdriveis set to 0, and is the only mode that clips audio signals at 0 dB.
- MODE_ATAN =
1— Flattens the waveform in a smooth manner, following an arctangent curve. The audio decreases in volume, before flattening peaks toPI * 4.0(linear value), if it was normalized beforehand.
- MODE_LOFI =
2— Decreases audio bit depth to achieve a low-resolution audio signal, going from 16-bit to 2-bit. Can be used to emulate the sound of early digital audio devices.
- MODE_OVERDRIVE =
3— Emulates the warm distortion produced by a field effect transistor, which is commonly used in solid-state musical instrument amplifiers.drivehas no effect in this mode.
- MODE_WAVESHAPE =
4— Flattens the waveform in a smooth manner, until it reaches a sharp peak atdrive = 1, following a generic absolute sigmoid function.
Property descriptions
Section titled “Property descriptions”float drive = 0.0
Setter/getter: set_drive(), get_drive()
Distortion intensity. Controls how much of the input audio is affected by the distortion curve by moving from a linear function to a nonlinear one. Value can range from 0 to 1.
keep_hf_hz
Section titled “keep_hf_hz”float keep_hf_hz = 16000.0
Setter/getter: set_keep_hf_hz(), get_keep_hf_hz()
High-pass filter, in Hz. Frequencies higher than this value will not be affected by the distortion. Value can range from 1 to 20000.
AudioEffectDistortion.Mode mode = 0
Setter/getter: set_mode(), get_mode()
Distortion type. Changes the nonlinear function used to distort the waveform. See Mode.
post_gain
Section titled “post_gain”float post_gain = 0.0
Setter/getter: set_post_gain(), get_post_gain()
Gain after the effect, in dB. Value can range from -80 to 24.
pre_gain
Section titled “pre_gain”float pre_gain = 0.0
Setter/getter: set_pre_gain(), get_pre_gain()
Gain before the effect, in dB. Value can range from -60 to 60.