MayaFlux 0.1.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
Yantra.hpp
Go to the documentation of this file.
1#pragma once
2
4
5/**
6 * @file API/Yantra.hpp
7 * @brief Data analysis and transformation convenience API
8 *
9 * This header provides high-level functions for common data analysis and transformation
10 * operations. These are simple, direct dispatch functions for immediate results.
11 * For complex, multi-stage, or grammar-driven processing, use ComputePipeline,
12 * ComputeGrammar, or the full Yantra operation classes directly.
13 *
14 * Design Philosophy:
15 * - Simple input → simple output functions
16 * - Work with concrete types: std::vector<double>, DataVariant, and multi-channel data
17 * - Support both single-channel and multi-channel workflows
18 * - Common audio/signal analysis tasks with sensible multi-channel behavior
19 * - Immediate execution (no deferred/lazy evaluation)
20 * - Reasonable defaults for parameters
21 * - Progressive enhancement: existing single-channel functions remain unchanged
22 */
23
24namespace MayaFlux {
25
26//=========================================================================
27// STATISTICAL ANALYSIS - Quick data insights
28//=========================================================================
29
30/**
31 * @brief Calculate mean of single-channel data
32 * @param data Input data
33 * @return Mean value
34 */
35MAYAFLUX_API double mean(const std::vector<double>& data);
36MAYAFLUX_API double mean(const Kakshya::DataVariant& data);
37
38/**
39 * @brief Calculate mean per channel for multi-channel data
40 * @param channels Vector of channel data
41 * @return Vector of mean values, one per channel
42 */
43MAYAFLUX_API std::vector<double> mean_per_channel(const std::vector<Kakshya::DataVariant>& channels);
44
45/**
46 * @brief Calculate mean across all channels (mix then analyze)
47 * @param channels Vector of channel data
48 * @return Single mean value across all mixed channels
49 */
50MAYAFLUX_API double mean_combined(const std::vector<Kakshya::DataVariant>& channels);
51
52/**
53 * @brief Calculate RMS (Root Mean Square) energy of single-channel data
54 * @param data Input data
55 * @return RMS value
56 */
57MAYAFLUX_API double rms(const std::vector<double>& data);
58MAYAFLUX_API double rms(const Kakshya::DataVariant& data);
59
60/**
61 * @brief Calculate RMS energy per channel for multi-channel data
62 * @param channels Vector of channel data
63 * @return Vector of RMS values, one per channel
64 */
65MAYAFLUX_API std::vector<double> rms_per_channel(const std::vector<Kakshya::DataVariant>& channels);
66
67/**
68 * @brief Calculate RMS energy across all channels (mix then analyze)
69 * @param channels Vector of channel data
70 * @return Single RMS value across all mixed channels
71 */
72MAYAFLUX_API double rms_combined(const std::vector<Kakshya::DataVariant>& channels);
73
74/**
75 * @brief Calculate standard deviation of single-channel data
76 * @param data Input data
77 * @return Standard deviation
78 */
79MAYAFLUX_API double std_dev(const std::vector<double>& data);
80MAYAFLUX_API double std_dev(const Kakshya::DataVariant& data);
81
82/**
83 * @brief Calculate standard deviation per channel for multi-channel data
84 * @param channels Vector of channel data
85 * @return Vector of standard deviation values, one per channel
86 */
87MAYAFLUX_API std::vector<double> std_dev_per_channel(const std::vector<Kakshya::DataVariant>& channels);
88
89/**
90 * @brief Calculate standard deviation across all channels (mix then analyze)
91 * @param channels Vector of channel data
92 * @return Single standard deviation value across all mixed channels
93 */
94MAYAFLUX_API double std_dev_combined(const std::vector<Kakshya::DataVariant>& channels);
95
96/**
97 * @brief Calculate dynamic range (max/min ratio in dB) of single-channel data
98 * @param data Input data
99 * @return Dynamic range in dB
100 */
101MAYAFLUX_API double dynamic_range(const std::vector<double>& data);
102MAYAFLUX_API double dynamic_range(const Kakshya::DataVariant& data);
103
104/**
105 * @brief Calculate dynamic range per channel for multi-channel data
106 * @param channels Vector of channel data
107 * @return Vector of dynamic range values in dB, one per channel
108 */
109MAYAFLUX_API std::vector<double> dynamic_range_per_channel(const std::vector<Kakshya::DataVariant>& channels);
110
111/**
112 * @brief Calculate dynamic range across all channels (global min/max)
113 * @param channels Vector of channel data
114 * @return Single dynamic range value in dB across all channels
115 */
116MAYAFLUX_API double dynamic_range_global(const std::vector<Kakshya::DataVariant>& channels);
117
118/**
119 * @brief Find peak amplitude in single-channel data
120 * @param data Input data
121 * @return Peak amplitude value
122 */
123MAYAFLUX_API double peak(const std::vector<double>& data);
124MAYAFLUX_API double peak(const Kakshya::DataVariant& data);
125
126/**
127 * @brief Find peak amplitude across all channels (global peak)
128 * @param channels Vector of channel data
129 * @return Peak amplitude value across all channels
130 */
131MAYAFLUX_API double peak(const std::vector<Kakshya::DataVariant>& channels);
132
133/**
134 * @brief Find peak amplitude per channel for multi-channel data
135 * @param channels Vector of channel data
136 * @return Vector of peak amplitude values, one per channel
137 */
138MAYAFLUX_API std::vector<double> peak_per_channel(const std::vector<Kakshya::DataVariant>& channels);
139
140/**
141 * @brief Find peak amplitude in specific channel
142 * @param channels Vector of channel data
143 * @param channel_index Index of channel to analyze
144 * @return Peak amplitude value for specified channel
145 */
146MAYAFLUX_API double peak_channel(const std::vector<Kakshya::DataVariant>& channels, size_t channel_index);
147
148//=========================================================================
149// FEATURE EXTRACTION - Common audio analysis
150//=========================================================================
151
152/**
153 * @brief Detect zero crossings in single-channel signal
154 * @param data Input signal data
155 * @param threshold Minimum amplitude difference for crossing detection (default: 0.0)
156 * @return Vector of zero crossing indices
157 */
158MAYAFLUX_API std::vector<size_t> zero_crossings(const std::vector<double>& data, double threshold = 0.0);
159MAYAFLUX_API std::vector<size_t> zero_crossings(const Kakshya::DataVariant& data, double threshold = 0.0);
160
161/**
162 * @brief Detect zero crossings per channel for multi-channel signal
163 * @param channels Vector of channel data
164 * @param threshold Minimum amplitude difference for crossing detection (default: 0.0)
165 * @return Vector of zero crossing indices for each channel
166 */
167MAYAFLUX_API std::vector<std::vector<size_t>> zero_crossings_per_channel(const std::vector<Kakshya::DataVariant>& channels, double threshold = 0.0);
168
169/**
170 * @brief Calculate zero crossing rate for single-channel data
171 * @param data Input signal data
172 * @param window_size Analysis window size (0 = whole signal)
173 * @return Zero crossing rate (crossings per sample)
174 */
175MAYAFLUX_API double zero_crossing_rate(const std::vector<double>& data, size_t window_size = 0);
176MAYAFLUX_API double zero_crossing_rate(const Kakshya::DataVariant& data, size_t window_size = 0);
177
178/**
179 * @brief Calculate zero crossing rate per channel for multi-channel data
180 * @param channels Vector of channel data
181 * @param window_size Analysis window size (0 = whole signal)
182 * @return Vector of zero crossing rates, one per channel
183 */
184MAYAFLUX_API std::vector<double> zero_crossing_rate_per_channel(const std::vector<Kakshya::DataVariant>& channels, size_t window_size = 0);
185
186/**
187 * @brief Find spectral centroid (brightness measure) for single-channel data
188 * @param data Input signal data
189 * @param sample_rate Sample rate for frequency calculation (default: 48000 Hz)
190 * @return Spectral centroid in Hz
191 */
192MAYAFLUX_API double spectral_centroid(const std::vector<double>& data, double sample_rate = 48000.0);
193MAYAFLUX_API double spectral_centroid(const Kakshya::DataVariant& data, double sample_rate = 48000.0);
194
195/**
196 * @brief Find spectral centroid per channel for multi-channel data
197 * @param channels Vector of channel data
198 * @param sample_rate Sample rate for frequency calculation (default: 48000 Hz)
199 * @return Vector of spectral centroids in Hz, one per channel
200 */
201MAYAFLUX_API std::vector<double> spectral_centroid_per_channel(const std::vector<Kakshya::DataVariant>& channels, double sample_rate = 48000.0);
202
203/**
204 * @brief Detect onset times in single-channel signal
205 * @param data Input signal data
206 * @param sample_rate Sample rate for time calculation (default: 48000 Hz)
207 * @param threshold Energy threshold for onset detection (default: 0.1)
208 * @return Vector of onset times in seconds
209 */
210MAYAFLUX_API std::vector<double> detect_onsets(const std::vector<double>& data, double sample_rate = 48000.0, double threshold = 0.1);
211MAYAFLUX_API std::vector<double> detect_onsets(const Kakshya::DataVariant& data, double sample_rate = 48000.0, double threshold = 0.1);
212
213/**
214 * @brief Detect onset times per channel for multi-channel signal
215 * @param channels Vector of channel data
216 * @param sample_rate Sample rate for time calculation (default: 48000 Hz)
217 * @param threshold Energy threshold for onset detection (default: 0.1)
218 * @return Vector of onset times for each channel
219 */
220MAYAFLUX_API std::vector<std::vector<double>> detect_onsets_per_channel(const std::vector<Kakshya::DataVariant>& channels, double sample_rate = 48000.0, double threshold = 0.1);
221
222//=========================================================================
223// MULTI-CHANNEL SPECIFIC ANALYSIS - Channel relationships
224//=========================================================================
225
226/**
227 * @brief Mix multi-channel data to mono using equal weighting
228 * @param channels Vector of channel data
229 * @return Single-channel mixed result
230 */
231MAYAFLUX_API Kakshya::DataVariant mix_to_mono(const std::vector<Kakshya::DataVariant>& channels);
232
233/**
234 * @brief Convert stereo L/R channels to Mid/Side format
235 * @param lr_channels Vector containing exactly 2 channels (L, R)
236 * @return Pair of DataVariants (Mid, Side)
237 * @throws std::invalid_argument if input doesn't have exactly 2 channels
238 */
239MAYAFLUX_API std::pair<Kakshya::DataVariant, Kakshya::DataVariant> stereo_to_mid_side(const std::vector<Kakshya::DataVariant>& lr_channels);
240
241/**
242 * @brief Convert Mid/Side channels to stereo L/R format
243 * @param ms_channels Vector containing exactly 2 channels (Mid, Side)
244 * @return Pair of DataVariants (Left, Right)
245 * @throws std::invalid_argument if input doesn't have exactly 2 channels
246 */
247MAYAFLUX_API std::pair<Kakshya::DataVariant, Kakshya::DataVariant> mid_side_to_stereo(const std::vector<Kakshya::DataVariant>& ms_channels);
248
249/**
250 * @brief Calculate stereo width measure for L/R channels
251 * @param lr_channels Vector containing exactly 2 channels (L, R)
252 * @return Stereo width value (0.0 = mono, 1.0 = full stereo)
253 * @throws std::invalid_argument if input doesn't have exactly 2 channels
254 */
255MAYAFLUX_API double stereo_width(const std::vector<Kakshya::DataVariant>& lr_channels);
256
257/**
258 * @brief Calculate correlation matrix between all channel pairs
259 * @param channels Vector of channel data
260 * @return Correlation matrix as flat vector (row-major order)
261 */
262MAYAFLUX_API std::vector<double> channel_correlation_matrix(const std::vector<Kakshya::DataVariant>& channels);
263
264/**
265 * @brief Calculate phase correlation between two channels
266 * @param channel1 First channel data
267 * @param channel2 Second channel data
268 * @return Phase correlation value (-1.0 to 1.0)
269 */
270MAYAFLUX_API double phase_correlation(const Kakshya::DataVariant& channel1, const Kakshya::DataVariant& channel2);
271
272/**
273 * @brief Multi-channel feature analysis result
274 */
275struct MAYAFLUX_API MultiChannelFeatures {
276 std::vector<double> per_channel_rms; ///< RMS energy per channel
277 std::vector<double> per_channel_peak; ///< Peak amplitude per channel
278 std::vector<double> per_channel_mean; ///< Mean value per channel
279 double overall_peak; ///< Peak amplitude across all channels
280 double channel_balance; ///< Balance measure (0.5 = perfectly balanced)
281 std::vector<double> correlation_matrix; ///< Channel correlation matrix (flat)
282 size_t num_channels; ///< Number of input channels
283};
284
285/**
286 * @brief Comprehensive multi-channel analysis in single operation
287 * @param channels Vector of channel data
288 * @return MultiChannelFeatures struct with analysis results
289 */
290MAYAFLUX_API MultiChannelFeatures analyze_channels(const std::vector<Kakshya::DataVariant>& channels);
291
292//=========================================================================
293// BASIC TRANSFORMATIONS - Simple modifications
294//=========================================================================
295
296/**
297 * @brief Apply gain to single-channel data (in-place)
298 * @param data Input data (modified in-place)
299 * @param gain_factor Multiplication factor
300 */
301MAYAFLUX_API void apply_gain(std::vector<double>& data, double gain_factor);
302MAYAFLUX_API void apply_gain(Kakshya::DataVariant& data, double gain_factor);
303
304/**
305 * @brief Apply gain to multi-channel data (in-place)
306 * @param channels Vector of channel data (modified in-place)
307 * @param gain_factor Multiplication factor applied to all channels
308 */
309MAYAFLUX_API void apply_gain_channels(std::vector<Kakshya::DataVariant>& channels, double gain_factor);
310
311/**
312 * @brief Apply different gain to each channel (in-place)
313 * @param channels Vector of channel data (modified in-place)
314 * @param gain_factors Vector of gain factors (must match channels.size())
315 * @throws std::invalid_argument if gain_factors.size() != channels.size()
316 */
317MAYAFLUX_API void apply_gain_per_channel(std::vector<Kakshya::DataVariant>& channels, const std::vector<double>& gain_factors);
318
319/**
320 * @brief Apply gain to single-channel data (non-destructive)
321 * @param data Input data
322 * @param gain_factor Multiplication factor
323 * @return Modified copy of data
324 */
325MAYAFLUX_API std::vector<double> with_gain(const std::vector<double>& data, double gain_factor);
326MAYAFLUX_API Kakshya::DataVariant with_gain(const Kakshya::DataVariant& data, double gain_factor);
327
328/**
329 * @brief Apply gain to multi-channel data (non-destructive)
330 * @param channels Vector of channel data
331 * @param gain_factor Multiplication factor applied to all channels
332 * @return Vector of modified channel copies
333 */
334MAYAFLUX_API std::vector<Kakshya::DataVariant> with_gain_channels(const std::vector<Kakshya::DataVariant>& channels, double gain_factor);
335
336/**
337 * @brief Normalize single-channel data to specified peak level (in-place)
338 * @param data Input data (modified in-place)
339 * @param target_peak Target peak amplitude (default: 1.0)
340 */
341MAYAFLUX_API void normalize(std::vector<double>& data, double target_peak = 1.0);
342MAYAFLUX_API void normalize(Kakshya::DataVariant& data, double target_peak = 1.0);
343
344/**
345 * @brief Normalize each channel independently to specified peak level (in-place)
346 * @param channels Vector of channel data (modified in-place)
347 * @param target_peak Target peak amplitude (default: 1.0)
348 */
349MAYAFLUX_API void normalize_channels(std::vector<Kakshya::DataVariant>& channels, double target_peak = 1.0);
350
351/**
352 * @brief Normalize multi-channel data relative to global peak (in-place)
353 * @param channels Vector of channel data (modified in-place)
354 * @param target_peak Target peak amplitude (default: 1.0)
355 */
356MAYAFLUX_API void normalize_together(std::vector<Kakshya::DataVariant>& channels, double target_peak = 1.0);
357
358/**
359 * @brief Normalize single-channel data (non-destructive)
360 * @param data Input data
361 * @param target_peak Target peak amplitude (default: 1.0)
362 * @return Normalized copy of data
363 */
364MAYAFLUX_API std::vector<double> normalized(const std::vector<double>& data, double target_peak = 1.0);
365MAYAFLUX_API Kakshya::DataVariant normalized(const Kakshya::DataVariant& data, double target_peak = 1.0);
366
367/**
368 * @brief Normalize each channel independently (non-destructive)
369 * @param channels Vector of channel data
370 * @param target_peak Target peak amplitude (default: 1.0)
371 * @return Vector of normalized channel copies
372 */
373MAYAFLUX_API std::vector<Kakshya::DataVariant> normalized_channels(const std::vector<Kakshya::DataVariant>& channels, double target_peak = 1.0);
374
375/**
376 * @brief Reverse time order of single-channel data (in-place)
377 * @param data Input data (modified in-place)
378 */
379MAYAFLUX_API void reverse(std::vector<double>& data);
380MAYAFLUX_API void reverse(Kakshya::DataVariant& data);
381
382/**
383 * @brief Reverse time order of multi-channel data (in-place)
384 * @param channels Vector of channel data (modified in-place)
385 */
386MAYAFLUX_API void reverse_channels(std::vector<Kakshya::DataVariant>& channels);
387
388/**
389 * @brief Reverse time order of single-channel data (non-destructive)
390 * @param data Input data
391 * @return Time-reversed copy of data
392 */
393MAYAFLUX_API std::vector<double> reversed(const std::vector<double>& data);
394MAYAFLUX_API Kakshya::DataVariant reversed(const Kakshya::DataVariant& data);
395
396/**
397 * @brief Reverse time order of multi-channel data (non-destructive)
398 * @param channels Vector of channel data
399 * @return Vector of time-reversed channel copies
400 */
401MAYAFLUX_API std::vector<Kakshya::DataVariant> reversed_channels(const std::vector<Kakshya::DataVariant>& channels);
402
403//=========================================================================
404// FREQUENCY DOMAIN - Quick spectral operations
405//=========================================================================
406
407/**
408 * @brief Compute magnitude spectrum for single-channel data
409 * @param data Input time-domain data
410 * @param window_size FFT size (0 = use data size)
411 * @return Magnitude spectrum
412 */
413MAYAFLUX_API std::vector<double> magnitude_spectrum(const std::vector<double>& data, size_t window_size = 0);
414MAYAFLUX_API std::vector<double> magnitude_spectrum(const Kakshya::DataVariant& data, size_t window_size = 0);
415
416/**
417 * @brief Compute magnitude spectrum per channel for multi-channel data
418 * @param channels Vector of channel data
419 * @param window_size FFT size (0 = use data size)
420 * @return Vector of magnitude spectra, one per channel
421 */
422std::vector<std::vector<double>> magnitude_spectrum_per_channel(const std::vector<Kakshya::DataVariant>& channels, size_t window_size = 0);
423
424/**
425 * @brief Compute power spectrum for single-channel data
426 * @param data Input time-domain data
427 * @param window_size FFT size (0 = use data size)
428 * @return Power spectrum (magnitude squared)
429 */
430MAYAFLUX_API std::vector<double> power_spectrum(const std::vector<double>& data, size_t window_size = 0);
431MAYAFLUX_API std::vector<double> power_spectrum(const Kakshya::DataVariant& data, size_t window_size = 0);
432
433/**
434 * @brief Compute power spectrum per channel for multi-channel data
435 * @param channels Vector of channel data
436 * @param window_size FFT size (0 = use data size)
437 * @return Vector of power spectra, one per channel
438 */
439MAYAFLUX_API std::vector<std::vector<double>> power_spectrum_per_channel(const std::vector<Kakshya::DataVariant>& channels, size_t window_size = 0);
440
441//=========================================================================
442// PITCH AND TIME - Common audio manipulations
443//=========================================================================
444
445/**
446 * @brief Estimate fundamental frequency using autocorrelation for single-channel data
447 * @param data Input signal data
448 * @param sample_rate Sample rate (default: 48000 Hz)
449 * @param min_freq Minimum expected frequency (default: 80 Hz)
450 * @param max_freq Maximum expected frequency (default: 2000 Hz)
451 * @return Estimated F0 in Hz (0 if not detected)
452 */
453MAYAFLUX_API double estimate_pitch(const std::vector<double>& data, double sample_rate = 48000.0,
454 double min_freq = 80.0, double max_freq = 2000.0);
455MAYAFLUX_API double estimate_pitch(const Kakshya::DataVariant& data, double sample_rate = 48000.0,
456 double min_freq = 80.0, double max_freq = 2000.0);
457
458/**
459 * @brief Estimate fundamental frequency per channel for multi-channel data
460 * @param channels Vector of channel data
461 * @param sample_rate Sample rate (default: 48000 Hz)
462 * @param min_freq Minimum expected frequency (default: 80 Hz)
463 * @param max_freq Maximum expected frequency (default: 2000 Hz)
464 * @return Vector of estimated F0 values in Hz, one per channel (0 if not detected)
465 */
466MAYAFLUX_API std::vector<double> estimate_pitch_per_channel(const std::vector<Kakshya::DataVariant>& channels, double sample_rate = 48000.0,
467 double min_freq = 80.0, double max_freq = 2000.0);
468
469//=========================================================================
470// WINDOWING AND SEGMENTATION - Data organization
471//=========================================================================
472
473/**
474 * @brief Extract silent regions from single-channel data
475 * @param data Input audio data
476 * @param threshold Silence threshold (amplitude, default: 0.01)
477 * @param min_silence_duration Minimum silence length in samples (default: 1024)
478 * @return Vector of silent data segments
479 */
480MAYAFLUX_API std::vector<double> extract_silent_data(const std::vector<double>& data,
481 double threshold,
482 size_t min_silence_duration);
483MAYAFLUX_API std::vector<double> extract_silent_data(const Kakshya::DataVariant& data,
484 double threshold,
485 size_t min_silence_duration);
486
487/**
488 * @brief Extract zero crossing regions from single-channel data
489 * @param data Input audio data
490 * @param threshold Minimum amplitude difference for zero crossing detection (default: 0.0)
491 * @param region_size Size of each region in samples (default: 1024)
492 * @return Vector of zero crossing regions
493 */
494MAYAFLUX_API std::vector<double> extract_zero_crossing_regions(const std::vector<double>& data,
495 double threshold,
496 size_t region_size);
497MAYAFLUX_API std::vector<double> extract_zero_crossing_regions(const Kakshya::DataVariant& data,
498 double threshold,
499 size_t region_size);
500
501/**
502 * @brief Apply window function to single-channel data (in-place)
503 * @param data Input data (modified in-place)
504 * @param window_type "hann", "hamming", "blackman", "rectangular" (default: "hann")
505 */
506MAYAFLUX_API void apply_window(std::vector<double>& data, const std::string& window_type = "hann");
507MAYAFLUX_API void apply_window(Kakshya::DataVariant& data, const std::string& window_type = "hann");
508
509/**
510 * @brief Apply window function to multi-channel data (in-place)
511 * @param channels Vector of channel data (modified in-place)
512 * @param window_type "hann", "hamming", "blackman", "rectangular" (default: "hann")
513 */
514MAYAFLUX_API void apply_window_channels(std::vector<Kakshya::DataVariant>& channels, const std::string& window_type = "hann");
515
516/**
517 * @brief Split single-channel data into overlapping windows
518 * @param data Input data
519 * @param window_size Size of each window
520 * @param hop_size Step size between windows
521 * @return Vector of windowed segments
522 */
523MAYAFLUX_API std::vector<std::vector<double>> windowed_segments(const std::vector<double>& data,
524 size_t window_size,
525 size_t hop_size);
526MAYAFLUX_API std::vector<std::vector<double>> windowed_segments(const Kakshya::DataVariant& data,
527 size_t window_size,
528 size_t hop_size);
529
530/**
531 * @brief Split multi-channel data into overlapping windows per channel
532 * @param channels Vector of channel data
533 * @param window_size Size of each window
534 * @param hop_size Step size between windows
535 * @return Vector of windowed segments for each channel
536 */
537MAYAFLUX_API std::vector<std::vector<std::vector<double>>> windowed_segments_per_channel(const std::vector<Kakshya::DataVariant>& channels,
538 size_t window_size,
539 size_t hop_size);
540
541/**
542 * @brief Detect silence regions in single-channel data
543 * @param data Input data
544 * @param threshold Silence threshold (amplitude, default: 0.01)
545 * @param min_silence_duration Minimum silence length in samples (default: 1024)
546 * @return Vector of (start, end) silence regions
547 */
548MAYAFLUX_API std::vector<std::pair<size_t, size_t>> detect_silence(const std::vector<double>& data,
549 double threshold = 0.01,
550 size_t min_silence_duration = 1024);
551MAYAFLUX_API std::vector<std::pair<size_t, size_t>> detect_silence(const Kakshya::DataVariant& data,
552 double threshold = 0.01,
553 size_t min_silence_duration = 1024);
554
555/**
556 * @brief Detect silence regions per channel for multi-channel data
557 * @param channels Vector of channel data
558 * @param threshold Silence threshold (amplitude, default: 0.01)
559 * @param min_silence_duration Minimum silence length in samples (default: 1024)
560 * @return Vector of silence regions for each channel
561 */
562MAYAFLUX_API std::vector<std::vector<std::pair<size_t, size_t>>> detect_silence_per_channel(const std::vector<Kakshya::DataVariant>& channels,
563 double threshold = 0.01,
564 size_t min_silence_duration = 1024);
565
566//=========================================================================
567// UTILITY AND CONVERSION - Data helpers
568//=========================================================================
569
570/**
571 * @brief Mix multiple data streams with equal weighting
572 * @param streams Vector of data streams to mix
573 * @return Mixed output data (average of all streams)
574 */
575MAYAFLUX_API std::vector<double> mix(const std::vector<std::vector<double>>& streams);
576MAYAFLUX_API std::vector<double> mix(const std::vector<Kakshya::DataVariant>& streams);
577
578/**
579 * @brief Mix multiple data streams with specified gains
580 * @param streams Vector of data streams to mix
581 * @param gains Vector of gain factors (must match streams.size())
582 * @return Mixed output data
583 * @throws std::invalid_argument if gains.size() != streams.size()
584 */
585MAYAFLUX_API std::vector<double> mix_with_gains(const std::vector<std::vector<double>>& streams,
586 const std::vector<double>& gains);
587MAYAFLUX_API std::vector<double> mix_with_gains(const std::vector<Kakshya::DataVariant>& streams,
588 const std::vector<double>& gains);
589
590/**
591 * @brief Convert DataVariant to vector<double> if possible
592 * @param data Input DataVariant
593 * @return Extracted double vector, empty if conversion fails
594 */
595MAYAFLUX_API std::vector<double> to_double_vector(const Kakshya::DataVariant& data);
596
597/**
598 * @brief Convert vector<double> to DataVariant
599 * @param data Input double vector
600 * @return DataVariant containing the data
601 */
602MAYAFLUX_API Kakshya::DataVariant to_data_variant(const std::vector<double>& data);
603
604/**
605 * @brief Convert multi-channel data to vector of double vectors
606 * @param channels Vector of channel data
607 * @return Vector of double vectors, one per channel
608 */
609MAYAFLUX_API std::vector<std::vector<double>> to_double_vectors(const std::vector<Kakshya::DataVariant>& channels);
610
611/**
612 * @brief Convert vector of double vectors to multi-channel DataVariant format
613 * @param channel_data Vector of channel data as double vectors
614 * @return Vector of DataVariants, one per channel
615 */
616MAYAFLUX_API std::vector<Kakshya::DataVariant> to_data_variants(const std::vector<std::vector<double>>& channel_data);
617
618//=========================================================================
619// REGISTRY ACCESS - Bridge to full Yantra system
620//=========================================================================
621
622/**
623 * @brief Initialize Yantra subsystem with default configuration
624 *
625 * Called automatically by engine initialization, but can be called manually
626 * for custom setups or testing.
627 */
628MAYAFLUX_API void initialize_yantra();
629
630} // namespace MayaFlux
std::variant< std::vector< double >, std::vector< float >, std::vector< uint8_t >, std::vector< uint16_t >, std::vector< uint32_t >, std::vector< std::complex< float > >, std::vector< std::complex< double > >, std::vector< glm::vec2 >, std::vector< glm::vec3 >, std::vector< glm::vec4 >, std::vector< glm::mat4 > > DataVariant
Multi-type data storage for different precision needs.
Definition NDData.hpp:73
std::vector< std::vector< double > > to_double_vectors(const std::vector< Kakshya::DataVariant > &channels)
Convert multi-channel data to vector of double vectors.
Definition Yantra.cpp:1148
std::vector< size_t > zero_crossings(const std::vector< double > &data, double threshold)
Detect zero crossings in single-channel signal.
Definition Yantra.cpp:266
MAYAFLUX_API double stereo_width(const std::vector< Kakshya::DataVariant > &lr_channels)
Calculate stereo width measure for L/R channels.
Kakshya::DataVariant to_data_variant(const std::vector< double > &data)
Convert vector<double> to DataVariant.
Definition Yantra.cpp:1143
std::vector< double > zero_crossing_rate_per_channel(const std::vector< Kakshya::DataVariant > &channels, size_t window_size)
Calculate zero crossing rate per channel for multi-channel data.
Definition Yantra.cpp:371
std::vector< Kakshya::DataVariant > with_gain_channels(const std::vector< Kakshya::DataVariant > &channels, double gain_factor)
Apply gain to multi-channel data (non-destructive)
Definition Yantra.cpp:549
std::vector< double > dynamic_range_per_channel(const std::vector< Kakshya::DataVariant > &channels)
Calculate dynamic range per channel for multi-channel data.
Definition Yantra.cpp:182
double std_dev_combined(const std::vector< Kakshya::DataVariant > &channels)
Calculate standard deviation across all channels (mix then analyze)
Definition Yantra.cpp:154
std::vector< std::vector< double > > magnitude_spectrum_per_channel(const std::vector< Kakshya::DataVariant > &channels, size_t window_size)
Compute magnitude spectrum per channel for multi-channel data.
Definition Yantra.cpp:699
std::vector< double > estimate_pitch_per_channel(const std::vector< Kakshya::DataVariant > &channels, double sample_rate, double min_freq, double max_freq)
Estimate fundamental frequency per channel for multi-channel data.
Definition Yantra.cpp:781
double estimate_pitch(const std::vector< double > &data, double sample_rate, double min_freq, double max_freq)
Estimate fundamental frequency using autocorrelation for single-channel data.
Definition Yantra.cpp:757
std::vector< Kakshya::DataVariant > reversed_channels(const std::vector< Kakshya::DataVariant > &channels)
Reverse time order of multi-channel data (non-destructive)
Definition Yantra.cpp:665
std::vector< double > peak_per_channel(const std::vector< Kakshya::DataVariant > &channels)
Find peak amplitude per channel for multi-channel data.
Definition Yantra.cpp:242
double zero_crossing_rate(const std::vector< double > &data, size_t window_size)
Calculate zero crossing rate for single-channel data.
Definition Yantra.cpp:349
void reverse(std::vector< double > &data)
Reverse time order of single-channel data (in-place)
Definition Yantra.cpp:625
std::vector< double > mean_per_channel(const std::vector< Kakshya::DataVariant > &data)
Calculate mean per channel for multi-channel data.
Definition Yantra.cpp:55
void apply_gain_channels(std::vector< Kakshya::DataVariant > &channels, double gain_factor)
Apply gain to multi-channel data (in-place)
Definition Yantra.cpp:511
MAYAFLUX_API MultiChannelFeatures analyze_channels(const std::vector< Kakshya::DataVariant > &channels)
Comprehensive multi-channel analysis in single operation.
void normalize_together(std::vector< Kakshya::DataVariant > &channels, double target_peak)
Normalize multi-channel data relative to global peak (in-place)
Definition Yantra.cpp:583
MAYAFLUX_API std::pair< Kakshya::DataVariant, Kakshya::DataVariant > stereo_to_mid_side(const std::vector< Kakshya::DataVariant > &lr_channels)
Convert stereo L/R channels to Mid/Side format.
std::vector< double > to_double_vector(const Kakshya::DataVariant &data)
Convert DataVariant to vector<double> if possible.
Definition Yantra.cpp:1137
std::vector< std::vector< std::vector< double > > > windowed_segments_per_channel(const std::vector< Kakshya::DataVariant > &channels, size_t window_size, size_t hop_size)
Split multi-channel data into overlapping windows per channel.
Definition Yantra.cpp:945
std::vector< double > with_gain(const std::vector< double > &data, double gain_factor)
Apply gain to single-channel data (non-destructive)
Definition Yantra.cpp:531
double dynamic_range(const std::vector< double > &data)
Calculate dynamic range (max/min ratio in dB) of single-channel data.
Definition Yantra.cpp:166
std::vector< std::pair< size_t, size_t > > detect_silence(const std::vector< double > &data, double threshold, size_t min_silence_duration)
Detect silence regions in single-channel data.
Definition Yantra.cpp:959
double rms(const std::vector< double > &data)
Calculate RMS (Root Mean Square) energy of single-channel data.
Definition Yantra.cpp:82
void normalize_channels(std::vector< Kakshya::DataVariant > &channels, double target_peak)
Normalize each channel independently to specified peak level (in-place)
Definition Yantra.cpp:576
void reverse_channels(std::vector< Kakshya::DataVariant > &channels)
Reverse time order of multi-channel data (in-place)
Definition Yantra.cpp:641
double peak_channel(const std::vector< Kakshya::DataVariant > &channels, size_t channel_index)
Find peak amplitude in specific channel.
Definition Yantra.cpp:254
std::vector< double > extract_zero_crossing_regions(const std::vector< double > &data, double threshold, size_t region_size)
Extract zero crossing regions from single-channel data.
Definition Yantra.cpp:832
std::vector< double > std_dev_per_channel(const std::vector< Kakshya::DataVariant > &channels)
Calculate standard deviation per channel for multi-channel data.
Definition Yantra.cpp:142
std::vector< double > reversed(const std::vector< double > &data)
Reverse time order of single-channel data (non-destructive)
Definition Yantra.cpp:649
std::vector< std::vector< double > > power_spectrum_per_channel(const std::vector< Kakshya::DataVariant > &channels, size_t window_size)
Compute power spectrum per channel for multi-channel data.
Definition Yantra.cpp:737
std::vector< Kakshya::DataVariant > to_data_variants(const std::vector< std::vector< double > > &channel_data)
Convert vector of double vectors to multi-channel DataVariant format.
Definition Yantra.cpp:1161
std::vector< double > extract_silent_data(const std::vector< double > &data, double threshold, size_t min_silence_duration)
Extract silent regions from single-channel data.
Definition Yantra.cpp:802
MAYAFLUX_API std::pair< Kakshya::DataVariant, Kakshya::DataVariant > mid_side_to_stereo(const std::vector< Kakshya::DataVariant > &ms_channels)
Convert Mid/Side channels to stereo L/R format.
double dynamic_range_global(const std::vector< Kakshya::DataVariant > &channels)
Calculate dynamic range across all channels (global min/max)
Definition Yantra.cpp:194
std::vector< double > magnitude_spectrum(const std::vector< double > &data, size_t window_size)
Compute magnitude spectrum for single-channel data.
Definition Yantra.cpp:677
void apply_window_channels(std::vector< Kakshya::DataVariant > &channels, const std::string &window_type)
Apply window function to multi-channel data (in-place)
Definition Yantra.cpp:894
std::vector< std::vector< double > > detect_onsets_per_channel(const std::vector< Kakshya::DataVariant > &channels, double sample_rate, double threshold)
Detect onset times per channel for multi-channel signal.
Definition Yantra.cpp:458
MAYAFLUX_API std::vector< double > channel_correlation_matrix(const std::vector< Kakshya::DataVariant > &channels)
Calculate correlation matrix between all channel pairs.
void normalize(std::vector< double > &data, double target_peak)
Normalize single-channel data to specified peak level (in-place)
Definition Yantra.cpp:558
void apply_window(std::vector< double > &data, const std::string &window_type)
Apply window function to single-channel data (in-place)
Definition Yantra.cpp:864
double rms_combined(const std::vector< Kakshya::DataVariant > &channels)
Calculate RMS energy across all channels (mix then analyze)
Definition Yantra.cpp:110
std::vector< std::vector< double > > windowed_segments(const std::vector< double > &data, size_t window_size, size_t hop_size)
Split single-channel data into overlapping windows.
Definition Yantra.cpp:901
std::vector< double > mix_with_gains(const std::vector< std::vector< double > > &streams, const std::vector< double > &gains)
Mix multiple data streams with specified gains.
Definition Yantra.cpp:1076
std::vector< Kakshya::DataVariant > normalized_channels(const std::vector< Kakshya::DataVariant > &channels, double target_peak)
Normalize each channel independently (non-destructive)
Definition Yantra.cpp:611
MAYAFLUX_API double phase_correlation(const Kakshya::DataVariant &channel1, const Kakshya::DataVariant &channel2)
Calculate phase correlation between two channels.
std::vector< double > spectral_centroid_per_channel(const std::vector< Kakshya::DataVariant > &channels, double sample_rate)
Find spectral centroid per channel for multi-channel data.
Definition Yantra.cpp:405
double spectral_centroid(const std::vector< double > &data, double sample_rate)
Find spectral centroid (brightness measure) for single-channel data.
Definition Yantra.cpp:387
void initialize_yantra()
Initialize Yantra subsystem with default configuration.
Definition Yantra.cpp:1177
double std_dev(const std::vector< double > &data)
Calculate standard deviation of single-channel data.
Definition Yantra.cpp:126
std::vector< double > normalized(const std::vector< double > &data, double target_peak)
Normalize single-channel data (non-destructive)
Definition Yantra.cpp:593
double mean(const std::vector< double > &data)
Calculate mean of single-channel data.
Definition Yantra.cpp:39
double mean_combined(const std::vector< Kakshya::DataVariant > &channels)
Calculate mean across all channels (mix then analyze)
Definition Yantra.cpp:70
std::vector< double > detect_onsets(const std::vector< double > &data, double sample_rate, double threshold)
Detect onset times in single-channel signal.
Definition Yantra.cpp:419
std::vector< std::vector< size_t > > zero_crossings_per_channel(const std::vector< Kakshya::DataVariant > &channels, double threshold)
Detect zero crossings per channel for multi-channel signal.
Definition Yantra.cpp:319
double peak(const std::vector< double > &data)
Find peak amplitude in single-channel data.
Definition Yantra.cpp:214
MAYAFLUX_API Kakshya::DataVariant mix_to_mono(const std::vector< Kakshya::DataVariant > &channels)
Mix multi-channel data to mono using equal weighting.
void apply_gain(std::vector< double > &data, double gain_factor)
Apply gain to single-channel data (in-place)
Definition Yantra.cpp:489
void apply_gain_per_channel(std::vector< Kakshya::DataVariant > &channels, const std::vector< double > &gain_factors)
Apply different gain to each channel (in-place)
Definition Yantra.cpp:520
std::vector< double > mix(const std::vector< std::vector< double > > &streams)
Mix multiple data streams with equal weighting.
Definition Yantra.cpp:1019
std::vector< double > rms_per_channel(const std::vector< Kakshya::DataVariant > &channels)
Calculate RMS energy per channel for multi-channel data.
Definition Yantra.cpp:98
std::vector< std::vector< std::pair< size_t, size_t > > > detect_silence_per_channel(const std::vector< Kakshya::DataVariant > &channels, double threshold, size_t min_silence_duration)
Detect silence regions per channel for multi-channel data.
Definition Yantra.cpp:1001
std::vector< double > power_spectrum(const std::vector< double > &data, size_t window_size)
Compute power spectrum for single-channel data.
Definition Yantra.cpp:715
Main namespace for the Maya Flux audio engine.
Definition LiveAid.hpp:6
double channel_balance
Balance measure (0.5 = perfectly balanced)
Definition Yantra.hpp:280
std::vector< double > per_channel_peak
Peak amplitude per channel.
Definition Yantra.hpp:277
size_t num_channels
Number of input channels.
Definition Yantra.hpp:282
double overall_peak
Peak amplitude across all channels.
Definition Yantra.hpp:279
std::vector< double > per_channel_rms
RMS energy per channel.
Definition Yantra.hpp:276
std::vector< double > correlation_matrix
Channel correlation matrix (flat)
Definition Yantra.hpp:281
std::vector< double > per_channel_mean
Mean value per channel.
Definition Yantra.hpp:278
Multi-channel feature analysis result.
Definition Yantra.hpp:275