Vital
Loading...
Searching...
No Matches
vital::Wavetable Class Reference

A class representing a wavetable, holding multiple frames of waveforms and their frequency-domain representations. More...

#include <wavetable.h>

Classes

struct  WavetableData
 Struct holding all necessary data for the Wavetable, including multiple frames. More...
 

Public Member Functions

 Wavetable (int max_frames)
 Construct a new Wavetable object with a given maximum number of frames.
 
void loadDefaultWavetable ()
 Load a default wavetable containing a single, default frame.
 
void setNumFrames (int num_frames)
 Set the number of frames in the wavetable.
 
void setFrequencyRatio (float frequency_ratio)
 Set the frequency ratio for this wavetable.
 
void setSampleRate (float rate)
 Set the sample rate associated with this wavetable.
 
std::string getName ()
 Get the user-defined name of this wavetable.
 
std::string getAuthor ()
 Get the author of this wavetable.
 
void setName (const std::string &name)
 Set a user-defined name for this wavetable.
 
void setAuthor (const std::string &author)
 Set the author for this wavetable.
 
force_inline int clampFrame (int frame)
 Clamp a frame index to be within the valid range for the current data.
 
force_inline const WavetableDatagetAllData ()
 Get a pointer to the current WavetableData.
 
force_inline mono_floatgetBuffer (int frame_index)
 Get a pointer to the time-domain waveform buffer for a given frame.
 
force_inline poly_floatgetFrequencyAmplitudes (int frame_index)
 Get a pointer to the frequency amplitude data for a given frame.
 
force_inline poly_floatgetNormalizedFrequencies (int frame_index)
 Get a pointer to the normalized frequency data for a given frame.
 
force_inline int getVersion ()
 Get the version number of the current wavetable data.
 
force_inline int clampActiveFrame (int frame)
 Clamp a frame index to be within the valid range of the active (in-use) wavetable data.
 
force_inline float getActiveFrequencyRatio () const
 Get the frequency ratio of the active wavetable data.
 
force_inline float getActiveSampleRate () const
 Get the sample rate of the active wavetable data.
 
force_inline const WavetableDatagetAllActiveData ()
 Get a pointer to the active (in-use) WavetableData.
 
force_inline poly_floatgetActiveFrequencyAmplitudes (int frame_index)
 Get a pointer to the active frequency amplitudes for a given frame.
 
force_inline poly_floatgetActiveNormalizedFrequencies (int frame_index)
 Get a pointer to the active normalized frequencies for a given frame.
 
force_inline int getActiveVersion ()
 Get the version number of the active wavetable data.
 
void loadWaveFrame (const WaveFrame *wave_frame)
 Load a WaveFrame into the wavetable at the frame index specified by the WaveFrame.
 
void loadWaveFrame (const WaveFrame *wave_frame, int to_index)
 Load a WaveFrame into the wavetable at a specific frame index.
 
void postProcess (float max_span)
 Post-process the loaded wavetable frames, scaling them based on a maximum span.
 
force_inline int numFrames () const
 Get the number of frames in the current wavetable data.
 
force_inline int numActiveFrames () const
 Get the number of frames in the active wavetable data.
 
force_inline void markUsed ()
 Mark the current wavetable data as used (active).
 
force_inline void markUnused ()
 Mark the active wavetable data as unused, allowing for changes.
 
force_inline void setShepardTable (bool shepard)
 Enable or disable "Shepard" table mode.
 
force_inline bool isShepardTable ()
 Check if the wavetable is currently in Shepard mode.
 

Static Public Member Functions

static constexpr const mono_floatnull_waveform ()
 Returns a constant pointer to a zeroed waveform.
 
static force_inline mono_float getFrequencyFloatBin (mono_float phase_increment)
 Compute a float-based frequency bin from a phase increment.
 
static force_inline int getFrequencyBin (mono_float phase_increment)
 Compute an integer frequency bin from a phase increment.
 

Static Public Attributes

static constexpr int kFrequencyBins = WaveFrame::kWaveformBits
 Number of frequency bins (equal to number of wave bits in a frame).
 
static constexpr int kWaveformSize = WaveFrame::kWaveformSize
 Size of each waveform frame.
 
static constexpr int kExtraValues = 3
 Number of extra values to store beyond the main waveform size.
 
static constexpr int kNumHarmonics = kWaveformSize / 2 + 1
 Number of harmonics in the waveform (half the size plus one).
 
static constexpr int kPolyFrequencySize = 2 * kNumHarmonics / poly_float::kSize + 2
 The size for poly frequency buffers, ensuring alignment and vectorization.
 

Protected Member Functions

 Wavetable ()=default
 Protected default constructor for the Wavetable, intended for subclassing or internal use.
 
void loadFrequencyAmplitudes (const std::complex< float > *frequencies, int to_index)
 Load frequency amplitude data from a set of complex frequency-domain coefficients.
 
void loadNormalizedFrequencies (const std::complex< float > *frequencies, int to_index)
 Load normalized frequency and phase data from a set of complex frequency-domain coefficients.
 

Protected Attributes

std::string name_
 User-defined name of the wavetable.
 
std::string author_
 Author of the wavetable.
 
int max_frames_
 Maximum number of frames allocated for this wavetable.
 
WavetableDatacurrent_data_
 Pointer to the currently editable wavetable data.
 
std::atomic< WavetableData * > active_audio_data_
 Pointer to the currently active wavetable data used by the audio thread.
 
std::unique_ptr< WavetableDatadata_
 Owning pointer to the wavetable data.
 
bool shepard_table_
 Flag indicating if this wavetable is in Shepard mode.
 
mono_float fft_data_ [2 *kWaveformSize]
 Internal FFT buffer data used in processing.
 

Static Protected Attributes

static const mono_float kZeroWaveform [kWaveformSize+kExtraValues] = { }
 A static zeroed-out waveform for reference or fallback.
 

Detailed Description

A class representing a wavetable, holding multiple frames of waveforms and their frequency-domain representations.

This class encapsulates a collection of waveforms (frames) and provides methods to manipulate, retrieve, and process frequency-domain and time-domain representations. It leverages both mono and SIMD (poly) data types to efficiently handle frequency bins and operations on multiple harmonics.

Constructor & Destructor Documentation

◆ Wavetable() [1/2]

vital::Wavetable::Wavetable ( int max_frames)

Construct a new Wavetable object with a given maximum number of frames.

Construct a new Wavetable object and load a default wavetable.

Parameters
max_framesThe maximum number of frames this wavetable can hold.
max_framesThe maximum number of frames to allocate.

◆ Wavetable() [2/2]

vital::Wavetable::Wavetable ( )
protecteddefault

Protected default constructor for the Wavetable, intended for subclassing or internal use.

Member Function Documentation

◆ clampActiveFrame()

force_inline int vital::Wavetable::clampActiveFrame ( int frame)
inline

Clamp a frame index to be within the valid range of the active (in-use) wavetable data.

Parameters
frameThe frame index to clamp.
Returns
A valid frame index for the active data.

◆ clampFrame()

force_inline int vital::Wavetable::clampFrame ( int frame)
inline

Clamp a frame index to be within the valid range for the current data.

Parameters
frameThe frame index to clamp.
Returns
A valid frame index.

◆ getActiveFrequencyAmplitudes()

force_inline poly_float * vital::Wavetable::getActiveFrequencyAmplitudes ( int frame_index)
inline

Get a pointer to the active frequency amplitudes for a given frame.

Parameters
frame_indexThe frame index.
Returns
A pointer to the active frequency amplitudes buffer.

◆ getActiveFrequencyRatio()

force_inline float vital::Wavetable::getActiveFrequencyRatio ( ) const
inline

Get the frequency ratio of the active wavetable data.

Returns
The active frequency ratio.

◆ getActiveNormalizedFrequencies()

force_inline poly_float * vital::Wavetable::getActiveNormalizedFrequencies ( int frame_index)
inline

Get a pointer to the active normalized frequencies for a given frame.

Parameters
frame_indexThe frame index.
Returns
A pointer to the active normalized frequencies buffer.

◆ getActiveSampleRate()

force_inline float vital::Wavetable::getActiveSampleRate ( ) const
inline

Get the sample rate of the active wavetable data.

Returns
The active sample rate.

◆ getActiveVersion()

force_inline int vital::Wavetable::getActiveVersion ( )
inline

Get the version number of the active wavetable data.

Returns
The active version number.

◆ getAllActiveData()

force_inline const WavetableData * vital::Wavetable::getAllActiveData ( )
inline

Get a pointer to the active (in-use) WavetableData.

Returns
A pointer to the active WavetableData.

◆ getAllData()

force_inline const WavetableData * vital::Wavetable::getAllData ( )
inline

Get a pointer to the current WavetableData.

Returns
A pointer to the current WavetableData structure.

◆ getAuthor()

std::string vital::Wavetable::getAuthor ( )
inline

Get the author of this wavetable.

Returns
The author name as a string.

◆ getBuffer()

force_inline mono_float * vital::Wavetable::getBuffer ( int frame_index)
inline

Get a pointer to the time-domain waveform buffer for a given frame.

Parameters
frame_indexThe index of the frame.
Returns
A pointer to the waveform buffer.

◆ getFrequencyAmplitudes()

force_inline poly_float * vital::Wavetable::getFrequencyAmplitudes ( int frame_index)
inline

Get a pointer to the frequency amplitude data for a given frame.

Parameters
frame_indexThe index of the frame.
Returns
A pointer to the frequency amplitudes buffer.

◆ getFrequencyBin()

static force_inline int vital::Wavetable::getFrequencyBin ( mono_float phase_increment)
inlinestatic

Compute an integer frequency bin from a phase increment.

Parameters
phase_incrementThe phase increment.
Returns
The computed integer frequency bin.

◆ getFrequencyFloatBin()

static force_inline mono_float vital::Wavetable::getFrequencyFloatBin ( mono_float phase_increment)
inlinestatic

Compute a float-based frequency bin from a phase increment.

Parameters
phase_incrementThe phase increment.
Returns
The computed float frequency bin.

◆ getName()

std::string vital::Wavetable::getName ( )
inline

Get the user-defined name of this wavetable.

Returns
The name as a string.

◆ getNormalizedFrequencies()

force_inline poly_float * vital::Wavetable::getNormalizedFrequencies ( int frame_index)
inline

Get a pointer to the normalized frequency data for a given frame.

Parameters
frame_indexThe index of the frame.
Returns
A pointer to the normalized frequencies buffer.

◆ getVersion()

force_inline int vital::Wavetable::getVersion ( )
inline

Get the version number of the current wavetable data.

Returns
The version number.

◆ isShepardTable()

force_inline bool vital::Wavetable::isShepardTable ( )
inline

Check if the wavetable is currently in Shepard mode.

Returns
True if Shepard mode is enabled, false otherwise.

◆ loadDefaultWavetable()

void vital::Wavetable::loadDefaultWavetable ( )

Load a default wavetable containing a single, default frame.

◆ loadFrequencyAmplitudes()

void vital::Wavetable::loadFrequencyAmplitudes ( const std::complex< float > * frequencies,
int to_index )
protected

Load frequency amplitude data from a set of complex frequency-domain coefficients.

Parameters
frequenciesA pointer to the complex frequency-domain data.
to_indexThe frame index to load the data into.

◆ loadNormalizedFrequencies()

void vital::Wavetable::loadNormalizedFrequencies ( const std::complex< float > * frequencies,
int to_index )
protected

Load normalized frequency and phase data from a set of complex frequency-domain coefficients.

Parameters
frequenciesA pointer to the complex frequency-domain data.
to_indexThe frame index to load the data into.

◆ loadWaveFrame() [1/2]

void vital::Wavetable::loadWaveFrame ( const WaveFrame * wave_frame)

Load a WaveFrame into the wavetable at the frame index specified by the WaveFrame.

Parameters
wave_frameA pointer to the WaveFrame containing time-domain and frequency-domain data.

◆ loadWaveFrame() [2/2]

void vital::Wavetable::loadWaveFrame ( const WaveFrame * wave_frame,
int to_index )

Load a WaveFrame into the wavetable at a specific frame index.

Parameters
wave_frameA pointer to the WaveFrame containing time-domain and frequency-domain data.
to_indexThe index at which to place the WaveFrame data.

◆ markUnused()

force_inline void vital::Wavetable::markUnused ( )
inline

Mark the active wavetable data as unused, allowing for changes.

◆ markUsed()

force_inline void vital::Wavetable::markUsed ( )
inline

Mark the current wavetable data as used (active).

◆ null_waveform()

static constexpr const mono_float * vital::Wavetable::null_waveform ( )
inlinestaticconstexpr

Returns a constant pointer to a zeroed waveform.

Returns
A pointer to a static zero waveform.

◆ numActiveFrames()

force_inline int vital::Wavetable::numActiveFrames ( ) const
inline

Get the number of frames in the active wavetable data.

Returns
The number of active frames.

◆ numFrames()

force_inline int vital::Wavetable::numFrames ( ) const
inline

Get the number of frames in the current wavetable data.

Returns
The number of frames.

◆ postProcess()

void vital::Wavetable::postProcess ( float max_span)

Post-process the loaded wavetable frames, scaling them based on a maximum span.

This can be used to normalize amplitude and correct normalized frequency data across frames.

Parameters
max_spanThe maximum amplitude span used for normalization.

◆ setAuthor()

void vital::Wavetable::setAuthor ( const std::string & author)
inline

Set the author for this wavetable.

Parameters
authorThe author name to set.

◆ setFrequencyRatio()

void vital::Wavetable::setFrequencyRatio ( float frequency_ratio)

Set the frequency ratio for this wavetable.

Parameters
frequency_ratioThe frequency ratio to set.

◆ setName()

void vital::Wavetable::setName ( const std::string & name)
inline

Set a user-defined name for this wavetable.

Parameters
nameThe name to set.

◆ setNumFrames()

void vital::Wavetable::setNumFrames ( int num_frames)

Set the number of frames in the wavetable.

This method reallocates or resizes the wavetable data. It also ensures that the currently active wavetable data is not being used by the audio thread before modification.

Parameters
num_framesThe new number of frames.

◆ setSampleRate()

void vital::Wavetable::setSampleRate ( float rate)

Set the sample rate associated with this wavetable.

Parameters
rateThe new sample rate.

◆ setShepardTable()

force_inline void vital::Wavetable::setShepardTable ( bool shepard)
inline

Enable or disable "Shepard" table mode.

Shepard mode is a special mode for certain types of wavetable transformations.

Parameters
shepardTrue to enable Shepard mode, false to disable.

Member Data Documentation

◆ active_audio_data_

std::atomic<WavetableData*> vital::Wavetable::active_audio_data_
protected

Pointer to the currently active wavetable data used by the audio thread.

◆ author_

std::string vital::Wavetable::author_
protected

Author of the wavetable.

◆ current_data_

WavetableData* vital::Wavetable::current_data_
protected

Pointer to the currently editable wavetable data.

◆ data_

std::unique_ptr<WavetableData> vital::Wavetable::data_
protected

Owning pointer to the wavetable data.

◆ fft_data_

mono_float vital::Wavetable::fft_data_[2 *kWaveformSize]
protected

Internal FFT buffer data used in processing.

◆ kExtraValues

int vital::Wavetable::kExtraValues = 3
staticconstexpr

Number of extra values to store beyond the main waveform size.

◆ kFrequencyBins

int vital::Wavetable::kFrequencyBins = WaveFrame::kWaveformBits
staticconstexpr

Number of frequency bins (equal to number of wave bits in a frame).

◆ kNumHarmonics

int vital::Wavetable::kNumHarmonics = kWaveformSize / 2 + 1
staticconstexpr

Number of harmonics in the waveform (half the size plus one).

◆ kPolyFrequencySize

int vital::Wavetable::kPolyFrequencySize = 2 * kNumHarmonics / poly_float::kSize + 2
staticconstexpr

The size for poly frequency buffers, ensuring alignment and vectorization.

◆ kWaveformSize

int vital::Wavetable::kWaveformSize = WaveFrame::kWaveformSize
staticconstexpr

Size of each waveform frame.

◆ kZeroWaveform

const mono_float vital::Wavetable::kZeroWaveform = { }
staticprotected

A static zeroed-out waveform for reference or fallback.

◆ max_frames_

int vital::Wavetable::max_frames_
protected

Maximum number of frames allocated for this wavetable.

◆ name_

std::string vital::Wavetable::name_
protected

User-defined name of the wavetable.

◆ shepard_table_

bool vital::Wavetable::shepard_table_
protected

Flag indicating if this wavetable is in Shepard mode.


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