222 {
223 try {
225 DataStructureInfo structure_info = info;
226
227 std::vector<std::span<const double>> data_span;
228 data_span.reserve(numeric_data.size());
229
230 for (auto& span : numeric_data) {
231 data_span.emplace_back(span.data(), span.size());
232 }
233
234 std::vector<std::vector<double>> extracted_data;
235
238 double energy_threshold = this->template get_parameter_or_default<double>("energy_threshold", 0.1);
240 break;
241 }
243 double threshold = this->template get_parameter_or_default<double>("threshold", 0.1);
244 double min_distance = this->template get_parameter_or_default<double>("min_distance", 10.0);
245 uint32_t region_size = this->template get_parameter_or_default<uint32_t>("region_size", 256);
246 extracted_data =
extract_peak_data(data_span, threshold, min_distance, region_size);
247 break;
248 }
250 double std_dev_threshold = this->template get_parameter_or_default<double>("std_dev_threshold", 2.0);
252 break;
253 }
255 double spectral_threshold = this->template get_parameter_or_default<double>("spectral_threshold", 0.1);
257 break;
258 }
260 double mean_multiplier = this->template get_parameter_or_default<double>("mean_multiplier", 1.5);
262 break;
263 }
265 double overlap = this->template get_parameter_or_default<double>("overlap", 0.5);
267 break;
268 }
270 double threshold = this->template get_parameter_or_default<double>("threshold", 0.0);
271 double min_distance = this->template get_parameter_or_default<double>("min_distance", 1.0);
272 uint32_t region_size = this->template get_parameter_or_default<uint32_t>("region_size", 1);
274 break;
275 }
277 double silence_threshold = this->template get_parameter_or_default<double>("silence_threshold", 0.01);
278 uint32_t min_duration = this->template get_parameter_or_default<uint32_t>("min_duration", 1024);
280 break;
281 }
283 double threshold = this->template get_parameter_or_default<double>("threshold", 0.3);
284 uint32_t region_size = this->template get_parameter_or_default<uint32_t>("region_size", 512);
285 uint32_t fft_window = this->template get_parameter_or_default<uint32_t>("fft_window_size", 1024);
287 break;
288 }
289 default:
290 throw std::invalid_argument("Unknown extraction method");
291 }
292
293 output_type output = this->convert_result(extracted_data, structure_info);
294
295 output.template set_metadata<std::string>("extractor_type", "FeatureExtractor");
297 output.template set_metadata<uint32_t>(
"window_size",
static_cast<uint32_t
>(
m_window_size));
298 output.template set_metadata<uint32_t>(
"hop_size",
static_cast<uint32_t
>(
m_hop_size));
299 output.template set_metadata<size_t>("extracted_samples", extracted_data.size());
300 output.template set_metadata<size_t>("original_samples", data_span.size());
301
302 return output;
303
304 } catch (const std::exception& e) {
305 throw std::runtime_error(std::string("FeatureExtractor failed: ") + e.what());
306 }
307 }
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...
std::vector< std::vector< double > > extract_overlapping_windows(const std::vector< std::span< const double > > &data, uint32_t window_size, double overlap)
Extract overlapping windows of actual data.
std::vector< std::vector< double > > extract_outlier_data(const std::vector< std::span< const double > > &data, double std_dev_threshold, uint32_t window_size, uint32_t hop_size)
Extract data from statistical outlier regions.
std::vector< std::vector< double > > extract_silence_data(const std::vector< std::span< const double > > &data, double silence_threshold, uint32_t min_duration, uint32_t window_size, uint32_t hop_size)
Extract data from silent regions using existing EnergyAnalyzer.
std::vector< std::vector< double > > extract_high_spectral_data(const std::vector< std::span< const double > > &data, double spectral_threshold, uint32_t window_size, uint32_t hop_size)
Extract data from regions with high spectral energy.
std::vector< std::vector< double > > extract_onset_data(const std::vector< std::span< const double > > &data, double threshold, uint32_t region_size, uint32_t window_size, uint32_t hop_size)
Extract data at onset/transient positions using spectral flux.
std::vector< std::vector< double > > extract_above_mean_data(const std::vector< std::span< const double > > &data, double mean_multiplier, uint32_t window_size, uint32_t hop_size)
Extract data from regions with values above statistical mean.
@ ABOVE_MEAN_DATA
Extract data above statistical mean.
@ SILENCE_DATA
Extract actual silent regions.
@ PEAK_DATA
Extract data around detected peaks.
@ OUTLIER_DATA
Extract data from statistical outlier regions.
@ ZERO_CROSSING_DATA
Extract actual data at zero crossing points.
@ HIGH_ENERGY_DATA
Extract data from high-energy regions.
@ HIGH_SPECTRAL_DATA
Extract data from high spectral energy regions.
@ OVERLAPPING_WINDOWS
Extract overlapping windowed data.
@ ONSET_DATA
Extract actual onset/transient regions.
std::vector< std::vector< double > > extract_peak_data(const std::vector< std::span< const double > > &data, double threshold, double min_distance, uint32_t region_size)
Extract data from peak regions using peak detection.
std::vector< std::vector< double > > extract_high_energy_data(const std::vector< std::span< const double > > &data, double energy_threshold, uint32_t window_size, uint32_t hop_size)
Extract data from high-energy regions using EnergyAnalyzer.
std::vector< std::vector< double > > extract_zero_crossing_data(const std::vector< std::span< const double > > &data, double threshold, double min_distance, uint32_t region_size)
Extract data at zero crossing points using existing EnergyAnalyzer.