32template <ComputeData InputType = std::vector<Kakshya::DataVariant>, ComputeData OutputType = InputType>
45 set_default_parameters();
54 return TransformationType::TEMPORAL;
63 return std::string(
"TemporalTransformer_").append(Utils::enum_to_string(m_operation));
79 switch (m_operation) {
80 case TemporalOperation::TIME_REVERSE: {
81 if (this->is_in_place()) {
88 case TemporalOperation::TIME_STRETCH: {
89 auto stretch_factor = get_parameter_or<double>(
"stretch_factor", 1.0);
90 if (this->is_in_place()) {
97 case TemporalOperation::DELAY: {
98 auto delay_samples = get_parameter_or<uint32_t>(
"delay_samples", 1000);
99 auto fill_value = get_parameter_or<double>(
"fill_value", 0.0);
100 if (this->is_in_place()) {
101 return create_output(
transform_delay(input, delay_samples, fill_value));
104 return create_output(
transform_delay(input, delay_samples, fill_value, m_working_buffer));
107 case TemporalOperation::FADE_IN_OUT: {
108 auto fade_in_ratio = get_parameter_or<double>(
"fade_in_ratio", 0.1);
109 auto fade_out_ratio = get_parameter_or<double>(
"fade_out_ratio", 0.1);
110 if (this->is_in_place()) {
111 return create_output(
transform_fade(input, fade_in_ratio, fade_out_ratio));
114 return create_output(
transform_fade(input, fade_in_ratio, fade_out_ratio, m_working_buffer));
117 case TemporalOperation::SLICE: {
118 auto start_ratio = get_parameter_or<double>(
"start_ratio", 0.0);
119 auto end_ratio = get_parameter_or<double>(
"end_ratio", 1.0);
120 if (this->is_in_place()) {
124 return create_output(
transform_slice(input, start_ratio, end_ratio, m_working_buffer));
127 case TemporalOperation::INTERPOLATE: {
128 auto target_size = get_parameter_or<size_t>(
"target_size", 0);
129 auto use_cubic = get_parameter_or<bool>(
"use_cubic",
false);
130 if (target_size > 0) {
132 if (this->is_in_place()) {
139 if (this->is_in_place()) {
144 return create_output(input);
148 return create_output(input);
171 if (name ==
"operation") {
172 if (
auto op_result = safe_any_cast<TemporalOperation>(value)) {
173 m_operation = *op_result.value;
176 if (
auto str_result = safe_any_cast<std::string>(value)) {
177 if (
auto op_enum = Utils::string_to_enum_case_insensitive<TemporalOperation>(*str_result.value)) {
178 m_operation = *op_enum;
200 this->set_parameter(
"stretch_factor", 1.0);
201 this->set_parameter(
"delay_samples", uint32_t { 1000 });
202 this->set_parameter(
"fill_value", 0.0);
203 this->set_parameter(
"fade_in_ratio", 0.1);
204 this->set_parameter(
"fade_out_ratio", 0.1);
205 this->set_parameter(
"start_ratio", 0.0);
206 this->set_parameter(
"end_ratio", 1.0);
207 this->set_parameter(
"target_size",
size_t { 0 });
208 this->set_parameter(
"use_cubic",
false);
218 template <
typename T>
221 auto param = this->get_transformation_parameter(name);
222 if (!param.has_value())
223 return default_value;
225 auto result = safe_any_cast<T>(param);
226 return result.value_or(default_value);
240 if constexpr (std::is_same_v<InputType, OutputType>) {
243 auto [result_data, metadata] = OperationHelper::extract_structured_double(input);
244 return this->convert_result(result_data, metadata);
DataType interpolate_cubic(DataType &input, size_t target_size)
Cubic interpolation between data points using C++20 ranges (IN-PLACE)
DataType interpolate_linear(DataType &input, size_t target_size)
Linear interpolation between data points using C++20 ranges (IN-PLACE)
DataType transform_time_reverse(DataType &input)
Time reversal transformation using C++20 ranges (IN-PLACE)
DataType transform_delay(DataType &input, uint32_t delay_samples, double fill_value=0.0)
Delay transformation that extends buffer size (IN-PLACE)
DataType transform_time_stretch(DataType &input, double stretch_factor)
Simple time stretching via resampling using C++20 ranges (IN-PLACE)
DataType transform_slice(DataType &input, double start_ratio, double end_ratio)
Slice transformation to extract a portion of the data based on ratios (IN-PLACE)
DataType transform_fade(DataType &input, double fade_in_duration_ratio=0.0, double fade_out_duration_ratio=0.0)
Fade transformation (linear fade-in and fade-out) using C++20 ranges (IN-PLACE)
TransformationType
Categories of transformation operations for discovery and organization.
TemporalOperation
Specific temporal operations supported.
@ SLICE
Extract temporal slice.
@ TIME_REVERSE
Reverse temporal order.
@ TIME_STRETCH
Change playback speed.
@ DELAY
Add temporal delay.
@ FADE_IN_OUT
Apply fade envelope.
@ INTERPOLATE
Temporal interpolation.
Input/Output container for computation pipeline data flow with structure preservation.