Forums > MaxMSP

non-linear to linear


alb
February 16, 2009 | 9:57 pm

I would like to scale exponential data coming from a potentiometer (slider) to linear. Does anyone have any hints?



zoe
February 16, 2009 | 10:06 pm

Have a look at the ‘expr‘ object (for instance, expr exp($f1))
Zoe



zoe
February 16, 2009 | 10:09 pm

Or for your case, maybe more kindof ‘expr log($f1)’, or ‘expr ln($f1)’, depending on what kind of log you’re after.

Maybe ‘dbtoa’ or ‘atodb’ could also be helpful – Z.


February 16, 2009 | 10:13 pm

You can use a logarithmic function as a reciprocal function for any exponential function.

For instance if your exponential function is pow(2, x) the function log2(x) will allow you to get a linear output. It means you must know the base of the exponential function.

There is no log object allowing you to choose the base you want, however there is a property of logarithms you can use :
log a (b) = log c (a)/ log c (b)

With expr, this would result in this:
expr log($f1)/log($f2) with $f1 being the numbers coming from the slider and $f2 being the base of the logarithm (2 in the former example).

Hope this helps.

Roald Baudoux



alb
February 17, 2009 | 9:36 am

I am not fluent in thinking in log and exp therefore I’ve build a little patch that does virtually what I need. It would be lovely to learn how I could use one object to do this:

{
"patcher" : {
"fileversion" : 1,
"rect" : [ 404.0, 135.0, 388.0, 243.0 ],
"bglocked" : 0,
"defrect" : [ 404.0, 135.0, 388.0, 243.0 ],
"openrect" : [ 0.0, 0.0, 0.0, 0.0 ],
"openinpresentation" : 0,
"default_fontsize" : 10.0,
"default_fontface" : 0,
"default_fontname" : "Verdana",
"gridonopen" : 0,
"gridsize" : [ 15.0, 15.0 ],
"gridsnaponopen" : 0,
"toolbarvisible" : 1,
"boxanimatetime" : 200,
"imprint" : 0,
"metadata" : [ ],
"boxes" : [ {
"box" : {
"maxclass" : "number",
"outlettype" : [ "int", "bang" ],
"patching_rect" : [ 112.0, 199.0, 50.0, 19.0 ],
"fontsize" : 10.0,
"id" : "obj-2",
"numinlets" : 1,
"fontname" : "Verdana",
"numoutlets" : 2
}

}
, {
"box" : {
"maxclass" : "number",
"outlettype" : [ "int", "bang" ],
"patching_rect" : [ 197.0, 93.0, 50.0, 19.0 ],
"fontsize" : 10.0,
"id" : "obj-71",
"numinlets" : 1,
"fontname" : "Verdana",
"numoutlets" : 2
}

}
, {
"box" : {
"maxclass" : "newobj",
"text" : "scale 21 950 85 127",
"outlettype" : [ "int" ],
"patching_rect" : [ 197.0, 125.0, 113.0, 19.0 ],
"fontsize" : 10.0,
"id" : "obj-72",
"numinlets" : 6,
"fontname" : "Verdana",
"numoutlets" : 1
}

}
, {
"box" : {
"maxclass" : "number",
"outlettype" : [ "int", "bang" ],
"patching_rect" : [ 197.0, 155.0, 50.0, 19.0 ],
"fontsize" : 10.0,
"id" : "obj-73",
"numinlets" : 1,
"fontname" : "Verdana",
"numoutlets" : 2
}

}
, {
"box" : {
"maxclass" : "number",
"outlettype" : [ "int", "bang" ],
"patching_rect" : [ 40.0, 93.0, 50.0, 19.0 ],
"fontsize" : 10.0,
"id" : "obj-70",
"numinlets" : 1,
"fontname" : "Verdana",
"numoutlets" : 2
}

}
, {
"box" : {
"maxclass" : "newobj",
"text" : "if $i1 < 21 then $i1 else out2 $i1",
"outlettype" : [ "", "" ],
"patching_rect" : [ 40.0, 66.0, 177.0, 19.0 ],
"fontsize" : 10.0,
"id" : "obj-69",
"numinlets" : 1,
"fontname" : "Verdana",
"numoutlets" : 2
}

}
, {
"box" : {
"maxclass" : "newobj",
"text" : "scale 0 20 0 85",
"outlettype" : [ "int" ],
"patching_rect" : [ 40.0, 125.0, 88.0, 19.0 ],
"fontsize" : 10.0,
"id" : "obj-67",
"numinlets" : 6,
"fontname" : "Verdana",
"numoutlets" : 1
}

}
, {
"box" : {
"maxclass" : "number",
"outlettype" : [ "int", "bang" ],
"patching_rect" : [ 40.0, 35.0, 52.0, 19.0 ],
"fontsize" : 10.0,
"id" : "obj-39",
"numinlets" : 1,
"fontname" : "Verdana",
"numoutlets" : 2
}

}
, {
"box" : {
"maxclass" : "number",
"outlettype" : [ "int", "bang" ],
"patching_rect" : [ 40.0, 155.0, 50.0, 19.0 ],
"fontsize" : 10.0,
"id" : "obj-33",
"numinlets" : 1,
"fontname" : "Verdana",
"numoutlets" : 2
}

}
],
"lines" : [ {
"patchline" : {
"source" : [ "obj-73", 0 ],
"destination" : [ "obj-2", 0 ],
"hidden" : 0,
"midpoints" : [ ]
}

}
, {
"patchline" : {
"source" : [ "obj-33", 0 ],
"destination" : [ "obj-2", 0 ],
"hidden" : 0,
"midpoints" : [ ]
}

}
, {
"patchline" : {
"source" : [ "obj-69", 1 ],
"destination" : [ "obj-71", 0 ],
"hidden" : 0,
"midpoints" : [ ]
}

}
, {
"patchline" : {
"source" : [ "obj-39", 0 ],
"destination" : [ "obj-69", 0 ],
"hidden" : 0,
"midpoints" : [ ]
}

}
, {
"patchline" : {
"source" : [ "obj-69", 0 ],
"destination" : [ "obj-70", 0 ],
"hidden" : 0,
"midpoints" : [ ]
}

}
, {
"patchline" : {
"source" : [ "obj-67", 0 ],
"destination" : [ "obj-33", 0 ],
"hidden" : 0,
"midpoints" : [ ]
}

}
, {
"patchline" : {
"source" : [ "obj-70", 0 ],
"destination" : [ "obj-67", 0 ],
"hidden" : 0,
"midpoints" : [ ]
}

}
, {
"patchline" : {
"source" : [ "obj-72", 0 ],
"destination" : [ "obj-73", 0 ],
"hidden" : 0,
"midpoints" : [ ]
}

}
, {
"patchline" : {
"source" : [ "obj-71", 0 ],
"destination" : [ "obj-72", 0 ],
"hidden" : 0,
"midpoints" : [ ]
}

}
]
}

}


February 17, 2009 | 9:46 am



alb
February 17, 2009 | 10:26 am

Thanks. I made 3 splits and tuned them to the slider output. Works fine for now.


Viewing 7 posts - 1 through 7 (of 7 total)