How can I create a slider to do smooth gains

dhjdhjdhj's icon

My math skills are unfortunately very rusty. I have a [gain~] which I want to be able to adjust smoothly from a pedal but I have observed that most of the volume increase happens towards the very top of the range.

I realize that one is to supposed to use some kind of log conversion to compensate for this but I don't know the right function/coefficients to use.

So if I have a pedal that produces MIDI values from 0 to 127, how can I translate that into the correct values to get perceptually smooth volume changes across the entire range?

Thanks in advance,
D

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

Hi, I think that gain~ is the complex object and it's really easier to implement than you think. Gain uses a dB (log) scaling and the slider is linear so you just have to do the old school Amplitude scaling with it : https://cycling74.com/docs/max6/dynamic/c74_docs.html#mspchapter02

hope this helps.
Matthieu
PS : if you really want to deal with the perceived loudness, you'll have to deal with the frequency, that would be really more complex I guess : http://en.wikipedia.org/wiki/Equal-loudness_contourEDIT : I just had alook at your profile and I guess I misunderstood your question sorry, ignore the post above... :)

dhjdhjdhj's icon

Hmmm, not sure what's in my profile that would lead you to misunderstand my question !

The amplitude amount changes more rapidly as one gets to the top of possible values, i.e, much of the gain happens in a very small portion of the slider range.

Therefore, I'd like to arrange things so that the rate of change of the gain slider is reduced the higher is the value of the input control (0..127)

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

Sounds like you might be happier with a linear response:

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

this is an abstraction I use for your situation-- generally when I want to change the throw of a physical slider in a midi controller-- it remaps a straight line into a parabolic segment
it takes arguments in the same way [scale] does, but the curvature coeff is more useful (in my opinion)

dhjdhjdhj's icon

Terry, this is exactly what I'm looking for except that the behavior is exactly opposite to what I want.

At the bottom, moving source slider a lot only moves the target slider a little.

I want EXACTLY the opposite of that, i.e, at the bottom, moving the source slider a little will move the target slider a lot, and then at the top, moving the source slider a lot will just move the target slider a little as very slight changes in the gain~ are much more noticable at the top end.

Err0r_500's icon

Hi, did you try setting the curvature to -1?

Chris Muir's icon

Did you try the linear response thing I posted? Was that closer to the curve you're looking for?

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

That one didn't change the gain~ at all. It was the total level that I was trying to change. In the meantime I came up with a simple log function that I'm getting ready to test when I get to my studio but visually it looks close to what I wanted.

Floating Point's icon

goodness gracious, dhj did you read the text in the comment box that came with my abstraction? as error_500 says, alter the curvature argument (the 5th arg)-- may i suggest about -0.7 is a good feel. It's got the same types of args as [scale]

Chris Muir's icon

It's true that my patch didn't change the gain~ slider, but it did try point out that a linear change might be close to what you're after. If so, why are you using gain~ at all? Why not use the line~ *~ combo? The log/antilog behavior seems silly if what you're after is a sort of linear response.

Also gain~ goes from -∞ to 0db over the range 0-127. 128 to 157 is adding gain, which you probably don't want.

dhjdhjdhj's icon

Well, it's partially my lack of understanding of some of the audio stuff, where I have very little experience.

I have built a mixing console with individual channel strips and a system that allows me to create VSTs on the fly and route them without patching.

The output of each VST or VST FX goes into a channel strip that has a gain~ slider to control volume. Then the final master output strip uses a gain~ for the final level. Everything goes to a MOTU 828 mk3

I found as I adjusted those gain sliders from the GUI (or via incoming MIDI expression pedals) that volume changes were very concentrated towards the top of the range, i.e. very slight changes in slider movement had huge impact on volume and so I wanted to compensate for that.

I'm absolutely open to better ways of doing this. At this time, Max has completely replaced Apple MainStage for me and it's just working brilliantly.

I appreciate your comments and response.

D

jvkr's icon

Part of a set of abstractions is a gain that I use always in my own work. It can be downloaded from jvkr.nl or directly using this link: http://jvkr.nl/public_downloads/jx.all.zip
This jx.gain~ has been modeled to be equal to a fader on a mixing desk. Particularly when controlling with midi faders, it gives the feel you describe you're looking for, in which gain~ is lacking.

dhjdhjdhj's icon

@Terry yes I did..and I tried negative ales but it didn't seem to do what I needed. The single expr with scaling seemed todo the trick though I'm stil interested in what Chris had to say

@jvkr thanks for telling me about your library. As soon as I'm at my Mac, I will take a look.

D

dhjdhjdhj's icon

@jvkr do your abstractions work with Max 6.x?

dhjdhjdhj's icon

I just started looking at jx.gain2 (I need stero) and have a few questions. First of all, I don't really understand what exactly is going on, the purpose of the buffer, peek, line~ and so forth.

What exactly is this doing that could not be done by just appropriately scaling the gain~ slider?

Thanks,
D

jvkr's icon

The peek~ is used to store 128 values, the default range of the slider or dial that will be controlling it. The development of this set of abstractions started in a time when it made sense to calculate all values at launch time and store them in a table (or a buffer, in the case of floats), rather then recalculating them each time. Especially as there are two powers in the calculation.

The whole idea is that a slider reads out values for a multiplication factor. A line~ is used to avoid discontinuities in the signal.

Maybe it is possible to find values for inc and scale to get similar behavior but I can't find documentation on what the calculation looks like and don't feel like finding it out.

This abstraction solves for me the issue that you mentioned in the initial post. I use in almost all cases this gain. The live.gain~ is kind of fine with me too, especially as it is stereo.

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

Below patch gives a little more explanation.

dhjdhjdhj's icon

Thank you --- most illuminating.

moss's icon

I use the following settings with a dial and a gain~ to control it via midi CC:

gain~: Number of Step = 300 (158 by default)
dial : Number of Steps/Range = 100 (128 by default)
Minimum Value = 200 (0 by default)

dhjdhjdhj's icon

Are you then scaling midi cc values 0-127 to dial values 200-300?

moss's icon

Yes, for me that's fine but I guess you could also scale it to a wider range. Just fiddled that long with it till I got the result I expected.