# pow

## MIDI mapping to amplitude

Mapping one range of values to another needed range of values is a crucial technique in computer music. In this example, we want to map MIDI data values that range from 0 to 127 into a useful range for controlling the amplitude—and thus the loudness—of a sound in MSP.

## Calculate pitchbend transposition

This patch shows how to calculate pitch bend transposition.

## Converting MIDI pitch to frequency

This patch shows three different ways to convert MIDI pitch value to frequency.

## Trigger sample with metro

This program triggers a sound repeatedly, and changes the sound's playback rate with each repetition. The sound file is so short that there's really no need to turn it off with a 0, so we just start it with a 1. The playback rate is calculated so as to cause a random transposition from -12 to +12 equal-tempered semitones, using the twelfth root of 2; the number of semitones (x) of transposition is determined by setting the rate to "2 to the x/12 power". You can put the patch into Presentation mode, which will present a cleaner user interface.

## Avoiding infinity in pow and /

Taking 0 to the power of any negative exponent equals infinity. In Max, this yields the unique float value inf. In cases where you want to avoid getting inf, and would prefer to get 0, you can simply make a special case for a 0 input, and pass it on directly, avoiding the pow object. On the left is an example of how to use routepass to force Max to output 0 when it would otherwise calculate infinity, such as when using a pow -1 object.

## Use stored waveform for a synthesizer

This patch demonstrates the technique of wavetable synthesis: using one cycle of a stored waveform as the wave type for a synthesizer tone. The cycle~ object with no argument produces a cosine wave; however, cycle~ can also refer to a waveform stored in a buffer~, and use that as a wavetable. To do that, you need to create a buffer~, store a waveform in it, and then refer to that buffer~ by creating a cycle~ with the same name.

## Time interval and rate

This patch provides examples that compare linear rate changes to exponential rate changes. As with pitch and loudness, our sense of change in the rate of events is based on the ratio of tempos rather than the (subtractive) difference between tempos. In these examples, the rate changes by a factor of 16, from 1 event per second to 16 events per second, or vice versa.

## Half speed and double speed

For specifying the rate of an audio file or the rate of a video file, the number 1 is used for normal rate, and we may want to be able to increase or decrease the rate by a certain ratio. For example we may want to double or halve the rate, setting it to either 2 times normal or 1/2 of normal.