MayaFlux 0.1.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
ExtractionHelper.hpp
Go to the documentation of this file.
1#pragma once
2
4
5/**
6 * @file ExtractionHelper.hpp
7 * @brief Central helper for extraction operations - uses analyzers to find data
8 *
9 * ExtractionHelper uses analyzers to identify regions/features of interest,
10 * then extracts and returns the actual DATA from those regions.
11 *
12 * Key concept: Analyzers find WHERE, extractors return WHAT.
13 * - Analyzer: "High energy at samples 1000-1500, 3000-3500"
14 * - Extractor: Returns the actual audio data from samples 1000-1500, 3000-3500
15 */
16
17namespace MayaFlux::Yantra {
18
19/**
20 * @brief Extract data from high-energy regions using EnergyAnalyzer
21 * @param data Input data span
22 * @param energy_threshold Minimum energy threshold for region selection
23 * @param window_size Analysis window size
24 * @param hop_size Hop size between windows
25 * @return Vector containing actual data from high-energy regions
26 */
27std::vector<std::vector<double>> extract_high_energy_data(
28 const std::vector<std::span<const double>>& data,
29 double energy_threshold = 0.1,
30 uint32_t window_size = 512,
31 uint32_t hop_size = 256);
32
33/**
34 * @brief Extract data from peak regions using peak detection
35 * @param data Input data span
36 * @param threshold Peak detection threshold
37 * @param min_distance Minimum distance between peaks
38 * @param region_size Size of region around each peak to extract
39 * @return Vector containing actual data from peak regions
40 */
41std::vector<std::vector<double>> extract_peak_data(
42 const std::vector<std::span<const double>>& data,
43 double threshold = 0.1,
44 double min_distance = 10.0,
45 uint32_t region_size = 256);
46
47/**
48 * @brief Extract data from statistical outlier regions
49 * @param data Input data span
50 * @param std_dev_threshold Number of standard deviations for outlier detection
51 * @param window_size Analysis window size
52 * @param hop_size Hop size between windows
53 * @return Vector containing actual data from outlier regions
54 */
55std::vector<std::vector<double>> extract_outlier_data(
56 const std::vector<std::span<const double>>& data,
57 double std_dev_threshold = 2.0,
58 uint32_t window_size = 512,
59 uint32_t hop_size = 256);
60
61/**
62 * @brief Extract data from regions with high spectral energy
63 * @param data Input data span
64 * @param spectral_threshold Minimum spectral energy threshold
65 * @param window_size Analysis window size
66 * @param hop_size Hop size between windows
67 * @return Vector containing actual data from high spectral energy regions
68 */
69std::vector<std::vector<double>> extract_high_spectral_data(
70 const std::vector<std::span<const double>>& data,
71 double spectral_threshold = 0.1,
72 uint32_t window_size = 512,
73 uint32_t hop_size = 256);
74
75/**
76 * @brief Extract data from regions with values above statistical mean
77 * @param data Input data span
78 * @param mean_multiplier Multiplier for mean threshold (e.g., 1.5 = 1.5x mean)
79 * @param window_size Analysis window size
80 * @param hop_size Hop size between windows
81 * @return Vector containing actual data from above-mean regions
82 */
83std::vector<std::vector<double>> extract_above_mean_data(
84 const std::vector<std::span<const double>>& data,
85 double mean_multiplier = 1.5,
86 uint32_t window_size = 512,
87 uint32_t hop_size = 256);
88
89/**
90 * @brief Extract overlapping windows of actual data
91 * @param data Input data span
92 * @param window_size Size of each window
93 * @param overlap Overlap ratio (0.0 to 1.0)
94 * @return Vector of data segments (each segment contains actual data values)
95 */
96std::vector<std::vector<double>> extract_overlapping_windows(
97 const std::vector<std::span<const double>>& data,
98 uint32_t window_size = 512,
99 double overlap = 0.5);
100
101/**
102 * @brief Extract specific data windows by indices
103 * @param data Input data span
104 * @param window_indices Vector of starting indices for windows
105 * @param window_size Size of each window
106 * @return Vector of data segments from specified windows
107 */
108std::vector<std::vector<double>> extract_windowed_data_by_indices(
109 const std::vector<std::span<const double>>& data,
110 const std::vector<size_t>& window_indices,
111 uint32_t window_size = 512);
112
113/**
114 * @brief Extract actual data from specified regions
115 * @param data Input data span
116 * @param regions Vector of regions to extract data from
117 * @return Vector containing concatenated data from all regions
118 */
119std::vector<std::vector<double>> extract_data_from_regions(
120 const std::vector<std::span<const double>>& data,
121 const std::vector<Kakshya::Region>& regions);
122
123/**
124 * @brief Extract data from a RegionGroup
125 * @param data Input data span
126 * @param region_group RegionGroup containing regions to extract
127 * @return Vector containing concatenated data from all regions in group
128 */
129std::vector<std::vector<double>> extract_data_from_region_group(
130 const std::vector<std::span<const double>>& data,
131 const Kakshya::RegionGroup& region_group);
132
133/**
134 * @brief Get available extraction methods
135 * @return Vector of method names
136 */
137std::vector<std::string> get_available_extraction_methods();
138
139/**
140 * @brief Validate extraction parameters
141 * @param window_size Window size to validate
142 * @param hop_size Hop size to validate
143 * @param data_size Size of data to process
144 * @return True if parameters are valid
145 */
146bool validate_extraction_parameters(uint32_t window_size, uint32_t hop_size, size_t data_size);
147
148/**
149 * @brief Extract data at zero crossing points using existing EnergyAnalyzer
150 * @param data Input data span
151 * @param threshold Zero crossing threshold (default: 0.0)
152 * @param min_distance Minimum distance between crossings
153 * @param region_size Size of region around each crossing to extract
154 * @return Vector containing actual data from zero crossing regions
155 */
156std::vector<std::vector<double>> extract_zero_crossing_data(
157 const std::vector<std::span<const double>>& data,
158 double threshold = 0.0,
159 double min_distance = 1.0,
160 uint32_t region_size = 1);
161
162/**
163 * @brief Extract data from silent regions using existing EnergyAnalyzer
164 * @param data Input data span
165 * @param silence_threshold Energy threshold below which regions are considered silent
166 * @param min_duration Minimum duration for silence regions
167 * @param window_size Analysis window size
168 * @param hop_size Hop size between windows
169 * @return Vector containing actual data from silent regions
170 */
171std::vector<std::vector<double>> extract_silence_data(
172 const std::vector<std::span<const double>>& data,
173 double silence_threshold = 0.01,
174 uint32_t min_duration = 1024,
175 uint32_t window_size = 512,
176 uint32_t hop_size = 256);
177
178/**
179 * @brief Extract data at onset/transient positions using spectral flux
180 * @param data Input data span
181 * @param threshold Onset detection threshold (normalized 0-1)
182 * @param region_size Size of region around each onset to extract
183 * @param window_size FFT window size for spectral analysis
184 * @param hop_size Hop size for spectral analysis
185 * @return Vector containing actual data from onset regions
186 */
187std::vector<std::vector<double>> extract_onset_data(
188 const std::vector<std::span<const double>>& data,
189 double threshold = 0.3,
190 uint32_t region_size = 512,
191 uint32_t window_size = 1024,
192 uint32_t hop_size = 256);
193
194} // namespace MayaFlux::Yantra
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.
bool validate_extraction_parameters(uint32_t window_size, uint32_t hop_size, size_t data_size)
Validate extraction parameters.
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_windowed_data_by_indices(const std::vector< std::span< const double > > &data, const std::vector< size_t > &window_indices, uint32_t window_size)
Extract specific data windows by indices.
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.
std::vector< std::vector< double > > extract_data_from_region_group(const std::vector< std::span< const double > > &data, const Kakshya::RegionGroup &region_group)
Extract data from a RegionGroup.
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::string > get_available_extraction_methods()
Get available extraction methods.
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.
std::vector< std::vector< double > > extract_data_from_regions(const std::vector< std::span< const double > > &data, const std::vector< Kakshya::Region > &regions)
Extract actual data from specified regions.
Organizes related signal regions into a categorized collection.