compareAudioWaveformsUltraFast static method
Ultra-fast comparison with aggressive downsampling (8x) for real-time matching
Implementation
static double compareAudioWaveformsUltraFast(
Uint8List audio1, Uint8List audio2) {
if (audio1.isEmpty || audio2.isEmpty) return 0.0;
// Convert PCM bytes to float samples with aggressive downsampling (every 8th sample)
final samples1 = _pcmToFloatDownsampled(audio1, 8);
final samples2 = _pcmToFloatDownsampled(audio2, 8);
if (samples1.isEmpty || samples2.isEmpty) return 0.0;
// Normalize to same length (take minimum)
final minLength = math.min(samples1.length, samples2.length);
final normalized1 = samples1.sublist(0, minLength);
final normalized2 = samples2.sublist(0, minLength);
// Only use the most important similarity measure for speed
final waveformSimilarity =
_calculateWaveformSimilarityUltraFast(normalized1, normalized2);
final energySimilarity =
_calculateEnergySimilarityFast(normalized1, normalized2);
// Simplified combination - only 2 measures for speed
return (waveformSimilarity * 0.7 + energySimilarity * 0.3).clamp(0.0, 1.0);
}