Table of Contents

Class PeakValue

Namespace
PluginUI.Dsp
Assembly
PluginUI.dll

Thread-safe single value published by the audio thread and read by the UI (meters, LEDs, gain reduction). Stores the maximum since the last read so short peaks are never missed.

public sealed class PeakValue
Inheritance
PeakValue
Inherited Members

Examples

The processor publishes one peak per block and channel; the editor gives the values to a meter:

// Shared by the processor and the editor (e.g. through PluginUIProcessor.CreateSharedState).
public sealed class Meters
{
    public PeakValue[] Output { get; } = [new PeakValue(), new PeakValue()];
}

// Audio thread, at the end of ProcessMain: lock-free, no allocation.
meters.Output[0].PushBlockPeak(left[..sampleCount]);
meters.Output[1].PushBlockPeak(right[..sampleCount]);

// Editor: the meter reads (and resets) the values at each frame.
var meter = new LevelMeter { Sources = meters.Output };

Remarks

Magnitudes only (values ≥ 0, e.g. linear peak, RMS, gain reduction in positive dB): the value resets to 0 on each read. A PeakValue has a single reader: give each meter its own instance.

Methods

Push(float)

Audio thread: records a value (keeps the maximum until ReadAndReset()).

public void Push(float value)

Parameters

value float

PushBlockPeak(ReadOnlySpan<float>)

Audio thread: computes (vectorized) and records the absolute peak of a block.

public void PushBlockPeak(ReadOnlySpan<float> samples)

Parameters

samples ReadOnlySpan<float>

ReadAndReset()

UI thread: returns the maximum since the previous call and resets it to 0.

public float ReadAndReset()

Returns

float