# Signal Parameters in MSP

## Decibels

• In Max, we can use the expression object to calculate amplitude in dB from a linear amplitude control value: Fig. 1: An MSP expression to convert amplitude values to dB.

• As well, the atodb~ and dbtoa~ objects exist in MSP for converting between linear amplitude and dB scales. ## Midi/Frequency Conversion

• 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.

## Max Message to MSP Signal Converters

• The sig~ object takes a control-rate float or int value and outputs that value at the audio rate.

• The gain~ object provides an interpolating logarithmic signal fader.

• The number~ object can be used to monitor incoming signal values or generate a constant audio-rate signal.

## MSP Signal to Max Message Converters • The average~ object computes a running average of an input signal over a specified number of samples. It can provide three different average types, bipolar'', absolute'', and rms''.

• The avg~ object computes the average of the absolute value of an input signal between bangs.

• The meter~ object provides a graphical signal level meter.

• The snapshot~ object outputs the current audio sample value when a bang is received.

• The peakamp~ object reports the maximum absolute value of audio data between bangs or at regular intervals.

• The spike~ object reports intervals of zero to non-zero transitions.

• The zerox~ object counts zero-crossings, which can be used to distinguish transients from pitched signals.

## Signal Feature Extraction in MSP

• 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.
• The fiddle~ 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.

• Trond Lossius 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. ©2004-2019 McGill University. All Rights Reserved.Maintained by Gary P. Scavone.