BPicture: Fix archive constructor.
[haiku.git] / src / add-ons / kernel / file_systems / cdda / cddb.cpp
blob76cf40b6c6cdcad52def1097226e4cdbd9839b06
1 /*
2 * Copyright 2007, Axel Dörfler, axeld@pinc-software.de.
3 * Distributed under the terms of the MIT License.
4 */
7 #include "cddb.h"
10 static int32
11 cddb_sum(int32 n)
13 int32 result = 0;
15 while (n > 0) {
16 result = result + (n % 10);
17 n = n / 10;
20 return result;
24 // #pragma mark - exported functions
27 /*!
28 Computes the CD Disc ID as specified in the FreeDB how-to (code taken from there).
30 uint32
31 compute_cddb_disc_id(scsi_toc_toc &toc)
33 int32 numTracks = toc.last_track + 1 - toc.first_track;
34 uint32 n = 0;
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);
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);
46 return (n % 0xff) << 24 | t << 8 | numTracks;