MayaFlux 0.3.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 222 of file FeatureExtractor.hpp.

223 {
224 try {
225 auto [numeric_data, info] = OperationHelper::extract_structured_double(const_cast<input_type&>(input));
226 DataStructureInfo structure_info = info;
227
228 std::vector<std::span<const double>> channels;
229 channels.reserve(numeric_data.size());
230 for (auto& s : numeric_data)
231 channels.emplace_back(s.data(), s.size());
232
233 std::vector<std::vector<double>> extracted_data;
234
235 switch (m_method) {
236
238 extracted_data = extract_high_energy(channels,
239 this->template get_parameter_or_default<double>("energy_threshold", 0.1),
241 break;
242
244 extracted_data = extract_peaks(channels,
245 this->template get_parameter_or_default<double>("threshold", 0.1),
246 this->template get_parameter_or_default<double>("min_distance", 10.0),
247 this->template get_parameter_or_default<uint32_t>("region_size", 256));
248 break;
249
251 extracted_data = extract_outliers(channels,
252 this->template get_parameter_or_default<double>("std_dev_threshold", 2.0),
254 break;
255
257 extracted_data = extract_high_spectral(channels,
258 this->template get_parameter_or_default<double>("spectral_threshold", 0.1),
260 break;
261
263 extracted_data = extract_above_mean(channels,
264 this->template get_parameter_or_default<double>("mean_multiplier", 1.5),
266 break;
267
269 extracted_data = extract_overlapping_windows(channels,
271 this->template get_parameter_or_default<double>("overlap", 0.5));
272 break;
273
275 extracted_data = extract_zero_crossings(channels,
276 this->template get_parameter_or_default<double>("threshold", 0.0),
277 this->template get_parameter_or_default<double>("min_distance", 1.0),
278 this->template get_parameter_or_default<uint32_t>("region_size", 1));
279 break;
280
282 extracted_data = extract_silence(channels,
283 this->template get_parameter_or_default<double>("silence_threshold", 0.01),
284 this->template get_parameter_or_default<uint32_t>("min_duration", 1024),
286 break;
287
289 extracted_data = extract_onsets(channels,
290 this->template get_parameter_or_default<double>("threshold", 0.3),
291 this->template get_parameter_or_default<uint32_t>("region_size", 512),
292 this->template get_parameter_or_default<uint32_t>("fft_window_size", 1024),
293 m_hop_size);
294 break;
295
296 default:
297 error<std::invalid_argument>(Journal::Component::Yantra, Journal::Context::ComputeMatrix, std::source_location::current(), "Unknown extraction method");
298 }
299
300 output_type output = this->convert_result(extracted_data, structure_info);
301
302 output.template set_metadata<std::string>("extractor_type", "FeatureExtractor");
303 output.template set_metadata<std::string>("extraction_method", method_to_string(m_method));
304 output.template set_metadata<uint32_t>("window_size", static_cast<uint32_t>(m_window_size));
305 output.template set_metadata<uint32_t>("hop_size", static_cast<uint32_t>(m_hop_size));
306 output.template set_metadata<size_t>("extracted_samples", extracted_data.size());
307
308 return output;
309
310 } catch (const std::exception& e) {
311 MF_ERROR(Journal::Component::Yantra, Journal::Context::ComputeMatrix, "Feature extraction failed: {}", e.what());
312 return output_type {};
313 }
314 }
#define MF_ERROR(comp, ctx,...)
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 Datum container or direct ComputeData with automatic container ha...
@ ComputeMatrix
Compute operations (Yantra - algorithms, matrices, DSP)
@ Yantra
DSP algorithms, computational units, matrix operations, Grammar.
std::vector< std::vector< double > > extract_outliers(const std::vector< std::span< const double > > &channels, double std_dev_threshold, uint32_t window_size, uint32_t hop_size)
std::vector< std::vector< double > > extract_onsets(const std::vector< std::span< const double > > &channels, double threshold, uint32_t region_size, uint32_t fft_window_size, uint32_t hop_size)
std::vector< std::vector< double > > extract_above_mean(const std::vector< std::span< const double > > &channels, double mean_multiplier, uint32_t window_size, uint32_t hop_size)
std::vector< std::vector< double > > extract_high_energy(const std::vector< std::span< const double > > &channels, double energy_threshold, uint32_t window_size, uint32_t hop_size)
@ 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_zero_crossings(const std::vector< std::span< const double > > &channels, double threshold, double min_distance, uint32_t region_size)
std::vector< std::vector< double > > extract_peaks(const std::vector< std::span< const double > > &channels, double threshold, double min_distance, uint32_t region_size)
std::vector< std::vector< double > > extract_silence(const std::vector< std::span< const double > > &channels, double silence_threshold, uint32_t min_duration, uint32_t window_size, uint32_t hop_size)
std::vector< std::vector< double > > extract_overlapping_windows(const std::vector< std::span< const double > > &channels, uint32_t window_size, double overlap)
std::vector< std::vector< double > > extract_high_spectral(const std::vector< std::span< const double > > &channels, double spectral_threshold, uint32_t window_size, uint32_t hop_size)

References MayaFlux::Yantra::extract_above_mean(), MayaFlux::Yantra::extract_high_energy(), MayaFlux::Yantra::extract_high_spectral(), MayaFlux::Yantra::extract_onsets(), MayaFlux::Yantra::extract_outliers(), MayaFlux::Yantra::extract_overlapping_windows(), MayaFlux::Yantra::extract_peaks(), MayaFlux::Yantra::extract_silence(), MayaFlux::Yantra::extract_zero_crossings(), and MF_ERROR.

+ Here is the call graph for this function: