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

◆ extract_implementation()

template<ComputeData InputType = std::vector<Kakshya::DataVariant>, ComputeData OutputType = std::vector<std::vector<double>>>
output_type MayaFlux::Yantra::FeatureExtractor< InputType, OutputType >::extract_implementation ( const input_type input)
inlineoverrideprotected

Core extraction implementation - delegates to ExtractionHelper.

Parameters
inputInput data with metadata
Returns
Extracted data with metadata

Definition at line 221 of file FeatureExtractor.hpp.

222 {
223 try {
224 auto [numeric_data, info] = OperationHelper::extract_structured_double(const_cast<input_type&>(input));
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
236 switch (m_method) {
238 double energy_threshold = this->template get_parameter_or_default<double>("energy_threshold", 0.1);
239 extracted_data = extract_high_energy_data(data_span, energy_threshold, m_window_size, m_hop_size);
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);
251 extracted_data = extract_outlier_data(data_span, std_dev_threshold, m_window_size, m_hop_size);
252 break;
253 }
255 double spectral_threshold = this->template get_parameter_or_default<double>("spectral_threshold", 0.1);
256 extracted_data = extract_high_spectral_data(data_span, spectral_threshold, m_window_size, m_hop_size);
257 break;
258 }
260 double mean_multiplier = this->template get_parameter_or_default<double>("mean_multiplier", 1.5);
261 extracted_data = extract_above_mean_data(data_span, mean_multiplier, m_window_size, m_hop_size);
262 break;
263 }
265 double overlap = this->template get_parameter_or_default<double>("overlap", 0.5);
266 extracted_data = extract_overlapping_windows(data_span, m_window_size, overlap);
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);
273 extracted_data = extract_zero_crossing_data(data_span, threshold, min_distance, region_size);
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);
279 extracted_data = extract_silence_data(data_span, silence_threshold, min_duration, m_window_size, m_hop_size);
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);
286 extracted_data = extract_onset_data(data_span, threshold, region_size, fft_window, m_hop_size);
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");
296 output.template set_metadata<std::string>("extraction_method", method_to_string(m_method));
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::string method_to_string(ExtractionMethod method)
Convert extraction method enum to string.
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.

References MayaFlux::Yantra::extract_above_mean_data(), MayaFlux::Yantra::extract_high_energy_data(), MayaFlux::Yantra::extract_high_spectral_data(), MayaFlux::Yantra::extract_onset_data(), MayaFlux::Yantra::extract_outlier_data(), MayaFlux::Yantra::extract_overlapping_windows(), MayaFlux::Yantra::extract_peak_data(), MayaFlux::Yantra::extract_silence_data(), and MayaFlux::Yantra::extract_zero_crossing_data().

+ Here is the call graph for this function: