summaryrefslogtreecommitdiff
path: root/fpcsrc/packages/cdrom/src/discid.pp
blob: a8c90c794ef33ffea35f7c690a3f5fb209f43c24 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
{
    Copyright (c) 1999-2000 by Michael Van Canneyt

    Unit to read a disc TOC and get discid for a cddb query.


    See the file COPYING.FPC, included in this distribution,
    for details about the copyright.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

 **********************************************************************}
unit discid;

{$mode objfpc}

interface

uses cdrom,sysutils;

Function CDDBDiscID(Const CDTOC : Array of TTocEntry; Count : Integer) : integer ;
Function GetCDDBQueryString(Const Tracks : Array of TTocEntry; Count : Integer) : String;

Implementation

Function cddb_sum(N : Integer) : Cardinal;

begin
  Result:=0;
  while (n > 0) do
    begin
    Inc(result,(n mod 10));
    n:=n div 10;
    end;
end;

Function cddbdiscid(Const cdtoc : Array of TTocEntry; Count : Integer) : integer ;

Var
 i,t,n :  cardinal;

begin
  t:=0;
  n:=0;
  i:= 0;
  For I:=0 to count-1 do
    n := n + cddb_sum((cdtoc[i].min * 60) + cdtoc[i].sec);
  t:=((cdtoc[Count].min * 60) + cdtoc[Count].sec) -
     ((cdtoc[0].min * 60) + cdtoc[0].sec);
  Result:=(((n mod $ff) shl 24) or (t shl 8 or count));
end;

Function GetCDDBQueryString(Const Tracks : Array of TTocEntry; Count : Integer) : String;


Var
  I,TheDiscID : Integer;

begin
  TheDiscID:=cddbdiscid(Tracks,Count);
  Result:=Lowercase(HexStr(TheDiscID,8))+' '+intToStr(Count);
  for I:=0 to Count-1 do
     Result:=Result+' '+IntToStr(tracks[i].frame);
  Result:=Result+' '+IntToStr(tracks[Count].frame div 75);
end;

end.