71 float range_prev,
float range,
float range_next,
float t) {
77 range_prev, range, range_next, t);
88 float amplitude =
linearTween(amplitude_from, amplitude_to, t);
89 amplitude *= amplitude;
94 float phase = phase_from + t * phase_delta;
95 if (amplitude_from == 0)
97 wave_frame_->frequency_domain[i] = std::polar(amplitude, phase);
114 float range_prev,
float range,
float range_next,
float t) {
121 float amplitude =
cubicTween(amplitude_prev, amplitude_from, amplitude_to, amplitude_next,
122 range_prev, range, range_next, t);
123 amplitude *= amplitude;
130 float phase_from = phase_prev;
132 phase_from += phase_delta_from;
133 float phase_to = phase_from;
135 phase_to += phase_delta_to;
136 float phase_next = phase_to;
138 phase_next += phase_delta_next;
140 float phase =
cubicTween(phase_prev, phase_from, phase_to, phase_next, range_prev, range, range_next, t);
141 wave_frame_->frequency_domain[i] = std::polar(amplitude, phase);
149 wave_frame_->frequency_domain[0] =
cubicTween(dc_prev, dc_from, dc_to, dc_next, range_prev, range, range_next, t);
157 last_harmonic_to, last_harmonic_next,
158 range_prev, range, range_next, t);
197 data[
"wave_data"] = encoded.toStdString();
205 std::string wave_data = data[
"wave_data"];
206 Base64::convertFromBase64(decoded, wave_data);
json stateToJson() override
Serializes the component’s state and all keyframes to a JSON object.
Definition wave_source.cpp:35
std::unique_ptr< WaveSourceKeyframe > compute_frame_
A keyframe for intermediate interpolation computations.
Definition wave_source.h:79
virtual ~WaveSource()
Definition wave_source.cpp:15
InterpolationMode interpolation_mode_
The mode of interpolation.
Definition wave_source.h:80
void jsonToState(json data) override
Restores the component’s state from a JSON object.
Definition wave_source.cpp:41
vital::WaveFrame * getWaveFrame(int index)
Gets a WaveFrame from a specified keyframe index.
Definition wave_source.cpp:47
void render(vital::WaveFrame *wave_frame, float position) override
Renders the waveform at a given position into a WaveFrame.
Definition wave_source.cpp:24
WaveSourceKeyframe * getKeyframe(int index)
Retrieves a WaveSourceKeyframe by index.
Definition wave_source.cpp:51
WavetableKeyframe * createKeyframe(int position) override
Creates a new keyframe at a given position.
Definition wave_source.cpp:17
@ kFrequency
Interpolate in frequency domain.
Definition wave_source.h:33
WaveSource()
Constructs a WaveSource with a default frequency-domain interpolation mode.
Definition wave_source.cpp:10
WavetableComponentFactory::ComponentType getType() override
Returns the type of this WavetableComponent.
Definition wave_source.cpp:31
A keyframe that holds a single WaveFrame and supports various interpolation methods.
Definition wave_source.h:92
WaveSource::InterpolationMode interpolation_mode_
The mode (time or frequency) used for this keyframe's interpolation.
Definition wave_source.h:199
void copy(const WavetableKeyframe *keyframe) override
Copies the state from another keyframe of the same type.
Definition wave_source.cpp:56
void smoothInterpolate(const WavetableKeyframe *prev_keyframe, const WavetableKeyframe *from_keyframe, const WavetableKeyframe *to_keyframe, const WavetableKeyframe *next_keyframe, float t) override
Performs a smooth (cubic) interpolation using four keyframes for even smoother transitions.
Definition wave_source.cpp:173
void cubicTimeInterpolate(const vital::WaveFrame *prev, const vital::WaveFrame *from, const vital::WaveFrame *to, const vital::WaveFrame *next, float range_prev, float range, float range_next, float t)
Cubic interpolation in time domain using four WaveFrames for smooth transitions.
Definition wave_source.cpp:69
void linearFrequencyInterpolate(const vital::WaveFrame *from, const vital::WaveFrame *to, float t)
Linear interpolation in frequency domain.
Definition wave_source.cpp:82
json stateToJson() override
Serializes the state of this keyframe to a JSON object.
Definition wave_source.cpp:193
void setInterpolationMode(WaveSource::InterpolationMode mode)
Sets the interpolation mode for this keyframe.
Definition wave_source.h:188
void jsonToState(json data) override
Restores the keyframe's state from a JSON object.
Definition wave_source.cpp:201
void linearTimeInterpolate(const vital::WaveFrame *from, const vital::WaveFrame *to, float t)
Linearly interpolate two WaveFrames in the time domain.
Definition wave_source.cpp:62
std::unique_ptr< vital::WaveFrame > wave_frame_
The WaveFrame representing this keyframe’s waveform.
Definition wave_source.h:198
vital::WaveFrame * wave_frame()
Provides direct access to the stored WaveFrame.
Definition wave_source.h:107
void cubicFrequencyInterpolate(const vital::WaveFrame *prev, const vital::WaveFrame *from, const vital::WaveFrame *to, const vital::WaveFrame *next, float range_prev, float range, float range_next, float t)
Cubic interpolation in frequency domain using four WaveFrames.
Definition wave_source.cpp:112
void interpolate(const WavetableKeyframe *from_keyframe, const WavetableKeyframe *to_keyframe, float t) override
Linearly interpolates between two keyframes.
Definition wave_source.cpp:162
ComponentType
Enumerates all known WavetableComponents, including sources and modifiers.
Definition wavetable_component_factory.h:28
@ kWaveSource
A basic wave source.
Definition wavetable_component_factory.h:29
virtual json stateToJson()
Serializes the component’s state and all keyframes to a JSON object.
Definition wavetable_component.cpp:49
void interpolate(WavetableKeyframe *dest, float position)
Interpolates a destination keyframe at a given position.
Definition wavetable_component.cpp:68
virtual void jsonToState(json data)
Restores the component’s state from a JSON object.
Definition wavetable_component.cpp:37
std::vector< std::unique_ptr< WavetableKeyframe > > keyframes_
The list of keyframes sorted by position.
Definition wavetable_component.h:219
Represents a single state of a waveform at a specific position in a wavetable.
Definition wavetable_keyframe.h:35
static float linearTween(float point_from, float point_to, float t)
Performs linear interpolation between two points.
Definition wavetable_keyframe.cpp:11
int position() const
Gets the wavetable frame position of this keyframe.
Definition wavetable_keyframe.h:81
static float cubicTween(float point_prev, float point_from, float point_to, float point_next, float range_prev, float range, float range_next, float t)
Performs cubic interpolation taking into account a previous and next point for smoother curves.
Definition wavetable_keyframe.cpp:16
virtual json stateToJson()
Serializes the state of this keyframe to a JSON object.
Definition wavetable_keyframe.cpp:37
virtual void jsonToState(json data)
Restores the keyframe's state from a JSON object.
Definition wavetable_keyframe.cpp:41
Represents a single frame of a wavetable, containing both time-domain and frequency-domain data.
Definition wave_frame.h:16
void copy(const WaveFrame *other)
Copies another WaveFrame's time and frequency domain data into this one.
Definition wave_frame.cpp:57
std::complex< float > frequency_domain[kWaveformSize]
The frequency-domain representation (complex spectrum).
Definition wave_frame.h:125
static constexpr int kWaveformSize
The size of the waveform (number of samples per frame).
Definition wave_frame.h:21
mono_float time_domain[2 *kWaveformSize]
The time-domain data, extended buffer size for FFT alignment.
Definition wave_frame.h:124
static constexpr int kNumRealComplex
The number of real-valued frequency components (half the size + 1).
Definition wave_frame.h:23
nlohmann::json json
Definition line_generator.h:7