discid.pp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. {
  2. Copyright (c) 1999-2000 by Michael Van Canneyt
  3. Unit to read a disc TOC and get discid for a cddb query.
  4. See the file COPYING.FPC, included in this distribution,
  5. for details about the copyright.
  6. This program is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  9. **********************************************************************}
  10. unit discid;
  11. {$mode objfpc}
  12. interface
  13. uses cdrom,sysutils;
  14. Function CDDBDiscID(Const CDTOC : Array of TTocEntry; Count : Integer) : integer ;
  15. Function GetCDDBQueryString(Const Tracks : Array of TTocEntry; Count : Integer) : String;
  16. Implementation
  17. Function cddb_sum(N : Integer) : Cardinal;
  18. begin
  19. Result:=0;
  20. while (n > 0) do
  21. begin
  22. Inc(result,(n mod 10));
  23. n:=n div 10;
  24. end;
  25. end;
  26. Function cddbdiscid(Const cdtoc : Array of TTocEntry; Count : Integer) : integer ;
  27. Var
  28. i,t,n : cardinal;
  29. begin
  30. t:=0;
  31. n:=0;
  32. i:= 0;
  33. For I:=0 to count-1 do
  34. n := n + cddb_sum((cdtoc[i].min * 60) + cdtoc[i].sec);
  35. t:=((cdtoc[Count].min * 60) + cdtoc[Count].sec) -
  36. ((cdtoc[0].min * 60) + cdtoc[0].sec);
  37. Result:=(((n mod $ff) shl 24) or (t shl 8 or count));
  38. end;
  39. Function GetCDDBQueryString(Const Tracks : Array of TTocEntry; Count : Integer) : String;
  40. Var
  41. I,TheDiscID : Integer;
  42. begin
  43. TheDiscID:=cddbdiscid(Tracks,Count);
  44. Result:=Lowercase(HexStr(TheDiscID,8))+' '+intToStr(Count);
  45. for I:=0 to Count-1 do
  46. Result:=Result+' '+IntToStr(tracks[i].frame);
  47. Result:=Result+' '+IntToStr(tracks[Count].frame div 75);
  48. end;
  49. end.