Table of Contents

Class FrequencyResponseView

Namespace
PluginUI
Assembly
PluginUI.dll

Frequency-response display: any number of curves on a logarithmic or linear frequency axis, a fixed left axis (magnitude) and an auto-scaled right axis (phase, phase delay, group delay…), an optional analyzed input spectrum and the same spectrum shaped by a response without a second FFT, and draggable nodes.

public class FrequencyResponseView : Control
Inheritance
FrequencyResponseView
Inherited Members

Examples

var view = new FrequencyResponseView { SampleRate = 48000, SpectrumSource = shared.Input };
// Curves: any function of the frequency in Hz (here the magnitude in dB of the plug-in's own filter).
view.Curves.Add(new ResponseCurve("Band 1", Color.FromRgb(0xFF7043), f => band1.MagnitudeDb(f)));
view.Curves.Add(new ResponseCurve("Phase", Color.FromRgb(0xFFB300), f => cascade.Phase(f), ResponseAxis.Right));
view.RightAxisTicks = RightAxisTicks.PiMultiples;
view.SpectrumFilter = f => cascade.MagnitudeDb(f);   // output spectrum without a second FFT
// A gain node, and a band node defined by its two edges.
view.Nodes.Add(new ResponseNode { FrequencyParameter = Parameters[model.Freq], ValueParameter = Parameters[model.Gain], IsValueEditable = true, WheelParameter = Parameters[model.Q] });
view.Nodes.Add(new ResponseNode { UsesBandEdges = true, LowFrequencyParameter = Parameters[model.Low], HighFrequencyParameter = Parameters[model.High] });
view.ContentVersion = () => model.Shape.NormalizedValue;   // repaint when a design parameter changes

Remarks

Curves. The element does no filter design: each ResponseCurve supplies its values, so the display is exact for any filter the consumer can evaluate.

Spectrum. SpectrumSource is read sequentially (the view is its only reader); a Hann-windowed FFT of FftSize points runs every FftSize/2 new samples (50 % overlap) and each bin is smoothed with an instant attack and an exponential release (SpectrumReleaseSeconds). A full-scale sine reads 0 dB. The filtered spectrum adds SpectrumFilter (dB at a frequency) to every bin of the smoothed input spectrum: the output spectrum of a linear filter, obtained from the input FFT alone.

Mouse. Drag a node to change its frequency (and its value when editable; Shift = fine), drag a band-edge handle to move one edge, turn the wheel over a node to change its band ratio or step its WheelParameter. Drags send complete edit gestures, all parameters of the node in parallel.

Constructors

FrequencyResponseView()

Creates a frequency-response view.

public FrequencyResponseView()

Properties

AxisMaxFrequency

Highest displayed frequency in Hz.

public double AxisMaxFrequency { get; }

Property Value

double

AxisMinFrequency

Lowest displayed frequency in Hz.

public double AxisMinFrequency { get; }

Property Value

double

ContentVersion

Returns a value that changes whenever the curves change for a reason the view cannot see (a design parameter not bound to a node); polled every frame, the view repaints when it changes. Node parameters are tracked already.

[Browsable(false)]
public Func<double>? ContentVersion { get; set; }

Property Value

Func<double>

Curves

The curves, drawn in list order (later curves on top).

[Browsable(false)]
public IList<ResponseCurve> Curves { get; }

Property Value

IList<ResponseCurve>

DecibelConvention

Decibel convention of the spectrum (the curves are drawn as supplied).

public DecibelConvention DecibelConvention { get; set; }

Property Value

DecibelConvention

DefaultSize

Natural size used when no explicit size is given.

protected override Size DefaultSize { get; }

Property Value

Size

FftSize

FFT size of the analyzer (power of two, 64 to 32768).

public int FftSize { get; set; }

Property Value

int

FilteredSpectrumColor

Filtered spectrum color.

public Color FilteredSpectrumColor { get; set; }

Property Value

Color

FrequencyScale

Frequency axis.

public FrequencyScale FrequencyScale { get; set; }

Property Value

FrequencyScale

InputSpectrumColor

Input spectrum color.

public Color InputSpectrumColor { get; set; }

Property Value

Color

LeftMax

Top of the left axis.

public double LeftMax { get; set; }

Property Value

double

LeftMin

Bottom of the left axis.

public double LeftMin { get; set; }

Property Value

double

LeftStep

Grid step of the left axis.

public double LeftStep { get; set; }

Property Value

double

LeftUnit

Unit appended to the left-axis labels.

public string LeftUnit { get; set; }

Property Value

string

MaxBandRatio

Largest ratio between the band edges of a node.

public double MaxBandRatio { get; set; }

Property Value

double

MaxFrequency

Highest frequency of the logarithmic axis, in Hz (limited to the Nyquist frequency).

public double MaxFrequency { get; set; }

Property Value

double

MinBandRatio

Smallest ratio between the band edges of a node.

public double MinBandRatio { get; set; }

Property Value

double

MinFrequency

Lowest frequency of the logarithmic axis, in Hz.

public double MinFrequency { get; set; }

Property Value

double

Nodes

The draggable nodes.

[Browsable(false)]
public IList<ResponseNode> Nodes { get; }

Property Value

IList<ResponseNode>

RightAxisColor

Color of the right-axis labels (null = the color of the first visible right-axis curve).

public Color? RightAxisColor { get; set; }

Property Value

Color?

RightAxisTicks

Tick labelling of the right axis.

public RightAxisTicks RightAxisTicks { get; set; }

Property Value

RightAxisTicks

RightUnit

Unit shown at the top of the right axis.

public string RightUnit { get; set; }

Property Value

string

SampleRate

Sample rate in Hz (Nyquist limit of the linear axis, bin spacing of the spectrum).

public double SampleRate { get; set; }

Property Value

double

SelectedIndex

Selected node index (−1 = none).

[Browsable(false)]
public int SelectedIndex { get; set; }

Property Value

int

ShowFilteredSpectrum

Draws the input spectrum shaped by SpectrumFilter.

public bool ShowFilteredSpectrum { get; set; }

Property Value

bool

ShowInputSpectrum

Draws the analyzed input spectrum.

public bool ShowInputSpectrum { get; set; }

Property Value

bool

SpectrumFilter

Gain in dB applied to the input spectrum at a frequency to obtain the filtered spectrum, or null.

[Browsable(false)]
public Func<double, double>? SpectrumFilter { get; set; }

Property Value

Func<double, double>

SpectrumFrameCount

Number of FFT frames analyzed so far (diagnostics and tests).

[Browsable(false)]
public long SpectrumFrameCount { get; }

Property Value

long

SpectrumMaxDb

Spectrum level at the top of the plot.

public double SpectrumMaxDb { get; set; }

Property Value

double

SpectrumMinDb

Spectrum level at the bottom of the plot.

public double SpectrumMinDb { get; set; }

Property Value

double

SpectrumReleaseSeconds

Release time constant of the spectrum smoothing, in seconds (0 = none).

public double SpectrumReleaseSeconds { get; set; }

Property Value

double

SpectrumSource

Audio analyzed for the spectra, or null. The view reads it sequentially (single reader).

[Browsable(false)]
public AudioRingBuffer? SpectrumSource { get; set; }

Property Value

AudioRingBuffer

Methods

AnalyzeSpectrum()

Reads the new samples of SpectrumSource and runs one FFT per half frame. Called every frame by the view; exposed for tests and for hosts that drive the view without a ticker.

public void AnalyzeSpectrum()

FormatHz(double)

Formats a frequency for an axis label ("50", "1.5k", "20k").

public static string FormatHz(double hz)

Parameters

hz double

Frequency in Hz.

Returns

string

The label.

FrequencyTicks(double, double)

Grid frequencies of the current axis: 1-2-…-9 × 10ⁿ (log) or round steps (linear).

public IEnumerable<double> FrequencyTicks(double lo, double hi)

Parameters

lo double

Lowest frequency.

hi double

Highest frequency.

Returns

IEnumerable<double>

The tick frequencies in Hz.

FrequencyToX(double, Rect)

X coordinate of a frequency in a plot area.

public float FrequencyToX(double hz, Rect area)

Parameters

hz double

Frequency in Hz.

area Rect

Plot area.

Returns

float

The x coordinate.

OnAttached()

Called when the element joins a host (subscribe to external events here).

protected override void OnAttached()

OnCaptureLost()

The mouse capture was lost without a button release.

protected override void OnCaptureLost()

OnDetached()

Called when the element leaves its host (unsubscribe here).

protected override void OnDetached()

OnMouseDown(MouseEventArgs)

Mouse button pressed over the element (or captured).

protected override void OnMouseDown(MouseEventArgs e)

Parameters

e MouseEventArgs

OnMouseLeave()

The mouse left the element.

protected override void OnMouseLeave()

OnMouseMove(MouseEventArgs)

Mouse moved over the element (or captured).

protected override void OnMouseMove(MouseEventArgs e)

Parameters

e MouseEventArgs

OnMouseUp(MouseEventArgs)

Mouse button released.

protected override void OnMouseUp(MouseEventArgs e)

Parameters

e MouseEventArgs

OnMouseWheel(MouseEventArgs)

Mouse wheel over the element.

protected override void OnMouseWheel(MouseEventArgs e)

Parameters

e MouseEventArgs

PlotArea(Rect)

Plot area inside the element bounds (room for the frequency labels below).

public static Rect PlotArea(Rect widget)

Parameters

widget Rect

Element bounds.

Returns

Rect

The plot rectangle.

RenderVector(DrawingContext, Rect, VectorStyle)

Vector rendering of the widget area.

protected override void RenderVector(DrawingContext dc, Rect widget, VectorStyle style)

Parameters

dc DrawingContext
widget Rect
style VectorStyle

SpectrumLevel(double)

Smoothed input spectrum level (dB) at a frequency, interpolated between bins; NaN before the first frame.

public double SpectrumLevel(double hz)

Parameters

hz double

Frequency in Hz.

Returns

double

The level in dB.

XToFrequency(float, Rect)

Frequency at an x coordinate of a plot area.

public double XToFrequency(float x, Rect area)

Parameters

x float

X coordinate.

area Rect

Plot area.

Returns

double

The frequency in Hz.

Events

NodeChanged

Raised after the user moved a node or changed it with the wheel.

public event Action<FrequencyResponseView, ResponseNode>? NodeChanged

Event Type

Action<FrequencyResponseView, ResponseNode>

NodeDoubleClicked

Raised when a node is double-clicked.

public event Action<FrequencyResponseView, ResponseNode>? NodeDoubleClicked

Event Type

Action<FrequencyResponseView, ResponseNode>

NodeWheel

Raised on a wheel notch over a node (after the built-in handling), with the signed delta.

public event Action<FrequencyResponseView, ResponseNode, float>? NodeWheel

Event Type

Action<FrequencyResponseView, ResponseNode, float>

SelectionChanged

Raised when SelectedIndex changes.

public event Action<FrequencyResponseView>? SelectionChanged

Event Type

Action<FrequencyResponseView>