updateLevels method
Update level meters (call during recording/playback)
Implementation
void updateLevels(List<int> audioData) {
if (audioData.isEmpty) return;
// Calculate RMS level
double sum = 0;
int maxSample = 0;
for (final sample in audioData) {
sum += sample * sample;
if (sample.abs() > maxSample) {
maxSample = sample.abs();
}
}
final rms = math.sqrt(sum / audioData.length);
final dbLevel = 20 * math.log(rms / 32768) / math.ln10;
_currentLevel.value = dbLevel.clamp(-60.0, 0.0);
if (dbLevel > _peakLevel.value) {
_peakLevel.value = dbLevel;
}
_isClipping.value = maxSample >= 32767;
}