/*
* open file containing impulse response samples. Check
* to see if it exists.
*
*/
if( (imp_F = fopen(fileName,"r")) == NULL) {
fprintf(stderr,"firtaps: file could not be opened.\n");
return(4);
}
fscanf(imp_F,"%d",&numberTaps);
/*
* Allocate memory and return pointers for tapped delay line x_P and
* array containing impulse response samples, h_P.
*
*/
if( (x_P = (int*)calloc(numberTaps,sizeof(int))) == NULL ||
(h_P = (double*)calloc(numberTaps,sizeof(double))) == NULL ) {
fprintf(stderr,"fxfirtaps: can't allocate work space\n");
return(4);
}
if( (fxfactor0_P = (int*)calloc(numberTaps,sizeof(int))) == NULL ||
(fxfactor1_P = (int*)calloc(numberTaps,sizeof(int))) == NULL ||
(fxfactLessFlag_P = (int*)calloc(numberTaps,sizeof(int))) == NULL) {
fprintf(stderr,"fxfirtaps: can't allocate work space\n");
return(5);
}
/*
* Read in the impulse response samples into the array
* and initialize the tapped delay line to zero.
*
*/
for (i=0; i 32) {
fprintf(stderr,"fxfirtaps: size can not be greater than 32\n");
return(6);
}
if ((size & 1) == 1) {
fprintf(stderr,"fxfirtaps: Sorry, size can not be an odd number\n");
return(7);
}
/*
* store fixed point tap coefficients (part1,part2,lessFlag)
*/
if (qbits > 30) {
/*
* Because 1<<31 becomes a negative number in this machine
*/
fprintf(stderr,"fxfirtaps:At most 30 bits are allowed for fraction\n");
return(7);
}
/*
* Calculate the maximum number to be represented by size bits
*/
maxv=1;
maxv <<= (size-1);
maxv -= 1;
val=1;
val <<= qbits;
for (i=0; i0.0)
fxfactor = (int)(factor * val + 0.5);
else
fxfactor = (int)(factor * val - 0.5);
if (fxfactor > maxv || (-fxfactor) > maxv) {
fprintf(stderr,"fxfirtaps: gain can not be represented by size bits\n");
return(8);
}
Fx_Part(size,fxfactor,&fxfactor1_P[i],&fxfactor0_P[i],&fxfactLessFlag_P[i]);
}