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: Help With Side Information (Read 5263 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Help With Side Information

Hey guys, I know I am going to sound like a bit of a newbie with these questions but I am struggling a bit with a piece of work that requires me to grab and possibly adjust the global gain value of each frame of an MP3 file and I would be very appreciative if someone could help me with a couple of points.

I am finding it hard to find any solid information on the side information header structure on the internet - I know that it is 32 bytes long for stereo data but I am confused by talk of granules and such like.  What I really need to know is there a really quick way that I can find the global gain value for an MP3 track without worrying about any other fields.  For example, if I can find the start of the main frame header, is there a quick and easy way from that position to grab the global gain value from there?  I basically want to create a piece of C code that can as efficiently as possible loop through the frames and then process this value without worrying about any of the other technical details of the MP3 file.

Also, out of interest, what is the maximum and minimum value for this gain as well and would changing this value by one create an audible difference in an MP3 track?  Part of the work I am doing might involve taking an MP3 file and generating a sample file by taking, say, the first 380 frames of a file and creating a fade in by adjusting the global gain slowly over the first 60-100 frames - would this work?

I know I have asked quite a few questions in this post but from a brief look over the forum there seems to be a lot of technical know-how floating around and I am hoping someone will be kind enough to help me out.  I appreciate any help that can be offered.

Cheers guys,

Jim.


Help With Side Information

Reply #2
Thanks for the link, I have looked at MP3 Gain but it seems overly complicated, the truth is, i'm used to programming on Win32 platforms with C# and Java and I am finding moving back to C quite a complex task.  MP3 Gain takes a lot of functions from an open source full blown encoder/decoder and had a lot of overly complicated structures and such related to fully processing each part of the various headers that I don't need.

I'm really looking for just a very simple thing: if I can find the start of the header, I know I can find the start of the side information by checking either straight after the main frame header or after the 16bit CRC value if present but I am not fully understanding of the layout of the side information header, how uniform it is across different bitrates or stereo/joint stereo so I can universally and easily, through a couple of functions, grab that global gain value as quickly and efficiently as possible without having to parse the rest of the frame information into various C structures to get to it.

If anyone can help me understand this task or answer any of the questions from my first post then I would be very appreciative.

Cheers again,

Jim.

 

Help With Side Information

Reply #3
The global_gain value you're looking for is part of the "granule side info" structure inside of each MP3 frame.

The number of "granule side info" structures per frame depends on the MPEG-version (MPEG-1 or MPEG-2 LSF) and the number of channels (one or two) of your particular mp3 file. MPEG-1 Layer III frames consist of two granules (you may call them "sub-frames" if that helps you  ). MPEG-2 LSF Layer III frames consist of only one granule. Btw, a granule decodes to 576 audio samples. Each granule contains one or two channels, for mono or (joint-)stereo/dual-mono frames, respectively.

So, how many global_gain values are there per mp3 frame?
MPEG-1 mono: 2
MPEG-1 stereo: 4
MPEG-2 mono: 1
MPEG-2 stereo: 2

The most reliable sources of information about any mp3 details are the source codes of existing and working mp3 decoders. I would suggest that you look at MAD. Get the libmad sources and start reading in frame.c and layer3.c (III_sideinfo function). Good luck. 

Help With Side Information

Reply #4
Thanks for that detailed response, it's very much appreciated - one last thing - if I am only ever dealing with MP3s and no other format will I ever come across MPEG-2 LSF files?

Cheers,

Jim.

Help With Side Information

Reply #5
MPEG-2 LSF (Low Sampling Frequency extension) is used for low-bitrate applications, such as mp3 streaming for internet radios.

MPEG-1: bitrate 32-320 kbps, sampling frequency 32/44.1/48 kHz
MPEG-2: bitrate 8-160 kbps, sampling frequency 16/22.05/24 kHz

See also the Programmer's corner at MP3 tech for more infos.