title
Products            Buy            Support Forum            Professional            About            Codec Central
 

AccurateRip ID

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sredmyer
    dBpoweramp Enthusiast

    • May 2008
    • 186

    AccurateRip ID

    I think I read somewhere where Spoon said that it is possible to calculate the AccurateRip ID from the raw TOC. If this is true, has Spoon ever shared the algorithm for calculating it.

    If not, Spoon, would you be willing to share it?

    Thanks,
    Steve
  • Spoon
    Administrator
    • Apr 2002
    • 44583

    #2
    Re: AccurateRip ID

    Here is the raw code:

    Code:
    //-------------------------------------------------------------------------------
    void AccurateRipFillInDiscIdent (STAcRipDiscIdent *pRDI, ARTOC *pTOCSend)
    {
    	ZeroMemory(pRDI, sizeof(STAcRipDiscIdent));
    
    	//----we dont want to touch orig TOC----
    	ARTOC TOC = *pTOCSend;
    	ARTOC *pTOC = &TOC;
    
    	//------create track lengths-----
    	SList lstRetTrackLBA;
    				
    	DWORD dwStart, dwLen;
    	bool WereSomeTracks = false;
            int i;
    	for( i = pTOC->FirstTrack; i <= pTOC->LastTrack; i++ )
    	{
    		WereSomeTracks = true;
    		//---only add if is audio!-----
    		if ( (pTOC->Tracks[i - 1].Adr & 4) == 0)	// not a data track?
    		{
    			MSB2DWORD( &dwStart, pTOC->Tracks[i - 1].Address );
    	 		MSB2DWORD( &dwLen, pTOC->Tracks[i].Address );
    			dwLen-= dwStart;
    			lstRetTrackLBA.Add((void *)dwStart);
    		}
    	}
    	//-------last track also------
    	if (WereSomeTracks)	// if want addresses then give address of last END
    	{
    		MSB2DWORD( &dwStart, pTOC->Tracks[i - 1].Address );
    		lstRetTrackLBA.Add((void *)dwStart);
    	}
    
    	pRDI->TrackCount = (unsigned char)lstRetTrackLBA.Count;
    	if (pRDI->TrackCount)
    		pRDI->TrackCount--;		// as are addresses the last one is the end address
    
    	for (i = 0; i < lstRetTrackLBA.Count; i++)
    	{
    		DWORD LBA = (DWORD)lstRetTrackLBA.Items[i];
    		pRDI->TrackOffsetsAdded+=LBA;
    		if (LBA == 0)
    			LBA++;
    		pRDI->TrackOffsetsMultiplied+=(LBA * (i+1));
    	}
    
    	//-----calc freedb-----
    	int NumTracks = pTOC->LastTrack - pTOC->FirstTrack + 1;
    	DWORD n = 0, j = 2;
    	DWORD pID[200];
    
    	for (int fr = pTOC->FirstTrack - 1; fr <= pTOC->LastTrack; fr++)
    		LBA2MSF(pTOC->Tracks[fr].Address);	// conv to MSF
    
    	for( i = pTOC->FirstTrack - 1; i < pTOC->LastTrack; i++, j++ )
    	{
    		pID[j] = ((( pTOC->Tracks[i].Address[1] * 60) + pTOC->Tracks[i].Address[2]) * 75) + pTOC->Tracks[i].Address[3];
    		n+= CDDBSum( 60 * pTOC->Tracks[i].Address[1] + pTOC->Tracks[i].Address[2] );
    	}
    	int t = ((60 * pTOC->Tracks[NumTracks].Address[1]) + pTOC->Tracks[NumTracks].Address[2]) - ((60 * pTOC->Tracks[0].Address[1]) + pTOC->Tracks[0].Address[2]);
    	pID[0] = ((n%0xFF) << 24) | (t << 8) | NumTracks;
    	pRDI->FreedBIdent = pID[0];
    }
    Spoon
    www.dbpoweramp.com

    Comment

    Working...

    ]]>