Exemplo n.º 1
0
        /// <summary>
        /// Retrieve a CDDB DiskID
        /// </summary>
        /// <returns></returns>
        public string GetCDDBDiskID()
        {
            int numTracks = GetNumTracks();

            if (numTracks == -1)
            {
                throw new Exception("Unable to retrieve the number of tracks, Cannot calculate DiskID.");
            }

            string postfix = numTracks.ToString();

            int i, t = 0, n = 0;

            double ofs = 0;

            int secs = 0;

            /* For backward compatibility this algorithm must not change */
            i = 0;

            while (i < numTracks)
            {
                Console.WriteLine("Track {0}: {1}:{2}", i, GetSeconds(i) / 60, GetSeconds(i) % 60);

                ofs      = (((toc.TrackData[i].Address_1 * 60) + toc.TrackData[i].Address_2) * 75) + toc.TrackData[i].Address_3;
                n        = n + cddb_sum((toc.TrackData[i].Address_1 * 60) + toc.TrackData[i].Address_2);
                secs    += GetSeconds(i);
                postfix += "+" + string.Format("{0}", ofs);

                i++;
            }


            int numSecs = toc.TrackData[i].Address_1 * 60 + toc.TrackData[i].Address_2;

            Console.WriteLine("n = {0}, numSecs = {1}, secs = {2}", n, numSecs, secs);

            postfix += "+" + numSecs;
            TrackData last  = toc.TrackData[numTracks];
            TrackData first = toc.TrackData[0];

            t = ((last.Address_1 * 60) + last.Address_2) -
                ((first.Address_1 * 60) + first.Address_2);

            ulong lDiscId = (((uint)n % 0xff) << 24 | (uint)t << 8 | (uint)numTracks);

            string sDiscId = String.Format("{0:x8}", lDiscId);

            return(sDiscId);
        }