
Home  Forums  Rules  Articles  diyAudio Store  Gallery  Blogs  Register  Donations  FAQ  Calendar  Search  Today's Posts  Mark Forums Read  Search 
Digital Line Level DACs, Digital Crossovers, Equalizers, etc. 

Please consider donating to help us continue to serve you.
Ads on/off / Custom Title / More PMs / More album space / Advanced printing & mass image saving 

Thread Tools  Search this Thread 
18th October 2011, 04:33 PM  #1 
diyAudio Member
Join Date: Oct 2011

math behind logarithmic volume control?
First, I am a software guy and know little to nothing about audio. I was tasked with converting a linear volume scale to a logarithmic one on an existing system. I'm not sure this is the right place to ask this, so please point me in the right direction if it is not.
As an overview, my software runs in a DSP, which sends a 16 bit value to a DAC. From my understanding, the DAC converts it to voltage and that goes to an amplifier and then that goes to a speaker. The volume control is just a multiplier to the 16 bit value. There are 9 volume levels which correspond to a table lockup of 9 multipliers. The values go from 0 to 1, in increments of .125. That is the linear volume scale. I need to make this into a logarithmic volume lockup table. Does that make sense? What equation do I need to use? From just asking and research, the following are my guesses. I think I want to relate voltage to dbA (sound pressure level). But I don't know how to do that. 
18th October 2011, 07:54 PM  #2 
diyAudio Member
Join Date: Mar 2004
Location: Budapest, Hungary

In a logarithmic scale you need to define the step value. Common is 3 dB, which is a clearly audible volume difference. The problem is that the range between the lowest and highest volume will be only 30 dB if you use 10 steps. This is not sufficient for audio volume control in general, you need at least 60 dB and a bit finer resolution (1.5 or 2 dB). That means 30 to 40 steps. 1 dB = 20 * log (V2/V1). You can do it in the digital domain, but you will lose the 16 bit resolution at low volume level. (BTW shifting the 16bit word to the left yields 6 dB attenuation). Better do do it in 24 or 32 bit arithmetic, and then truncate to 16 bit.

18th October 2011, 08:23 PM  #3 
diyAudio Member
Join Date: May 2007

For a rough approximation to a log scale, use 1000, 0110, 0100, 0011, 0010 etc. as multipliers. This gives alternate steps of 3.52 dB and 2.50dB, which are close enough to 3dB and have the advantage that multiplication will be quick  just a shift, or two shifts and an add.

18th October 2011, 08:43 PM  #4  
diyAudio Member
Join Date: Oct 2011

Quote:
It sounds like left shifting is nearly what I want. But I want a lookup table, not an algorithm. How do I make a lookup table that does the same thing as a left shift? 

18th October 2011, 09:01 PM  #5  
diyAudio Member
Join Date: Oct 2011

Quote:
So will my table will look like { 0, 1/128,1/64, 1/32,1/16,1/8,1/4,1/2,1}??? But that doesn't make sense to me since the last two steps since too great a difference. The current table has .5 as the 4th step. ({0,.125,.25,.375,.5, .625, .75, .875, 1}) 

18th October 2011, 10:15 PM  #6 
diyAudio Member


18th October 2011, 10:18 PM  #7 
diyAudio Member
Join Date: Nov 2005
Location: st.petersburg (russia)

May i help? :)
First, calculate lookup table in MS Excel. 1 dB step is overkill, 3 dB is not accurate. For power(!) dB = 10*lg(P1/P0). As i understand, P1/P0 (or, may be U1/U0) is equal to volume control register content. Try 1 dB step, at minus 60 dB disable DAC output (MUTE function). 
18th October 2011, 10:21 PM  #8 
diyAudio Member
Join Date: Nov 2008
Location: Oakmont PA

The standard 10 position attenuator uses 3 db steps except for the last three which are 6, 6 and off. A normal carbon control has 45 db range then essentially off.
So values of 1, .707, .5, .35, .25, .18, .9, .045. 0, would give you smooth sounding values from full on to off. 
18th October 2011, 10:30 PM  #9 
diyAudio Member
Join Date: Jun 2011

According to some authorities, 10dB represents a halving or doubling of perceived volume.
I would think 6dB would be a not unreasonable step. Left or right shift is a question of bigendian or littleendian, regardless you would want to divide by 1, 2, 4, 8, 16, 32, 64, 128. This will still leave you with a reasonable number out of 16 bits. This isn't something with an absolute hardandfast solution, so you can just pull the numbers out of your imagination, try the effect, and tweak the table if you don't like the result. You could do worse than look at the Dallas/Maxim linear > log digipot appnote, AN3996. Although it is specifically about digipots, it's a mathematical treatment of a related subject. 
18th October 2011, 10:58 PM  #10  
diyAudio Member
Join Date: May 2007

Quote:
I'm not sure what is puzzling you. As a software guy I assume you can think in binary? When I wrote code I had to think in octal and hexadecimal too. 

Thread Tools  Search this Thread 


Similar Threads  
Thread  Thread Starter  Forum  Replies  Last Post 
Volume control on DVD player remote. Lose resolution at low volume?  Circlotron  Digital Source  2  10th June 2011 08:20 PM 
Remote control Passive Volume Control with Display  ua100k  Swap Meet  2  31st May 2011 04:01 PM 
Replacing broken volume control with digital volume control  Gunawan W  Solid State  19  15th December 2010 11:46 AM 
i need preamp schematics w/o tone control or volume control  hernanstafe  Parts  7  30th January 2008 04:12 AM 
remote control motorised control for volume pot/knob  CharlesY  Parts  0  25th July 2005 12:12 PM 
New To Site?  Need Help? 