From 711dcdac7b420c96b69cee9b77a099f6e4ae9e3f Mon Sep 17 00:00:00 2001 From: rocky Date: Sat, 27 Aug 2005 14:29:12 +0000 Subject: [PATCH] Add C++ versions of paranoia.c and paranioa2.c --- example/C++/Makefile.am | 35 ++++++----- example/C++/paranoia.cpp | 119 ++++++++++++++++++++++++++++++++++++++ example/C++/paranoia2.cpp | 101 ++++++++++++++++++++++++++++++++ 3 files changed, 241 insertions(+), 14 deletions(-) create mode 100644 example/C++/paranoia.cpp create mode 100644 example/C++/paranoia2.cpp diff --git a/example/C++/Makefile.am b/example/C++/Makefile.am index 7c5cad47..22603971 100644 --- a/example/C++/Makefile.am +++ b/example/C++/Makefile.am @@ -1,4 +1,4 @@ -# $Id: Makefile.am,v 1.2 2005/07/15 21:38:57 rocky Exp $ +# $Id: Makefile.am,v 1.3 2005/08/27 14:29:12 rocky Exp $ # # Copyright (C) 2005 Rocky Bernstein # @@ -20,25 +20,32 @@ # Things to regression testing #################################################### # -noinst_PROGRAMS = device iso1 iso2 iso3 mmc1 mmc2 +noinst_PROGRAMS = device iso1 iso2 iso3 mmc1 mmc2 paranoia paranoia2 INCLUDES = -I$(top_srcdir) $(LIBCDIO_CFLAGS) -device_SOURCES = device.cpp -device_LDADD = $(LIBCDIO_LIBS) +device_SOURCES = device.cpp +device_LDADD = $(LIBCDIO_LIBS) -iso1_SOURCES = iso1.cpp -iso1_LDADD = $(LIBISO9660_LIBS) $(LIBCDIO_LIBS) $(LIBICONV) -iso2_SOURCES = iso2.cpp -iso2_LDADD = $(LIBISO9660_LIBS) $(LIBCDIO_LIBS) $(LIBICONV) -iso3_SOURCES = iso3.cpp -iso3_LDADD = $(LIBISO9660_LIBS) $(LIBCDIO_LIBS) $(LIBICONV) +paranoia_SOURCES = paranoia.cpp +paranoia_LDADD = $(LIBCDIO_PARANOIA_LIBS) $(LIBCDIO_CDDA_LIBS) \ + $(LIBCDIO_LIBS) +paranoia2_SOURCES = paranoia.cpp +paranoia2_LDADD = $(LIBCDIO_PARANOIA_LIBS) $(LIBCDIO_CDDA_LIBS) \ + $(LIBCDIO_LIBS) -mmc1_SOURCES = mmc1.cpp -mmc1_LDADD = $(LIBCDIO_LIBS) +iso1_SOURCES = iso1.cpp +iso1_LDADD = $(LIBISO9660_LIBS) $(LIBCDIO_LIBS) $(LIBICONV) +iso2_SOURCES = iso2.cpp +iso2_LDADD = $(LIBISO9660_LIBS) $(LIBCDIO_LIBS) $(LIBICONV) +iso3_SOURCES = iso3.cpp +iso3_LDADD = $(LIBISO9660_LIBS) $(LIBCDIO_LIBS) $(LIBICONV) -mmc2_SOURCES = mmc2.cpp -mmc2_LDADD = $(LIBCDIO_LIBS) +mmc1_SOURCES = mmc1.cpp +mmc1_LDADD = $(LIBCDIO_LIBS) + +mmc2_SOURCES = mmc2.cpp +mmc2_LDADD = $(LIBCDIO_LIBS) # iso programs create file "copying" MOSTLYCLEANFILES = copying diff --git a/example/C++/paranoia.cpp b/example/C++/paranoia.cpp new file mode 100644 index 00000000..803e11a4 --- /dev/null +++ b/example/C++/paranoia.cpp @@ -0,0 +1,119 @@ +/* + * 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. + */ + +#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-paranoia. */ + char **ppsz_cd_drives; /* List of all drives with a loaded CDDA in it. */ + + /* 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. */ + d=cdda_identify(*ppsz_cd_drives, 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); + + if ( !d ) { + printf("Unable to identify audio CD disc.\n"); + exit(1); + } + + /* 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); + } + + /* Okay now set up to read up to the first 300 frames of the first + audio track of the Audio CD. */ + { + cdrom_paranoia_t *p = paranoia_init(d); + lsn_t i_first_lsn = cdda_disc_firstsector(d); + + if ( -1 == i_first_lsn ) { + printf("Trouble getting starting LSN\n"); + } else { + lsn_t i_cursor; + track_t i_track = cdda_sector_gettrack(d, i_first_lsn); + lsn_t i_last_lsn = cdda_track_lastsector(d, i_track); + + /* For demo purposes we'll read only 300 frames (about 4 + seconds). We don't want this to take too long. On the other + hand, I suppose it should be something close to a real test. + */ + if ( i_last_lsn - i_first_lsn > 300) i_last_lsn = i_first_lsn + 299; + + printf("Reading track %d from LSN %ld to LSN %ld\n", i_track, + (long int) i_first_lsn, (long int) i_last_lsn); + + /* Set reading mode for full paranoia, but allow skipping sectors. */ + paranoia_modeset(p, PARANOIA_MODE_FULL^PARANOIA_MODE_NEVERSKIP); + + paranoia_seek(p, i_first_lsn, SEEK_SET); + + for ( i_cursor = i_first_lsn; i_cursor <= i_last_lsn; i_cursor ++) { + /* read a sector */ + int16_t *p_readbuf=paranoia_read(p, NULL); + char *psz_err=cdda_errors(d); + char *psz_mes=cdda_messages(d); + + if (psz_mes || psz_err) + printf("%s%s\n", psz_mes ? psz_mes: "", psz_err ? psz_err: ""); + + if (psz_err) free(psz_err); + if (psz_mes) free(psz_mes); + if( !p_readbuf ) { + printf("paranoia read error. Stopping.\n"); + break; + } + } + } + paranoia_free(p); + } + + cdda_close(d); + + exit(0); +} diff --git a/example/C++/paranoia2.cpp b/example/C++/paranoia2.cpp new file mode 100644 index 00000000..72c3e7c7 --- /dev/null +++ b/example/C++/paranoia2.cpp @@ -0,0 +1,101 @@ +/* + * 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. But in this version, we'll open a cdio object before + calling paranoia's open. I imagine 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-paranoia. */ + 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=cdio_cddap_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); + + if ( !d ) { + printf("Unable to identify audio CD disc.\n"); + exit(1); + } + + /* We'll set for verbose paranoia messages. */ + cdio_cddap_verbose_set(d, CDDA_MESSAGE_PRINTIT, CDDA_MESSAGE_PRINTIT); + + if ( 0 != cdio_cddap_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; + } + } + + cdio_cddap_close_no_free_cdio(d); + cdio_destroy( p_cdio ); + + exit(0); +}