jtorello
01-30-2003, 10:45 AM
Alright, this is for you audio engineers out there. I'm trying to answer a question my wife asked me about our new receiver.
The new receiver has a volume control scale that uses db. For example, when you turn the volume control the readout will say -30db or -70db, etc.
The old receiver used a 1-100 scale, 100 being loudest.
My wife wanted me to explain what the -30db meant and what scale it was based upon. In other words, -30db means 30 db less, but less than what? What's 0db in this scale equate to? Is there some reference level for 0db that the industry uses for this?
llbbl
01-30-2003, 11:48 AM
Notice to Programmers of Audio Software and Hardware
There is a single very annoying thing about lots of audio software products which is due either to lack of the programmers' knowledge about the human auditory system, or to laziness, or even both. If you are a programmer who could ever be involved, even remotely, in the development of a software or hardware product involving sound, please read this text carefully, burn its core message into your memory, and spread the news!
To the Point
Because people have so little time nowadays, here is the essention of this text, compressed into a few sentences:
Volume sliders must not be linear. Linear volume sliders are an annoyment to users because the human hearing is not linear at all, it is logarithmic. That's why all audio equipment worth its name, uses the dB scale to indicate volume and gain settings. For a relative volume level x, the dB value is equal to 20*log10(x). Positive dB values mean amplification, negative values mean attenuation.
The ideal volume slider follows an exponential curve, with its lowest setting corresponding to 0dB(A) and its highest setting to the loudest volume the user's audio equipment produces. This is quite unpractical to work with because you can only make vague assumptions about what equipment the user has, so forget about this unless you are working on a very high-end product.
A good all-around and computationally cheap approximation of an exponential curve which fits most consumer audio configurations, is the 4th power of the volume slider's position, so: volume scale factor = x4, where x is the volume slider's position, rescaled to the interval [0,1]. Use this simple formula for all your volume sliders, it's not perfect, but a billion times better than a linear slider!!!
If you want to know more, read on. Otherwise, read the third point again and make sure you'll never forget it.
About Volume Controls
Most audio software nowadays have sliders or even rotating knobs to control the volume. The intention is to simulate the sliders of 'classic' audio hardware. Unfortunately, there is one thing about a lot of volume sliders which makes them a pain in the ass: they are LINEAR. You might ask what could possibly be wrong with a linear slider: it is zero at the one end, 100% at the other end, and neatly linear in between, isn't that just ideal? The answer is a big NO.
Just try this: open your favourite audio player, start playing a song, and grab the volume slider, and wobble it to and fro at the 'loud' end of the volume range. Next, do the same at the 'silent' end of the volume range. Chances are that you will experience the following: almost no audible volume variations at the 'loud' end, and extreme volume variations at the 'silent' end, even if you made smaller excursions with the latter. In that case you can be pretty sure the slider is linear.
A few popular applications that suffer from this flaw, are:
QuickTime Player
iTunes
Windows Media Player
The evil has even spread to hardware: even the iMac's volume control is linear, and I'm afraid that this is just one of many examples. The result is that, even with a lot of steps, the most silent volume setting is still way too loud, and the maximum volume level is almost reached already in the middle of the slider. Ultimately this leads to frustrated people cursing the damn volume control. Luckily there are lots of products with correct volume controls, but I have the feeling that they are only a minority.
What is going wrong?
Now what exactly is wrong with a linear volume slider? The answer lies within the way our ears perceive sound. The point is that our sensation of 'loudness' is LOGARITHMIC. This means that with silent sounds, we are much more sensitive to small variations in volume than with loud sounds. This allows us to cope with a very large dynamic range of sound volumes. It also means that with a linear volume slider, we have a logarithmic sensation of volume variations, and that just doesn't feel right. At the right you can see a logarithmic curve. Two identical sections are marked on the horizontal axis (read: the volume slider). The vertical axis shows the perceived volume changes. As you can see, the corresponding section marked by the curve at the 'silent' end is much larger than at the 'loud' end.
The solution to implementing a REAL volume slider is fairly simple: instead of being linear, a volume slider should be EXPONENTIAL. For, log(exp(x)) = x, so the sensation of volume variations will be linear, and that's what we want.
Finding the 'ideal' curve
Exponential functions, however, have two annoying properties. The first is that they only reach zero at minus infinity. You can't make a slider that's infinitely long. The second is that an exponential function going through 2 points can have various shapes. Even a linear function is a limit case of such a curve. Mathematically, the problem consists of determining the constants a and b in the general formula of an exponential curve, y = a*exp(b*x). The value of a can already be determined, because we want the function to have a value of 1 for x = 1, so a = 1/exp(b).
So we only need to determine the value of b, and this value determines the shape of the curve. Small values produce a very 'curved' curve, while large values produce a more linear-like curve. To determine the correct value, we need more information. If we want to provide the user with a "fully linear volume control sensation", we would need to know how 'loud' his/her audio equipment plays at its loudest setting. You'll immediately understand that this is not a practical question. There simply is no specific answer to it, unless you are developing software for some very specific audio hardware. So we will have to take a certain assumption. First something about how sound 'loudness' is measured.
Measuring sound levels
Because the human auditory system has a logarithmic sensitivity curve, a special unit of 'sound loudness' was invented. The unit is the deciBel, abbreviated to dB. Actually the original unit is the Bel, but this unit is so small that it's always used with a factor 10, hence deci-Bel. There are two kinds of dB scales, an absolute scale and a relative scale.
The absolute scale tries to give an indication of how loud a certain sound is perceived by some average human listener, aka the "sound pressure level" (SPL). There are some variations on this scale, but the most widely used one is the "dB(A)" scale. To determine the dB(A) value for a certain sound, the sound has to be filtered through a filter which corresponds to the frequency response curve of the "average human". Next, the 10-base logarithm of the power is taken and the result is multiplied by 10. I won't go into more detail on this, because it is not of much use here. What you should know, is that the most silent audible volume level corresponds to 0dB(A), and the loudest volume level (the 'pain threshold') is about 120dB(A). A classical orchestra can produce about 94dB(A). Note that, because of the calculation, multiplying the power of a sound by a factor of 10 means adding 10 to the dB(A) value.
The relative scale is used for all kinds of physical quantities, and indicates the relative amplitude of a signal compared to another. The symbol is simply "dB". The calculation of the dB value depends on whether you are working with amplitude values or power values. For power values, the formula is 10*log10(x), with x the relative power. For amplitude values, the formula is 20*log10(x). The reason is that power = amplitude2, and the second power becomes a factor 2 after taking the logarithm.
llbbl
01-30-2003, 11:48 AM
Finding the not-so-ideal-but-still-quite-good curve
Now you know more about the dB scale, we can go back to our problem of determining a good b value. We should make sure the resulting curve results in a near linear loudness experience with the listener. Let's assume that the maximum volume that can be produced by the user's equipment is 60dB(A). This should be a realistic value for the average everyday volume setting of everuday users' speakers. We now know two points of our curve, namely: (0, 0dB(A)) and (1, 60dB(A)). Since we work with amplitudes, 60dB is 1060/20 = 1000 times the amplitude of 0dB. So, 1000 = exp(b*1), hence b = ln(1000) = 6.908. The value of a is simply 1/1000. So we now have a practical curve which should produce an agreeable result in most situations. In order to make sure the lowest setting of the slider produces no sound at all, we can just add "if(x == 0) ampl = 0;" to the slider code.
However, lots of programmers will not like to have to include an entire math library just to make their volume slider right. Luckily, there is an alternative which looks good enough like an exponential curve, is much cheaper and reaches zero at zero automatically. If you look at the graph at the right, you'll see 3 curves: the linear curve (yuck), the 60dB exponential curve (red), and the curve of the function x4 (blue). As you can see, the blue curve lies pretty close to the red curve, and you can also see how monstrously the linear curve deviates from this curve. The 4th power-function demands only 3 multiplications (or 2 at the cost of an extra line of code), and it starts from zero, what else could you want? I tried this curve in some experiments and for most volume settings it appears to have a very natural 'feel', so I can highly recommend it.
Remember that all this doesn't only apply to sliders. It also applies to rotating knobs (although these are quite rare in software, but you bet that all potentiometers of decent audio equipment have an exponential characteristic) and menus with volume presets. It also counts for equalizers, because these are volume controls in their own right, even if they only control the volume of a part of the frequency spectrum. Just burn it in your brain: volume must be exponential, or at least look like it!
About Frequency Controls and Analysis
This is somewhat less of an issue, because few applications have to deal with frequencies at the user end. However, for those that do, a similar story holds, but with a slight difference. The human sensation of 'tone' is also far from linear. But it's not exactly exponential either. At the low frequency side, it's more linear, while at the high frequency side it's exponential. However, an exponential curve is a much better overall approximation than a linear curve. So please, no linear frequency controls either! Ever seen a piano that was tuned to a linear scale?
This doesn't only count for sound generation, but also for sound analysis. If you want to create a spectral analysis, the graph should have a logarithmic scale (on both axes!!!), unless there are specific reasons to use a linear scale. With a linear frequency scale, all low frequencies will be squeezed into a few lines while the high frequencies will be smeared over a wide area. Mind that "high frequencies" are frequencies above ±2kHz, while the audible sound range reaches until 20kHz! The most interesting stuff in music happens below 2 kHz. For speech, you can't do much with frequencies above 4kHz (that's why telephones filter these out). Yet these would occupy 80% of a linear spectrogram!
Unfortunately, it's not easy to generate a spectrum with logarithmic frequency axis. FFT's are linear and the only way of getting a log scale from an FFT is to warp the output, resulting in poor resolution at the low frequencies and exaggerated resolution at the high frequencies. I don't know whether there are alternatives to the FFT which produce a log scale right away, but that doesn't mean that they don't exist of course. Anyone who knows something like this, is free to mail me.
Taken with permission from this site
http://www.dr-lex.34sp.com/info-stuff/volumecontrols.html
vBulletin® v3.8.1, Copyright ©2000-2009, Jelsoft Enterprises Ltd.