mirror of
https://github.com/claunia/flac.git
synced 2025-12-16 18:54:26 +00:00
switch to better method for getting floor(log2(double))
This commit is contained in:
@@ -145,10 +145,11 @@ redo_it:
|
|||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
const int log2cmax = (int)floor(log(cmax) / M_LN2); /* this is a good estimate but may not be precise enough, so we have to check for corner cases later when shifting */
|
int log2cmax;
|
||||||
const int maxshift = (int)precision - log2cmax - 1;
|
|
||||||
|
|
||||||
*shift = maxshift;
|
(void)frexp(cmax, &log2cmax);
|
||||||
|
log2cmax--;
|
||||||
|
*shift = (int)precision - log2cmax - 1;
|
||||||
|
|
||||||
if(*shift < min_shiftlimit || *shift > max_shiftlimit) {
|
if(*shift < min_shiftlimit || *shift > max_shiftlimit) {
|
||||||
return 1;
|
return 1;
|
||||||
@@ -159,7 +160,7 @@ redo_it:
|
|||||||
for(i = 0; i < order; i++) {
|
for(i = 0; i < order; i++) {
|
||||||
qlp_coeff[i] = (FLAC__int32)floor((double)lp_coeff[i] * (double)(1 << *shift));
|
qlp_coeff[i] = (FLAC__int32)floor((double)lp_coeff[i] * (double)(1 << *shift));
|
||||||
|
|
||||||
/* check for corner cases mentioned in the comment for log2cmax above */
|
/* double-check the result */
|
||||||
if(qlp_coeff[i] > qmax || qlp_coeff[i] < qmin) {
|
if(qlp_coeff[i] > qmax || qlp_coeff[i] < qmin) {
|
||||||
#ifdef FLAC__OVERFLOW_DETECT
|
#ifdef FLAC__OVERFLOW_DETECT
|
||||||
fprintf(stderr,"FLAC__lpc_quantize_coefficients: compensating for overflow, qlp_coeff[%u]=%d, lp_coeff[%u]=%f, cmax=%f, precision=%u, shift=%d, q=%f, f(q)=%f\n", i, qlp_coeff[i], i, lp_coeff[i], cmax, precision, *shift, (double)lp_coeff[i] * (double)(1 << *shift), floor((double)lp_coeff[i] * (double)(1 << *shift)));
|
fprintf(stderr,"FLAC__lpc_quantize_coefficients: compensating for overflow, qlp_coeff[%u]=%d, lp_coeff[%u]=%f, cmax=%f, precision=%u, shift=%d, q=%f, f(q)=%f\n", i, qlp_coeff[i], i, lp_coeff[i], cmax, precision, *shift, (double)lp_coeff[i] * (double)(1 << *shift), floor((double)lp_coeff[i] * (double)(1 << *shift)));
|
||||||
@@ -177,7 +178,7 @@ redo_it:
|
|||||||
for(i = 0; i < order; i++) {
|
for(i = 0; i < order; i++) {
|
||||||
qlp_coeff[i] = (FLAC__int32)floor((double)lp_coeff[i] / (double)(1 << nshift));
|
qlp_coeff[i] = (FLAC__int32)floor((double)lp_coeff[i] / (double)(1 << nshift));
|
||||||
|
|
||||||
/* check for corner cases mentioned in the comment for log2cmax above */
|
/* double-check the result */
|
||||||
if(qlp_coeff[i] > qmax || qlp_coeff[i] < qmin) {
|
if(qlp_coeff[i] > qmax || qlp_coeff[i] < qmin) {
|
||||||
#ifdef FLAC__OVERFLOW_DETECT
|
#ifdef FLAC__OVERFLOW_DETECT
|
||||||
fprintf(stderr,"FLAC__lpc_quantize_coefficients: compensating for overflow, qlp_coeff[%u]=%d, lp_coeff[%u]=%f, cmax=%f, precision=%u, shift=%d, q=%f, f(q)=%f\n", i, qlp_coeff[i], i, lp_coeff[i], cmax, precision, *shift, (double)lp_coeff[i] / (double)(1 << nshift), floor((double)lp_coeff[i] / (double)(1 << nshift)));
|
fprintf(stderr,"FLAC__lpc_quantize_coefficients: compensating for overflow, qlp_coeff[%u]=%d, lp_coeff[%u]=%f, cmax=%f, precision=%u, shift=%d, q=%f, f(q)=%f\n", i, qlp_coeff[i], i, lp_coeff[i], cmax, precision, *shift, (double)lp_coeff[i] / (double)(1 << nshift), floor((double)lp_coeff[i] / (double)(1 << nshift)));
|
||||||
|
|||||||
Reference in New Issue
Block a user