music.interval_between

music.interval_between(lower, upper)[source]

The interval in semitones between two frequencies, rounded.

Parameters:
lower, upperscalar

Frequencies in Hertz. upper is expected above lower.

Returns:
integer

Semitones, to the nearest one – the frequencies of real notes are not exactly tempered, and an interval is a name for a neighbourhood rather than for one ratio.

Raises:
ValueError

If either frequency is not positive, or upper is below lower.

Parameters:
Return type:

int

See also

interval_names

names the result.

hz_to_midi

the same conversion, against a fixed reference.

Examples

>>> interval_between(220.0, 330.0)   # a fifth, near enough
7
>>> interval_names(interval_between(220.0, 440.0))
('P8',)