## Exponential interpolation with [pattrstorage]

Dec 9, 2011 at 12:48am

# Exponential interpolation with [pattrstorage]

I’m using a `[pattstorage]` to interpolate between presets. I’m changing the level of two different `[gain~]` objects between presets–the level of one increases while the level of another decreases. In addition, this relationship may change–the one that increases from one preset to another may decrease in a different preset shift and vice versa.

Obviously, changing the value of a `[gain~]` object linearly doesn’t result in a smooth change in amplitude. So, I know I should be interpolating according to some exponential curve here. However, I have two problems. First, what exponent for this power curve should I use? Second, this curve holds with `[pattrstorage]` irrespective of whether or not the values are increasing or decreasing. In other words, in the case where an amplitude should be increasing, some number less than 1.0 gives me the correct general shape of the curve, but when the same amplitude later decreases for a different preset, I have a resulting amplitude that drops far too quickly (here I should be using an exponent greater than 1.0.) Is there some trick I have missed? I hope I’ve explained my question clearly–if not, please let me know where I can clarify things. Thanks!

#60574
Dec 9, 2011 at 5:14pm

may i ask why you use [pattrstorage] to control [gain~] ?

i find [gain~] a totally stupid object, its cryptic math just doesnt make any sense.

#218005
Dec 12, 2011 at 5:59pm

Good question. Another control may in fact be the answer to this particular issue, but my larger question about the maintaining the shape of an interpolation curve between two presets still stands… ;)

#218006
Dec 12, 2011 at 10:54pm

gain~ has exponential scaling built in, so you can send it linearly changing int values from 0 to 128 and it will scale exponentially from 0. to 0.999999 (with sample-by-sample interpolation according to the ramp time you specify for gain~’s ‘interp’ attribute).

If you find that to be “totally stupid”, you can do your own conversion of linear to exponential, using pow, expr, dbtoa, or ‘pow’ interpolation in pattrstorage. There’s no magic “right” number for the exponent; it depends on the type of curve you want. For scaling audio signals, I find that dbtoa works fine, and you can use number~ to do the sample-by-sample interpolation (in the amount of time specified by number~’s ‘interval’ attribute).

(Both gain~ and number~ use linear interpolation for their sample-by-sample interpolation between input values, but if you send enough intermediate input values in a smooth progression you won’t hear them interpolating linearly between exponentially-changing inputs.)

Here are a few examples to demonstrate.

– Pasted Max Patch, click to expand. –
– Pasted Max Patch, click to expand. –
– Pasted Max Patch, click to expand. –
– Pasted Max Patch, click to expand. –

(This last one requires the attached file.)

###### Attachments:
1. dBexamplepresets.json
#218007
Dec 13, 2011 at 10:09am

I’m a fan of the first and last ones, frankly. There’s not a whole lot that’s mysterious about `[gain~]`, I was just thinking about it the wrong way. Thanks for the examples!

#218008

You must be logged in to reply to this topic.