Class SpectrumAnalyzer
- 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:
- Call Start() to begin spectrum analysis
- Feed FFT results via Update(Complex[] fftResults)
- Call Stop() to pause analysis
- 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, IAddChildInheritance
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:
- Checks if the analyzer is started and applies frame rate limiting
- Adapts to FFT size changes by adjusting bin count and scaling
- Processes frequency bins with point reduction for smoother visualization
- Converts complex FFT data to logarithmic amplitude values
- 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
fftResultsComplex[]-
Complex FFT results array, typically from audio processing pipeline.