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: global_gain in AAC decoders (Read 10615 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

global_gain in AAC decoders

hi all,
i've added the funcionality of modifying the global gain value of AAC in BeSplit.
supported forms :
- Syntactic elements : ID_SCE (mono track) & ID_CPE (stereo).
- File structure : ADTS.
- Profile : non LTP.
- no crc correction, atm.

question is as follows :
it seems that FAAD only reads the global_gain of the first individual_channel_stream.
i've noticed that by modifying only the first global_gain tag, and getting the whole stereo signal being amplified.
modifying the second global_gain tag means more parsing work, so i wondered - is it common in AAC decoders to use the first global_gain value for the two individual streams ?
@ivan, @menno
have you happen to know how it's like in Phillips' Expanium ?
(btw, are phillips using VLSI to decode AAC or some dsp Software ?)

Cheers,
Dg.

global_gain in AAC decoders

Reply #1
There are 2 ways of writing the ICS for CPEs. One is with common_window == 0 where there are 2 seperate ICSs, for each channel one. The other way is when common_window == 1 where the ICS is shared among the 2 channels. I guess that in psytel and faac encoded aac files, common_window always equals 1, so global_gain is the same for both channels.
I think FAAD2 is doing all this correct, but I need to check it.

Menno

global_gain in AAC decoders

Reply #2
hi Menno,
thank you for your answer.
according to the copy of iso 13818-7 i have, global_gain tag is defined inside an individual_channel_stream, and not inside ics_info.

another question,
i've noticed that iso 14496-3 adts_fixed_headers includes an 'emphasis' tag (only for specifiec ID ?), while this tag doesn't exist in iso 13818-7. can you clarify ?

global_gain in AAC decoders

Reply #3
You are right, the ISO specs stated that the Global Gain Tag is defined inside an
individual_channel_stream. So in CPE mode, there will always be 2 Global Gains regardless of what the common_window flag is..  I thought the common window flag depended on whether both L & R channels having the same blocktype? Because the when common flag is set to 1, both L & R channels share the same ICS info which defines blocktype, also window grouping for short block and predictor info??

What happened if an attack is detected in L channel and not R channel ?



kww

global_gain in AAC decoders

Reply #4
OK, I was just replying from what I assumed :-), I'll have a look at the code.

ADTS is indeed different for MPEG-2 and MPEG-4, the emphasis is added, I think, to make the headers basically the same as mp3 headers. But someone with some better mp3 knowledge should confirm that.
The ID defines whether the file is MPEG-4 or MPEG-2.

common_window is mainly available to save bits on frames where both the channels are very similar. The things wkw names are correct, as well as the scalefactor band MS decision.
If the 2 channels have the same block type it still doesn't neccessarily have to be a common_window frame, it's totally upto the encoder to decide that. I think psytel always uses common_window frames, if any of the 2 needs to be a short block, they will both be short block frames.

Menno

global_gain in AAC decoders

Reply #5
As you'll see in the FAAD2 code in syntax.c, individual_channel_stream() is called twice after each other in channel_pair_element(), one time with ics1 the other time with ics2, so data will be filled in in 2 seperate data structures.
No problem, I guess.

Menno

global_gain in AAC decoders

Reply #6
afaik, ID is default to be 1, so if it's 0, it means we have an added 'emphasis' field.
(if i remember correctly, mpeg1 specs were talking about 12bit for syncword + 1bit for ID, and later it considered to be - 11bits for syncword and 2bits for mpeg version).

Quote
Originally posted by wkw
You are right, the ISO specs stated that the Global Gain Tag is defined inside an 
individual_channel_stream. So in CPE mode, there will always be 2 Global Gains regardless of what the common_window flag is.. 

yes, but the weird thing is that although i only change the value of global_gain of the very first element, the whole signal is being scaled.

Quote
Originally posted by wkw
I thought the common window flag depended on whether both L & R channels having the same blocktype? Because the when common flag is set to 1, both L & R channels share the same ICS info which defines blocktype, also window grouping for short block and predictor info?? 

What happened if an attack is detected in L channel and not R channel ?
[/b]menno says that faac doesn't use this feature. let's wait for ivan's comment regarding aacenc.

ok, menno, waiting for your inputs..

global_gain in AAC decoders

Reply #7
Quote
Originally posted by menno
As you'll see in the FAAD2 code in syntax.c, individual_channel_stream() is called twice after each other in channel_pair_element(), one time with ics1 the other time with ics2, so data will be filled in in 2 seperate data structures.
No problem, I guess.

Menno
hmmm... !

global_gain in AAC decoders

Reply #8
btw, when (if ever) will faac/aacenc use a CC element to represent a stereo signal ?

global_gain in AAC decoders

Reply #9
Channel coupling, from what I understand of it (not much), is mainly used to "couple" a voice signal in music, allowing for different languages in a movie. it's not really used for improving coding efficiency, but I'm not sure about that.

I'll test that global_gain thing, might be a little bug somewhere.

Menno

global_gain in AAC decoders

Reply #10
Quote
Originally posted by menno
I'll test that global_gain thing, might be a little bug somewhere.
maybe gain is being parsed twice, but being asserted once.. (in accordance to first value) ?

global_gain in AAC decoders

Reply #11
Ok, I figure that the problem is that MS and IS are done after applying the scalefactors. So if MS or IS is used the amplified values will be copied to the other channel. You could test this by creating a file without MS, I haven't done it, so I'm still just 'figuring'. But the values that arrive at apply_scalefactors() correct when just one channel is amplified (one file test, so still no certainty).
I don't really see any need to change this at the moment, why would you want to amplify one channel more or less than the other?

Menno

global_gain in AAC decoders

Reply #12
Quote
Originally posted by menno
why would you want to amplify one channel more or less than the other?
i want to amplify the whole track.
currently, i only implemented the parsing part until reaching the first individual element, so i said to myself - 'what the hack, let's see that this part works', then i found out that both channels were scaled.

i understand that FAAD2 will copy the gg value into second channel when IS or MS are used. question is - can we expect that from all decoders ?
and what would be the relative scaling using FAAD2 if i had modified both gg values ?

global_gain in AAC decoders

Reply #13
FAAD2 will not copy the global_gain value when MS or IS is used.
I'll try to explain:
The global_gain (actually the scale_factors but global_gain is part of each scale_factor) amplifies the decoded data back to the actual spectral data. MS will copy (add or subtract) spectral data from one channel to the other (and vice versa). If the data in one of the channels get amplified more, because you increased the global_gain for that channel, the spectral data that is copied to the other channel is also amplified more than it should have been. So the data in the other channel will also be amplified a bit more.
If MS would be done before the amplification, you wouldn't have that problem. But this would require quite big changes since AAC does some reordering of the spectral data on short blocks that has to be done before the MS. If the amplification would be moved behind that reordering the amplification would become more complex.
But, as you want to amplify the whole track, there shouldn't be a problem

Menno

global_gain in AAC decoders

Reply #14
Quote
Originally posted by menno
So if MS or IS is used the amplified values will be copied to the other channel.
Quote
Originally posted by menno
FAAD2 will not copy the global_gain value when MS or IS is used.
hehe, just kiddin'

now, more seriously..
when MS is used, will the first individual channel stream hold the Mid information and the second the Side infromation ?
in that case, i would still have to modify the gg of both.

global_gain in AAC decoders

Reply #15
Yes it will, you indeed always need to increase both.

Menno

global_gain in AAC decoders

Reply #16
Quote
Originally posted by menno
Yes it will, you indeed always need to increase both.
back to plan A.

thanks menno !
Dg.

global_gain in AAC decoders

Reply #17
if i'll have some free time this weekend, i will be able to introduce AACGAIN next week.

global_gain in AAC decoders

Reply #18
Quote
Originally posted by DSPguru
if i'll have some free time this weekend, i will be able to introduce AACGAIN next week.


Great!!!

global_gain in AAC decoders

Reply #19
hi guys!

as aac is coming big these days i was searching the board for something like aacgain and i found many threads with pointing to good old    dspguru working on that issue and i thought this thread would be the best to warm up the thing...

so, any progress in aacgain (or any other working possibilies)?
I know, that I know nothing (Socrates)

global_gain in AAC decoders

Reply #20
Quote
I think psytel always uses common_window frames, if any of the 2 needs to be a short block, they will both be short block frames.

You might just reveal a big secret of Psytel aacenc.  I think that choosing a same block type for a channel pair definitely not to save the bit-rate by having a common_window, but to compensate the bad imaging effect when L/R perform different block type encoding.

global_gain in AAC decoders

Reply #21
Quote
to compensate the bad imaging effect when L/R perform different block type encoding.

Do you have details about this?

global_gain in AAC decoders

Reply #22
Quote
Quote
to compensate the bad imaging effect when L/R perform different block type encoding.

Do you have details about this?

that is my personal experience and i name it as so called stereo imaging problem (effect) by no technical reference.

You can have a synced frame of sequence contains transient at L channel, tone at R channel. It goes saying that chooses short block type for L channel  whereas long for R channel. At a 128 Kbps stereo case, you may have good L and R channel reconstructed when you listening to them separately. But you may listen some artifact when listen to them by headphone at the same time.

I must apology for the poor setting of the above experiment. In facts, the result may not be true for everyone in any circumstances.  Just propose for speculation to particular algorithm setting.

global_gain in AAC decoders

Reply #23
If you have a short test case that exhibit this imaging problem, I would be interested.

global_gain in AAC decoders

Reply #24
Quote
if i'll have some free time this weekend, i will be able to introduce AACGAIN next week.

Ciao...


is this gonna be a command line..
and.. will this work upon aac in mp4 container..

(kinda daft question.. but still curious.) 

this sounds awesome..