paranoia.cpp: write WAV file of up to the first 300 sectors of the first track

*/Makefile.am remove any created WAV files.
README: update paranoia descriptions
parananoia.c: track-01.wav -> track01s.wav
This commit is contained in:
rocky
2009-04-20 07:06:02 -04:00
parent 768c2ff249
commit 2c37ff8db5
6 changed files with 66 additions and 19 deletions

View File

@@ -64,4 +64,4 @@ mmc2_DEPENDENCIES = $(LIBCDIO_DEPS)
mmc2_LDADD = $(LIBCDIO_LIBS) mmc2_LDADD = $(LIBCDIO_LIBS)
# iso programs create file "copying" # iso programs create file "copying"
MOSTLYCLEANFILES = copying MOSTLYCLEANFILES = copying *.wav

View File

@@ -28,7 +28,9 @@ mmc2.cpp: A more involved MMC command to list features from
paranoia.cpp: A program to show using CD-DA paranoia (a library for jitter paranoia.cpp: A program to show using CD-DA paranoia (a library for jitter
detection and audio-read error correction). This program uses detection and audio-read error correction). This program uses
an interface compatible (mostly) with cdparanoia. an interface compatible (mostly) with cdparanoia. It looks for
a CD-ROM with an audio CD in it and rips the first 300 sectors
of track 1 to file track1s.wav.
paranoia2.cpp: Another program to show using CD-DA paranoia using a more paranoia2.cpp: Another program to show using CD-DA paranoia using a more
libcdio-oriented initialization. Probably more suited to libcdio-oriented initialization. Probably more suited to

View File

@@ -1,7 +1,7 @@
/* /*
$Id: paranoia.cpp,v 1.3 2008/03/24 15:30:56 karl Exp $ $Id: paranoia.cpp,v 1.3 2008/03/24 15:30:56 karl Exp $
Copyright (C) 2005, 2008 Rocky Bernstein <rocky@gnu.org> Copyright (C) 2005, 2008, 2009 Rocky Bernstein <rocky@gnu.org>
This program is free software: you can redistribute it and/or modify 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 it under the terms of the GNU General Public License as published by
@@ -24,14 +24,24 @@
# include "config.h" # include "config.h"
#endif #endif
#include <cdio/paranoia.h> #include <iostream>
#include <cdio/cd_types.h> #include <cstdlib>
#include <stdio.h> #include <fstream>
#include <iomanip>
using namespace std;
extern "C"{
#include <cdio/paranoia.h>
#include <cdio/cd_types.h>
#include <stdio.h>
#ifdef HAVE_STDLIB_H #ifdef HAVE_STDLIB_H
#include <stdlib.h> #include <stdlib.h>
#endif #endif
}
int int
main(int argc, const char *argv[]) main(int argc, const char *argv[])
{ {
@@ -44,26 +54,26 @@ main(int argc, const char *argv[])
if (ppsz_cd_drives) { if (ppsz_cd_drives) {
/* Found such a CD-ROM with a CD-DA loaded. Use the first drive in /* Found such a CD-ROM with a CD-DA loaded. Use the first drive in
the list. */ the list. */
d=cdda_identify(*ppsz_cd_drives, 1, NULL); d = cdda_identify(*ppsz_cd_drives, 1, NULL);
} else { } else {
printf("Unable find or access a CD-ROM drive with an audio CD in it.\n"); cerr << "Unable to access to a CD-ROM drive with audio CD in it";
exit(1); return -1;
} }
/* Don't need a list of CD's with CD-DA's any more. */ /* Don't need a list of CD's with CD-DA's any more. */
cdio_free_device_list(ppsz_cd_drives); cdio_free_device_list(ppsz_cd_drives);
if ( !d ) { if ( !d ) {
printf("Unable to identify audio CD disc.\n"); cerr << "Unable to identify audio CD disc.\n";
exit(1); return -1;
} }
/* We'll set for verbose paranoia messages. */ /* We'll set for verbose paranoia messages. */
cdda_verbose_set(d, CDDA_MESSAGE_PRINTIT, CDDA_MESSAGE_PRINTIT); cdda_verbose_set(d, CDDA_MESSAGE_PRINTIT, CDDA_MESSAGE_PRINTIT);
if ( 0 != cdda_open(d) ) { if ( 0 != cdda_open(d) ) {
printf("Unable to open disc.\n"); cerr << "Unable to open disc.\n";
exit(1); return -1;
} }
/* Okay now set up to read up to the first 300 frames of the first /* Okay now set up to read up to the first 300 frames of the first
@@ -92,6 +102,37 @@ main(int argc, const char *argv[])
paranoia_modeset(p, PARANOIA_MODE_FULL^PARANOIA_MODE_NEVERSKIP); paranoia_modeset(p, PARANOIA_MODE_FULL^PARANOIA_MODE_NEVERSKIP);
paranoia_seek(p, i_first_lsn, SEEK_SET); paranoia_seek(p, i_first_lsn, SEEK_SET);
//Get the track size in bytes and conver it to string
unsigned int byte_count =
( i_last_lsn - i_first_lsn + 1 ) * CDIO_CD_FRAMESIZE_RAW;
// Open the output file
ofstream outfile ("track01.wav",
ofstream::binary | ofstream::app | ofstream::out);
// Write format header specification
const int waweChunkLength = byte_count + 44 - 8;
const int fmtChunkLength = 16;
const int compressionCode = 1;
const int numberOfChannels = 2;
const int sampleRate = 44100; // Hz
const int blockAlign = sampleRate*2*2;
const int significantBps = 4;
const int extraFormatBytes = 16;
#define writestr(str) outfile.write(str, sizeof(str)-1)
writestr("RIFF");
outfile.write((char*)&waweChunkLength, 4);
writestr("WAVEfmt ");
outfile.write((char*) &fmtChunkLength, 4);
outfile.write((char*) &compressionCode, 2);
outfile.write((char*) &numberOfChannels, 2);
outfile.write((char*) &sampleRate, 4);
outfile.write((char*) &blockAlign, 4);
outfile.write((char*) &significantBps, 2);
outfile.write((char*) &extraFormatBytes, 2);
writestr("data");
outfile.write((char*) &byte_count,4);
for ( i_cursor = i_first_lsn; i_cursor <= i_last_lsn; i_cursor ++) { for ( i_cursor = i_first_lsn; i_cursor <= i_last_lsn; i_cursor ++) {
/* read a sector */ /* read a sector */
@@ -100,14 +141,18 @@ main(int argc, const char *argv[])
char *psz_mes=cdda_messages(d); char *psz_mes=cdda_messages(d);
if (psz_mes || psz_err) if (psz_mes || psz_err)
printf("%s%s\n", psz_mes ? psz_mes: "", psz_err ? psz_err: ""); cerr << psz_err << psz_mes;
if (psz_err) free(psz_err); if (psz_err) free(psz_err);
if (psz_mes) free(psz_mes); if (psz_mes) free(psz_mes);
if( !p_readbuf ) { if( !p_readbuf ) {
printf("paranoia read error. Stopping.\n"); cerr << "paranoia read error. Stopping.\n";
break; break;
} }
char *temp= (char*) p_readbuf;
outfile.write(temp, CDIO_CD_FRAMESIZE_RAW);
} }
} }
paranoia_free(p); paranoia_free(p);

View File

@@ -94,4 +94,4 @@ udffile_LDADD = $(LIBUDF_LIBS) $(LIBCDIO_LIBS) $(LTLIBICONV)
# iso programs create file "copying" # iso programs create file "copying"
MOSTLYCLEANFILES = copying MOSTLYCLEANFILES = copying *.wav

View File

@@ -59,7 +59,7 @@ paranoia: A program to show using CD-DA paranoia (a library for jitter
detection and audio-read error correction). This program uses detection and audio-read error correction). This program uses
an interface compatible (mostly) with cdparanoia. It looks for an interface compatible (mostly) with cdparanoia. It looks for
a CD-ROM with an audio CD in it and rips the first 300 sectors a CD-ROM with an audio CD in it and rips the first 300 sectors
of track 1 to file track-01.wav. of track 1 to file track01s.wav.
paranoia2: Another program to show using CD-DA paranoia using a more paranoia2: Another program to show using CD-DA paranoia using a more
libcdio-oriented initialization. Probably more suited to libcdio-oriented initialization. Probably more suited to

View File

@@ -128,7 +128,7 @@ main(int argc, const char *argv[])
lsn_t i_cursor; lsn_t i_cursor;
track_t i_track = cdda_sector_gettrack(d, i_first_lsn); track_t i_track = cdda_sector_gettrack(d, i_first_lsn);
lsn_t i_last_lsn = cdda_track_lastsector(d, i_track); lsn_t i_last_lsn = cdda_track_lastsector(d, i_track);
int fd = creat("track-01.wav", 0644); int fd = creat("track1s.wav", 0644);
/* For demo purposes we'll read only 300 frames (about 4 /* For demo purposes we'll read only 300 frames (about 4
seconds). We don't want this to take too long. On the other seconds). We don't want this to take too long. On the other