# [music-dsp] dB decrease

Luke Drummond lukedrummond at gmail.com
Wed Oct 19 19:03:51 EDT 2011

```Hi Vokan,

Yes, Chuck is correct.  As far as I am aware, this is the method used
in professional audio applications.  The audio data is almost always
converted into a floating point value between -1.0 - +1.0 and then
multiplied by the constant obtained from chuck's derivation.

If you use C, here is a simple function for doing what you want
(WARNING it overwrites the original floating point audio stream).
Because most systems interleave the channels, this will work for
multichannel streams, though as can be seen, all channels will receive
the attenuation/gain

void gain(float * audioData, int streamLen, float dbGain)
{
/*
if(!audioData)
{
fprintf(stderr, "void audio track passed\n");
fprintf(stderr, "doing nothing...\n");
return;
}

float gainConstant;
int i;

/* calculate gain constant */
gainConstant = powf(10, dbGain / 20);

/* apply gain proper */
for(i = 0; i < streamLen; i++)
{
*(audioData+i) = gainConstant * (*(audioData+i));
}
return;
}
Hope that helps

Luke

On 19 October 2011 15:24, Charles Henry <czhenry at gmail.com> wrote:
> Hi, Vokan
>
> Yes, it really is that simple.  You probably also want to know how to
> calculate the gain factory (number to multiply by ).
>
> dB are a logarithmic scale for power--10 dB corresponds to a 10-fold
> increase in power
>
> The amplitude of your signals is not the same as power.  Power is
> proportional to the amplitude squared.  So, a different factor is used
> when working with amplitude.
>
> 20 dB corresponds to a 10-fold increase in signal amplitude
>
> So, to calculate your gain factor:
>
> G = 10 ^ ( X / 20)
>
> Where X is the number of decibels you want to increase (+dB) or
> decrease (-dB) by.
>
> Chuck
>
>
> On Wed, Oct 19, 2011 at 5:38 AM, Volkan Ozyilmaz <volkan at volkoaudio.com> wrote:
>> Hi,
>>
>> I don't know more about dsp and I need to write a dB decrease algorithm.
>>
>> Firstly, I thought I don't increase volume and I don't need a special
>> algorithm.
>> Can I just multiply the values and that's it? For example:
>>
>> If I need to decrease volume %10 I just need to multiply it with 0.9,
>> I mean all the wave file.
>>
>> I am curious if this technique is good or bad? The quality is important for me.
>> I don't want to increase the volume, I just need to decrease it.
>> With this technique would I lose the quality?
>>
>> Regards,
>>
>>
>> --
>> ---------------------------------------------------
>> Volkan Ozyilmaz
>> volkan at volkoaudio.com
>> Volko Audio
>> www.volkoaudio.com
>> www.soundcloud.com/volkoaudio
>> ---------------------------------------------------
>> --
>> dupswapdrop -- the music-dsp mailing list and website:
>> subscription info, FAQ, source code archive, list archive, book reviews, dsp links
>> http://music.columbia.edu/cmc/music-dsp
>> http://music.columbia.edu/mailman/listinfo/music-dsp
>>
> --
> dupswapdrop -- the music-dsp mailing list and website:
> subscription info, FAQ, source code archive, list archive, book reviews, dsp links
> http://music.columbia.edu/cmc/music-dsp
> http://music.columbia.edu/mailman/listinfo/music-dsp
>
```