MayaFlux 1.0.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 104 of file MathematicalTransformer.hpp.

105 {
106 switch (m_operation) {
107
109 const auto a = get_parameter_or<double>("gain_factor", 1.0);
110 return apply_per_channel(input, [a](std::span<double> ch) {
111 D::linear(ch, a, 0.0);
112 });
113 }
114
116 const auto b = get_parameter_or<double>("offset_value", 0.0);
117 return apply_per_channel(input, [b](std::span<double> ch) {
118 D::linear(ch, 1.0, b);
119 });
120 }
121
123 const auto exp = get_parameter_or<double>("exponent", 2.0);
124 return apply_per_channel(input, [exp](std::span<double> ch) {
125 D::power(ch, exp);
126 });
127 }
128
130 const auto a = get_parameter_or<double>("scale", 1.0);
131 const auto b = get_parameter_or<double>("input_scale", 1.0);
132 const auto c = get_parameter_or<double>("offset", 1.0);
133 const auto base = get_parameter_or<double>("base", std::numbers::e);
134 return apply_per_channel(input, [a, b, c, base](std::span<double> ch) {
135 D::logarithmic(ch, a, b, c, base);
136 });
137 }
138
140 const auto a = get_parameter_or<double>("scale", 1.0);
141 const auto b = get_parameter_or<double>("rate", 1.0);
142 const auto base = get_parameter_or<double>("base", std::numbers::e);
143 return apply_per_channel(input, [a, b, base](std::span<double> ch) {
144 D::exponential(ch, a, b, base);
145 });
146 }
147
149 const auto fn = get_parameter_or<std::string>("trig_function", "sin");
150 const auto freq = get_parameter_or<double>("frequency", 1.0);
151 const auto amp = get_parameter_or<double>("amplitude", 1.0);
152 const auto ph = get_parameter_or<double>("phase", 0.0);
153 if (fn == "cos")
154 return apply_per_channel(input, [freq, amp, ph](std::span<double> ch) {
155 D::apply_trig(ch, [](double x) { return std::cos(x); }, freq, amp, ph);
156 });
157 if (fn == "tan")
158 return apply_per_channel(input, [freq, amp, ph](std::span<double> ch) {
159 D::apply_trig(ch, [](double x) { return std::tan(x); }, freq, amp, ph);
160 });
161 return apply_per_channel(input, [freq, amp, ph](std::span<double> ch) {
162 D::apply_trig(ch, [](double x) { return std::sin(x); }, freq, amp, ph);
163 });
164 }
165
167 const auto bits = get_parameter_or<uint8_t>("bits", 16);
168 return apply_per_channel(input, [bits](std::span<double> ch) {
169 D::quantize(ch, bits);
170 });
171 }
172
174 const auto peak = get_parameter_or<double>("target_peak", 1.0);
175 return apply_per_channel(input, [peak](std::span<double> ch) {
176 D::normalize(ch, -peak, peak);
177 });
178 }
179
181 const auto coeffs = get_parameter_or<std::vector<double>>(
182 "coefficients", std::vector<double> { 0.0, 1.0 });
183 auto poly = std::make_shared<Nodes::Generator::Polynomial>(coeffs);
184 return apply_per_channel(input, [&poly](std::span<double> ch) {
185 std::ranges::transform(ch, ch.begin(),
186 [&poly](double x) { return poly->process_sample(x); });
187 });
188 }
189
190 default:
191 return create_output(input);
192 }
193 }
Core::GlobalInputConfig input
Definition Config.cpp:42
size_t a
size_t b
uint32_t ph
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 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 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 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
std::vector< double > peak(std::span< const double > data, size_t n_windows, uint32_t hop_size, uint32_t window_size)
Peak amplitude per window.
Definition Analysis.cpp:51
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 linear(std::span< double > data, double a, double b) noexcept
Linear map y = a*x + b applied in-place.
Definition Transform.cpp:11
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.

References a, MayaFlux::Yantra::MathematicalTransformer< InputType, OutputType >::apply_per_channel(), MayaFlux::Kinesis::Discrete::apply_trig(), b, MayaFlux::Yantra::MathematicalTransformer< InputType, OutputType >::create_output(), MayaFlux::Kinesis::Discrete::exponential(), MayaFlux::Yantra::EXPONENTIAL, MayaFlux::Yantra::GAIN, input, MayaFlux::Kinesis::Discrete::linear(), MayaFlux::Kinesis::Discrete::logarithmic(), MayaFlux::Yantra::LOGARITHMIC, MayaFlux::Yantra::MathematicalTransformer< InputType, OutputType >::m_operation, MayaFlux::Kinesis::Discrete::normalize(), MayaFlux::Yantra::NORMALIZE, MayaFlux::Yantra::OFFSET, ph, MayaFlux::Yantra::POLYNOMIAL, MayaFlux::Kinesis::Discrete::power(), MayaFlux::Yantra::POWER, MayaFlux::Kinesis::Discrete::quantize(), MayaFlux::Yantra::QUANTIZE, and MayaFlux::Yantra::TRIGONOMETRIC.

+ Here is the call graph for this function: