From 674ab628222deaa21933307a7d9039d266fc7c09 Mon Sep 17 00:00:00 2001 From: rocky Date: Sat, 22 Jan 2005 03:41:50 +0000 Subject: [PATCH] Add an example which opens the cdio object first. Also show off data_bigendianp(). --- example/Makefile.am | 10 +++-- example/paranoia.c | 4 +- example/paranoia2.c | 97 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 106 insertions(+), 5 deletions(-) create mode 100644 example/paranoia2.c diff --git a/example/Makefile.am b/example/Makefile.am index 44aa9e41..6f6a40af 100644 --- a/example/Makefile.am +++ b/example/Makefile.am @@ -1,6 +1,6 @@ -# $Id: Makefile.am,v 1.14 2005/01/18 02:18:49 rocky Exp $ +# $Id: Makefile.am,v 1.15 2005/01/22 03:41:50 rocky Exp $ # -# Copyright (C) 2003, 2004 Rocky Bernstein +# Copyright (C) 2003, 2004, 2005 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 @@ -22,10 +22,11 @@ # if DISABLE_CPP noinst_PROGRAMS = cdtext drives iso1 iso2 iso3 scsi-mmc1 scsi-mmc2 \ - tracks sample2 sample3 sample4 + paranoia paranoia2 tracks sample2 sample3 sample4 else noinst_PROGRAMS = cdtext drives iso1 iso2 iso3 paranoia scsi-mmc1 scsi-mmc2 \ - tracks sample2 sample3 sample4 iso1cpp iso2cpp iso3cpp + paranoia paranoia2 tracks sample2 sample3 sample4 \ + iso1cpp iso2cpp iso3cpp endif INCLUDES = -I$(top_srcdir) $(LIBCDIO_CFLAGS) @@ -35,6 +36,7 @@ cdtext_LDADD = $(LIBCDIO_LIBS) drives_LDADD = $(LIBCDIO_LIBS) paranoia_LDADD = $(LIBCDIO_PARANOIA_LIBS) $(LIBCDIO_CDDA_LIBS) $(LIBCDIO_LIBS) +paranoia2_LDADD = $(LIBCDIO_PARANOIA_LIBS) $(LIBCDIO_CDDA_LIBS) $(LIBCDIO_LIBS) iso1_LDADD = $(LIBISO9660_LIBS) $(LIBCDIO_LIBS) $(LIBICONV) iso2_LDADD = $(LIBISO9660_LIBS) $(LIBCDIO_LIBS) $(LIBICONV) diff --git a/example/paranoia.c b/example/paranoia.c index 86b016d5..afd9a229 100644 --- a/example/paranoia.c +++ b/example/paranoia.c @@ -16,7 +16,9 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * */ -/* Simple program to show using libcdio's version of cdparanoia. */ +/* Simple program to show using libcdio's version of the CD-DA paranoia. + library. + */ #ifdef HAVE_CONFIG_H # include "config.h" diff --git a/example/paranoia2.c b/example/paranoia2.c new file mode 100644 index 00000000..23a85b1d --- /dev/null +++ b/example/paranoia2.c @@ -0,0 +1,97 @@ +/* + * Copyright (C) 2005 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 2, 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, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + */ +/* Simple program to show using libcdio's version of the CD-DA + paranoia library. In this version, we'll open a cdio object before + calling paranoia's open. I image in many cases such as media + players this may be what will be done since, one may want to get + CDDB/CD-Text info beforehand. + */ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include +#include +#include + +#ifdef HAVE_STDLIB_H +#include +#endif + +int +main(int argc, const char *argv[]) +{ + cdrom_drive_t *d = NULL; /* Place to store handle given by cd-parapnioa. */ + char **ppsz_cd_drives; /* List of all drives with a loaded CDDA in it. */ + CdIo_t *p_cdio = NULL; + + /* See if we can find a device with a loaded CD-DA in it. */ + ppsz_cd_drives = cdio_get_devices_with_cap(NULL, CDIO_FS_AUDIO, false); + + if (ppsz_cd_drives) { + /* Found such a CD-ROM with a CD-DA loaded. Use the first drive in + the list. */ + p_cdio = cdio_open(*ppsz_cd_drives, DRIVER_UNKNOWN); + d=cdda_identify_cdio(p_cdio, 1, NULL); + } else { + printf("Unable find or access a CD-ROM drive with an audio CD in it.\n"); + exit(1); + } + + /* Don't need a list of CD's with CD-DA's any more. */ + cdio_free_device_list(ppsz_cd_drives); + free(ppsz_cd_drives); + + /* We'll set for verbose paranoia messages. */ + cdda_verbose_set(d, CDDA_MESSAGE_PRINTIT, CDDA_MESSAGE_PRINTIT); + + if ( 0 != cdda_open(d) ) { + printf("Unable to open disc.\n"); + exit(1); + } + + /* In the paranoia example was a reading. Here we are going to do + something trivial (but I think neat any way - get the Endian-ness + of the drive. */ + { + const int i_endian = data_bigendianp(d); + switch (i_endian) { + case 0: + printf("Drive returns audio data Little Endian." + " Your drive is like most.\n"); + break; + case 1: + printf("Drive returns audio data Big Endian.\n"); + break; + case -1: + printf("Don't know whether drive is Big or Little Endian.\n"); + break; + default: + printf("Whoah - got a return result I'm not expecting %d.\n", + i_endian); + break; + } + } + + cdda_close(d); + + exit(0); +} +