# How to change volume of a PCM 16 bit signed audio?

I know I can multiply samples, then clip but perceived volume is non-linear for humans.

Can you please help with a formula.

• Why was this question downvoted? It is clearly relevant for this board. – Jim Clay Jul 30 '12 at 16:12
• The question is not very clearly formulated, not even grammatically. Besides that, what kind of non-linearity do you want to compensate for: amplitude only, or frequency-dependent amplitude? – heltonbiker Jul 30 '12 at 16:18
• I read this mini tutorial: ypass.net/blog/2010/01/… And this guy used tan function to make volume not linear but he said thi is not perfect way. So I thought at that DSP forum You will understand what I mean even its not gramaticaly posted. – apocalypse Jul 30 '12 at 18:13
• I think that question is very concise and very clear. When you work with audio you instantly understand what @zgnilec means. This is a psychoaccoustics issue : the perception of audio volume in humans is non-linear. So the question is : "how you do you make an audio gain change that is perceived as linear?" – sebpiq Dec 23 '15 at 11:06
• A range of -48dB to +6dB makes 54dB in amplitude. – be999 Oct 4 '17 at 18:20

## 1 Answer

Changing the volume of an audio signal must be done by applying a gain (multiplication) - and optionally clipping if your system has a limited dynamic range. This is as simple as that. Applying a non-linear function to an audio signal will cause distortion and add harmonics, and you don't want this to happen - you want to modify the loudness of the signal, not its timbre. [To be fair, there are non-linear processings designed to change the perceived loudness of the signal without affecting the timbre, within a given dynamic range constraint (eg. multiband compression), but it doesn't look like this is what you need.]

Where non-linearity and fancy response curves come to play is when designing a user interface - when deciding on the relationship between the position of the control (knob or slider, whether on a GUI or as physical hardware) and the gain applied to the signal. This is where perception matters, because the users will expect a mapping between the position of the slider and their perception of loudness. Please note that even if the relationship between the position of the volume control and the gain applied to the signal is non-linear, the process of applying the gain to the signal is linear, and non-linearity would be unwanted there!

When it comes to physical volume controls, eg in hifi systems or personal audio players, the relationship between the knob position and the attenuation is closer to an exponential curve, though its shape has been tweaked and is constrained by the manufacturing process - sometimes it's just two or three linear segments. You can find those curves in the datasheets from manufacturers ("A" taper). Mixing console faders usually have their response compressed so that the upper half of their travel covers the useful range of -20 dB..+6dB.

In the software world - at least for music production - it is most common to have volume/gain knobs calibrated in dB. For example, if you have a 100 pixels long volume slider graduated from -48dB to +6dB, the gain applied to the signal would be $10^{\frac{-48 + 54 \frac{x}{100}}{20}}$.

• when x is 0 = 24, x=100 gives 3. Is this correct? I need more time to understand this :< – apocalypse Jul 31 '12 at 6:35
• 10 ** ((-48 + 54 * 0 / 100.0) / 20.0) = 0.004 ; 10 ** ((-48 + 54 * 100 / 100.0) / 20.0) = 1.995 – pichenettes Jul 31 '12 at 8:02
• This is an exponent, not a multiplication. 10 ^, not 10 * – pichenettes Jul 31 '12 at 11:17
• Where does the 54 come from? – Ansis Māliņš Aug 28 '17 at 12:54