Vixen
02b45cc4
csharp
public sealed class SpectrumAnalyzerEffect

Measures what is going through a bus, and changes none of it.

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

Remarks

An effect that is not an effect: it passes the signal through untouched and publishes its spectrum. docs/plan/13 asks the audio overlay for mixer levels, which AudioBus.PeakLevel already answers; this is the other half — which frequencies, which is what turns "the mix is muddy" from an opinion into a picture. It is also what a music visualiser reads.

Windowed, because a transform assumes what it is given repeats forever. A block cut out of a continuous signal almost never joins up with itself, and the discontinuity at the seam smears energy across every bin — a pure tone appears as a tone plus a wide skirt of nothing. A Hann window fades the block in and out so the seam is silent, at the cost of spreading each real peak over about three bins. That trade is the reason every analyser ever written applies a window.

Published through a sequence lock. The audio thread fills the magnitudes and the game thread copies them; neither waits, and a reader that catches a write in progress retries a few times and then keeps last frame's picture. The same mechanism Published<T> uses for a voice's spatial settings, and for the same reason — an array of five hundred floats cannot be written atomically.

The channels are summed before the transform. A spectrum per channel would be two pictures nobody wants to look at, and the interesting question — what is in the mix — is about all of it.

Fields and properties (6)

  • public int Size

    How many samples each picture is taken from.

  • public int BinCount

    How many magnitudes there are — the bins from zero up to Nyquist.

  • public float BinWidthHz

    How many hertz apart the bins are.

  • public float Smoothing

    How much of the previous picture each new one keeps, from 0 to just under 1.

  • public bool Enabled

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

  • public IReadOnlyList<string> Properties

    The knobs this effect will answer to, by name.

Methods (7)

  • public SpectrumAnalyzerEffect(int size = 1024)

    An analyser of a size.

  • public bool TryCopyTo(Span<float> destination)

    Copies the latest magnitudes out, if they can be read cleanly.

  • 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)

    Processes a block in place.

  • 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)

  • MixControlTestsVixen.Audio.Tests
  • MixerAssetTestsVixen.Audio.Tests
  • ResamplerTestsVixen.Audio.Tests
  • ShapingEffectTestsVixen.Audio.Tests
  • SpectrumAnalyzerEffectAssetVixen.Audio
  • SpectrumAnalyzerTestsVixen.Audio.Tests