[PD] range of numbers

Frank Barknecht fbar at footils.org
Fri Aug 20 23:54:48 CEST 2004

vanDongen/Gilcher hat gesagt: // vanDongen/Gilcher wrote:

> You want to map a range of 0.5 length f.i. starting at 0.1 to another range 
> starting at 0 or any other number.
> You do that by
> 1)
> subtract the smallest number (so that is mapped to zero)

You need not necessarily use the smallest number, though. If you want
to invert the input and for example map [127,10] to [20,40] it's
possible as well like this (x is input):
 * (20-40)/(127-10)  (ratio of out- and input ranges)
 + 20

although 10 and not 127 would be the smaller number, or more

(x-il) * (il-ih)/(ol-oh) + ol

and in "expr" form for Pd: 

 [ expr ($f1-$f2) * ($f4-$f5) / ($f2-$f3) + $f4 ]

using input, from_low, from_hi, to_low, to_high as inlets.

Basically this all is an application of the "rule of three" from

 Frank Barknecht                               _ ______footils.org__

More information about the Pd-list mailing list