ASPiK SDK
VSTGUI::SpectrumView Class Reference

This object displays the FFT of the incoming data.
. More...

#include <customviews.h>

Inheritance diagram for VSTGUI::SpectrumView:
ICustomView

Public Member Functions

 SpectrumView (const CRect &size, IControlListener *listener, int32_t tag)
 SpectrumView constructor. More...
 
virtual void updateView () override
 
virtual void pushDataValue (double data) override
 
void showFilledFFT (bool _filledFFT)
 
void setWindow (spectrumViewWindowType _window)
 
void draw (CDrawContext *pContext) override
 
- Public Member Functions inherited from ICustomView
virtual void sendMessage (void *data)
 

Protected Member Functions

bool addFFTInputData (double inputSample)
 
double getMagnitude (double re, double im)
 
double normalizeBufferGetFMax (double *buffer, unsigned int bufferSize, int *ptrMaxIndex)
 
double interpArrayValue (double *array, int arraySize, double fractionalIndex)
 

Protected Attributes

spectrumViewWindowType window = spectrumViewWindowType::kRectWindow
 window type
 
fftw_complex * data = nullptr
 fft input data
 
fftw_complex * fft_result = nullptr
 fft output data
 
fftw_complex * ifft_result = nullptr
 ifft output (not used)
 
fftw_plan plan_forward
 plan for FFT
 
fftw_plan plan_backward
 plan for IFFT (not used)
 
int fftInputCounter = 0
 input counter for FFT
 
double fftMagnitudeArray_A [FFT_LEN] = {0.0}
 1/2 of double buffer (yes this is overkill but showing as demonstration!!)
 
double fftMagnitudeArray_B [FFT_LEN] = {0.0}
 1/2 of double buffer (yes this is overkill but showing as demonstration!!)
 
double fftWindow [FFT_LEN] = {1.0}
 window buffer
 
double * currentFFTMagBuffer = nullptr
 poitner to current FFT buffer
 
bool filledFFT = true
 flag for filled FFT
 

Detailed Description

This object displays the FFT of the incoming data.
.

SpectrumView:

  • uses a lock-free ring buffer for queueing up input data from the plugin
  • implements ICustomView::pushDataValue() and ICustomView::updateData()
  • uses a pair of lock-free ring buffers to implement a safe double-buffering system
  • during updates, the queue is dumped into the FFT array
  • when a new FFT is processed, its magnitude array is calculated in the first available buffer in the empty queue; it is then placed in the filled (ready) queue
  • the draw() function is on the same thread with the PluginKernel/PluginGUI paradigm\ but just in case it ISN'T, the drawing uses the double buffer to safely get the next available magnitude array to display
  • the result is a super fast visually synchronized display
Author
Will Pirkle http://www.willpirkle.com
Remarks
This object is included in Designing Audio Effects Plugins in C++ 2nd Ed. by Will Pirkle
Version
Revision : 1.0
Date
Date : 2018 / 09 / 7

Constructor & Destructor Documentation

◆ SpectrumView()

VSTGUI::SpectrumView::SpectrumView ( const CRect &  size,
IControlListener *  listener,
int32_t  tag 
)

SpectrumView constructor.

Parameters
size- the control rectangle
listener- the control's listener (usuall PluginGUI object)
tag- the control ID value

Member Function Documentation

◆ addFFTInputData()

bool VSTGUI::SpectrumView::addFFTInputData ( double  inputSample)
protected

returns true if the input buffer is full and ready for a FFT operation
will keep track of indexing and reject samples when full

Parameters
inputSampleinput point for FFT

◆ draw()

void VSTGUI::SpectrumView::draw ( CDrawContext *  pContext)
override

override to draw, called if the view should draw itself

◆ interpArrayValue()

double VSTGUI::SpectrumView::interpArrayValue ( double *  array,
int  arraySize,
double  fractionalIndex 
)
inlineprotected

interpolate a value from an array

Parameters
array- pointer to array to interpolate
arraySize- length of array
fractionalIndex- fractional location of value in array (e.g. 3.446 is 0.446 between 3 and 4)

◆ normalizeBufferGetFMax()

double VSTGUI::SpectrumView::normalizeBufferGetFMax ( double *  buffer,
unsigned int  bufferSize,
int *  ptrMaxIndex 
)
inlineprotected

normalize a buffer and find the index of the maximum value at the same time

Parameters
buffer- pointer to buffer to normalize
bufferSize- length of buffer
ptrMaxIndex- return value passed by pointer of INDEX of max value in buffer

◆ pushDataValue()

void VSTGUI::SpectrumView::pushDataValue ( double  data)
overridevirtual

ICustomView method: push a new audio sample into the ring buffer

Reimplemented from ICustomView.

◆ setWindow()

void VSTGUI::SpectrumView::setWindow ( spectrumViewWindowType  _window)

set the window

Parameters
_windowthe window type (seee windowType)

◆ showFilledFFT()

void VSTGUI::SpectrumView::showFilledFFT ( bool  _filledFFT)
inline

show FFT as filled (or unfilled) plot

◆ updateView()

void VSTGUI::SpectrumView::updateView ( )
overridevirtual

ICustomView method: this repaints the control

Implements ICustomView.


The documentation for this class was generated from the following files: