Western music notation and scale systems are based on "octave equivalence". Sounds related by integer multiples of an octave are perceived as distinct in terms of "register" but similar in pitch quality.
In cycles per second, or Hertz, octaves are related by multiples of 2. If we wanted to raise a given pitch by three octaves, we would multiply its frequency by the factor 23 or 8. To lower a given pitch by three octaves, its frequency would be multiplied by 2-3 or 1/8.
An Equal Tempered tuning system is based on twelve "equal" divisions of an octave. But because octaves are related by factors of 2, each equal division of the octave is given by a factor of 21/12.
MIDI note numbers range from 0 to 127. We can convert a MIDI note to a frequency value, given that MIDI note number 69 represents the equal tempered frequency 440 Hz, by the formula:
f(n) = 440 * 2(n-69)/12
where n is the given MIDI note number.
The figure below plots the frequency values for MIDI note numbers 57 - 93.
Fig. 2: Frequency values for MIDI note numbers 57-93.
Despite the relative simplicity of the MIDI-to-Frequency conversion formula given above, most software systems instead use a lookup table indexed by note number to retrieve the corresponding frequency values. This makes sense because there are only 127 MIDI note values and the calculation of exponential functions is relatively "expensive" computationally.
Given the relationship above, we can convert a frequency value to a MIDI note number via the formula:
This formula can be expressed in the C programming language as shown below. It is necessary to account for quantization inaccuracies in floating-point calculations when casting to an integer result.
int n = (int) ( ( 12 * log(f / 220.0) / log(2.0) ) + 57.01 );
Given the exponential spacing of music intervals, it is difficult to use a lookup table for conversions of this type because intermediate frequency values cannot simply be rounded to the nearest table value.
The mtof object peforms control-rate MIDI note to Frequency conversion.
The ftom object performs control-rate Frequency to MIDI note conversions.
A large number of objects are available from Tristan Jehan
for estimating signal parameters and features.
The brightness~ object (by Tristan Jehan) provides a ``brightness'' indicator (spectral centroid measure).
The noisiness~ object (by Tristan Jehan) estimates noise in terms of spectral flatness.
The beat~ object (by Tristan Jehan) is a signal beat and tempo detector.
Several different options exist for pitch tracking in MSP. Be advised that pitch detection is a difficult and long-running problem in digital audio processing, especially for noisy or polyphonic sounds.
The fzero~ object is built into Max/MSP and attempts to estimate a fundamental frequency for monophonic signals.
object, written by Miller Puckette, provides an estimate of the fundamental frequency and amplitude of an input sound. If specified, it will attempt to track more than one voice at the same time.
The pitch~ object (by Tristan Jehan) is based on fiddle~.
More generally, the YIN algorithm
uses autocorrelation to estimate the fundamental frequency of speech or musical sounds.
also has a number of Max/MSP objects available free for download.
The tl.envfollow~ abstraction (from Trond Lossius) will track the amplitude envelope of a signal.