Whether you are building an instrument tuner, a singing practice tool, or an audio visualization app in .NET, one of the first utility modules you will need is a reliable converter from raw fundamental frequency in Hertz (Hz) to musical pitch notation, cent deviation, and vocal range classification.

In this post, we will implement a compact, dependency-free C# helper that covers the human vocal band from C2 (65.41 Hz) to F6 (1,396.91 Hz) and classifies a measured range against the seven classic voice types from bass to soprano.

1. Mapping Frequency (Hz) to MIDI Note Numbers and Cents

Under twelve-tone equal temperament tuned to A4 = 440 Hz (MIDI note 69), every doubling of frequency corresponds to one octave (12 semitones). Using Math.Log2 in modern .NET makes the conversion exact and readable:

public readonly record struct PitchResult(string NoteName, int MidiNote, double CentsOff, double FrequencyHz);

public static class PitchMath
{
    private static readonly string[] NoteNames =
        ["C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B"];

    public static PitchResult FromFrequency(double frequencyHz)
    {
        if (frequencyHz <= 0)
            throw new ArgumentOutOfRangeException(nameof(frequencyHz));

        double exactMidi = 69.0 + 12.0 * Math.Log2(frequencyHz / 440.0);
        int nearestMidi = (int)Math.Round(exactMidi);
        double cents = (exactMidi - nearestMidi) * 100.0;

        int noteIndex = ((nearestMidi % 12) + 12) % 12;
        int octave = (nearestMidi / 12) - 1;
        string name = $"{NoteNames[noteIndex]}{octave}";

        return new PitchResult(name, nearestMidi, Math.Round(cents, 1), frequencyHz);
    }
}

Because each semitone is divided into 100 cents, CentsOff immediately tells a user whether they are sharp (positive) or flat (negative) relative to the nearest piano key.

2. Measuring Octave Span Without Letting Brief Cracks Inflate Results

Once your audio pipeline produces pitch readings dozens of times per second (for example from NAudio on desktop or a browser Web Audio front end), computing a singer's range is simply (highestMidi - lowestMidi) / 12.0 octaves. The subtle engineering catch is noise at the edges of a voice.

A brief vocal crack or a half-second squeak can easily register two or three semitones higher than a note the singer can actually sustain. In practice, requiring a note to remain within a narrow tolerance for roughly 2 seconds before updating the confirmed minimum or maximum MIDI value produces far more realistic vocal range measurements, while brief extremes can still be logged separately.

3. Matching a Vocal Range Against Standard Voice Types

Standard choral and vocal pedagogy divides ranges into seven overlapping voice types: Bass, Baritone, Tenor, Countertenor, Alto (Contralto), Mezzo-Soprano, and Soprano. You can see how those note boundaries line up on a standard vocal range chart before encoding them as MIDI intervals in C#:

public readonly record struct VoiceTypeBand(string Name, int LowMidi, int HighMidi);

public static class VoiceClassifier
{
    // Standard approximate MIDI intervals (C2 = 36, C4 = 60, C6 = 84)
    private static readonly VoiceTypeBand[] Bands =
    [
        new("Bass",          40, 64), // E2 - E4
        new("Baritone",      45, 69), // A2 - A4
        new("Tenor",         48, 72), // C3 - C5
        new("Countertenor",  52, 76), // E3 - E5
        new("Alto",          53, 77), // F3 - F5
        new("Mezzo-Soprano", 57, 81), // A3 - A5
        new("Soprano",       60, 84), // C4 - C6
    ];

    public static IEnumerable<(string VoiceType, double OverlapPercent)> RankMatches(int userLowMidi, int userHighMidi)
    {
        int userSpan = Math.Max(1, userHighMidi - userLowMidi);

        return Bands.Select(band =>
        {
            int overlapLow = Math.Max(userLowMidi, band.LowMidi);
            int overlapHigh = Math.Min(userHighMidi, band.HighMidi);
            int overlap = Math.Max(0, overlapHigh - overlapLow);
            int bandSpan = band.HighMidi - band.LowMidi;

            // Balanced overlap score relative to both the user's span and the voice-type band
            double score = (2.0 * overlap) / (userSpan + bandSpan) * 100.0;
            return (band.Name, Math.Round(score, 1));
        })
        .OrderByDescending(x => x.Item2);
    }
}

4. Why Overlap Scoring Works Better Than Midpoint Rules

A naive classifier only checks the midpoint of a singer's range, which breaks down when someone has an unusually wide range (for instance, spanning three full octaves) or tests only their comfortable chest register. Using a symmetric overlap score (similar to the Dice coefficient) rewards both coverage of the target voice band and proximity of boundaries, giving beginners a sensible first estimate.

Keep in mind that real-world classical voice classification (Fach) also considers timbre, tessitura (where the voice sounds most effortless), and vocal weight — so range-based classification should always be presented as an educational estimate rather than a formal diagnosis.

Wrapping Up

With under 60 lines of clean C#, you get accurate Hz-to-note conversion, cent-level tuning feedback, octave span math, and transparent voice-type ranking. Because all calculations are pure floating-point arithmetic, the exact same logic runs cleanly in ASP.NET backends, Blazor WebAssembly apps, or desktop .NET audio tools.