diff --git a/example/C++/Makefile.am b/example/C++/Makefile.am index 134cdab1..e81266bf 100644 --- a/example/C++/Makefile.am +++ b/example/C++/Makefile.am @@ -64,4 +64,4 @@ mmc2_DEPENDENCIES = $(LIBCDIO_DEPS) mmc2_LDADD = $(LIBCDIO_LIBS) # iso programs create file "copying" -MOSTLYCLEANFILES = copying +MOSTLYCLEANFILES = copying *.wav diff --git a/example/C++/README b/example/C++/README index b648de99..b2286af3 100644 --- a/example/C++/README +++ b/example/C++/README @@ -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 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 libcdio-oriented initialization. Probably more suited to diff --git a/example/C++/paranoia.cpp b/example/C++/paranoia.cpp index 45207de5..045de6cf 100644 --- a/example/C++/paranoia.cpp +++ b/example/C++/paranoia.cpp @@ -1,7 +1,7 @@ /* $Id: paranoia.cpp,v 1.3 2008/03/24 15:30:56 karl Exp $ - Copyright (C) 2005, 2008 Rocky Bernstein + Copyright (C) 2005, 2008, 2009 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 @@ -24,14 +24,24 @@ # include "config.h" #endif -#include -#include -#include +#include +#include +#include +#include +using namespace std; + +extern "C"{ + #include + #include + #include #ifdef HAVE_STDLIB_H -#include + #include #endif +} + + int main(int argc, const char *argv[]) { @@ -44,26 +54,26 @@ main(int argc, const char *argv[]) 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); + 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); + cerr << "Unable to access to a CD-ROM drive with audio CD in it"; + return -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); + cerr << "Unable to identify audio CD disc.\n"; + return -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); + cerr << "Unable to open disc.\n"; + return -1; } /* 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_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 ++) { /* read a sector */ @@ -100,14 +141,18 @@ main(int argc, const char *argv[]) char *psz_mes=cdda_messages(d); 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_mes) free(psz_mes); if( !p_readbuf ) { - printf("paranoia read error. Stopping.\n"); + cerr << "paranoia read error. Stopping.\n"; break; } + + char *temp= (char*) p_readbuf; + outfile.write(temp, CDIO_CD_FRAMESIZE_RAW); + } } paranoia_free(p); diff --git a/example/Makefile.am b/example/Makefile.am index 6f38b041..4c6f86a7 100644 --- a/example/Makefile.am +++ b/example/Makefile.am @@ -94,4 +94,4 @@ udffile_LDADD = $(LIBUDF_LIBS) $(LIBCDIO_LIBS) $(LTLIBICONV) # iso programs create file "copying" -MOSTLYCLEANFILES = copying +MOSTLYCLEANFILES = copying *.wav diff --git a/example/README b/example/README index 16a5256b..f99307af 100644 --- a/example/README +++ b/example/README @@ -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 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 track-01.wav. + of track 1 to file track01s.wav. paranoia2: Another program to show using CD-DA paranoia using a more libcdio-oriented initialization. Probably more suited to diff --git a/example/paranoia.c b/example/paranoia.c index 38e201a2..c933dffd 100644 --- a/example/paranoia.c +++ b/example/paranoia.c @@ -128,7 +128,7 @@ main(int argc, const char *argv[]) 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); - int fd = creat("track-01.wav", 0644); + int fd = creat("track1s.wav", 0644); /* For demo purposes we'll read only 300 frames (about 4 seconds). We don't want this to take too long. On the other