Vital
|
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 WavetableData * | getAllData () |
Get a pointer to the current WavetableData. | |
force_inline mono_float * | getBuffer (int frame_index) |
Get a pointer to the time-domain waveform buffer for a given frame. | |
force_inline poly_float * | getFrequencyAmplitudes (int frame_index) |
Get a pointer to the frequency amplitude data for a given frame. | |
force_inline poly_float * | getNormalizedFrequencies (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 WavetableData * | getAllActiveData () |
Get a pointer to the active (in-use) WavetableData. | |
force_inline poly_float * | getActiveFrequencyAmplitudes (int frame_index) |
Get a pointer to the active frequency amplitudes for a given frame. | |
force_inline poly_float * | getActiveNormalizedFrequencies (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_float * | null_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. | |
WavetableData * | current_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< WavetableData > | data_ |
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. | |
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.
vital::Wavetable::Wavetable | ( | int | max_frames | ) |
|
protecteddefault |
Protected default constructor for the Wavetable, intended for subclassing or internal use.
|
inline |
Clamp a frame index to be within the valid range of the active (in-use) wavetable data.
frame | The frame index to clamp. |
|
inline |
Clamp a frame index to be within the valid range for the current data.
frame | The frame index to clamp. |
|
inline |
Get a pointer to the active frequency amplitudes for a given frame.
frame_index | The frame index. |
|
inline |
Get the frequency ratio of the active wavetable data.
|
inline |
Get a pointer to the active normalized frequencies for a given frame.
frame_index | The frame index. |
|
inline |
Get the sample rate of the active wavetable data.
|
inline |
Get the version number of the active wavetable data.
|
inline |
Get a pointer to the active (in-use) WavetableData.
|
inline |
Get a pointer to the current WavetableData.
|
inline |
Get the author of this wavetable.
|
inline |
Get a pointer to the time-domain waveform buffer for a given frame.
frame_index | The index of the frame. |
|
inline |
Get a pointer to the frequency amplitude data for a given frame.
frame_index | The index of the frame. |
|
inlinestatic |
Compute an integer frequency bin from a phase increment.
phase_increment | The phase increment. |
|
inlinestatic |
Compute a float-based frequency bin from a phase increment.
phase_increment | The phase increment. |
|
inline |
Get the user-defined name of this wavetable.
|
inline |
Get a pointer to the normalized frequency data for a given frame.
frame_index | The index of the frame. |
|
inline |
Get the version number of the current wavetable data.
|
inline |
Check if the wavetable is currently in Shepard mode.
void vital::Wavetable::loadDefaultWavetable | ( | ) |
Load a default wavetable containing a single, default frame.
|
protected |
Load frequency amplitude data from a set of complex frequency-domain coefficients.
frequencies | A pointer to the complex frequency-domain data. |
to_index | The frame index to load the data into. |
|
protected |
Load normalized frequency and phase data from a set of complex frequency-domain coefficients.
frequencies | A pointer to the complex frequency-domain data. |
to_index | The frame index to load the data into. |
void vital::Wavetable::loadWaveFrame | ( | const WaveFrame * | wave_frame | ) |
void vital::Wavetable::loadWaveFrame | ( | const WaveFrame * | wave_frame, |
int | to_index ) |
|
inline |
Mark the active wavetable data as unused, allowing for changes.
|
inline |
Mark the current wavetable data as used (active).
|
inlinestaticconstexpr |
Returns a constant pointer to a zeroed waveform.
|
inline |
Get the number of frames in the active wavetable data.
|
inline |
Get the number of frames in the current wavetable data.
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.
max_span | The maximum amplitude span used for normalization. |
|
inline |
Set the author for this wavetable.
author | The author name to set. |
void vital::Wavetable::setFrequencyRatio | ( | float | frequency_ratio | ) |
Set the frequency ratio for this wavetable.
frequency_ratio | The frequency ratio to set. |
|
inline |
Set a user-defined name for this wavetable.
name | The name to set. |
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.
num_frames | The new number of frames. |
void vital::Wavetable::setSampleRate | ( | float | rate | ) |
Set the sample rate associated with this wavetable.
rate | The new sample rate. |
|
inline |
Enable or disable "Shepard" table mode.
Shepard mode is a special mode for certain types of wavetable transformations.
shepard | True to enable Shepard mode, false to disable. |
|
protected |
Pointer to the currently active wavetable data used by the audio thread.
|
protected |
Author of the wavetable.
|
protected |
Pointer to the currently editable wavetable data.
|
protected |
Owning pointer to the wavetable data.
|
protected |
Internal FFT buffer data used in processing.
|
staticconstexpr |
Number of extra values to store beyond the main waveform size.
|
staticconstexpr |
Number of frequency bins (equal to number of wave bits in a frame).
|
staticconstexpr |
Number of harmonics in the waveform (half the size plus one).
|
staticconstexpr |
The size for poly frequency buffers, ensuring alignment and vectorization.
|
staticconstexpr |
Size of each waveform frame.
|
staticprotected |
A static zeroed-out waveform for reference or fallback.
|
protected |
Maximum number of frames allocated for this wavetable.
|
protected |
User-defined name of the wavetable.
|
protected |
Flag indicating if this wavetable is in Shepard mode.