smooth method

double smooth(
  1. double rawVolume
)

Processes a raw volume value and returns the smoothed result.

rawVolume should be a value between 0.0 and 1.0. Returns the smoothed volume value.

Implementation

double smooth(double rawVolume) {
  // Clamp input to valid range
  rawVolume = rawVolume.clamp(0.0, 1.0);

  // Add to history
  _volumeHistory.addLast(rawVolume);

  // Maintain history size limit
  while (_volumeHistory.length > _maxHistorySize) {
    _volumeHistory.removeFirst();
  }

  // For the first value, initialize without smoothing
  if (_isFirstValue) {
    _currentSmoothedVolume = rawVolume;
    _isFirstValue = false;
    return _currentSmoothedVolume;
  }

  // Apply exponential moving average smoothing
  // Formula: smoothed = (1 - factor) * new_value + factor * previous_smoothed
  _currentSmoothedVolume = (1.0 - smoothingFactor) * rawVolume +
      smoothingFactor * _currentSmoothedVolume;

  return _currentSmoothedVolume;
}