gain~ object, more linear?

blindpilot's icon

Hi,

For a particular use use, I find the gain~ object too "logarithmic".  Is there an easy way to make it behave in a more "linear" way?

Thanks for your help!

Manuel

John's icon
Max Patch
Copy patch and select New From Clipboard in Max.

This will scale an MSP signal linearly, but does not use the gain~ object:

Is that what you're looking for?

John's icon
Max Patch
Copy patch and select New From Clipboard in Max.

I believe the expr object in this patcher scales 0-127 to 0. 1. along the same curve as gain~

blindpilot's icon

Thanks John,
The situation, in more detail, is this: for a sound installation I need to control the volumen of a loudspeaker using an Arduino and an ultrasonic distance sensor. It is now working fine but I find that the distance value outputed by the arduino has some spike noise and needs some smoothing.
I can successfully smooth it out using the gain~ object with its ramp property set to 500ms. but the problem with this object is that the change in volumen in relation to the change of distance seems too "logarithmic"

I cannot use a linear slider, as you say, because I do need the smoothing factor provided by the 500ms ramp of the gain~ object.

Roman Thilenius's icon

you can implement the interpolation yourself by putting a [line~ 500.] between the slider and the [*~ 0.]

John's icon

Blindpilot,

"I cannot use a linear slider, as you say, because I do need the smoothing factor provided by the 500ms ramp of the gain~ object."

That is true, but line~ can be used to ramp numbers in a way similar to gain~. sending line~ a message with two numbers [x y] where x is a float representing the destination gain value and y is a ramp time in MS will generate a smooth transition. In the example I pasted the line~ is sending its values to the right inlet of *~. MSP signals sent to the left input will be multiplied by the output from line~.
As Roman states, the ramp time can be anything...5, 500, 5000, 5,000,000

blindpilot's icon

Got it working now with the slider and line~ to smooth it out :)

Thanks both for your kind help!!