Performs the spectral operation specified by m_operation on the input data. Operations are performed using FFT/IFFT transforms with windowing for overlap-add processing. Supports both in-place and out-of-place transformations.
75 {
78 auto shift_hz = get_parameter_or<double>("shift_hz", 0.0);
79 auto window_size = get_parameter_or<uint32_t>("window_size", 1024);
80 auto hop_size = get_parameter_or<uint32_t>("hop_size", 512);
81 auto sample_rate = get_parameter_or<double>("sample_rate", 48000.0);
82
83 auto low_freq = std::max(0.0, shift_hz);
84 auto high_freq = sample_rate / 2.0 + shift_hz;
85
88 }
90 }
91
93 auto pitch_ratio = get_parameter_or<double>("pitch_ratio", 1.0);
94 auto window_size = get_parameter_or<uint32_t>("window_size", 1024);
95 auto hop_size = get_parameter_or<uint32_t>("hop_size", 512);
96
97 double semitones = 12.0 * std::log2(pitch_ratio);
98
101 }
103 }
104
106 auto low_freq = get_parameter_or<double>("low_freq", 20.0);
107 auto high_freq = get_parameter_or<double>("high_freq", 20000.0);
108 auto window_size = get_parameter_or<uint32_t>("window_size", 1024);
109 auto hop_size = get_parameter_or<uint32_t>("hop_size", 512);
110 auto sample_rate = get_parameter_or<double>("sample_rate", 48000.0);
111
114 }
116 }
117
119 auto enhancement_factor = get_parameter_or<double>("enhancement_factor", 2.0);
120 auto window_size = get_parameter_or<uint32_t>("window_size", 1024);
121 auto hop_size = get_parameter_or<uint32_t>("hop_size", 512);
122
125
126 auto processor = [enhancement_factor](Eigen::VectorXcd& spectrum, size_t) {
127 for (int i = 1; i < spectrum.size() / 2; ++i) {
128 double freq_factor = 1.0 + (enhancement_factor - 1.0) * (double(i) / (spectrum.size() / 2));
129 spectrum[i] *= freq_factor;
130 spectrum[spectrum.size() - i] *= freq_factor;
131 }
132 };
133
134 for (auto& span : data_span) {
136 std::ranges::copy(result, span.begin());
137 }
138
139 auto reconstructed_data = data_span
140 | std::views::transform([](const auto& span) {
141 return std::vector<double>(span.begin(), span.end());
142 })
143 | std::ranges::to<std::vector>();
144
145 return create_output(OperationHelper::reconstruct_from_double<InputType>(reconstructed_data, structure_info));
146 }
147
149 auto processor = [enhancement_factor](Eigen::VectorXcd& spectrum, size_t) {
150 for (int i = 1; i < spectrum.size() / 2; ++i) {
151 double freq_factor = 1.0 + (enhancement_factor - 1.0) * (double(i) / (spectrum.size() / 2));
152 spectrum[i] *= freq_factor;
153 spectrum[spectrum.size() - i] *= freq_factor;
154 }
155 };
156
157 for (size_t i = 0; i < target_data.size(); ++i) {
160 }
161
163 }
164
166 auto threshold = get_parameter_or<double>("threshold", -40.0);
167 auto window_size = get_parameter_or<uint32_t>("window_size", 1024);
168 auto hop_size = get_parameter_or<uint32_t>("hop_size", 512);
169
170 double linear_threshold = std::pow(10.0, threshold / 20.0);
171
174
175 auto processor = [linear_threshold](Eigen::VectorXcd& spectrum, size_t) {
176 std::ranges::transform(spectrum, spectrum.begin(), [linear_threshold](const std::complex<double>& bin) {
177 return (std::abs(bin) > linear_threshold) ? bin : std::complex<double>(0.0, 0.0);
178 });
179 };
180
181 for (auto& span : data_span) {
183 std::ranges::copy(result, span.begin());
184 }
185
186 auto reconstructed_data = data_span
187 | std::views::transform([](const auto& span) {
188 return std::vector<double>(span.begin(), span.end());
189 })
190 | std::ranges::to<std::vector>();
191
192 return create_output(OperationHelper::reconstruct_from_double<InputType>(reconstructed_data, structure_info));
193 }
194
196 auto processor = [linear_threshold](Eigen::VectorXcd& spectrum, size_t) {
197 std::ranges::transform(spectrum, spectrum.begin(), [linear_threshold](const std::complex<double>& bin) {
198 return (std::abs(bin) > linear_threshold) ? bin : std::complex<double>(0.0, 0.0);
199 });
200 };
201
202 for (size_t i = 0; i < target_data.size(); ++i) {
205 }
206
208 }
209
210 default:
212 }
213 }
static std::tuple< std::vector< std::span< double > >, DataStructureInfo > extract_structured_double(T &compute_data)
Extract structured double data from IO container or direct ComputeData with automatic container handl...
static auto setup_operation_buffer(T &input, std::vector< std::vector< double > > &working_buffer)
Setup operation buffer from IO or ComputeData type.
std::vector< double > process_spectral_windows(std::span< double > data, uint32_t window_size, uint32_t hop_size, ProcessorFunc &&processor)
Common spectral processing helper to eliminate code duplication.
@ SPECTRAL_FILTER
Filter frequency bands.
@ SPECTRAL_GATE
Spectral gating.
@ HARMONIC_ENHANCE
Enhance harmonics.
@ PITCH_SHIFT
Pitch-preserving shift.
@ FREQUENCY_SHIFT
Shift entire spectrum.
DataType transform_spectral_filter(DataType &input, double low_freq, double high_freq, double sample_rate=48000.0, uint32_t window_size=1024, uint32_t hop_size=256)
Spectral filtering using existing FFT infrastructure with C++20 ranges (IN-PLACE)
DataType transform_pitch_shift(DataType &input, double semitones, uint32_t window_size=1024, uint32_t hop_size=256)
Pitch shifting using existing FFT from AnalysisHelper with C++20 ranges (IN-PLACE)