quick fix for SF#1601812 where an error of exactly 0 (very rare) in FLAC__lpc_compute_lp_coefficients() could cause an infinite loop later in FLAC__lpc_quantize_coefficients()

This commit is contained in:
Josh Coalson
2006-11-27 16:27:41 +00:00
parent d9ac0bd63a
commit 32b9baedb4
3 changed files with 13 additions and 6 deletions

View File

@@ -100,7 +100,7 @@ void FLAC__lpc_compute_autocorrelation_asm_ia32_3dnow(const FLAC__real data[], u
* in lp_coeff[8][0,8], the LP coefficients for order 8 will be * in lp_coeff[8][0,8], the LP coefficients for order 8 will be
* in lp_coeff[7][0,7], etc. * in lp_coeff[7][0,7], etc.
*/ */
void FLAC__lpc_compute_lp_coefficients(const FLAC__real autoc[], unsigned max_order, FLAC__real lp_coeff[][FLAC__MAX_LPC_ORDER], FLAC__double error[]); void FLAC__lpc_compute_lp_coefficients(const FLAC__real autoc[], unsigned *max_order, FLAC__real lp_coeff[][FLAC__MAX_LPC_ORDER], FLAC__double error[]);
/* /*
* FLAC__lpc_quantize_coefficients() * FLAC__lpc_quantize_coefficients()

View File

@@ -105,18 +105,19 @@ void FLAC__lpc_compute_autocorrelation(const FLAC__real data[], unsigned data_le
} }
} }
void FLAC__lpc_compute_lp_coefficients(const FLAC__real autoc[], unsigned max_order, FLAC__real lp_coeff[][FLAC__MAX_LPC_ORDER], FLAC__double error[]) void FLAC__lpc_compute_lp_coefficients(const FLAC__real autoc[], unsigned *max_order, FLAC__real lp_coeff[][FLAC__MAX_LPC_ORDER], FLAC__double error[])
{ {
unsigned i, j; unsigned i, j;
FLAC__double r, err, ref[FLAC__MAX_LPC_ORDER], lpc[FLAC__MAX_LPC_ORDER]; FLAC__double r, err, ref[FLAC__MAX_LPC_ORDER], lpc[FLAC__MAX_LPC_ORDER];
FLAC__ASSERT(0 < max_order); FLAC__ASSERT(0 != max_order);
FLAC__ASSERT(max_order <= FLAC__MAX_LPC_ORDER); FLAC__ASSERT(0 < *max_order);
FLAC__ASSERT(*max_order <= FLAC__MAX_LPC_ORDER);
FLAC__ASSERT(autoc[0] != 0.0); FLAC__ASSERT(autoc[0] != 0.0);
err = autoc[0]; err = autoc[0];
for(i = 0; i < max_order; i++) { for(i = 0; i < *max_order; i++) {
/* Sum up this iteration's reflection coefficient. */ /* Sum up this iteration's reflection coefficient. */
r = -autoc[i+1]; r = -autoc[i+1];
for(j = 0; j < i; j++) for(j = 0; j < i; j++)
@@ -139,6 +140,12 @@ void FLAC__lpc_compute_lp_coefficients(const FLAC__real autoc[], unsigned max_or
for(j = 0; j <= i; j++) for(j = 0; j <= i; j++)
lp_coeff[i][j] = (FLAC__real)(-lpc[j]); /* negate FIR filter coeff to get predictor coeff */ lp_coeff[i][j] = (FLAC__real)(-lpc[j]); /* negate FIR filter coeff to get predictor coeff */
error[i] = err; error[i] = err;
/*@@@@@@ see SF bug #1601812 http://sourceforge.net/tracker/index.php?func=detail&aid=1601812&group_id=13478&atid=113478 */
if(err == 0.0) {
*max_order = i+1;
return;
}
} }
} }

View File

@@ -3532,7 +3532,7 @@ FLAC__bool process_subframe_(
encoder->private_->local_lpc_compute_autocorrelation(encoder->private_->windowed_signal, frame_header->blocksize, max_lpc_order+1, autoc); encoder->private_->local_lpc_compute_autocorrelation(encoder->private_->windowed_signal, frame_header->blocksize, max_lpc_order+1, autoc);
/* if autoc[0] == 0.0, the signal is constant and we usually won't get here, but it can happen */ /* if autoc[0] == 0.0, the signal is constant and we usually won't get here, but it can happen */
if(autoc[0] != 0.0) { if(autoc[0] != 0.0) {
FLAC__lpc_compute_lp_coefficients(autoc, max_lpc_order, encoder->private_->lp_coeff, lpc_error); FLAC__lpc_compute_lp_coefficients(autoc, &max_lpc_order, encoder->private_->lp_coeff, lpc_error);
if(encoder->protected_->do_exhaustive_model_search) { if(encoder->protected_->do_exhaustive_model_search) {
min_lpc_order = 1; min_lpc_order = 1;
} }