Hallo!
Ich will ein kleines Programm in C# schreiben, was mir die von einer CD die ID gemäß den Vorgaben von freedb.org liefert, und eben dann auch die CD-Daten.
Mein derzeitiges Problem bezieht sich auf die Berechnung der ID.
auf freedb.org gibt es folgenden C Beispielcode:
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: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102:
|
struct toc { int min; int sec; int frame; };
struct toc cdtoc[100];
int read_cdtoc_from_drive(void) { return (tot_trks); }
int cddb_sum(int n) { int ret;
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;
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)); }
|
Daraus habe ich folgenden Code fabriziert:
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:
| private struct toc { public int min; public int sec; public int frame; };
private toc[] cdtoc = new toc[100];
ulong cddb_sum(int n) { ulong ret = 0; while (n > 0) { ret = ret + (ulong)(n % 10); n /= 10; } return (ret); }
int cddb_discid() { int Tracks = CD.GetNumTracks(); for (int i = 0; i <= Tracks; i++) { double Offset = 150; for (int k = 1; k <= i; k++) { Offset += CD.TrackSize(k) / 2352 + 1; } double f = Offset; double m = Math.Floor(f / 75 / 60); double s = Math.Round(f / 75 - m * 60); cdtoc[i].frame = (int)f; cdtoc[i].min = (int)m; cdtoc[i].sec = (int)s; } int t = 0, n = 0; for (int i = 0; i < Tracks; i++) { n += (int)cddb_sum((cdtoc[i].min * 60) + cdtoc[i].sec); } t = (int)((cdtoc[Tracks].min * 60) + cdtoc[Tracks].sec) - ((cdtoc[0].min * 60) + cdtoc[0].sec); return ((n % 0xff) << 24 | t << 8 | Tracks); } |
das was cd_discid zurückliefert in Hexadezimaler schreibweise ist die Disc-ID.
Das Füllen des CD-Arrays stimmt. Habe ich anhand eines kleinen Tools, auch von freedb.org überprüft.
Lediglich bei der Disc-ID (8 Stellen Hex) scheinen bei manchen CDs die ersten beiden Stellen nicht zu stimmen.
Ich denke, dass es vielleicht mit der Genauigkeit der verwendeten Variablen zusammenhängt. Stehe aber im Moment auf'em Schlauch