hx3d  1
2D/3D Simple Game Framework
Public Member Functions | List of all members
hx3d::audio::Spectrum Class Reference

Audio spectrum displaying. More...

#include <spectrum.hpp>

Public Member Functions

 Spectrum (const unsigned int minFreq, const unsigned int maxFreq, const unsigned int barCount)
 Create an empty spectrum with a refresh delay of 50. More...
 
 Spectrum (const unsigned int minFreq, const unsigned int maxFreq, const unsigned int barCount, const int refreshDelay)
 Create an empty spectrum with a custom refresh delay. More...
 
virtual void update (const Sint16 *stream, const int length, const float delta) override
 Update the display. More...
 
virtual void onInitialization () override
 Use this to execute code after initialization. More...
 
float getNormalizedFrequencyAmplitude (const unsigned int frequency, const unsigned int range)
 Get the average normalized amplitude for a center frequency and a range. More...
 
unsigned int getBarCount ()
 Get the bar count. More...
 
- Public Member Functions inherited from hx3d::audio::Display
 Display ()
 Create an empty display with a refresh delay of 50. More...
 
 Display (const int refreshDelay)
 Create an empty display with a custom refresh delay. More...
 
void initialize (const unsigned int width, const unsigned int height)
 Initialize the display. More...
 
void setRefreshDelay (const int refreshDelay)
 Set the refresh delay. More...
 
- Public Member Functions inherited from hx3d::graphics::Sprite
 Sprite ()
 Create a sprite without texture. More...
 
void setTexture (const Ptr< Texture > &texture)
 Set the sprite texture. More...
 
void setTexture (Framebuffer &buffer)
 Set the sprite texture from a framebuffer color buffer. More...
 
void setTexture (TextureRegion &region)
 Set the sprite texture from a texture region. More...
 
Ptr< TexturegetTexture ()
 Get the sprite texture. More...
 
void scaleTexture ()
 Scale the texture coordinates following the texture size.
 
virtual void draw (Ptr< Shader > shader) override
 Draw the mesh using a shader. More...
 
- Public Member Functions inherited from hx3d::graphics::Mesh
void setTint (Color tint)
 Set the mesh tint. More...
 
ColorgetTint ()
 Get the mesh tint. More...
 
void updateColor ()
 Update the mesh color from the tint.
 
void setGeometry (Ptr< geom::BaseGeometry > geometry)
 Set the mesh geometry. More...
 
Ptr< geom::BaseGeometry > & getGeometry ()
 Get the mesh geometry. More...
 

Additional Inherited Members

- Public Attributes inherited from hx3d::graphics::Mesh
Transform transform
 Mesh transformation.
 
- Protected Member Functions inherited from hx3d::audio::Display
void drawBorders ()
 Draw white borders.
 
- Protected Attributes inherited from hx3d::audio::Display
graphics::Image _image
 Drawing image.
 
Timer _timer
 Refresh timer.
 
int _refreshDelay
 Refresh delay.
 
bool _initialized
 Is the display initialized ?
 
- Protected Attributes inherited from hx3d::graphics::Mesh
Color _tint
 Tint color.
 
Ptr< geom::BaseGeometry_geometry
 Current geometry.
 

Detailed Description

Audio spectrum displaying.

Example code

// Inside a create function...
// Create a spectrum from 100Hz to 10KHz, with 10 bars
audio::Spectrum spectrum(100, 10000, 10);
spectrum.transform.position.x = 100;
spectrum.transform.position.y = 100;
[...]
// Inside an update function...
// Get a signed short stream (see audio::S16Converter)
short* stream = s16converter.getS16Stream();
// Update the spectrum
spectrum.update(stream, s16converter.getSampleSize(), delta);
// Look for an amplitude (for example 1KHz with a 500Hz range) -> between 0 and 1
float amp = spectrum.getNormalizedFrequencyAmplitude(1000, 500);
// > Do whatever you want with the amplitude ! (tempo measure ?)
[...]
// Inside a render function...
// Display the spectrum
batch.draw(spectrum);

Definition at line 66 of file spectrum.hpp.

Constructor & Destructor Documentation

hx3d::audio::Spectrum::Spectrum ( const unsigned int  minFreq,
const unsigned int  maxFreq,
const unsigned int  barCount 
)

Create an empty spectrum with a refresh delay of 50.

See also
initialize to construct the texture.
Parameters
minFreqMin. frequency
maxFreqMax. frequency
barCountBars count

Definition at line 35 of file spectrum.cpp.

hx3d::audio::Spectrum::Spectrum ( const unsigned int  minFreq,
const unsigned int  maxFreq,
const unsigned int  barCount,
const int  refreshDelay 
)

Create an empty spectrum with a custom refresh delay.

See also
initialize to construct the texture.
Parameters
minFreqMin. frequency
maxFreqMax. frequency
barCountBars count
refreshDelayRefresh delay

Definition at line 39 of file spectrum.cpp.

Member Function Documentation

unsigned int hx3d::audio::Spectrum::getBarCount ( )

Get the bar count.

Returns
Bar count

Definition at line 180 of file spectrum.cpp.

float hx3d::audio::Spectrum::getNormalizedFrequencyAmplitude ( const unsigned int  frequency,
const unsigned int  range 
)

Get the average normalized amplitude for a center frequency and a range.

Use this to detect a "beat" into a frequency range.

Parameters
frequencyCenter frequency
rangeRange
Returns
Normalized amplitude

Definition at line 149 of file spectrum.cpp.

void hx3d::audio::Spectrum::onInitialization ( )
overridevirtual

Use this to execute code after initialization.

See also
Spectrum::onInitialization.

Reimplemented from hx3d::audio::Display.

Definition at line 48 of file spectrum.cpp.

void hx3d::audio::Spectrum::update ( const Sint16 *  stream,
const int  length,
const float  delta 
)
overridevirtual

Update the display.

Parameters
streamStream of amplitudes (between -32767 and 32767)
lengthLength of the stream
deltaDelta time

Implements hx3d::audio::Display.

Definition at line 77 of file spectrum.cpp.


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