Vital
Loading...
Searching...
No Matches
Spectrogram Class Reference

Renders a frequency-domain representation (spectrogram) using OpenGL. More...

#include <oscilloscope.h>

Inheritance diagram for Spectrogram:
OpenGlLineRenderer OpenGlComponent

Public Member Functions

 Spectrogram ()
 Constructs the Spectrogram with default parameters.
 
virtual ~Spectrogram ()
 Destructor.
 
void drawWaveform (OpenGlWrapper &open_gl, int index)
 Draws the frequency-domain waveform (spectrogram line) for a given channel index.
 
void render (OpenGlWrapper &open_gl, bool animate) override
 Renders the spectrogram for both channels.
 
void setAudioMemory (const vital::StereoMemory *memory)
 Sets the StereoMemory from which audio data is read for the FFT.
 
void paintBackground (Graphics &g) override
 Paints a background using JUCE's Graphics (e.g., frequency lines).
 
void setOversampleAmount (int oversample)
 Sets the oversampling amount used for adjusting frequency scaling.
 
void setMinFrequency (float frequency)
 Sets the minimum frequency displayed in the spectrogram.
 
void setMaxFrequency (float frequency)
 Sets the maximum frequency displayed in the spectrogram.
 
void setMinDb (float db)
 Sets the minimum dB level displayed.
 
void setMaxDb (float db)
 Sets the maximum dB level displayed.
 
void paintBackgroundLines (bool paint)
 Enables or disables painting background frequency lines.
 
- Public Member Functions inherited from OpenGlLineRenderer
 OpenGlLineRenderer (int num_points, bool loop=false)
 Constructs an OpenGlLineRenderer for a given number of points.
 
virtual ~OpenGlLineRenderer ()
 Destructor.
 
virtual void init (OpenGlWrapper &open_gl) override
 Initializes OpenGL resources for rendering the line.
 
virtual void destroy (OpenGlWrapper &open_gl) override
 Destroys OpenGL resources allocated by this line renderer.
 
force_inline void setColor (Colour color)
 Sets the line color.
 
force_inline void setLineWidth (float width)
 Sets the line width in pixels.
 
force_inline void setBoost (float boost)
 Sets a global boost value affecting line thickness.
 
force_inline float boostLeftAt (int index) const
 Gets the left-side boost at a given point index.
 
force_inline float boostRightAt (int index) const
 Gets the right-side boost at a given point index.
 
force_inline float yAt (int index) const
 Gets the y-coordinate of a point at a given index.
 
force_inline float xAt (int index) const
 Gets the x-coordinate of a point at a given index.
 
force_inline void setBoostLeft (int index, float val)
 Sets the left-side boost for a point, marking data as dirty.
 
force_inline void setBoostRight (int index, float val)
 Sets the right-side boost for a point, marking data as dirty.
 
force_inline void setYAt (int index, float val)
 Sets the y-coordinate of a point, marking data as dirty.
 
force_inline void setXAt (int index, float val)
 Sets the x-coordinate of a point, marking data as dirty.
 
void setFillVertices (bool left)
 Sets fill vertices according to the current line and boost data.
 
void setLineVertices (bool left)
 Sets line vertices according to the current line and boost data.
 
force_inline void setFill (bool fill)
 Enables or disables filling below the line.
 
force_inline void setFillColor (Colour fill_color)
 Sets a uniform fill color if only one color is needed.
 
force_inline void setFillColors (Colour fill_color_from, Colour fill_color_to)
 Sets a gradient fill from one color to another.
 
force_inline void setFillCenter (float fill_center)
 Sets the vertical center for the fill area.
 
force_inline void setFit (bool fit)
 Enables fitting the line inside the available area.
 
force_inline void setBoostAmount (float boost_amount)
 Sets the boost amount that affects line thickness.
 
force_inline void setFillBoostAmount (float boost_amount)
 Sets the boost amount that affects fill thickness.
 
force_inline void setIndex (int index)
 Sets an index used for custom behavior (e.g., multiple line sets).
 
void boostLeftRange (float start, float end, int buffer_vertices, float min)
 Boosts left-side range of the line.
 
void boostRightRange (float start, float end, int buffer_vertices, float min)
 Boosts right-side range of the line.
 
void boostRange (float *boosts, float start, float end, int buffer_vertices, float min)
 Boosts a range for the given boost array.
 
void boostRange (vital::poly_float start, vital::poly_float end, int buffer_vertices, vital::poly_float min)
 Boosts left and right arrays using poly_float parameters.
 
void decayBoosts (vital::poly_float mult)
 Decays all boosts by a multiplicative factor, allowing animated damping.
 
void enableBackwardBoost (bool enable)
 Enables backward boost calculation for symmetrical line deformation.
 
force_inline int numPoints () const
 Gets the number of points in the line.
 
force_inline Colour color () const
 Gets the current line color.
 
void drawLines (OpenGlWrapper &open_gl, bool left)
 Draws the line and optional fill using OpenGL.
 
bool anyBoostValue ()
 Checks if any boost value is set.
 
- Public Member Functions inherited from OpenGlComponent
 OpenGlComponent (String name="")
 Constructs an OpenGlComponent.
 
virtual ~OpenGlComponent ()
 Destructor.
 
virtual void resized () override
 Called when the component is resized.
 
virtual void parentHierarchyChanged () override
 Called when the component's parent hierarchy changes.
 
void addRoundedCorners ()
 Adds rounded corners to the component's edges.
 
void addBottomRoundedCorners ()
 Adds rounded corners only at the bottom of the component.
 
void renderCorners (OpenGlWrapper &open_gl, bool animate, Colour color, float rounding)
 Renders the corner shapes using the given color and rounding amount.
 
void renderCorners (OpenGlWrapper &open_gl, bool animate)
 Renders corners with default body color and rounding.
 
void repaintBackground ()
 Requests a repaint of the component's background on the OpenGL layer.
 
Colour getBodyColor () const
 Retrieves the component's body color.
 
void setParent (const SynthSection *parent)
 Sets a pointer to the parent SynthSection for skin value lookups.
 
float findValue (Skin::ValueId value_id)
 Finds a float value from the skin associated with this component's parent.
 
void setSkinValues (const Skin &skin)
 Applies the skin overrides to this component's colors.
 
void setSkinOverride (Skin::SectionOverride skin_override)
 Sets a skin override to control the component's color scheme.
 
force_inline void checkGlError ()
 Checks for and asserts that there are no OpenGL errors.
 
void setBackgroundColor (const Colour &color)
 Sets the background color of the component for painting operations.
 

Static Public Attributes

static constexpr int kResolution = 300
 Number of points in the frequency line.
 
static constexpr float kDecayMult = 0.008f
 Decay multiplier for amplitude smoothing.
 
static constexpr int kBits = 14
 Number of bits, defining the transform size (2^kBits).
 
static constexpr int kAudioSize = 1 << kBits
 Size of audio block for the FFT.
 
static constexpr float kDefaultMaxDb = 0.0f
 Default maximum dB level displayed.
 
static constexpr float kDefaultMinDb = -50.0f
 Default minimum dB level displayed.
 
static constexpr float kDefaultMinFrequency = 9.2f
 Default minimum frequency.
 
static constexpr float kDefaultMaxFrequency = 21000.0f
 Default maximum frequency.
 
static constexpr float kDbSlopePerOctave = 3.0f
 dB slope per octave for visualization.
 
- Static Public Attributes inherited from OpenGlLineRenderer
static constexpr int kLineFloatsPerVertex = 3
 Floats per vertex in the line data (x, y, and potentially others).
 
static constexpr int kFillFloatsPerVertex = 4
 Floats per vertex in the fill data (x, y, and boost value).
 
static constexpr int kLineVerticesPerPoint = 6
 Number of vertices per point in the line representation.
 
static constexpr int kFillVerticesPerPoint = 2
 Number of vertices per point in the fill representation.
 
static constexpr int kLineFloatsPerPoint = kLineVerticesPerPoint * kLineFloatsPerVertex
 Floats per point in the line data (6 vertices * 3 floats each).
 
static constexpr int kFillFloatsPerPoint = kFillVerticesPerPoint * kFillFloatsPerVertex
 Floats per point in the fill data (2 vertices * 4 floats each).
 

Additional Inherited Members

- Static Public Member Functions inherited from OpenGlComponent
static bool setViewPort (Component *component, Rectangle< int > bounds, OpenGlWrapper &open_gl)
 Sets the OpenGL viewport to match a specified rectangle within a component.
 
static bool setViewPort (Component *component, OpenGlWrapper &open_gl)
 Convenience overload that sets the viewport for the entire component's local bounds.
 
static void setScissor (Component *component, OpenGlWrapper &open_gl)
 Sets the OpenGL scissor region to the entire component's local bounds.
 
static void setScissorBounds (Component *component, Rectangle< int > bounds, OpenGlWrapper &open_gl)
 Sets the OpenGL scissor region to a specified rectangle within a component.
 
static std::unique_ptr< OpenGLShaderProgram::Uniform > getUniform (const OpenGlWrapper &open_gl, const OpenGLShaderProgram &program, const char *name)
 Retrieves a uniform from the shader program if it exists.
 
static std::unique_ptr< OpenGLShaderProgram::Attribute > getAttribute (const OpenGlWrapper &open_gl, const OpenGLShaderProgram &program, const char *name)
 Retrieves an attribute from the shader program if it exists.
 
static String translateFragmentShader (const String &code)
 Translates a fragment shader code snippet to be compatible with the current GL version.
 
static String translateVertexShader (const String &code)
 Translates a vertex shader code snippet to be compatible with the current GL version.
 
- Protected Member Functions inherited from OpenGlComponent
bool setViewPort (OpenGlWrapper &open_gl)
 Sets the viewport for this component using the current OpenGlWrapper.
 
- Protected Attributes inherited from OpenGlComponent
std::unique_ptr< OpenGlCornerscorners_
 Optional corners for rounded edges.
 
bool only_bottom_corners_
 Flag to round only the bottom corners.
 
Colour background_color_
 The background color of the component.
 
Colour body_color_
 The body color of the component.
 
const SynthSectionparent_
 Pointer to parent SynthSection for skin lookups.
 
Skin::SectionOverride skin_override_
 Skin override for custom appearance.
 
const vital::StatusOutputnum_voices_readout_
 StatusOutput for voice count lookups.
 

Detailed Description

Renders a frequency-domain representation (spectrogram) using OpenGL.

The Spectrogram class uses a Fourier transform to display the frequency content of audio data over time. It reads from a StereoMemory buffer, applies a window function, performs an FFT, and then visualizes the amplitude across frequencies as a line. Both left and right channels are represented, and various frequency and dB range parameters can be set.

Constructor & Destructor Documentation

◆ Spectrogram()

Spectrogram::Spectrogram ( )

Constructs the Spectrogram with default parameters.

◆ ~Spectrogram()

Spectrogram::~Spectrogram ( )
virtualdefault

Destructor.

Member Function Documentation

◆ drawWaveform()

void Spectrogram::drawWaveform ( OpenGlWrapper & open_gl,
int index )

Draws the frequency-domain waveform (spectrogram line) for a given channel index.

Parameters
open_glThe OpenGlWrapper providing the current OpenGL context.
indexThe channel index (0 for left, 1 for right).

◆ paintBackground()

void Spectrogram::paintBackground ( Graphics & g)
overridevirtual

Paints a background using JUCE's Graphics (e.g., frequency lines).

Parameters
gThe graphics context.

Reimplemented from OpenGlComponent.

◆ paintBackgroundLines()

void Spectrogram::paintBackgroundLines ( bool paint)
inline

Enables or disables painting background frequency lines.

Parameters
paintTrue to paint background lines, false otherwise.

◆ render()

void Spectrogram::render ( OpenGlWrapper & open_gl,
bool animate )
overridevirtual

Renders the spectrogram for both channels.

Parameters
open_glThe OpenGlWrapper providing the current OpenGL context.
animateIf true, animations/boosts may be applied.

Reimplemented from OpenGlLineRenderer.

◆ setAudioMemory()

void Spectrogram::setAudioMemory ( const vital::StereoMemory * memory)
inline

Sets the StereoMemory from which audio data is read for the FFT.

Parameters
memoryPointer to a vital::StereoMemory holding stereo audio samples.

◆ setMaxDb()

void Spectrogram::setMaxDb ( float db)
inline

Sets the maximum dB level displayed.

Parameters
dbThe new maximum dB level.

◆ setMaxFrequency()

void Spectrogram::setMaxFrequency ( float frequency)
inline

Sets the maximum frequency displayed in the spectrogram.

Parameters
frequencyThe new maximum frequency in Hz.

◆ setMinDb()

void Spectrogram::setMinDb ( float db)
inline

Sets the minimum dB level displayed.

Parameters
dbThe new minimum dB level.

◆ setMinFrequency()

void Spectrogram::setMinFrequency ( float frequency)
inline

Sets the minimum frequency displayed in the spectrogram.

Parameters
frequencyThe new minimum frequency in Hz.

◆ setOversampleAmount()

void Spectrogram::setOversampleAmount ( int oversample)
inline

Sets the oversampling amount used for adjusting frequency scaling.

Parameters
oversampleThe oversample factor.

Member Data Documentation

◆ kAudioSize

int Spectrogram::kAudioSize = 1 << kBits
staticconstexpr

Size of audio block for the FFT.

◆ kBits

int Spectrogram::kBits = 14
staticconstexpr

Number of bits, defining the transform size (2^kBits).

◆ kDbSlopePerOctave

float Spectrogram::kDbSlopePerOctave = 3.0f
staticconstexpr

dB slope per octave for visualization.

◆ kDecayMult

float Spectrogram::kDecayMult = 0.008f
staticconstexpr

Decay multiplier for amplitude smoothing.

◆ kDefaultMaxDb

float Spectrogram::kDefaultMaxDb = 0.0f
staticconstexpr

Default maximum dB level displayed.

◆ kDefaultMaxFrequency

float Spectrogram::kDefaultMaxFrequency = 21000.0f
staticconstexpr

Default maximum frequency.

◆ kDefaultMinDb

float Spectrogram::kDefaultMinDb = -50.0f
staticconstexpr

Default minimum dB level displayed.

◆ kDefaultMinFrequency

float Spectrogram::kDefaultMinFrequency = 9.2f
staticconstexpr

Default minimum frequency.

◆ kResolution

int Spectrogram::kResolution = 300
staticconstexpr

Number of points in the frequency line.


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