Creating a mapped curve for a slider..

Paul Malinowski's icon

Hey all,

I'm creating a program that uses gestures to perform certain audio tasks and for this example i have a game in unity that i use a gamepad (left and right analog sticks) to open a door. The creaking sound is triggered in Max using the gamepad too but currently the forward movement of the analog stick is mapped directly to the slider so the more the stick is pushed forward the higher the slider value.

However, in order to create the right sound, the slider value needs to rise up then down slightly, so that when you push forward on the gamepad stick it makes the slider go up then down.

I hope I've explained it clearly. Basically i just need to map the linear movement of the analog stick to a sad-face curve of the slider.

Any ideas?

I would post my patch but i'd need to post the entire project for it to work.

Thanks,

Paul..

brendan mccloskey's icon

Set the slider's max val to 0.5, then pass it through a sine function [sin], or add 0.75 and send it to [cos].

Christopher Dobrian's icon

The general-purpose answer is that you can use a table object to look up an output value according to any shape you put in the table. In your case, you can alternatively use an expr object to calculate the shape of the first half of a sine wave (up, then down) and use your slider as the input to the expr. In this example, I use the latter method to fill the lookup table once, then use the table to look up the desired output.

Max Patch
Copy patch and select New From Clipboard in Max.

michelez's icon

This little patch might help understand how to turn a linear function into an exponential, not sure it's what you want but it can't hurt either...

Max Patch
Copy patch and select New From Clipboard in Max.

John Daniel's icon

This patch has been invaluable for getting just the right "feel" for me when using a gamepad as a controller... some very kind soul sent this to me a while back

Just feed your number into the top slider, the pacth bends the numbers to the curve you setup

cheers!

jd

Max Patch
Copy patch and select New From Clipboard in Max.

Paul Malinowski's icon

John Daniel, you are a saviour. Yours is perfect for what i need. Works perfectly.

Thanks to everyone else who chipped in. I tried the others and they work great, it was just John's one was the easier for me to work with.

Paul Malinowski's icon

Is there any way to mark this as answered? I can't see a button or link anywhere.

brendan mccloskey's icon

Login, and edit your first post - there's an option to edit post title.

exeterdown's icon

I've used this little function a few times to get softer values around a mid-point.

I wish I knew a way to acheive the same thing using expr.
I spend ages trying to make it work with if < 0.5 then pow 1.9 and so on...

But it flicks around too much at the 0.5 mark.

Max Patch
Copy patch and select New From Clipboard in Max.