57 std::unique_ptr<mono_float[][kWaveformSize]>
wave_data;
63 std::unique_ptr<poly_float[][kPolyFrequencySize]>
phases;
155 int num_waves = 1.0f / phase_increment;
377 std::unique_ptr<WavetableData>
data_;
Represents a single frame of a wavetable, containing both time-domain and frequency-domain data.
Definition wave_frame.h:16
static constexpr int kWaveformBits
The number of bits that define the size of the waveform (2^kWaveformBits = kWaveformSize).
Definition wave_frame.h:19
static constexpr int kWaveformSize
The size of the waveform (number of samples per frame).
Definition wave_frame.h:21
A class representing a wavetable, holding multiple frames of waveforms and their frequency-domain rep...
Definition wavetable.h:20
force_inline float getActiveFrequencyRatio() const
Get the frequency ratio of the active wavetable data.
Definition wavetable.h:232
force_inline int numActiveFrames() const
Get the number of frames in the active wavetable data.
Definition wavetable.h:319
std::string author_
Author of the wavetable.
Definition wavetable.h:373
void loadWaveFrame(const WaveFrame *wave_frame)
Load a WaveFrame into the wavetable at the frame index specified by the WaveFrame.
Definition wavetable.cpp:89
force_inline void markUnused()
Mark the active wavetable data as unused, allowing for changes.
Definition wavetable.h:329
std::string getAuthor()
Get the author of this wavetable.
Definition wavetable.h:122
force_inline void setShepardTable(bool shepard)
Enable or disable "Shepard" table mode.
Definition wavetable.h:338
std::string getName()
Get the user-defined name of this wavetable.
Definition wavetable.h:115
force_inline poly_float * getActiveNormalizedFrequencies(int frame_index)
Get a pointer to the active normalized frequencies for a given frame.
Definition wavetable.h:270
Wavetable()=default
Protected default constructor for the Wavetable, intended for subclassing or internal use.
void setName(const std::string &name)
Set a user-defined name for this wavetable.
Definition wavetable.h:129
force_inline float getActiveSampleRate() const
Get the sample rate of the active wavetable data.
Definition wavetable.h:241
void setAuthor(const std::string &author)
Set the author for this wavetable.
Definition wavetable.h:136
bool shepard_table_
Flag indicating if this wavetable is in Shepard mode.
Definition wavetable.h:378
std::unique_ptr< WavetableData > data_
Owning pointer to the wavetable data.
Definition wavetable.h:377
void setFrequencyRatio(float frequency_ratio)
Set the frequency ratio for this wavetable.
Definition wavetable.cpp:81
force_inline poly_float * getActiveFrequencyAmplitudes(int frame_index)
Get a pointer to the active frequency amplitudes for a given frame.
Definition wavetable.h:260
force_inline bool isShepardTable()
Check if the wavetable is currently in Shepard mode.
Definition wavetable.h:345
std::string name_
User-defined name of the wavetable.
Definition wavetable.h:372
force_inline int clampActiveFrame(int frame)
Clamp a frame index to be within the valid range of the active (in-use) wavetable data.
Definition wavetable.h:223
static force_inline int getFrequencyBin(mono_float phase_increment)
Compute an integer frequency bin from a phase increment.
Definition wavetable.h:154
force_inline poly_float * getNormalizedFrequencies(int frame_index)
Get a pointer to the normalized frequency data for a given frame.
Definition wavetable.h:204
force_inline int clampFrame(int frame)
Clamp a frame index to be within the valid range for the current data.
Definition wavetable.h:165
force_inline poly_float * getFrequencyAmplitudes(int frame_index)
Get a pointer to the frequency amplitude data for a given frame.
Definition wavetable.h:194
static constexpr int kNumHarmonics
Number of harmonics in the waveform (half the size plus one).
Definition wavetable.h:29
mono_float fft_data_[2 *kWaveformSize]
Internal FFT buffer data used in processing.
Definition wavetable.h:380
void setSampleRate(float rate)
Set the sample rate associated with this wavetable.
Definition wavetable.cpp:85
WavetableData * current_data_
Pointer to the currently editable wavetable data.
Definition wavetable.h:375
static constexpr int kFrequencyBins
Number of frequency bins (equal to number of wave bits in a frame).
Definition wavetable.h:23
void setNumFrames(int num_frames)
Set the number of frames in the wavetable.
Definition wavetable.cpp:27
void loadDefaultWavetable()
Load a default wavetable containing a single, default frame.
Definition wavetable.cpp:21
force_inline const WavetableData * getAllData()
Get a pointer to the current WavetableData.
Definition wavetable.h:174
force_inline int getActiveVersion()
Get the version number of the active wavetable data.
Definition wavetable.h:279
force_inline int getVersion()
Get the version number of the current wavetable data.
Definition wavetable.h:213
static const mono_float kZeroWaveform[kWaveformSize+kExtraValues]
A static zeroed-out waveform for reference or fallback.
Definition wavetable.h:370
std::atomic< WavetableData * > active_audio_data_
Pointer to the currently active wavetable data used by the audio thread.
Definition wavetable.h:376
static constexpr int kExtraValues
Number of extra values to store beyond the main waveform size.
Definition wavetable.h:27
void loadNormalizedFrequencies(const std::complex< float > *frequencies, int to_index)
Load normalized frequency and phase data from a set of complex frequency-domain coefficients.
Definition wavetable.cpp:163
force_inline const WavetableData * getAllActiveData()
Get a pointer to the active (in-use) WavetableData.
Definition wavetable.h:250
static constexpr int kPolyFrequencySize
The size for poly frequency buffers, ensuring alignment and vectorization.
Definition wavetable.h:31
static constexpr const mono_float * null_waveform()
Returns a constant pointer to a zeroed waveform.
Definition wavetable.h:71
static force_inline mono_float getFrequencyFloatBin(mono_float phase_increment)
Compute a float-based frequency bin from a phase increment.
Definition wavetable.h:144
int max_frames_
Maximum number of frames allocated for this wavetable.
Definition wavetable.h:374
force_inline void markUsed()
Mark the current wavetable data as used (active).
Definition wavetable.h:324
force_inline mono_float * getBuffer(int frame_index)
Get a pointer to the time-domain waveform buffer for a given frame.
Definition wavetable.h:184
void loadFrequencyAmplitudes(const std::complex< float > *frequencies, int to_index)
Load frequency amplitude data from a set of complex frequency-domain coefficients.
Definition wavetable.cpp:153
static constexpr int kWaveformSize
Size of each waveform frame.
Definition wavetable.h:25
void postProcess(float max_span)
Post-process the loaded wavetable frames, scaling them based on a maximum span.
Definition wavetable.cpp:102
force_inline int numFrames() const
Get the number of frames in the current wavetable data.
Definition wavetable.h:312
#define force_inline
Definition common.h:23
Contains faster but less accurate versions of utility math functions, such as exponential,...
force_inline poly_float log2(poly_float value)
Approximates log2(value) for poly_float values using a polynomial approximation.
Definition futils.h:68
force_inline int iclamp(int value, int min_val, int max_val)
Clamps an integer between [min_val, max_val].
Definition utils.h:250
force_inline int ilog2(int value)
Computes the floor of the base-2 logarithm of an integer (effectively the index of the highest set bi...
Definition utils.h:259
Contains classes and functions used within the Vital synthesizer framework.
constexpr int kDefaultSampleRate
Default sample rate in Hz.
Definition common.h:41
float mono_float
Definition common.h:33
Struct holding all necessary data for the Wavetable, including multiple frames.
Definition wavetable.h:41
WavetableData(int frames, int table_version)
Construct a new WavetableData object.
Definition wavetable.h:48
std::unique_ptr< poly_float[][kPolyFrequencySize]> frequency_amplitudes
Frequency amplitudes: an array of [num_frames][kPolyFrequencySize].
Definition wavetable.h:59
mono_float sample_rate
The sample rate associated with the wavetable frames.
Definition wavetable.h:53
int num_frames
The number of frames in the wavetable.
Definition wavetable.h:51
std::unique_ptr< poly_float[][kPolyFrequencySize]> phases
Phase data: an array of [num_frames][kPolyFrequencySize].
Definition wavetable.h:63
mono_float frequency_ratio
The frequency ratio used for playback.
Definition wavetable.h:52
std::unique_ptr< mono_float[][kWaveformSize]> wave_data
Time-domain wave data: an array of [num_frames][kWaveformSize].
Definition wavetable.h:57
int version
The version number of this wavetable data.
Definition wavetable.h:54
std::unique_ptr< poly_float[][kPolyFrequencySize]> normalized_frequencies
Normalized frequency data: an array of [num_frames][kPolyFrequencySize].
Definition wavetable.h:61
Represents a vector of floating-point values using SIMD instructions.
Definition poly_values.h:600
static force_inline simd_type vector_call load(const float *memory)
Loads floating-point values from memory into a SIMD register.
Definition poly_values.h:683
Provides various utility functions, classes, and constants for audio, math, and general-purpose opera...