Help - Search - Members - Calendar
Full Version: What is the MP3Gain clipping detection algorithm?
Hydrogenaudio Forums > Lossy Audio Compression > MP3 > MP3 - General
Gauss256
After some time googling around and looking at the MP3Gain source code I still can't seem to put my finger on the algorithm that MP3Gain (and other software that involves replay gain?) uses to detect whether clipping is going to occur in an MP3 file.

Can someone point me to something that explains this? Thanks!

Bruce
Synthetic Soul
This thread may be of interest:

http://www.hydrogenaudio.org/forums/index....showtopic=33263

In the GUI source the code is in frmMain.frm

CODE
       If mp3Inf.AlbumdBGain <> NOREALNUM Then
           If mp3Inf.CurrMaxAmp * 2# ^ (CDbl(mp3Inf.AlbumMp3Gain) / 4#) > 32767# Then
               If mp3Inf.CurrMaxAmp * 2# ^ ((83# - (DEFAULTTARGET + mp3Inf.ModifydBGain - mp3Inf.AlbumdBGain)) / 6.0206) > 32767# Then
                   itmX.ListSubItems(lsAlbumClip).Text = strClipMaybe
                   itmX.ListSubItems(lsAlbumClip).ForeColor = vbBlue
                   If itmX.ForeColor = vbBlack Then 'Don't change to blue if already red
                       itmX.ForeColor = vbBlue
                       itmX.ListSubItems(glPath).ForeColor = vbBlue
                       itmX.ListSubItems(glPath) = itmX.ListSubItems(glPath)
                       itmX.ListSubItems(glFile).ForeColor = vbBlue
                       itmX.ListSubItems(glFile) = itmX.ListSubItems(glFile)
                   End If
               Else
                   itmX.ListSubItems(lsAlbumClip).Text = strClipYes
                   itmX.ListSubItems(lsAlbumClip).ForeColor = vbRed
                   itmX.ForeColor = vbRed
                   itmX.ListSubItems(glPath).ForeColor = vbRed
                   itmX.ListSubItems(glPath) = itmX.ListSubItems(glPath)
                   itmX.ListSubItems(glFile).ForeColor = vbRed
                   itmX.ListSubItems(glFile) = itmX.ListSubItems(glFile)
               End If
           Else
               itmX.ListSubItems(lsAlbumClip).Text = ""
               itmX.ListSubItems(lsAlbumClip).ForeColor = vbBlack
           End If
       End If


You'll see that the maximum amplitude (mp3Inf.CurrMaxAmp) and album gain (mp3Inf.AlbumMp3Gain) are required. The maximum amplitude is obtained by mp3gain.exe - so I guess you'll have to check that source, or find some other code to do the same. The album gain refers to the current suggested gain for the album - and is the variable - i.e.: if clipping is occurring then it needs to be decreased - see jth's script on the referenced thread.

Edit: Another source of info may be WaveGain (application and source available at http://www.rarewares.org/others.html).
Gauss256
Thanks, you've at least reminded me that there is code in those VB form files that I need to look at.

I think the clipping I'm talking about is different from what the information you've referenced is talking about. It is the "Y" that can show up in the "clipping" column. I can't figure out how that is determined.

Maybe the answer is there in what you have given me, I'll work through it.

Thanks again,
Bruce
Synthetic Soul
The code above should set that "Y" - I assume that's what strClipYes is (strClipYes = "Y").

It's also the code that changes the text to red when a track is currently clipped/will be clipped with the suggested dB level.

It seems like it will use blue if clipping may occur. I've never seen this before I don't think.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.