Table of Contents

Class SpectrumAnalyzer

Namespace
VisioForge.Core.UI.WPF.VolumeMeterPro
Assembly
VisioForge.Core.dll

Real-time audio spectrum analyzer control for WPF applications providing frequency domain visualization.

This control displays audio frequency content as a dynamic spectrum graph, converting FFT (Fast Fourier Transform) results into a visual representation of audio frequency distribution over time. It's designed for professional audio applications, music software, and diagnostic tools requiring frequency analysis.

Key features:

  • Real-time FFT visualization with configurable bin resolution
  • Logarithmic frequency scaling for natural audio perception
  • Automatic scaling and normalization for optimal display
  • Performance optimized for real-time audio processing
  • Customizable appearance with professional styling
  • Frame rate limiting to prevent excessive GPU usage

Technical specifications:

  • Supports 512-bin FFT input (from 1024-point FFT)
  • Logarithmic amplitude scaling with -90dB minimum threshold
  • Point reduction for smoother visual representation
  • Automatic X-axis scaling based on control width
  • Yellow polyline visualization on black background

Performance characteristics:

  • Efficient canvas-based rendering using WPF Polyline
  • Frame rate limiting (every 2nd frame) to reduce CPU usage
  • Minimal memory allocation through point reuse
  • Optimized for continuous real-time operation

Usage pattern:

  1. Call Start() to begin spectrum analysis
  2. Feed FFT results via Update(Complex[] fftResults)
  3. Call Stop() to pause analysis
  4. Call Clear() to reset the display

Thread safety: All methods should be called from the UI thread as this control manipulates WPF visual elements.

public class SpectrumAnalyzer : UserControl, IAnimatable, ISupportInitialize, IFrameworkInputElement, IInputElement, IQueryAmbient, IAddChild

Inheritance

Implements

Inherited Members

Constructors

SpectrumAnalyzer()

Initializes a new instance of the VisioForge.Core.UI.WPF.VolumeMeterPro.SpectrumAnalyzer class.

Sets up the spectrum analyzer with professional appearance and optimal performance settings:

  • Creates a black canvas background for professional audio visualization
  • Initializes a yellow polyline for frequency curve rendering
  • Calculates initial X-axis scaling based on default bin count
  • Registers size change handlers for responsive layout

The control is created in a stopped state and requires Start() to begin processing.

public SpectrumAnalyzer()

Methods

Clear()

Clears the spectrum display by removing all frequency curve points.

This method resets the visualization to a blank state while maintaining the analyzer's started/stopped state. Useful for clearing the display when switching audio sources or resetting the visualization.

Thread safety: Must be called from the UI thread.

public void Clear()

Start()

Starts the spectrum analyzer to begin processing and displaying FFT data.

Once started, the analyzer will process FFT results provided via Update() method and display the frequency spectrum in real-time. The control remains active until Stop() is called.

Thread safety: Must be called from the UI thread.

public void Start()

Stop()

Stops the spectrum analyzer and pauses FFT data processing.

When stopped, the analyzer ignores Update() calls and maintains the last displayed spectrum until Start() is called again. The display is not cleared automatically - use Clear() if needed.

Thread safety: Must be called from the UI thread.

public void Stop()

Update(Complex[])

Updates the spectrum display with new FFT results.

This method processes FFT data and updates the visual representation of the frequency spectrum. It performs the following operations:

  1. Checks if the analyzer is started and applies frame rate limiting
  2. Adapts to FFT size changes by adjusting bin count and scaling
  3. Processes frequency bins with point reduction for smoother visualization
  4. Converts complex FFT data to logarithmic amplitude values
  5. Updates the polyline points for rendering

Performance optimizations:

  • Frame rate limiting (processes every 2nd frame) to reduce CPU usage
  • Point averaging across multiple bins for smoother curves
  • Efficient polyline point management

Thread safety: Must be called from the UI thread.

public void Update(Complex[] fftResults)

Parameters

fftResults Complex[]

Complex FFT results array, typically from audio processing pipeline.