ProtoTracer  1.0
Real-time 3D rendering and animation engine
Loading...
Searching...
No Matches
SpectrumAnalyzer Class Reference

A material that visualizes audio data as a spectrum. More...

#include <SpectrumAnalyzer.h>

Inheritance diagram for SpectrumAnalyzer:
Collaboration diagram for SpectrumAnalyzer:

Public Member Functions

 SpectrumAnalyzer (Vector2D size, Vector2D offset, bool bounce=false, bool flipY=false, bool mirrorY=false)
 Constructor for SpectrumAnalyzer.
 
 ~SpectrumAnalyzer ()
 Destructor for SpectrumAnalyzer.
 
void SetMirrorYState (bool state)
 Sets the mirroring state for the visualization.
 
void SetFlipYState (bool state)
 Sets the flipping state for the visualization.
 
void SetMaterial (Material *material)
 Sets a custom material for additional effects.
 
floatGetFourierData ()
 Retrieves the Fourier data used for visualization.
 
void SetSize (Vector2D size)
 Sets the size of the visualization area.
 
void SetPosition (Vector2D offset)
 Sets the position of the visualization area.
 
void SetRotation (float angle)
 Sets the rotation angle of the visualization.
 
void SetHueAngle (float hueAngle)
 Sets the hue adjustment angle for the spectrum colors.
 
void Update (float *readData)
 Updates the spectrum visualization with new audio data.
 
RGBColor GetRGB (const Vector3D &position, const Vector3D &normal, const Vector3D &uvw) override
 Computes the color at a given position in the material.
 
- Public Member Functions inherited from Material
virtual ~Material ()=default
 Virtual destructor for proper cleanup in derived classes.
 

Private Attributes

BouncePhysicsbPhy [128]
 Array of bounce physics objects for each frequency bin.
 
Vector2D size
 Size of the visualization area.
 
Vector2D offset
 Offset position of the visualization area.
 
float angle = 0.0f
 Rotation angle of the visualization.
 
float hueAngle = 0.0f
 Hue adjustment angle for the spectrum colors.
 
uint8_t colors
 Number of colors in the gradient.
 
floatdata
 Pointer to the input audio data.
 
float bounceData [128]
 Processed bounce data for visualization.
 
uint8_t bins = 128
 Number of frequency bins.
 
bool mirrorY = false
 Whether to mirror the visualization along the Y-axis.
 
bool flipY = false
 Whether to flip the visualization along the Y-axis.
 
bool bounce = false
 Whether to apply bouncing animation to the spectrum.
 
RGBColor rainbowSpectrum [6]
 Predefined rainbow color gradient.
 
GradientMaterial< 6 > gM = GradientMaterial<6>(rainbowSpectrum, 1.0f, false)
 Gradient material for coloring the spectrum.
 
Materialmaterial
 Optional sub-material for additional effects.
 

Additional Inherited Members

- Public Types inherited from Material
enum  Method {
  Base , Add , Subtract , Multiply ,
  Divide , Darken , Lighten , Screen ,
  Overlay , SoftLight , Replace , EfficientMask ,
  Bypass
}
 Defines blending methods for combining colors. More...
 

Detailed Description

A material that visualizes audio data as a spectrum.

The SpectrumAnalyzer class processes audio data to create a colorful and dynamic spectrum visualization with options for customization, including mirroring and flipping.

Definition at line 25 of file SpectrumAnalyzer.h.

Constructor & Destructor Documentation

◆ SpectrumAnalyzer()

SpectrumAnalyzer ( Vector2D  size,
Vector2D  offset,
bool  bounce = false,
bool  flipY = false,
bool  mirrorY = false 
)

Constructor for SpectrumAnalyzer.

Parameters
sizeThe size of the visualization area.
offsetThe offset position of the visualization.
bounceEnables bouncing animation for the spectrum.
flipYEnables flipping the visualization along the Y-axis.
mirrorYEnables mirroring the visualization along the Y-axis.

Definition at line 3 of file SpectrumAnalyzer.cpp.

References bounce, bPhy, Vector2D::Divide(), flipY, gM, material, mirrorY, offset, and size.

◆ ~SpectrumAnalyzer()

Destructor for SpectrumAnalyzer.

Definition at line 18 of file SpectrumAnalyzer.cpp.

References bPhy.

Member Function Documentation

◆ GetFourierData()

float * GetFourierData ( )

Retrieves the Fourier data used for visualization.

Returns
Pointer to the array of Fourier data.

Definition at line 36 of file SpectrumAnalyzer.cpp.

References bounce, bounceData, and data.

◆ GetRGB()

RGBColor GetRGB ( const Vector3D position,
const Vector3D normal,
const Vector3D uvw 
)
overridevirtual

Computes the color at a given position in the material.

Parameters
positionThe position in 3D space.
normalThe surface normal vector.
uvwThe texture coordinates.
Returns
The computed color as an RGBColor.

Implements Material.

Definition at line 72 of file SpectrumAnalyzer.cpp.

References angle, bins, bounce, bounceData, Mathematics::CosineInterpolation(), data, flipY, Material::GetRGB(), hueAngle, RGBColor::HueShift(), Mathematics::IsClose(), Mathematics::Map(), material, mirrorY, offset, Vector2D::Rotate(), size, Vector2D::X, Vector3D::X, Vector2D::Y, and Vector3D::Y.

◆ SetFlipYState()

◆ SetHueAngle()

◆ SetMaterial()

void SetMaterial ( Material material)

Sets a custom material for additional effects.

Parameters
materialPointer to the custom material.

Definition at line 32 of file SpectrumAnalyzer.cpp.

References material.

◆ SetMirrorYState()

◆ SetPosition()

void SetPosition ( Vector2D  offset)

Sets the position of the visualization area.

Parameters
offsetThe new position as a Vector2D.

Definition at line 48 of file SpectrumAnalyzer.cpp.

References offset.

Referenced by ProtogenProject::ProtogenProject().

◆ SetRotation()

void SetRotation ( float  angle)

Sets the rotation angle of the visualization.

Parameters
angleThe rotation angle in degrees.

Definition at line 52 of file SpectrumAnalyzer.cpp.

References angle.

Referenced by AlphaAnimation::Update().

◆ SetSize()

void SetSize ( Vector2D  size)

Sets the size of the visualization area.

Parameters
sizeThe new size as a Vector2D.

Definition at line 44 of file SpectrumAnalyzer.cpp.

References Vector2D::Divide(), and size.

Referenced by ProtogenProject::ProtogenProject().

◆ Update()

Member Data Documentation

◆ angle

float angle = 0.0f
private

Rotation angle of the visualization.

Definition at line 30 of file SpectrumAnalyzer.h.

Referenced by GetRGB(), and SetRotation().

◆ bins

uint8_t bins = 128
private

Number of frequency bins.

Definition at line 35 of file SpectrumAnalyzer.h.

Referenced by GetRGB().

◆ bounce

bool bounce = false
private

Whether to apply bouncing animation to the spectrum.

Definition at line 38 of file SpectrumAnalyzer.h.

Referenced by GetFourierData(), GetRGB(), SpectrumAnalyzer(), and Update().

◆ bounceData

float bounceData[128]
private

Processed bounce data for visualization.

Definition at line 34 of file SpectrumAnalyzer.h.

Referenced by GetFourierData(), GetRGB(), and Update().

◆ bPhy

BouncePhysics* bPhy[128]
private

Array of bounce physics objects for each frequency bin.

Definition at line 27 of file SpectrumAnalyzer.h.

Referenced by SpectrumAnalyzer(), Update(), and ~SpectrumAnalyzer().

◆ colors

uint8_t colors
private

Number of colors in the gradient.

Definition at line 32 of file SpectrumAnalyzer.h.

◆ data

float* data
private

Pointer to the input audio data.

Definition at line 33 of file SpectrumAnalyzer.h.

Referenced by GetFourierData(), GetRGB(), and Update().

◆ flipY

bool flipY = false
private

Whether to flip the visualization along the Y-axis.

Definition at line 37 of file SpectrumAnalyzer.h.

Referenced by GetRGB(), SetFlipYState(), and SpectrumAnalyzer().

◆ gM

Gradient material for coloring the spectrum.

Definition at line 49 of file SpectrumAnalyzer.h.

Referenced by SpectrumAnalyzer().

◆ hueAngle

float hueAngle = 0.0f
private

Hue adjustment angle for the spectrum colors.

Definition at line 31 of file SpectrumAnalyzer.h.

Referenced by GetRGB(), and SetHueAngle().

◆ material

Material* material
private

Optional sub-material for additional effects.

Definition at line 50 of file SpectrumAnalyzer.h.

Referenced by GetRGB(), SetMaterial(), and SpectrumAnalyzer().

◆ mirrorY

bool mirrorY = false
private

Whether to mirror the visualization along the Y-axis.

Definition at line 36 of file SpectrumAnalyzer.h.

Referenced by GetRGB(), SetMirrorYState(), and SpectrumAnalyzer().

◆ offset

Vector2D offset
private

Offset position of the visualization area.

Definition at line 29 of file SpectrumAnalyzer.h.

Referenced by GetRGB(), SetPosition(), and SpectrumAnalyzer().

◆ rainbowSpectrum

RGBColor rainbowSpectrum[6]
private
Initial value:
= {
RGBColor(255, 0, 0),
RGBColor(255, 255, 0),
RGBColor(0, 255, 0),
RGBColor(0, 255, 255),
RGBColor(0, 0, 255),
RGBColor(255, 0, 255)
}
Represents an RGB color and provides methods for manipulation.
Definition RGBColor.h:23

Predefined rainbow color gradient.

Definition at line 40 of file SpectrumAnalyzer.h.

◆ size

Vector2D size
private

Size of the visualization area.

Definition at line 28 of file SpectrumAnalyzer.h.

Referenced by GetRGB(), SetSize(), and SpectrumAnalyzer().


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