Exponential interpolation with [pattrstorage]

Brennon Bortz's icon

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!

Roman Thilenius's icon

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.

Brennon Bortz's icon

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... ;)

Christopher Dobrian's icon

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.)

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

Here are a few examples to demonstrate.

(This last one requires the attached file.)

3065.dBexamplepresets.json
json
Brennon Bortz's icon

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!