void CD_Extractor::Extract(int tracknum)
{
int size;
char *buf;
int16_t *readresult;
long result;
long x;
long firstsector,lastsector;
int i;
Paranoia = cdio_paranoia_init(Drive);
firstsector = cdio_cddap_track_firstsector(Drive, tracknum);
lastsector = cdio_cddap_track_lastsector(Drive, tracknum);
size = (lastsector - firstsector) + 1;
SectorsTotal = size;
SectorsRead = 0;
cdio_cddap_speed_set(Drive,32);
paranoia_modeset(Paranoia, PARANOIA_MODE_FULL); //^PARANOIA_MODE_NEVERSKIP);
paranoia_seek(Paranoia, firstsector, SEEK_SET);
QFile file("/home/patrick/SKG_Jukebox/tracks/Track" + QString::number(tracknum
) + ".wav");
WriteWav(file.handle(),size * CD_Framesize_Raw);
for (i = firstsector; i <= lastsector; i++)
{
try
{
//readresult = cdio_paranoia_read(Paranoia,NULL);
readresult = cdio_paranoia_read_limited(Paranoia,NULL,3);
SectorsRead++;
buf = (char*)readresult;
file.write(buf,CD_Framesize_Raw);
UpdateProgress(Progress());
}
catch(...)
{
break;
}
}
fname = file.fileName();
file.close();
cdio_paranoia_free(Paranoia);
ExtractFinished(fname);
}
void CD_Extractor::WriteWav(int f,long bytes)
{
/* quick and dirty */
write(f,"RIFF",4); /* 0-3 */
PutNum(bytes+44-8,f,0,4); /* 4-7 */
write(f,"WAVEfmt ",8); /* 8-15 */
PutNum(16,f,0,4); /* 16-19 */
PutNum(1,f,0,2); /* 20-21 */
PutNum(2,f,0,2); /* 22-23 */
PutNum(44100,f,0,4); /* 24-27 */
PutNum(44100*2*2,f,0,4); /* 28-31 */
PutNum(4,f,0,2); /* 32-33 */
PutNum(16,f,0,2); /* 34-35 */
write(f,"data",4); /* 36-39 */
PutNum(bytes,f,0,4); /* 40-43 */
}
void CD_Extractor::PutNum(long num,int f,int endianness,int bytes){
int i;
unsigned char c;
if(!endianness)
i=0;
else
i=bytes-1;
while(bytes--){
c=(num>>(i<<3))&0xff;
if(write(f,&c,1)==-1){
perror("Could not write to output.");
exit(1);
}
if(endianness)
i--;
else
i++;
}
}
void CD_Extractor::Extract(int tracknum)
{
int size;
char *buf;
int16_t *readresult;
long result;
long x;
long firstsector,lastsector;
int i;
QMessageBox box;
QString fname;
QByteArray arr;
Paranoia = cdio_paranoia_init(Drive);
firstsector = cdio_cddap_track_firstsector(Drive, tracknum);
lastsector = cdio_cddap_track_lastsector(Drive, tracknum);
size = (lastsector - firstsector) + 1;
SectorsTotal = size;
SectorsRead = 0;
cdio_cddap_speed_set(Drive,32);
paranoia_modeset(Paranoia, PARANOIA_MODE_FULL); //^PARANOIA_MODE_NEVERSKIP);
paranoia_seek(Paranoia, firstsector, SEEK_SET);
QFile file("/home/patrick/SKG_Jukebox/tracks/Track" + QString::number(tracknum) + ".wav");
file.open(QIODevice::WriteOnly);
WriteWav(file.handle(),size * CD_Framesize_Raw);
for (i = firstsector; i <= lastsector; i++)
{
try
{
//readresult = cdio_paranoia_read(Paranoia,NULL);
readresult = cdio_paranoia_read_limited(Paranoia,NULL,3);
SectorsRead++;
buf = (char*)readresult;
file.write(buf,CD_Framesize_Raw);
UpdateProgress(Progress());
QApplication::processEvents();
}
catch(...)
{
break;
}
}
fname = file.fileName();
file.close();
cdio_paranoia_free(Paranoia);
ExtractFinished(fname);
}
void CD_Extractor::WriteWav(int f,long bytes)
{
/* quick and dirty */
write(f,"RIFF",4); /* 0-3 */
PutNum(bytes+44-8,f,0,4); /* 4-7 */
write(f,"WAVEfmt ",8); /* 8-15 */
PutNum(16,f,0,4); /* 16-19 */
PutNum(1,f,0,2); /* 20-21 */
PutNum(2,f,0,2); /* 22-23 */
PutNum(44100,f,0,4); /* 24-27 */
PutNum(44100*2*2,f,0,4); /* 28-31 */
PutNum(4,f,0,2); /* 32-33 */
PutNum(16,f,0,2); /* 34-35 */
write(f,"data",4); /* 36-39 */
PutNum(bytes,f,0,4); /* 40-43 */
}
void CD_Extractor::PutNum(long num,int f,int endianness,int bytes){
int i;
unsigned char c;
if(!endianness)
i=0;
else
i=bytes-1;
while(bytes--){
c=(num>>(i<<3))&0xff;
if(write(f,&c,1)==-1){
perror("Could not write to output.");
exit(1);
}
if(endianness)
i--;
else
i++;
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks