AudioEffectDistortion
Adds a distortion audio effect to an audio bus. Remaps audio samples using a nonlinear function to achieve a distorted sound.
Adds a distortion audio effect to an audio bus. Remaps audio samples using a nonlinear function to achieve a distorted sound.
A "distortion" effect modifies the waveform via a nonlinear mathematical function (see available ones in AudioEffectDistortion.ModeEnum), 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 AudioEffectDistortion.Drive, the output sound will vary depending on the input's volume. To change the volume while maintaining the output waveform, use AudioEffectDistortion.PostGain.
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 AudioEffectDistortion.Drive is set to 0. This is not a bug. If this behavior is undesirable, consider disabling the effect using AudioServer.SetBusEffectEnabled.
Declarations checked against C# SDK 1.0.0. Expand a name to see declarations and documentation.
Constructors1
AudioEffectDistortionConstructor
public AudioEffectDistortion();Properties5
DriveProperty
public float Drive { get; set; }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.
KeepHfHzProperty
public float KeepHfHz { get; set; }High-pass filter, in Hz. Frequencies higher than this value will not be affected by the distortion. Value can range from 1 to 20000.
ModeProperty
public AudioEffectDistortion.ModeEnum Mode { get; set; }Distortion type. Changes the nonlinear function used to distort the waveform. See AudioEffectDistortion.ModeEnum.
PostGainProperty
public float PostGain { get; set; }Gain after the effect, in dB. Value can range from -80 to 24.
PreGainProperty
public float PreGain { get; set; }Gain before the effect, in dB. Value can range from -60 to 60.
Methods10
GetDrivefloat
public float GetDrive();floatGetKeepHfHzfloat
public float GetKeepHfHz();floatGetModeAudioEffectDistortion.ModeEnum
public AudioEffectDistortion.ModeEnum GetMode();AudioEffectDistortion.ModeEnumGetPostGainfloat
public float GetPostGain();floatGetPreGainfloat
public float GetPreGain();floatSetDrivevoid
public void SetDrive(float drive);| Name | Type | Default |
|---|---|---|
drive | float | — |
SetKeepHfHzvoid
public void SetKeepHfHz(float keepHfHz);| Name | Type | Default |
|---|---|---|
keepHfHz | float | — |
SetModevoid
public void SetMode(AudioEffectDistortion.ModeEnum mode);| Name | Type | Default |
|---|---|---|
mode | AudioEffectDistortion.ModeEnum | — |
SetPostGainvoid
public void SetPostGain(float postGain);| Name | Type | Default |
|---|---|---|
postGain | float | — |
SetPreGainvoid
public void SetPreGain(float preGain);| Name | Type | Default |
|---|---|---|
preGain | float | — |
AudioEffectDistortion.ModeEnum
| Value | Description |
|---|---|
Atan = 1 | Flattens the waveform in a smooth manner, following an arctangent curve. The audio decreases in volume, before flattening peaks to |
Clip = 0 | Flattens the waveform at 0 dB in a sharp manner. |
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. |
Overdrive = 3 | Emulates the warm distortion produced by a field effect transistor, which is commonly used in solid-state musical instrument amplifiers. |
Waveshape = 4 | Flattens the waveform in a smooth manner, until it reaches a sharp peak at |