add workaround for lack of lround() on MSVC

This commit is contained in:
Josh Coalson 2007-02-04 02:58:22 +00:00
parent 38ef5cad48
commit db3a0e78e3

View File

@ -204,9 +204,16 @@ int FLAC__lpc_quantize_coefficients(const FLAC__real lp_coeff[], unsigned order,
FLAC__int32 q;
for(i = 0; i < order; i++) {
error += lp_coeff[i] * (1 << *shift);
#if defined _MSC_VER
if(error >= 0.0)
q = (FLAC__int32)(error + 0.5);
else
q = (FLAC__int32)(error - 0.5);
#else
q = lround(error); /* round() is also suitable */
#endif
#ifdef FLAC__OVERFLOW_DETECT
if(q > qmax)
if(q > qmax+1) /* we expect q==qmax+1 occasionally due to lround() */
fprintf(stderr,"FLAC__lpc_quantize_coefficients: quantizer overflow: q>qmax %d>%d shift=%d cmax=%f precision=%u lpc[%u]=%f\n",q,qmax,*shift,cmax,precision+1,i,lp_coeff[i]);
else if(q < qmin)
fprintf(stderr,"FLAC__lpc_quantize_coefficients: quantizer overflow: q<qmin %d<%d shift=%d cmax=%f precision=%u lpc[%u]=%f\n",q,qmin,*shift,cmax,precision+1,i,lp_coeff[i]);
@ -232,9 +239,16 @@ int FLAC__lpc_quantize_coefficients(const FLAC__real lp_coeff[], unsigned order,
#endif
for(i = 0; i < order; i++) {
error += lp_coeff[i] / (1 << nshift);
#if defined _MSC_VER
if(error >= 0.0)
q = (FLAC__int32)(error + 0.5);
else
q = (FLAC__int32)(error - 0.5);
#else
q = lround(error); /* round() is also suitable */
#endif
#ifdef FLAC__OVERFLOW_DETECT
if(q > qmax)
if(q > qmax+1) /* we expect q==qmax+1 occasionally due to lround() */
fprintf(stderr,"FLAC__lpc_quantize_coefficients: quantizer overflow: q>qmax %d>%d shift=%d cmax=%f precision=%u lpc[%u]=%f\n",q,qmax,*shift,cmax,precision+1,i,lp_coeff[i]);
else if(q < qmin)
fprintf(stderr,"FLAC__lpc_quantize_coefficients: quantizer overflow: q<qmin %d<%d shift=%d cmax=%f precision=%u lpc[%u]=%f\n",q,qmin,*shift,cmax,precision+1,i,lp_coeff[i]);