getFrequencyValues method
Gets the frequency spectrum values from the FFT data.
Returns a list of values between 0.0 and 1.0 representing the magnitude of each frequency band.
Implementation
List<double> getFrequencyValues() {
if (fft == null || fft!.isEmpty) {
// Return a flat line if no data is available
return List.filled(32, 0.1);
}
// FFT data is in complex form (real/imaginary pairs)
// We need to calculate the magnitude of each pair
final result = <double>[];
try {
for (int i = 0; i < fft!.length; i += 2) {
if (i + 1 < fft!.length) {
final real = fft![i].toDouble() - 128;
final imag = fft![i + 1].toDouble() - 128;
final magnitude = _calculateMagnitude(real, imag);
result.add(magnitude);
}
}
// If we somehow got no results, return a default array
if (result.isEmpty) {
return List.filled(32, 0.1);
}
return result;
} catch (e) {
// Log error but continue with default data
// ignore: avoid_print
print('Error processing FFT data: $e');
return List.filled(32, 0.1);
}
}