## Duration Scaling

You can normalize the raw algorithm output values through the process of scaling. This will map output values into a duration range you choose. You specify the lowest duration value, dmin, and the highest duration value, dmax, in the text boxes of "Use values from __ to __." All output values will be scaled into values in this range. dmin must be at least 0, and dmax must be at most 5 and greater than or equal to dmin. A default range of 0 to 5 is provided. You must also decide how the values will scaled: using the division operation or the modulo operation.

The division operation scales the output values proportionally throughout the range you provide. The highest number in the list of output values, omax, will be scaled to the highest duration value you chose, dmax. Likewise, the lowest number in the list of output values, omin, will be scaled to the lowest duration value you chose, dmin. As an example, if the algorithm's output values are (1, 0, 2, 3) and you use the default duration range of 0 to 5, the division operation will yield the pitch values (1, 0, 3, 5). Note that decimals are truncated in the process to produce integer results. The assignment of a duration value, d, given an output value, o, is described by the formula

d = dmin + (dmax - dmin)(o - omin) / (omax - omin)

For example, if the output values are (64, 81, 100, 121, 144) and the duration values range from 1 to 3, then the duration value corresponding to 100 would be d = 1 + (3 - 1)(100 - 64) / (144 - 64) = 1.9 ~ 1 (truncated). The entire list of duration values would be (1, 1, 1, 2, 3).

The modulo operation scales the output values into a cyclical pattern throughout the range you provide. In general, a modulo b is the integer remainder resulting when a is divided by b. A duration value is computed using the formula

d = dmin + o % (dmax - dmin + 1)

Here, % indicates the modulo operation. As an example, consider the output values of (64, 81, 100, 121, 144) again. If the duration range is 0 to 5, the duration value corresponding to 100 would be d = 0 + 100 % (5 - 0 + 1) = 0 + 100 % 6 = 4, and the entire list of duration values would be (4, 3, 4, 1, 0). Using a duration range of 1 to 3 instead would produce a duration value d = 1 + 100 % (3 - 1 + 1) = 1 + 100 % 3 = 2 for the output value 100, and the entire list of duration values would be (2, 1, 2, 2, 1).

To derive the duration values once you've made your choices, simply click the Scale values button. If the derived duration values box was previously empty, the scaling will be performed on the algorithm output values. Otherwise, it will be performed on the existing duration values. This allows you to apply several successive scalings on scaled values if you wish, choosing a new range and operation with each scaling. If you make a mistake or would just rather apply scaling to the original algorithm output only, click the Start over button, which will clear the derived duration values box.