Vital
|
Represents a single frame of a wavetable, containing both time-domain and frequency-domain data. More...
#include <wave_frame.h>
Public Member Functions | |
WaveFrame () | |
Constructs a WaveFrame with default frequency ratio and sample rate. | |
mono_float | getMaxZeroOffset () const |
Retrieves the maximum absolute amplitude in the time-domain waveform. | |
void | normalize (bool allow_positive_gain=false) |
Normalizes the time-domain waveform samples to have a maximum absolute value of 1.0. | |
void | clear () |
Clears the waveform data, resetting it to default states. | |
void | setFrequencyRatio (float ratio) |
Sets the frequency ratio for this wave frame. | |
void | setSampleRate (float rate) |
Sets the sample rate for this wave frame. | |
void | multiply (mono_float value) |
Multiplies all samples in both time and frequency domains by a given value. | |
void | loadTimeDomain (float *buffer) |
Loads time-domain data from a given buffer and updates the frequency domain accordingly. | |
void | addFrom (WaveFrame *source) |
Adds another WaveFrame's data to this one, sample-by-sample, in both time and frequency domains. | |
void | copy (const WaveFrame *other) |
Copies another WaveFrame's time and frequency domain data into this one. | |
void | toFrequencyDomain () |
Converts the currently loaded time-domain data into frequency-domain representation. | |
void | toTimeDomain () |
Converts the currently loaded frequency-domain data into time-domain representation. | |
void | removedDc () |
Removes the DC offset from the waveform. | |
float * | getFrequencyData () |
Gets a pointer to the frequency-domain data interpreted as floats. | |
Public Attributes | |
int | index |
The index of this frame in a wavetable. | |
float | frequency_ratio |
The frequency ratio for this frame (e.g., for pitch scaling). | |
float | sample_rate |
The sample rate associated with this frame. | |
mono_float | time_domain [2 *kWaveformSize] |
The time-domain data, extended buffer size for FFT alignment. | |
std::complex< float > | frequency_domain [kWaveformSize] |
The frequency-domain representation (complex spectrum). | |
Static Public Attributes | |
static constexpr int | kWaveformBits = 11 |
The number of bits that define the size of the waveform (2^kWaveformBits = kWaveformSize). | |
static constexpr int | kWaveformSize = 1 << kWaveformBits |
The size of the waveform (number of samples per frame). | |
static constexpr int | kNumRealComplex = kWaveformSize / 2 + 1 |
The number of real-valued frequency components (half the size + 1). | |
static constexpr int | kNumExtraComplex = kWaveformSize - kNumRealComplex |
The number of "extra" complex bins to pad after the real frequency components. | |
static constexpr float | kDefaultFrequencyRatio = 1.0f |
The default frequency ratio for a WaveFrame (usually 1.0f). | |
static constexpr float | kDefaultSampleRate = 44100.0f |
The default sample rate for a WaveFrame. | |
Represents a single frame of a wavetable, containing both time-domain and frequency-domain data.
A WaveFrame holds a waveform in both time-domain and frequency-domain forms. It allows for operations such as normalization, clearing, transforming between time and frequency domains, and other utility functions to manipulate or analyze the waveform.
|
inline |
Constructs a WaveFrame with default frequency ratio and sample rate.
The waveform data is initialized to zero, and frequency/time domains are ready for loading or processing.
void vital::WaveFrame::addFrom | ( | WaveFrame * | source | ) |
void vital::WaveFrame::clear | ( | ) |
Clears the waveform data, resetting it to default states.
This sets the frequency ratio, sample rate to defaults, and zeros all frequency_domain and time_domain samples.
void vital::WaveFrame::copy | ( | const WaveFrame * | other | ) |
|
inline |
Gets a pointer to the frequency-domain data interpreted as floats.
mono_float vital::WaveFrame::getMaxZeroOffset | ( | ) | const |
Retrieves the maximum absolute amplitude in the time-domain waveform.
void vital::WaveFrame::loadTimeDomain | ( | float * | buffer | ) |
Loads time-domain data from a given buffer and updates the frequency domain accordingly.
buffer | Pointer to a float array of length kWaveformSize containing the time-domain samples. |
void vital::WaveFrame::multiply | ( | mono_float | value | ) |
Multiplies all samples in both time and frequency domains by a given value.
value | The value by which to scale the waveform data. |
void vital::WaveFrame::normalize | ( | bool | allow_positive_gain = false | ) |
Normalizes the time-domain waveform samples to have a maximum absolute value of 1.0.
allow_positive_gain | If true, allows scaling up the waveform if it's below the normalization threshold, otherwise only scales down. |
void vital::WaveFrame::removedDc | ( | ) |
Removes the DC offset from the waveform.
This modifies the time_domain samples by subtracting the DC component. The DC component is derived from the frequency_domain[0] bin.
Removes DC offset from the waveform by subtracting the imaginary part of frequency_domain[0].
The DC offset is found in the imaginary component of the first frequency bin. Subtracting this value from time_domain samples removes any constant offset.
|
inline |
Sets the frequency ratio for this wave frame.
ratio | The new frequency ratio value. |
|
inline |
Sets the sample rate for this wave frame.
rate | The new sample rate. |
void vital::WaveFrame::toFrequencyDomain | ( | ) |
Converts the currently loaded time-domain data into frequency-domain representation.
Converts the time_domain data into the frequency_domain representation using FFT.
This uses a forward real-to-complex FFT. The frequency_domain will then contain complex frequency bins representing the spectrum of the waveform.
void vital::WaveFrame::toTimeDomain | ( | ) |
Converts the currently loaded frequency-domain data into time-domain representation.
Converts the frequency_domain data back into the time_domain representation using an inverse FFT.
This restores the waveform from its frequency bins. If modifications were made in the frequency domain, this will produce the corresponding time-domain waveform.
std::complex<float> vital::WaveFrame::frequency_domain[kWaveformSize] |
The frequency-domain representation (complex spectrum).
float vital::WaveFrame::frequency_ratio |
The frequency ratio for this frame (e.g., for pitch scaling).
int vital::WaveFrame::index |
The index of this frame in a wavetable.
|
staticconstexpr |
The default frequency ratio for a WaveFrame (usually 1.0f).
|
staticconstexpr |
The default sample rate for a WaveFrame.
|
staticconstexpr |
The number of "extra" complex bins to pad after the real frequency components.
|
staticconstexpr |
The number of real-valued frequency components (half the size + 1).
|
staticconstexpr |
The number of bits that define the size of the waveform (2^kWaveformBits = kWaveformSize).
|
staticconstexpr |
The size of the waveform (number of samples per frame).
float vital::WaveFrame::sample_rate |
The sample rate associated with this frame.
mono_float vital::WaveFrame::time_domain[2 *kWaveformSize] |
The time-domain data, extended buffer size for FFT alignment.