Hi
Please tell me to go away if this request is inappropriate
Im trying to convert a C function into 4D
I know very very little C, so after 2 days I'm looking for some help
The C function looks like
struct toc {
int min;
int sec;
int frame;
};
struct toc cdtoc[100];
int
read_cdtoc_from_drive(void)
{
/* Do whatever is appropriate to read the TOC of the CD
* into the cdtoc[] structure array.
}
*/
return (tot_trks);
int
cddb_sum(int n)
{
int ret;
/* For backward compatibility this algorithm must not change */
ret = 0;
while (n > 0) {
ret = ret + (n % 10);
n = n / 10;
return (ret);
}
}
unsigned long
cddb_discid(int tot_trks)
{
int i,
t = 0,
n = 0;
/* For backward compatibility this algorithm must not change */
i = 0;
while (i < tot_trks) {
n = n + cddb_sum((cdtoc[i].min * 60) + cdtoc[i].sec);
i++; }
t = ((cdtoc[tot_trks].min * 60) + cdtoc[tot_trks].sec) -
((cdtoc[0].min * 60) + cdtoc[0].sec);
return ((n % 0xff) << 24 | t << 8 | tot_trks);
main()
} {
}
int tot_trks;
tot_trks = read_cdtoc_from_drive();
printf("The discid is %08x", cddb_discid(tot_trks));
My version Looks Like
n:=0
t:=0
For ($i;1;$NoTracks)
n:=n+cddb_Sum(StartSeconds{$i})
End for
t:=$LastTrack-StartSeconds{1}
$DisckIDNo:=(n%255) << 24 | t << 8 | $NoTracks // (n%255)<<24 results in a
huge negative number
$temp:=string($discIDNo;"&x")
DiscID:=substring($temp;3) //This should result in an 8 character string
in hex
and the subroutine cddb_sum Like This
c_Longint($position;$addDigits)
$Position:=$1
$addDigits:=0;
While ($Position>0)
$addDigits:=$addDigits+($Position%10)
$Position:=int($Position/10)
End while
$0:=$adddigits
I think Im misunderstanding the functioning of cddb_sum
But I dont get anything sensible at the end
This is supposed to calculate a discID used in the lookup for CD titles
from FreeDB
The TOC (Table of contents) is derived from the information retreived from
"drutil TOC"
There is some code that creates an array of start times (in Seconds). an
end time and the number of tracks
This is the code that does that is
C_TEXT($in;$out;$err)
ARRAY LONGINT(StartSeconds;0)
Array Longint(StartFrames;0)
LAUNCH EXTERNAL PROCESS("Drutil toc";$in;$out;$err)
$pos:=Position("Last Track:";$out)
$NoTracksString:=Substring($out;$pos+27;2)
$NoTracks:=num($NoTracksString)
$pos:=Position("Lead-Out:";$out)
$LastTrackString:=substring($out;$pos+27;8)
ConvertTOCToSeconds ($LastTrackString)
$LastTrack:=<>Seconds
$posStart:=$pos
$count:=1
for($i;1;$NoTracks)
$pos:=position("Track";$out;$posStart)
$trackStartstring:=substring($out;$pos+15;8)
ConvertTOCToSeconds ($TrackStartString)
APPEND TO ARRAY(StartSeconds;<>Seconds)
$posStart:=$pos+2
End for
Thanks
-pn
**********************************************************************
4D Internet Users Group (4D iNUG)
FAQ: http://lists.4d.com/faqnug.html
Archive: http://lists.4d.com/archives.html
Options: http://lists.4d.com/mailman/options/4d_tech
Unsub: mailto:[email protected]
**********************************************************************