How can I create a slider to do smooth gains

Feb 15, 2012 at 2:08am

How can I create a slider to do smooth gains

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?

D

#61784
Feb 15, 2012 at 7:08am

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 : http://cycling74.com/docs/max6/dynamic/c74_docs.html#mspchapter02

– Pasted Max Patch, click to expand. –

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_contour
EDIT : I just had alook at your profile and I guess I misunderstood your question sorry, ignore the post above… :)

#223052
Feb 15, 2012 at 8:32pm

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)

#223053
Feb 15, 2012 at 8:49pm

Sounds like you might be happier with a linear response:

– Pasted Max Patch, click to expand. –
#223054
Feb 15, 2012 at 9:07pm

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)

– Pasted Max Patch, click to expand. –
#223055
Feb 16, 2012 at 1:54pm

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.

#223056
Feb 16, 2012 at 1:57pm

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

#223057
Feb 16, 2012 at 6:57pm

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

#223058
Feb 16, 2012 at 8:30pm

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.

– Pasted Max Patch, click to expand. –
#223059
Feb 16, 2012 at 8:40pm

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]

#223060
Feb 16, 2012 at 9:37pm

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.

#223061
Feb 16, 2012 at 10:53pm

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.

D

#223062
Feb 16, 2012 at 11:15pm

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.

#223063
Feb 17, 2012 at 4:10am

@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

#223064
Feb 17, 2012 at 5:33pm

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

#223065
Feb 17, 2012 at 5:45pm

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

#223066
Feb 17, 2012 at 10:07pm

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.

Below patch gives a little more explanation.

– Pasted Max Patch, click to expand. –
#223067
Feb 17, 2012 at 11:43pm

Thank you — most illuminating.

#223068
Feb 19, 2012 at 7:25pm

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)

#223069
Feb 20, 2012 at 11:54am

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

#223070
Feb 22, 2012 at 7:46am

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.

#223071

You must be logged in to reply to this topic.