# [PD] Scaling values in pd

Lorenzo Sutton lorenzofsutton at gmail.com
Tue Sep 3 15:11:06 CEST 2013

```On 03/09/2013 14:06, Mario Mey wrote:
> IOhannes, you are right only in these cases:
>
> 0 127 0 500
> 0 300 0 1
> ...
>
> But, if I need:
>
> 50 10 0 500|
(assuming you want to map have 50 mapped to the 'minimum'):
|
[- 10]
|
[t b f]
|   /
[-  ]
|
[* 12.5]
|

> 3000 -3000 0.5 0.6
[* -1]
|
[+ 3000]
|
[/ 60000]
|
[+ 0.5]

> ...
>
> I will need a "linear equation conversion". As I wrote in last mail, I
> was needing something like this, first in ActionScript... then in
> Python... but I never could did it. Now, I needed again in Pd... so, I
> made lin-eq-conv.pd with extrapolation and lin-eq-conv-clip.pd for
> clipped values. I made it as neat as I could, to see how it works.
> Using x0-x1 and y0-y1, it uses expr to get "a" and "b" at load. Then,
> it only computes "aX + b = Y".
>
> I attach the lin-eq-conv.pd, lin-eq-conv-clip.pd and lin-eq-conv-help.pd.
>
> Also, I have some issues using [autoscale]. I start giving values and
> it outputs only 1. Then, I start to down the input and, then, it shows
> 64bits).
>
> PD: translated to Python:
>
> |def lin_eq_conv(x, x0, x1, y0, y1):
>    a = (y0 - y1) / (x0 - x1)
>    b = (a * x0) + y0
>    return a * x + b|
>
>
>
>
> El 03/09/13 03:32, IOhannes zmölnig escribió:
>> On 09/02/2013 06:17 PM, hghoyer wrote:
>>> Hi,
>>>
>>> in Max/MSP there is an object for simple scaling.
>>>
>>> If you create in MAX these object with this arguments:
>>>
>>> [scale 0 127 0 500] incomming messages from 0 to 127 are automatically
>>> scaled from 0 to 500...
>> honestly i'm of the firm conviction that you should learn how scaling
>> works: it really is only a matter of adding, multiplying, dividing,
>> subtracting - stuff you should heave learned in primary school.
>>
>> as frank pointed out, this should do for you:
>>
>> |
>> [/ 127]
>> |
>> [* 500]
>> |
>>
>> if you find it too tedious to do the maths over and over again, you
>> might want to create an abstraction.
>>
>>
>> being able to solve trivial problems like this will surely empower you
>> to solve more complex problems :-)
>>
>> gamsdr
>> IOhannes
>>
>>
>>
>>
>>
>> _______________________________________________
>> Pd-list at iem.at  mailing list
>> UNSUBSCRIBE and account-management ->http://lists.puredata.info/listinfo/pd-list
>
>
>
> _______________________________________________
> Pd-list at iem.at mailing list
> UNSUBSCRIBE and account-management -> http://lists.puredata.info/listinfo/pd-list

```