Vixen
02b45cc4
csharp
public sealed class CompressorEffect

Turns a bus down when it — or another bus — gets loud.

No guide page documents this yet — the page shows what the code says about itself.

Remarks

The reason this exists is ducking. Music that stays at its mixed level under dialogue makes the dialogue unintelligible, and turning the music down by hand from gameplay code means every system that can produce speech knowing about the music bus. Point this at the dialogue bus with AudioBus.SetSidechain instead and the music gets out of the way whenever anybody speaks, in proportion to how loudly they do.

Without a key it is an ordinary compressor, which is the other half of what a bus wants: a footstep bus with forty overlapping sources has a peak that wanders by 20 dB, and compressing it is how it sits at one level in the mix.

Feed-forward, and the gain computer works in decibels. That is the arrangement every software compressor uses: measure the input, decide a gain in dB, smooth it, apply it. A feedback design — measuring the output — is what analogue circuits did because they had to, and it makes the ratio depend on the signal.

One gain for every channel. Compressing channels independently pulls a stereo image apart: a loud transient on the left turns the left down and the sound walks to the right. The detector takes the loudest channel and every channel is scaled by the same number.

Fields and properties (9)

  • public float ThresholdDb

    Above this level, in decibels, the compressor starts working. 0 dB is full scale.

  • public float Ratio

    How much is taken off above the threshold. 4 means 4 dB in becomes 1 dB out.

  • public float KneeDb

    How wide the bend into the ratio is, in decibels.

  • public float AttackSeconds

    How fast it reacts to something getting louder.

  • public float ReleaseSeconds

    How fast it recovers when the signal drops.

  • public float MakeupDb

    A gain applied after compression, in decibels, to put the level back where it was.

  • public bool Enabled

    Whether it does anything. A bypassed effect costs one branch a block.

  • public float GainReductionDb

    How much the compressor is currently taking off, in decibels. Never positive.

  • public IReadOnlyList<string> Properties

    The knobs this effect will answer to, by name.

Methods (6)

  • public void Prepare(in AudioFormat format, int maxFrames)

    Sizes and clears every buffer the effect needs.

  • public void Process(Span<float> buffer, int frameCount, int channels)
  • public void Process(Span<float> buffer, ReadOnlySpan<float> key, int frameCount, int channels)

    Processes a block against a key signal.

  • public void Reset()

    Throws away everything the effect remembers about what came before.

  • public bool TrySetProperty(string name, float value)

    Sets one of the effect's knobs by name, for automation.

  • public bool TryGetProperty(string name, out float value)

    Reads one of the effect's knobs by name.

Used by (6)

  • AudioRoutingTestsVixen.Audio.Tests
  • CompressorEffectAssetVixen.Audio
  • DynamicsTestsVixen.Audio.Tests
  • MixControlTestsVixen.Audio.Tests
  • MixerAssetTestsVixen.Audio.Tests
  • MixerParameterTestsVixen.Audio.Tests