To detect when an audio event (such as a musical note) occurs, one straightforward method is to test whether the peak amplitude of the audio signal surpasses an established threshold that's slightly above the level of the ambient noise floor. The peakamp~ object periodically reports the greatest absolute value of amplitude that has occurred during the specified time interval. For quick response, that interval should usually be every 10 to 30 milliseconds.
This example plays the first sixteen harmonics based on a fundamental frequency where the rate at which each harmonic play is period / # of harmonic. For example, with a period of 10000 ms—meaning the fundamental plays every 10000 ms—the 4th harmonic will be heard every 10000/4 ms, or 2500 ms.
There are several ways to initialize UI objects, but the data is not stored with the object itself (except for the Live objects). Triggering an initializing message to the object with loadbang is one way. See also loadmess, patcherargs, and pattr.
The example demonstrates two methods. This first one uses smoothing to create a ramp on and off instead of an instantaneous switch on and off. This second one waits a certain amount of time before it begins the release ramp, and if the input signal goes back above the threshold during that time it cancels the release (the default amplitude threshold being -40 dB).
This is a flanger that can easily be used as an abstraction (subpatch) within any audio patch. Simply save this patch in Max's file search path with the file name "flange~.maxpat", and it can then be used as a flange~ object, as shown in the example "Try the flange~ abstraction".
This patch is designed to be used as an abstraction (subpatch) in another patch, such as the example "Mixing multiple audio processes". In order for that example to work, you should download this example and save it with the filename "pinger.maxpat" somewhere in the Max file search path.
To invert a musical phrase around a particular axis of symmetry, multiply the axis pitch by 2, then subtract the played pitches from that. For example to invert all pitches around the axis of middle C (MIDI key 60), you would subtract the pitches from 120.
The term "mapping" refers to making a map of correspondences between a source domain and some other "target" range. (Think of the game where you are given words in one category and are challenged to try to find an appropriate correspondence in another category, as in "Kitten is to cat as puppy is to ...".) The simplest kind of numerical mapping is called "linear mapping". That's when a one-to-one correspondence is drawn from every value in a source range X to a value that holds an exactly comparable position in a target range Y.