classify static method

VocalRange classify(
  1. double fundamentalHz
)

Classify a fundamental frequency into the best matching vocal range.

Finds the range whose center frequency is closest to fundamentalHz.

Implementation

static VocalRange classify(double fundamentalHz) {
  VocalRange best = VocalRange.bass;
  double bestDistance = double.infinity;

  for (final range in VocalRange.values) {
    final center = (range.minHz + range.maxHz) / 2;
    final distance = (fundamentalHz - center).abs();
    if (distance < bestDistance) {
      bestDistance = distance;
      best = range;
    }
  }

  return best;
}