getRmsValue method

double getRmsValue()

Gets the RMS (Root Mean Square) value of the PCM data.

This is a measure of the average power of the signal.

If the RMS value was provided when creating this object, that value is returned. Otherwise, it's calculated from the PCM data.

Implementation

double getRmsValue() {
  // If we already have an RMS value, use it
  if (rmsValue > 0) {
    return rmsValue;
  }

  // Otherwise calculate it from the PCM data
  final samples = getNormalizedSamples();
  if (samples.isEmpty) return 0.0;

  double sumOfSquares = 0.0;
  for (final sample in samples) {
    sumOfSquares += sample * sample;
  }

  return math.sqrt(sumOfSquares / samples.length);
}