[mb-devel] Calculate of DiscID trouble...

Thees Winkler thees79 at gmx.net
Sat May 19 11:23:26 UTC 2007


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

- -----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi,

I am the developer of the opensource program LameFE. I have a small
technical question on how to calculate the
Disc ID used by MusicBrainz for Audio-CDs having an extra data-track. For
several
reasons I do not want to use the musicbrainz-lib-3.0 to do the job for me...

I implemented the calculation of the DiscID following the guidelines of your
wiki
and the implementation from CDEx.
Hover for several Audio CDs with Data track my "method" does not work. Hope
you can
Help me out. (Example for CD that is not working for me is the following
one:
http://musicbrainz.org/release/bdd50f20-3d23-420d-9f25-58fbc5ca760f.html


Here is the code I use, hope you can help me out. The sha_* macros/functions
Have been taken from the lib



BOOL CMusicBrainzV3::CalculateMBID(char cDiscID[])
{

	SHA_INFO       sha;
	unsigned char  digest[20], *base64;
	unsigned long  size=0;
	char           temp[9];
	int            i;

	TRACE0( "Entering CMusicBrainz::CalculateMBID()\n");

	sha_init(&sha);

	sprintf(temp, "%02X", 1);  
	sha_update(&sha, (unsigned char *)temp, strlen(temp));

      // GetNumTracks returns the total number of tracks
      // including data-tracks
	sprintf(temp, "%02X", m_pCD->GetNumTracks());
	sha_update(&sha, (unsigned char *)temp, strlen(temp));

	// + 1 because we need the Start sector and not the
      // end sector
	sprintf(temp, "%08X", m_pCD->GetEndSector(m_pCD->GetNumTracks()) +
150 + 1);
	sha_update(&sha, (unsigned char *)temp, strlen(temp));


	for(i = 0; i < 100; i++){

		if (i >  m_pCD->GetNumTracks()){

			sprintf(temp, "%08X", 0);
		} 
		else {

			sprintf(temp, "%08X", m_pCD->GetStartSector(i)+150);
       }

       sha_update(&sha, (unsigned char *)temp, strlen(temp));
	}

	sha_final(digest, &sha);

	// Convert to a readable format
	base64 = rfc822_binary(digest, 20, &size);
	memcpy(cDiscID, base64, size);
	cDiscID[size] = 0;

	free(base64);
	return TRUE;
}

DWORD CCD::GetEndSector(int nTrack)
{

	int i;
	DWORD	dwEndSector = 0;

/////////////////
// (c) A.L. Faber
	// Loop through the available tracks
	for (i = 1; i <= m_nTocEntries; i++){

		if ((m_cdTracks[i-1].m_btTrack == nTrack) ||
(m_cdTracks[i-1].m_btTrack == LEAD_OUT_NBR)){

			// check if we cross a session border
			// and check if the next track is not the default
audio lead-out
			// but not the first track, due to extra CD format
			// where first track could be a data track, the
second an audio track
			if (((m_cdTracks[i-1].m_btFlags & CDROMDATAFLAG) !=
(m_cdTracks[i].m_btFlags & CDROMDATAFLAG)) &&
				 (m_cdTracks[i].m_btTrack != LEAD_OUT_NBR)
){

				// If we have crossed a session border, we
get an additional leadout
				// Session lead-out = 1m30s => 6750 sectors
				// Session lead-in  = 1m00s => 4500 sectors
				TRACE(_T("Correct end-sector of track %d for
session lead-out time by 11250 sectors\n"), i + 1);
				dwEndSector = m_cdTracks[i].m_dwStartSector
- 11250 - 1;
			}
			else{

				dwEndSector = m_cdTracks[i].m_dwStartSector
- 1;
			}

			break;
		}
	}
// end (c) A.L. Faber
/////////////////
	return dwEndSector;
}


- - ---
Regards,
Thees Winkler.
- -----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (MingW32)

iQEVAwUBRk7dwv2bGisf6kMoAQJLxAgAp7i61s4S9J43hLAbJAtu9uMyGyhRABzi
dN20jOFW6eLHQMWBPHuZftEIXO0pcWa8gMaaUcLPiCZ0KS/V5ATAoa4GUXrFN/Mq
XYSJqVIbTcIhT/WB0yorI+1q/MuQ6PpvDnoUjqTSlwLy/O+C57FK7uvslv2hXDIG
tecvtwqOrWIJlF0DyOEPzBcHrjf8z6pu3N7enNeEPAGybEVN6QclOP5cftoRXWi3
LFZtEmqVhhuZ13mytGluoUYCeBliwzMnIfd+K9oo+udV1Ytsyw9157IeVvXILUQ7
l7Mt9sWFIWWFhZJ+fb1Poal3ivnbt1Gf1I4GIu8xFyrbtyq1l6UgKw==
=HC9a
- -----END PGP SIGNATURE-----
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (MingW32)

iQEVAwUBRk7eI/2bGisf6kMoAQIZMQgAsKhlAU+EafJ1MAKFav5tvbv/HQ5Q99UM
dL+18u9JFX5YYBhO+4jSvV368Zpg/0SSxlpmgmAnXf+NYAdmJYgSVmgwvW2Thdzz
5fkNMIGP+D95ZvQ3R1g51hIK0iEFmaZLtaQOunx1TwMHq2AVqgy79ZMuJ9IeDl3v
uc5hmANbM1TseGC9IVJq8Dkmyq8QjwuMbrP+86lV72KIEY1KDE89tX6h2VGUC/DP
8TDNzS5D8njd38X9/OOybtJ5PWfQ89/I5M15qM8UiBmzYMilOGWxJOmGwLW9SBmu
T6/wsHMmCmBT/cR0mmYq+ZTFls2XbRnYUJLP3KYtbihDwr7DciyAbA==
=1Wnd
-----END PGP SIGNATURE-----




More information about the MusicBrainz-devel mailing list