Table of Contents

Struct KeyDetectionResult

Namespace
Celeritas.Core.Analysis
Assembly
Celeritas.dll

Result of key detection analysis.

public readonly record struct KeyDetectionResult : IEquatable<KeyDetectionResult>
Implements
Inherited Members

Constructors

KeyDetectionResult(KeySignature, float, KeyCorrelation[], int)

Result of key detection analysis.

public KeyDetectionResult(KeySignature Key, float Confidence, KeyCorrelation[] AllCorrelations, int DistinctPitchClasses = 0)

Parameters

Key KeySignature

The most likely key.

Confidence float

Margin between the best key's score and the runner-up's, relative to the best (clamped to 0-1). It is a separation measure, not a goodness-of-fit: it says how cleanly the winner beat the field, not how well the music fits the key. A clear detection typically lands around 0.1-0.35, so a value below 0.5 is not "low confidence".

AllCorrelations KeyCorrelation[]

All 24 key correlations, sorted most likely first. A run of keys whose correlations all lie within 1e-5 of the run's strongest is a tie, and a tie is listed in key order — majors C..B, then minors C..B — the same rule that chooses Key from a tie; the list leads with Key. The order is therefore the same on every machine: the SIMD kernels differ by about 1e-7, so sorting on the raw value alone let the CPU decide which of two symmetric keys came first.

DistinctPitchClasses int

How many of the twelve pitch classes the analyzed material actually sounded, 0-12. This is the evidence behind Confidence, reported separately because the two answer different questions: a margin can be wide on almost no evidence. Two notes a fifth apart separate their winner from the field about as cleanly as a whole phrase does, because a clean separation among candidates is not the same thing as enough music to decide a key. Fewer than about five distinct pitch classes cannot single out a seven-note scale, whatever the margin reads.

Properties

AllCorrelations

All 24 key correlations, sorted most likely first. A run of keys whose correlations all lie within 1e-5 of the run's strongest is a tie, and a tie is listed in key order — majors C..B, then minors C..B — the same rule that chooses Key from a tie; the list leads with Key. The order is therefore the same on every machine: the SIMD kernels differ by about 1e-7, so sorting on the raw value alone let the CPU decide which of two symmetric keys came first.

public KeyCorrelation[] AllCorrelations { get; init; }

Property Value

KeyCorrelation[]

Confidence

Margin between the best key's score and the runner-up's, relative to the best (clamped to 0-1). It is a separation measure, not a goodness-of-fit: it says how cleanly the winner beat the field, not how well the music fits the key. A clear detection typically lands around 0.1-0.35, so a value below 0.5 is not "low confidence".

public float Confidence { get; init; }

Property Value

float

DistinctPitchClasses

How many of the twelve pitch classes the analyzed material actually sounded, 0-12. This is the evidence behind Confidence, reported separately because the two answer different questions: a margin can be wide on almost no evidence. Two notes a fifth apart separate their winner from the field about as cleanly as a whole phrase does, because a clean separation among candidates is not the same thing as enough music to decide a key. Fewer than about five distinct pitch classes cannot single out a seven-note scale, whatever the margin reads.

public int DistinctPitchClasses { get; init; }

Property Value

int

IsDecidable

Whether the material carries enough distinct pitch classes for a key to be decidable at all. A seven-note scale cannot be singled out by fewer than five of them, however clean the Confidence margin looks.

public bool IsDecidable { get; }

Property Value

bool

Remarks

This is a necessary condition and not a sufficient one — it counts pitch classes and looks at nothing else. The chromatic aggregate has all twelve and reports true here while its Confidence is exactly 0, because twelve notes fit every key equally. Check both before treating Key as a real detection.

Key

The most likely key.

public KeySignature Key { get; init; }

Property Value

KeySignature

Methods

ToString()

Returns the detected key and confidence percentage (e.g. "C Major (confidence: 82%)").

public override string ToString()

Returns

string

TopKeys(int)

The first n keys of AllCorrelations: the most likely keys, a tie among them listed in key order (majors C..B, then minors C..B), so the same n keys in the same order on every machine.

public IEnumerable<KeyCorrelation> TopKeys(int n)

Parameters

n int

Returns

IEnumerable<KeyCorrelation>

Remarks

Ties were listed in whichever order the CPU's kernel rounded them into: the augmented triad C, E, G# ties C# minor, F minor and A minor three ways, and its top five ended in F minor and A minor on an AVX machine but A minor and C# minor on a scalar one. Over the 4095 pitch-class subsets the AVX kernels and the scalar one disagreed on 111 top-five lists. The winner itself was already chosen by key order within a tie; the list now follows the same rule, so that triad's top five ends in C# minor and F minor everywhere.