diff --git a/example/.gitignore b/example/.gitignore index 28c2f32f..258fcf94 100644 --- a/example/.gitignore +++ b/example/.gitignore @@ -11,6 +11,7 @@ /cdio-eject /cdtext /device +/discid /drives /eject /isofile diff --git a/example/Makefile.am b/example/Makefile.am index d54b6bcf..de65b5bb 100644 --- a/example/Makefile.am +++ b/example/Makefile.am @@ -25,7 +25,7 @@ if BUILD_CD_PARANOIA paranoia_progs = paranoia paranoia2 endif if BUILD_EXAMPLES -noinst_PROGRAMS = audio cdchange cdtext device drives eject \ +noinst_PROGRAMS = audio cdchange cdtext device discid drives eject \ isofile isofile2 isofuzzy isolist isolsn \ mmc1 mmc2 mmc2a mmc3 $(paranoia_progs) tracks \ sample3 sample4 udf1 udffile cdio-eject @@ -45,6 +45,9 @@ cdtext_LDADD = $(LIBCDIO_LIBS) $(LTLIBICONV) device_DEPENDENCIES = $(LIBCDIO_DEPS) device_LDADD = $(LIBCDIO_LIBS) $(LTLIBICONV) +discid_DEPENDENCIES = $(LIBCDIO_DEPS) +discid_LDADD = $(LIBCDIO_LIBS) $(LTLIBICONV) + drives_DEPENDENCIES = $(LIBCDIO_DEPS) drives_LDADD = $(LIBCDIO_LIBS) $(LTLIBICONV) diff --git a/example/README b/example/README index 4351b8bd..86b85bf2 100644 --- a/example/README +++ b/example/README @@ -29,6 +29,12 @@ cdio-eject.c: a stripped-down "eject" command to open or close a CDROM cdtext.c: A program to show CD-Text and CD disc mode info. +discid.c: http://sourceforge.net/projects/discid/ using libcdio: + a small program to calculate the disc-ID for audio + compact discs. The disc-ID can be used to query info + (tracks, title, interpret) about compact audio discs from + a CDDB-Server. + drives.c: A program to show drivers installed and what the default CD-ROM drive is and what CD drives are available. diff --git a/example/discid.c b/example/discid.c new file mode 100644 index 00000000..0075be97 --- /dev/null +++ b/example/discid.c @@ -0,0 +1,83 @@ +/* + Copyright (C) 2011 + Rocky Bernstein + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + 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. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +/* http://sourceforge.net/projects/discid/ using libcdio: + + a small program to calculate the disc-ID for audio compact + discs. The disc-ID can be used to query info (tracks, title, + interpret) about compact audio discs from a CDDB-Server. +*/ + +#include +#ifdef HAVE_SYS_TYPES_H +#include +#endif +#include + +static int cddb_sum(int n) +{ + int result = 0; + while (n > 0) + { + result += n % 10; + n /= 10; + } + + return result; +} + +int +main(int argc, const char *argv[]) +{ + CdIo_t *p_cdio = cdio_open (NULL, DRIVER_UNKNOWN); + track_t i_track; + track_t i_tracks; + unsigned n = 0; + + if (NULL == p_cdio) { + printf("Couldn't find a driver.. leaving.\n"); + return 1; + } + + i_tracks = cdio_get_num_tracks(p_cdio); + for (i_track = 1; i_track <= i_tracks; ++i_track) { + lba_t lba = cdio_get_track_lba(p_cdio, i_track); + n += cddb_sum(lba / CDIO_CD_FRAMES_PER_SEC); + } + { + unsigned start_sec = + cdio_get_track_lba(p_cdio, 1) / CDIO_CD_FRAMES_PER_SEC; + unsigned leadout_sec = + cdio_get_track_lba(p_cdio, CDIO_CDROM_LEADOUT_TRACK) + / CDIO_CD_FRAMES_PER_SEC; + unsigned total = leadout_sec - start_sec; + unsigned id = ((n % 0xff) << 24 | total << 8 | i_tracks); + + printf("%08X %d", id, i_tracks); + for (i_track = 1; i_track <= i_tracks; ++i_track) { + lba_t lba = cdio_get_track_lba(p_cdio, i_track); + printf(" %ld", (long) lba); + } + printf(" %ld\n", (long) cdio_get_track_lba(p_cdio, + CDIO_CDROM_LEADOUT_TRACK) + / CDIO_CD_FRAMES_PER_SEC); + } + + cdio_destroy(p_cdio); + return 0; +} diff --git a/lib/.gitignore b/lib/.gitignore index b336cc7c..ddeeca75 100644 --- a/lib/.gitignore +++ b/lib/.gitignore @@ -1,2 +1,3 @@ +/*~ /Makefile /Makefile.in