Put back original cdparanoia byte-swapping routines until we smoke out what's

going wrong on cygwin.
This commit is contained in:
rocky
2005-01-13 21:38:21 +00:00
parent cd919f6664
commit fde6bbbb1b
2 changed files with 193 additions and 3 deletions

View File

@@ -1,5 +1,5 @@
/*
$Id: common_interface.c,v 1.6 2005/01/09 12:32:19 rocky Exp $
$Id: common_interface.c,v 1.7 2005/01/13 21:38:21 rocky Exp $
Copyright (C) 2004, 2005 Rocky Bernstein <rocky@panix.com>
Copyright (C) 1998, 2002 Monty monty@xiph.org
@@ -40,6 +40,8 @@
the transform is looked at to see which has data in the FFT (or audible)
portion. (Or so that's how I understand it.)
*/
#if USELIBCDIO_ROUTINES
int
data_bigendianp(cdrom_drive_t *d)
{
@@ -51,7 +53,6 @@ data_bigendianp(cdrom_drive_t *d)
float *b=calloc(1024,sizeof(float));
long readsectors=5;
int16_t *buff=malloc(readsectors*CDIO_CD_FRAMESIZE_RAW);
memset(buff, 0, readsectors*CDIO_CD_FRAMESIZE_RAW);
/* look at the starts of the audio tracks */
@@ -173,6 +174,126 @@ data_bigendianp(cdrom_drive_t *d)
}
}
#else
int data_bigendianp(cdrom_drive *d){
float lsb_votes=0;
float msb_votes=0;
int i,checked;
int endiancache=d->bigendianp;
float *a=calloc(1024,sizeof(float));
float *b=calloc(1024,sizeof(float));
long readsectors=5;
int16_t *buff=malloc(readsectors*CDIO_CD_FRAMESIZE_RAW);
/* look at the starts of the audio tracks */
/* if real silence, tool in until some static is found */
/* Force no swap for now */
d->bigendianp=-1;
cdmessage(d,"\nAttempting to determine drive endianness from data...");
d->enable_cdda(d,1);
for(i=0,checked=0;i<d->tracks;i++){
float lsb_energy=0;
float msb_energy=0;
if(cdda_track_audiop(d,i+1)==1){
long firstsector=cdda_track_firstsector(d,i+1);
long lastsector=cdda_track_lastsector(d,i+1);
int zeroflag=-1;
long beginsec=0;
/* find a block with nonzero data */
while(firstsector+readsectors<=lastsector){
int j;
if(d->read_audio(d,buff,firstsector,readsectors)>0){
/* Avoid scanning through jitter at the edges */
for(beginsec=0;beginsec<readsectors;beginsec++){
int offset=beginsec*CDIO_CD_FRAMESIZE_RAW/2;
/* Search *half* */
for(j=460;j<128+460;j++)
if(buff[offset+j]!=0){
zeroflag=0;
break;
}
if(!zeroflag)break;
}
if(!zeroflag)break;
firstsector+=readsectors;
}else{
d->enable_cdda(d,0);
free(a);
free(b);
free(buff);
return(-1);
}
}
beginsec*=CDIO_CD_FRAMESIZE_RAW/2;
/* un-interleave for an fft */
if(!zeroflag){
int j;
for(j=0;j<128;j++)a[j]=le16_to_cpu(buff[j*2+beginsec+460]);
for(j=0;j<128;j++)b[j]=le16_to_cpu(buff[j*2+beginsec+461]);
fft_forward(128,a,NULL,NULL);
fft_forward(128,b,NULL,NULL);
for(j=0;j<128;j++)lsb_energy+=fabs(a[j])+fabs(b[j]);
for(j=0;j<128;j++)a[j]=be16_to_cpu(buff[j*2+beginsec+460]);
for(j=0;j<128;j++)b[j]=be16_to_cpu(buff[j*2+beginsec+461]);
fft_forward(128,a,NULL,NULL);
fft_forward(128,b,NULL,NULL);
for(j=0;j<128;j++)msb_energy+=fabs(a[j])+fabs(b[j]);
}
}
if(lsb_energy<msb_energy){
lsb_votes+=msb_energy/lsb_energy;
checked++;
}else
if(lsb_energy>msb_energy){
msb_votes+=lsb_energy/msb_energy;
checked++;
}
if(checked==5 && (lsb_votes==0 || msb_votes==0))break;
cdmessage(d,".");
}
free(buff);
free(a);
free(b);
d->bigendianp=endiancache;
d->enable_cdda(d,0);
/* How did we vote? Be potentially noisy */
if(lsb_votes>msb_votes){
char buffer[256];
cdmessage(d,"\n\tData appears to be coming back little endian.\n");
sprintf(buffer,"\tcertainty: %d%%\n",(int)
(100.*lsb_votes/(lsb_votes+msb_votes)+.5));
cdmessage(d,buffer);
return(0);
}else{
if(msb_votes>lsb_votes){
char buffer[256];
cdmessage(d,"\n\tData appears to be coming back big endian.\n");
sprintf(buffer,"\tcertainty: %d%%\n",(int)
(100.*msb_votes/(lsb_votes+msb_votes)+.5));
cdmessage(d,buffer);
return(1);
}
cdmessage(d,"\n\tCannot determine CDROM drive endianness.\n");
return(bigendianp());
return(-1);
}
}
#endif
/************************************************************************/
/*! Here we fix up a couple of things that will never happen. yeah,