1 /* 2 * Copyright 2007, Axel Dörfler, axeld@pinc-software.de. 3 * Distributed under the terms of the MIT License. 4 */ 5 6 7 #include "cddb.h" 8 9 10 static int32 cddb_sum(int32 n)11cddb_sum(int32 n) 12 { 13 int32 result = 0; 14 15 while (n > 0) { 16 result = result + (n % 10); 17 n = n / 10; 18 } 19 20 return result; 21 } 22 23 24 // #pragma mark - exported functions 25 26 27 /*! 28 Computes the CD Disc ID as specified in the FreeDB how-to (code taken from there). 29 */ 30 uint32 compute_cddb_disc_id(scsi_toc_toc & toc)31compute_cddb_disc_id(scsi_toc_toc &toc) 32 { 33 int32 numTracks = toc.last_track + 1 - toc.first_track; 34 uint32 n = 0; 35 36 for (int32 i = 0; i < numTracks; i++) { 37 n = n + cddb_sum((toc.tracks[i].start.time.minute * 60) 38 + toc.tracks[i].start.time.second); 39 } 40 41 int32 t = ((toc.tracks[numTracks].start.time.minute * 60) 42 + toc.tracks[numTracks].start.time.second) 43 - ((toc.tracks[0].start.time.minute * 60) 44 + toc.tracks[0].start.time.second); 45 46 return (n % 0xff) << 24 | t << 8 | numTracks; 47 } 48