discid.pp 1.7 KB

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