MayaFlux 0.3.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ transform_implementation()

template<ComputeData InputType = std::vector<Kakshya::DataVariant>, ComputeData OutputType = InputType>
output_type MayaFlux::Yantra::MathematicalTransformer< InputType, OutputType >::transform_implementation ( input_type input)
inlineoverrideprotectedvirtual

Core transformation implementation.

Parameters
inputInput data to transform
Returns
Transformed output data

Performs the mathematical operation specified by m_operation on the input data. Supports both in-place and out-of-place transformations based on transformer settings.

Implements MayaFlux::Yantra::UniversalTransformer< InputType, OutputType >.

Definition at line 80 of file MathematicalTransformer.hpp.

81 {
82 switch (m_operation) {
83
85 const auto a = get_parameter_or<double>("gain_factor", 1.0);
86 return apply_per_channel(input, [a](std::span<double> ch) {
87 D::linear(ch, a, 0.0);
88 });
89 }
90
92 const auto b = get_parameter_or<double>("offset_value", 0.0);
93 return apply_per_channel(input, [b](std::span<double> ch) {
94 D::linear(ch, 1.0, b);
95 });
96 }
97
99 const auto exp = get_parameter_or<double>("exponent", 2.0);
100 return apply_per_channel(input, [exp](std::span<double> ch) {
101 D::power(ch, exp);
102 });
103 }
104
106 const auto a = get_parameter_or<double>("scale", 1.0);
107 const auto b = get_parameter_or<double>("input_scale", 1.0);
108 const auto c = get_parameter_or<double>("offset", 1.0);
109 const auto base = get_parameter_or<double>("base", std::numbers::e);
110 return apply_per_channel(input, [a, b, c, base](std::span<double> ch) {
111 D::logarithmic(ch, a, b, c, base);
112 });
113 }
114
116 const auto a = get_parameter_or<double>("scale", 1.0);
117 const auto b = get_parameter_or<double>("rate", 1.0);
118 const auto base = get_parameter_or<double>("base", std::numbers::e);
119 return apply_per_channel(input, [a, b, base](std::span<double> ch) {
120 D::exponential(ch, a, b, base);
121 });
122 }
123
125 const auto fn = get_parameter_or<std::string>("trig_function", "sin");
126 const auto freq = get_parameter_or<double>("frequency", 1.0);
127 const auto amp = get_parameter_or<double>("amplitude", 1.0);
128 const auto ph = get_parameter_or<double>("phase", 0.0);
129 if (fn == "cos")
130 return apply_per_channel(input, [freq, amp, ph](std::span<double> ch) {
131 D::apply_trig(ch, [](double x) { return std::cos(x); }, freq, amp, ph);
132 });
133 if (fn == "tan")
134 return apply_per_channel(input, [freq, amp, ph](std::span<double> ch) {
135 D::apply_trig(ch, [](double x) { return std::tan(x); }, freq, amp, ph);
136 });
137 return apply_per_channel(input, [freq, amp, ph](std::span<double> ch) {
138 D::apply_trig(ch, [](double x) { return std::sin(x); }, freq, amp, ph);
139 });
140 }
141
143 const auto bits = get_parameter_or<uint8_t>("bits", 16);
144 return apply_per_channel(input, [bits](std::span<double> ch) {
145 D::quantize(ch, bits);
146 });
147 }
148
150 const auto peak = get_parameter_or<double>("target_peak", 1.0);
151 return apply_per_channel(input, [peak](std::span<double> ch) {
152 D::normalize(ch, -peak, peak);
153 });
154 }
155
157 const auto coeffs = get_parameter_or<std::vector<double>>(
158 "coefficients", std::vector<double> { 0.0, 1.0 });
159 auto poly = std::make_shared<Nodes::Generator::Polynomial>(coeffs);
160 return apply_per_channel(input, [&poly](std::span<double> ch) {
161 std::ranges::transform(ch, ch.begin(),
162 [&poly](double x) { return poly->process_sample(x); });
163 });
164 }
165
166 default:
167 return create_output(input);
168 }
169 }
size_t a
size_t b
output_type create_output(const input_type &input)
Creates output with proper type conversion.
MathematicalOperation m_operation
Current mathematical operation.
output_type apply_per_channel(input_type &input, Func &&func)
Extracts per-channel spans, applies an in-place func to each, and reconstructs.
void exponential(std::span< double > data, double a, double b, double base) noexcept
Exponential map y = a * base^(b*x) applied in-place Scalar transcendental — not SIMD hot-path.
Definition Transform.cpp:23
void linear(std::span< double > data, double a, double b) noexcept
Linear map y = a*x + b applied in-place.
Definition Transform.cpp:11
void normalize(std::span< double > data, double target_min, double target_max) noexcept
Normalize to [target_min, target_max] in-place Single-pass min/max reduction followed by a single tra...
Definition Transform.cpp:61
void logarithmic(std::span< double > data, double a, double b, double c, double base) noexcept
Logarithmic map y = a * log_base(b*x + c) applied in-place Values where (b*x + c) <= 0 are mapped to ...
Definition Transform.cpp:34
void quantize(std::span< double > data, uint8_t bits) noexcept
Quantize to n-bit resolution in-place Input is assumed to be in [-1, 1]; values outside are clamped f...
Definition Transform.cpp:50
std::vector< double > power(std::span< const double > data, size_t n_windows, uint32_t hop_size, uint32_t window_size)
Power (sum of squares) per window.
Definition Analysis.cpp:70
void apply_trig(std::span< double > data, TrigFunc func, double frequency, double amplitude, double phase) noexcept
Trigonometric map y = amplitude * f(frequency*x + phase) applied in-place.
Definition Transform.hpp:81
@ GAIN
Linear gain/attenuation.
@ QUANTIZE
Quantization/bit reduction.
@ TRIGONOMETRIC
Trigonometric functions.
@ LOGARITHMIC
Logarithmic transform.
@ EXPONENTIAL
Exponential transform.
double peak(const std::vector< double > &data)
Find peak amplitude in single-channel data.
Definition Yantra.cpp:216

References a, b, and MayaFlux::peak().

+ Here is the call graph for this function: