hello everybody i want to build a simple patch that converts the range 0 to 1 to -4 to 4 where 0.5 equals 0 in the second range. can anyone help? hugs bernardo
[number
|
[* 8]
|
[- 4]
|
[number\
bernardo amorim wrote:
hello everybody i want to build a simple patch that converts the range 0 to 1 to -4 to 4 where 0.5 equals 0 in the second range. can anyone help? hugs bernardo
-- Raging_Synth Bernardo Gomes de Amorim - 2007
Confidencialidade de Correio electrónico Este email destina-se exclusivamente à(s) pessoa(s) a quem é dirigido e não deverá em caso algum ser reencaminhado ou reutilizado para nenhum fim a não ser aquele para o qual foi criado. Aplicável tambem aos attachments.
PD-list@iem.at mailing list UNSUBSCRIBE and account-management -> http://lists.puredata.info/listinfo/pd-list
Hallo, bernardo amorim hat gesagt: // bernardo amorim wrote:
i want to build a simple patch that converts the range 0 to 1 to -4 to 4 where 0.5 equals 0 in the second range. can anyone help?
Now that you've already got some solutions for this case, it's maybe time to go for the more general case as well?
What you want to do is called scaling or mapping or interpolating one range to another range. First you need to adapt the lengths of your ranges: 0-1 has length 1, while -4 to 4 has length 4-(-4) = 4 + 4 = 8. So you first multiply by 8 to scale the length.
This will give you an intermediate mapping from 0-1 to 0-8. This then needs to be shifted to the starting point, -4 in the example, by adding the starting point's value: + (-4) or -4.
Now replace -4 by a variable, lets say, x1, and 4 by y1, to calculate the general formula for interpolation (and extrapolation, too):
scale_to_x1_y1(x) = x * (y1 - x1) + x1
You can put this into an expr-fomula: [expr $f1 * ($f3-$f2) - $f2] where x -> $f1, x1 -> $f2 and y1 -> $f3.
This also will work with "inverse" mappings, where the second number is smaller than the first, like mapping 0,1 to 3,-2 (needed when scaling gemmouse coordinates to gemwin coordinates):
scale_to_3_minus2(x) = x * (-2 - 3) + 3 = -5*x + 3
Note that the "length" of the ouput range is negative here: -5 This will make your scale be turned upside down as needed (in gemmouse->gemwin you'd scale the x-axis this way, it has 4 on top and -4 on bottom, while gemmouse has 0 on top, and 1 on bottom, so the mapping would be 0,1 -> 4,-4)
Lets test the borders:
left: scale_to_3_minus2(0) = 3 (good) right: scale_to_3_minus2(1) = -5 + 3 = -2 (good, too).
Scaling from arbitrary input ranges (x0,y0) is left as an excercise. Hint: First scale to (0,1).
Frank Barknecht _ ______footils.org__
That work too :
[loadbang] | |0, 1( | |0 \ <- change this | [autoscale -4 4] | |0 \
But i prefer this the derek's solution :
[number
|
[* 8]
|
[- 4]
|
[number\
++
Jack
Le 20 nov. 07 à 12:35, bernardo amorim a écrit :
hello everybody i want to build a simple patch that converts the range 0 to 1 to -4
to 4 where 0.5 equals 0 in the second range. can anyone help? hugs bernardo-- Raging_Synth Bernardo Gomes de Amorim - 2007
Confidencialidade de Correio electrónico Este email destina-se exclusivamente à(s) pessoa(s) a quem é
dirigido e não deverá em caso algum ser reencaminhado ou
reutilizado para nenhum fim a não ser aquele para o qual foi
criado. Aplicável tambem aos attachments. _______________________________________________ PD-list@iem.at mailing list UNSUBSCRIBE and account-management -> http://lists.puredata.info/ listinfo/pd-list