20 inline double highResPowerScale(
float value,
float power) {
21 static constexpr float kMinPower = 0.01f;
22 if (fabsf(power) < kMinPower)
25 double abs_value = fabsf(value);
27 double numerator =
exp(power * abs_value) - 1.0f;
28 double denominator =
exp(power) - 1.0f;
30 return numerator / denominator;
31 return -numerator / denominator;
67 float warped_horizontal = 0.0f;
69 warped_horizontal = highResPowerScale(horizontal, horizontal_power_);
73 warped_horizontal = 0.5f * highResPowerScale(2.0f * horizontal - 1.0f, horizontal_power_) + 0.5f;
78 int index = float_index;
83 float vertical = linearTween(vertical_from, vertical_to, float_index - index);
88 wave_frame->
time_domain[i] = 2.0f * highResPowerScale(0.5f * vertical + 0.5f, vertical_power_) - 1.0f;
90 wave_frame->
time_domain[i] = highResPowerScale(vertical, vertical_power_);
97 data[
"horizontal_power"] = horizontal_power_;
98 data[
"vertical_power"] = vertical_power_;
104 horizontal_power_ = data[
"horizontal_power"];
105 vertical_power_ = data[
"vertical_power"];
A keyframe class holding horizontal and vertical warp parameters at a given position.
Definition wave_warp_modifier.h:35
float vertical_power_
Controls vertical (amplitude-axis) warping.
Definition wave_warp_modifier.h:96
bool vertical_asymmetric_
If true, vertical warping is asymmetric.
Definition wave_warp_modifier.h:99
float horizontal_power_
Controls horizontal (time-axis) warping.
Definition wave_warp_modifier.h:95
WaveWarpModifierKeyframe()
Constructs a WaveWarpModifierKeyframe with default warp powers and symmetric warping.
Definition wave_warp_modifier.cpp:35
void interpolate(const WavetableKeyframe *from_keyframe, const WavetableKeyframe *to_keyframe, float t) override
Linearly interpolates between two keyframes.
Definition wave_warp_modifier.cpp:48
void render(vital::WaveFrame *wave_frame) override
Renders the waveform of this keyframe into a WaveFrame.
Definition wave_warp_modifier.cpp:59
void jsonToState(json data) override
Restores the keyframe's state from a JSON object.
Definition wave_warp_modifier.cpp:102
void setVerticalAsymmetric(bool vertical_asymmetric)
Sets whether vertical warping is asymmetric.
Definition wave_warp_modifier.h:92
void copy(const WavetableKeyframe *keyframe) override
Copies the state from another keyframe of the same type.
Definition wave_warp_modifier.cpp:42
void setHorizontalAsymmetric(bool horizontal_asymmetric)
Sets whether horizontal warping is asymmetric.
Definition wave_warp_modifier.h:85
json stateToJson() override
Serializes the state of this keyframe to a JSON object.
Definition wave_warp_modifier.cpp:95
bool horizontal_asymmetric_
If true, horizontal warping is asymmetric.
Definition wave_warp_modifier.h:98
WaveWarpModifierKeyframe compute_frame_
Keyframe used for intermediate computation.
Definition wave_warp_modifier.h:153
WavetableKeyframe * createKeyframe(int position) override
Creates a new keyframe at a given position.
Definition wave_warp_modifier.cpp:108
bool horizontal_asymmetric_
Controls horizontal warping symmetry.
Definition wave_warp_modifier.h:154
void render(vital::WaveFrame *wave_frame, float position) override
Renders the waveform at a given position into a WaveFrame.
Definition wave_warp_modifier.cpp:114
json stateToJson() override
Serializes the component’s state and all keyframes to a JSON object.
Definition wave_warp_modifier.cpp:126
void jsonToState(json data) override
Restores the component’s state from a JSON object.
Definition wave_warp_modifier.cpp:133
bool vertical_asymmetric_
Controls vertical warping symmetry.
Definition wave_warp_modifier.h:155
WavetableComponentFactory::ComponentType getType() override
Returns the type of this WavetableComponent.
Definition wave_warp_modifier.cpp:122
WaveWarpModifierKeyframe * getKeyframe(int index)
Retrieves a WaveWarpModifierKeyframe by index.
Definition wave_warp_modifier.cpp:139
ComponentType
Enumerates all known WavetableComponents, including sources and modifiers.
Definition wavetable_component_factory.h:28
@ kWaveWarp
Modifier that warps the waveform.
Definition wavetable_component_factory.h:41
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
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
std::complex< float > frequency_domain[kWaveformSize]
The frequency-domain representation (complex spectrum).
Definition wave_frame.h:125
void toFrequencyDomain()
Converts the currently loaded time-domain data into frequency-domain representation.
Definition wave_frame.cpp:64
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
Contains faster but less accurate versions of utility math functions, such as exponential,...
nlohmann::json json
Definition line_generator.h:7
force_inline mono_float exp(mono_float exponent)
Definition futils.h:132
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 poly_float clamp(poly_float value, mono_float min, mono_float max)
Clamps each lane of a vector to [min, max].
Definition poly_utils.h:306
Provides various utility functions, classes, and constants for audio, math, and general-purpose opera...