2
* Copyright (C) 2005 Rocky Bernstein <rocky@panix.com>
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License as published by
6
* the Free Software Foundation; either version 2, or (at your option)
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19
/* Simple program to show using libcdio's version of the CD-DA paranoia.
27
#include <cdio/paranoia.h>
28
#include <cdio/cd_types.h>
36
main(int argc, const char *argv[])
38
cdrom_drive_t *d = NULL; /* Place to store handle given by cd-paranoia. */
39
char **ppsz_cd_drives; /* List of all drives with a loaded CDDA in it. */
41
/* See if we can find a device with a loaded CD-DA in it. */
42
ppsz_cd_drives = cdio_get_devices_with_cap(NULL, CDIO_FS_AUDIO, false);
45
/* Found such a CD-ROM with a CD-DA loaded. Use the first drive in
47
d=cdda_identify(*ppsz_cd_drives, 1, NULL);
49
printf("Unable find or access a CD-ROM drive with an audio CD in it.\n");
53
/* Don't need a list of CD's with CD-DA's any more. */
54
cdio_free_device_list(ppsz_cd_drives);
57
printf("Unable to identify audio CD disc.\n");
61
/* We'll set for verbose paranoia messages. */
62
cdda_verbose_set(d, CDDA_MESSAGE_PRINTIT, CDDA_MESSAGE_PRINTIT);
64
if ( 0 != cdda_open(d) ) {
65
printf("Unable to open disc.\n");
69
/* Okay now set up to read up to the first 300 frames of the first
70
audio track of the Audio CD. */
72
cdrom_paranoia_t *p = paranoia_init(d);
73
lsn_t i_first_lsn = cdda_disc_firstsector(d);
75
if ( -1 == i_first_lsn ) {
76
printf("Trouble getting starting LSN\n");
79
track_t i_track = cdda_sector_gettrack(d, i_first_lsn);
80
lsn_t i_last_lsn = cdda_track_lastsector(d, i_track);
82
/* For demo purposes we'll read only 300 frames (about 4
83
seconds). We don't want this to take too long. On the other
84
hand, I suppose it should be something close to a real test.
86
if ( i_last_lsn - i_first_lsn > 300) i_last_lsn = i_first_lsn + 299;
88
printf("Reading track %d from LSN %ld to LSN %ld\n", i_track,
89
(long int) i_first_lsn, (long int) i_last_lsn);
91
/* Set reading mode for full paranoia, but allow skipping sectors. */
92
paranoia_modeset(p, PARANOIA_MODE_FULL^PARANOIA_MODE_NEVERSKIP);
94
paranoia_seek(p, i_first_lsn, SEEK_SET);
96
for ( i_cursor = i_first_lsn; i_cursor <= i_last_lsn; i_cursor ++) {
98
int16_t *p_readbuf=paranoia_read(p, NULL);
99
char *psz_err=cdda_errors(d);
100
char *psz_mes=cdda_messages(d);
102
if (psz_mes || psz_err)
103
printf("%s%s\n", psz_mes ? psz_mes: "", psz_err ? psz_err: "");
105
if (psz_err) free(psz_err);
106
if (psz_mes) free(psz_mes);
108
printf("paranoia read error. Stopping.\n");