Skip to main content

Notice

Please note that most of the software linked on this forum is likely to be safe to use. If you are unsure, feel free to ask in the relevant topics, or send a private message to an administrator or moderator. To help curb the problems of false positives, or in the event that you do find actual malware, you can contribute through the article linked here.
Topic: Formula to convert dB to AAC global_gain? (Read 9268 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Formula to convert dB to AAC global_gain?

I'm an experienced programmer but total newbie regarding digital audio. I don't have access to the ISO specs for AAC, but am more or less figuring them out by reading the FAAD2 source code.

As a way of learning more, I'm trying to build the "aacgain" program described in this thread. I've been able to hack FAAD2 to alter global_gain on each individual_file_stream and write out an updated mp4 file. Works great!

It looks pretty simple to port the replaygain code from either mp3gain or foobar_2000 into FAAD2.

The way I read the FAAD2 code is that in AAC,
scalefactor=POW(2, global_gain/4). Is this correct?

The replaygain algorithm gives results in dB, and my recollection is that
scalefactor=POW(10, dB/10). Is that correct?

So my question is: given a replaygain in dB, what is the function that converts a replaygain in dB to an adjustment for global_gain?

Many years ago I could have done this, but my brain cells that used to know algebra have been filled with other stuff not to be mentioned:-)

Thanks for the help!

Dave

Formula to convert dB to AAC global_gain?

Reply #1
Quote
So my question is: given a replaygain in dB, what is the function that converts a replaygain in dB to an adjustment for global_gain?[a href="index.php?act=findpost&pid=240183"][{POST_SNAPBACK}][/a]


After fighting with this a bit more, I came up with:

global_gain adjust = 4 * LOG2(POWER(10, replaygain/10))

Can some kind soul confirm if this is correct?

I'd also appreciate some opinions if DSPGuru's approach in the previously referenced post is correct. I have no idea what he meant my just having to adjust only the 1st global_gain; I needed to adjust all of them in each ICS to make it work.

Thanks again!

Dave

Formula to convert dB to AAC global_gain?

Reply #2
AFAIK an increase of 1 of the global_gain value is an increase of 0.25 dB in gain.

So if you know how much the gain needs to be increased you know the required change in global_gain.

Menno

Formula to convert dB to AAC global_gain?

Reply #3
Quote
AFAIK an increase of 1 of the global_gain value is an increase of 0.25 dB in gain.

So if you know how much the gain needs to be increased you know the required change in global_gain.

Menno
[a href="index.php?act=findpost&pid=240197"][{POST_SNAPBACK}][/a]


Wait a minute.. I thought an increased of the G_Gain by 1 is an increase of

20log10(2^0.25) dB at the decoder time domain samples?? .. .. which is log10(32).. about 1.5 dB ??? log10(32) = log10(10 * 3.2) = log10(10) + log10(3) = 1 + 0.4771 which is about 1.5dB  or 5 * log10(2) = 5 * 0.301 = 1.505 dB..

Formula to convert dB to AAC global_gain?

Reply #4
davelasker: Great that you are doing this! 
Juha Laaksonheimo

Formula to convert dB to AAC global_gain?

Reply #5
Well it's always fun to get conflicting advice:-)

Does global_gain in AAC have the same units as in MP3?

In the MP3GAIN source code,

global_gain =db*1.505,

while I interpreted wkwai's post to say that

db = global_gain*1.505.

Which is correct for AAC?

What is the relationship between 20log10(2^0.25) and the FAAD2 scalefactors?

Thanks for helping educate me!

Dave

Formula to convert dB to AAC global_gain?

Reply #6
Quote
Well it's always fun to get conflicting advice:-)

Does global_gain in AAC have the same units as in MP3?

In the MP3GAIN source code,

global_gain =db*1.505,

while I interpreted wkwai's post to say that

db = global_gain*1.505.

Which is correct for AAC?

What is the relationship between 20log10(2^0.25) and the FAAD2 scalefactors?

Thanks for helping educate me!

Dave
[a href="index.php?act=findpost&pid=240436"][{POST_SNAPBACK}][/a]


Hmm, you might be right

Of course if you are already able to change the global_gain it is easy to prove it empirically.

Menno

Formula to convert dB to AAC global_gain?

Reply #7
Quote
Of course if you are already able to change the global_gain it is easy to prove it empirically.
[a href="index.php?act=findpost&pid=240439"][{POST_SNAPBACK}][/a]


Please tell me how. I have no audio test equipment (other than my PC).

Thanks again!

Dave

Formula to convert dB to AAC global_gain?

Reply #8
Quote
Quote
Of course if you are already able to change the global_gain it is easy to prove it empirically.
[a href="index.php?act=findpost&pid=240439"][{POST_SNAPBACK}][/a]


Please tell me how. I have no audio test equipment (other than my PC).

Thanks again!

Dave
[a href="index.php?act=findpost&pid=240529"][{POST_SNAPBACK}][/a]


If you have an editor to view the replayed waveform,  you should see that adding 4 to the global
gain doubles the amplitude of the replay.

There is one possible problem with the technique: the individual scalefactor gains are differentially
coded from the global gain, but also limited to be between 0 and 255. If you change the global
gain too much, you could run individual gains outside limits. How any individual decoder would
behave in that case is unpredictable.

I think this is probably just a theoretical problem, because the gain range is so large that you
will probably never exceed those limits.

Tim.

Formula to convert dB to AAC global_gain?

Reply #9
Quote
If you have an editor to view the replayed waveform,  you should see that adding 4 to the global
gain doubles the amplitude of the replay.[a href="index.php?act=findpost&pid=240542"][{POST_SNAPBACK}][/a]


Hi Tim

Yes I can see that adding 4 to globbal_gain will double the amplitude just by reading the faad2 code. What I am trying to verify is the relationship between dB and global_gain. Do you know how to measure that?

Thanks for the help!

Dave

Formula to convert dB to AAC global_gain?

Reply #10
Quote
Quote

If you have an editor to view the replayed waveform,  you should see that adding 4 to the global
gain doubles the amplitude of the replay.[a href="index.php?act=findpost&pid=240542"][{POST_SNAPBACK}][/a]


Hi Tim

Yes I can see that adding 4 to globbal_gain will double the amplitude just by reading the faad2 code. What I am trying to verify is the relationship between dB and global_gain. Do you know how to measure that?

Thanks for the help!

Dave
[a href="index.php?act=findpost&pid=240587"][{POST_SNAPBACK}][/a]


Doubling the amplitude of a signal is equivalent to an increase of 6dB, hence the 1.5dB
cited above for each increment of global gain.

Tim.

Formula to convert dB to AAC global_gain?

Reply #11
Quote
In the MP3GAIN source code,
global_gain =db*1.505
[a href="index.php?act=findpost&pid=240436"][{POST_SNAPBACK}][/a]


Just to set the record straight, I was looking in the wrong place in the mp3gain code when I made the above rash statement. File mp3gain.c line 2304 says:

dblGainChange = dBchange / (5.0 * log10(2.0));

which is consistent with wkwai's post.

Thanks again to all for your help!

Dave

Formula to convert dB to AAC global_gain?

Reply #12
Hi Dave. Can we expect this app to become available soon?
Juha Laaksonheimo

Formula to convert dB to AAC global_gain?

Reply #13
Quote
Hi Dave. Can we expect this app to become available soon?
[{POST_SNAPBACK}][/a]


Yes but it will take a while. I have a full time job, so I only get to work on it a couple of hours a week. It's taking me a bit longer than [a href="http://www.hydrogenaudio.org/forums/index.php?showtopic=14322&pid=147583&mode=threaded&show=&st=&#entry147583]DSPGuru's 3 hour estimate.[/url]

As a first step I will post a patch to faad2 that allows manual adjustment of gain, similar to the /g option of mp3gain. Hopefully this will be done by next weekend.

After that I need to integrate the ReplayGain algorithm. That will take a bit longer .

Does anyone know if faad2 patches should be posted here, on audiocoding.com, or on sourceforge???

Thanks...

Dave

Formula to convert dB to AAC global_gain?

Reply #14
Thanks for the info.  Finally this kind of tool arrives

Faad2 patches shouldn't be a problem. Just contact Menno (or maybe Menno contacts you) either here or on Audiocoding.
Juha Laaksonheimo