Ideal log volume control

Sound synthesis techniques, DSP and related mathematics

Moderators: electrogear, exonerate

Ideal log volume control

Postby Leslie147 on Fri Nov 18, 2011 10:15 pm

In case it's of use to others, earlier this eve I needed a volume control (i.e. attenuator) having the characteristics of an ideal 'log' potentiometer which, of course, provide an exponential law of attenuation vs. rotation. I've been reading Douglas Self's excellent books on audio.

I wanted: 0 dB at full rotation, -20 dB at half rotation, -40 dB at about 0.1 rotation and no output at zero rotation.

Writing the rotation as R, with values between 0 and 1, and defining a constant K, playing around in Excel I soon converged on the very simple formula: ratio = [(K^R)-1]/(K-1) and multiplying the audio stream by ratio provides the desired attenuation. K can be evaluated by solution of what resolves into a quadratic equation and the result for ratio = 0.1 (i.e. -20 dB) at for R = 0.5 is K = 9^2 = 81. Different laws can be obtained with different values of K but the limits remain at ratio = 1 for R = 1, and ratio = 0 for R = 0.

I wouldn't be surprised if others have trodden this path many times before, perhaps on this Forum.

Chris
User avatar
Leslie147
essemer
 
Posts: 38
Joined: Sun Jun 24, 2007 4:34 pm
Location: West Wales

Re: Ideal log volume control

Postby infuzion on Fri Nov 18, 2011 11:15 pm

Cool, thanks for the tip!
Need help? First search the forum & WiKi, then post in the help forum with a clear topic, request, & OSM. Then please WiKi the correct solution. If you want my personal assistance, I charge by the hour or for an exchange of services.
infuzion
smstar
smstar
 
Posts: 6163
Joined: Wed May 04, 2005 8:02 pm
Location: Earth, USA, CO, Denver

Re: Ideal log volume control

Postby MegaHurtz on Sat Nov 19, 2011 3:16 pm

sqrt (K)
Visit my website at: http://www.schlukhash.nl
User avatar
MegaHurtz
smaniac
 
Posts: 1506
Joined: Mon Aug 11, 2008 5:29 pm
Location: Eindhoven/Netherlands

Re: Ideal log volume control

Postby Leslie147 on Sat Nov 19, 2011 6:53 pm

[quote="MegaHurtz"]sqrt (K)[/quote]

The quadratic is 0.1K - SQRT(K) + 0.9 = 0 ... the 0.1 comes from the requirement for 20 dB attenuation mid-scale and the square root comes from 0.5 rotation. Putting x^2 = K gives a conventional quadratic: 0.1x^2 - x + 0.9 = 0 for which the solutions are x = (1 +/- 0.8)/0.2 = 9 or 1. Disregarding the trivial solution, K = x^2 = 81.
User avatar
Leslie147
essemer
 
Posts: 38
Joined: Sun Jun 24, 2007 4:34 pm
Location: West Wales

Re: Ideal log volume control

Postby MegaHurtz on Sat Nov 19, 2011 7:12 pm

You could change the range of (K) at the knob?
But ..
Im only saying this because it seems to be a lot of math for such a small end result.
Must be adding like one or two percent. While a knob that is just a good indicator does have the same feeling (or better). Maybe even a parabolic function?
Visit my website at: http://www.schlukhash.nl
User avatar
MegaHurtz
smaniac
 
Posts: 1506
Joined: Mon Aug 11, 2008 5:29 pm
Location: Eindhoven/Netherlands

Re: Ideal log volume control

Postby cyto on Sat Nov 19, 2011 9:02 pm

Hi Leslie147,

I can tell from your user name that we have a lot in common ;) .

Regarding the log taper: though I am a huge fan of finding simple quadratic approximations for otherwise intensive math, I don't think this is really a case where you need to do that. Afterall, if we are just rescaling an 0-1 volume knob to make it logarithmic, all the math can be done in "green" so why not just use the real exponential functions? Below is an example of how to do so that follows all of your requirements. I'd be remiss if I didn't point out that an "ideal" log taper will never actually go all the way down to 0 (or more appropriately -INF dbFS). This example let's you choose whether to have the actual low limit of the taper or simply 0. You can also change the range of the taper by indicating the desired value at half rotation. Settings are done in the "properties" panel. Enjoy.

logScaler.osm
(13.48 KiB) Downloaded 198 times

-cyto
User avatar
cyto
essemilian
 
Posts: 317
Joined: Sun Nov 28, 2010 4:36 am
Location: CIN | OH | USA

Re: Ideal log volume control

Postby Leslie147 on Sat Nov 19, 2011 10:17 pm

Interesting, but surely much more complicated than what I posted ... with two Float powers, a Float equals and two Selectors. The solution of the quadratic is only needed to evaluate the constant K for a desired mid-sweep attenuation, then, as I posted originally, the green maths is just (K^R - 1)/(K - 1) where K is a constant and R the 0 to 1 rotation: one Float power and no selectors.

Chris
User avatar
Leslie147
essemer
 
Posts: 38
Joined: Sun Jun 24, 2007 4:34 pm
Location: West Wales

Re: Ideal log volume control

Postby cyto on Sun Nov 20, 2011 4:38 am

Leslie147 wrote:...but surely much more complicated than what I posted

Not necessarily. The selectors are just there to switch the thing off at zero and could certainly be simplified with a "boolean and" (I threw this together kinda fast). Your method is an interesting take on the issue, and works out very easily if the "a" value is a nice round number like 0.1. However, I would imagine that finding the x-intercepts might get frustrating (and error prone) if you want a center value like, say, -48dBFS where the "a" coefficient doesn't round out as nicely. Not that it can't be done, but sometimes it's just easier to throw a number into the box and let the software take care of the rest. Especially if you're prototyping and want to change tapers quickly (and without having to break out the graphing calculator).

-cyto
User avatar
cyto
essemilian
 
Posts: 317
Joined: Sun Nov 28, 2010 4:36 am
Location: CIN | OH | USA

Re: Ideal log volume control

Postby infuzion on Sun Nov 20, 2011 6:24 am

cyto wrote:
Leslie147 wrote:...but surely much more complicated than what I posted

Not necessarily. The selectors are just there to switch the thing off at zero and could certainly be simplified with a "boolean and" (I threw this together kinda fast).
Off at zero to prevent denormals?
Will this boolean and version work?
Attachments
logScaler volume taper MATH cyto infuzion.osm
(11.12 KiB) Downloaded 173 times
Need help? First search the forum & WiKi, then post in the help forum with a clear topic, request, & OSM. Then please WiKi the correct solution. If you want my personal assistance, I charge by the hour or for an exchange of services.
infuzion
smstar
smstar
 
Posts: 6163
Joined: Wed May 04, 2005 8:02 pm
Location: Earth, USA, CO, Denver

Re: Ideal log volume control

Postby martinvicanek on Sun Nov 20, 2011 8:21 am

I think what the OP had in mind was a pseudo log (or rather pseudo exp) response curve as used for volume controls in the analog world. It resembles an ideal exponential except at small settings where it gently goes to zero (as opposed to the hard switch-off in the other examples). The effort to calculate K is very modest.
Attachments
pseudoLogScaler.osm
Leslie's original idea?
(13.37 KiB) Downloaded 190 times
martinvicanek
essemilian
 
Posts: 306
Joined: Sun Mar 13, 2011 1:15 pm

Re: Ideal log volume control

Postby Leslie147 on Sun Nov 20, 2011 10:27 am

Precisely.
User avatar
Leslie147
essemer
 
Posts: 38
Joined: Sun Jun 24, 2007 4:34 pm
Location: West Wales

Re: Ideal log volume control

Postby martinvicanek on Sun Nov 20, 2011 11:07 am

While at it, I thought it may be useful to have a general purpose rational mapper where you can specify the min, max, and center value to achieve the desired range and response. Feel free to use and improve!
Attachments
rationalMapper.osm
(12.43 KiB) Downloaded 212 times
martinvicanek
essemilian
 
Posts: 306
Joined: Sun Mar 13, 2011 1:15 pm

Re: Ideal log volume control

Postby Leslie147 on Sun Nov 20, 2011 1:28 pm

Amazing!

Another thing I've been pondering recently is pan-pot laws. Of course linear laws can be used, with -6 dB at mid travel and rather abrupt transitions to offness near the ends of travel, but I gather from the literature than the generally-accepted optimum is half way (in dB) between sin and sin^2 of the rotation, so sin^1.5 as a 'voltage' ratio, giving -4.5 dB at mid-travel. The two different cases correspond to normal un-corellated stereo and both channels combined into mono, respectively.

The complement is cos^1.5 (or sin with Pi/2 angle offset) but, my question is: how can one do most of the processing 'in the green', as it were, and then require only a single link into one's fast code? I haven't thought of a way yet - indeed, recently I did the sin and cos in green and used two separate links into code, where I only needed a pair of multiplications. I appreciate the laws don't need to be very accurate so a pair of really simple algorithms for sin^1.5 and cos^1.5 could allow all the calculation to be conducted in code with a single 0 to 1 input from the 'pot'.

Chris
User avatar
Leslie147
essemer
 
Posts: 38
Joined: Sun Jun 24, 2007 4:34 pm
Location: West Wales

Re: Ideal log volume control

Postby cyto on Sun Nov 20, 2011 4:15 pm

infuzion wrote:Will this boolean and version work?

Yes, excellent!
martinvicanek wrote:While at it, I thought it may be useful to have a general purpose rational mapper where you can specify the min, max, and center value to achieve the desired range and response. Feel free to use and improve!

That is a handy little module. Awesome work (as always), Martin.

-cyto
User avatar
cyto
essemilian
 
Posts: 317
Joined: Sun Nov 28, 2010 4:36 am
Location: CIN | OH | USA

Re: Ideal log volume control

Postby martinvicanek on Sun Nov 20, 2011 8:55 pm

Leslie147 wrote:Another thing I've been pondering recently is pan-pot laws. [...]
Chris

Like this?
Attachments
Pan.osm
General Pan module with various panning laws
(22.76 KiB) Downloaded 186 times
Last edited by martinvicanek on Mon Nov 21, 2011 6:13 am, edited 1 time in total.
martinvicanek
essemilian
 
Posts: 306
Joined: Sun Mar 13, 2011 1:15 pm

Next

Return to Sound

Who is online

Users browsing this forum: No registered users and 0 guests

cron