quick fix for SF#1601812 where an error of exactly 0 (very rare) in FLAC__lpc_compute...
authorJosh Coalson <jcoalson@users.sourceforce.net>
Mon, 27 Nov 2006 16:27:41 +0000 (16:27 +0000)
committerJosh Coalson <jcoalson@users.sourceforce.net>
Mon, 27 Nov 2006 16:27:41 +0000 (16:27 +0000)
src/libFLAC/include/private/lpc.h
src/libFLAC/lpc.c
src/libFLAC/stream_encoder.c

index b99da8e..8d48310 100644 (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[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()
index aa9b1c3..5a13f3f 100644 (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;
        FLAC__double r, err, ref[FLAC__MAX_LPC_ORDER], lpc[FLAC__MAX_LPC_ORDER];
 
-       FLAC__ASSERT(0 < max_order);
-       FLAC__ASSERT(max_order <= FLAC__MAX_LPC_ORDER);
+       FLAC__ASSERT(0 != max_order);
+       FLAC__ASSERT(0 < *max_order);
+       FLAC__ASSERT(*max_order <= FLAC__MAX_LPC_ORDER);
        FLAC__ASSERT(autoc[0] != 0.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. */
                r = -autoc[i+1];
                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++)
                        lp_coeff[i][j] = (FLAC__real)(-lpc[j]); /* negate FIR filter coeff to get predictor coeff */
                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;
+               }
        }
 }
 
index 968ae2b..a8382b1 100644 (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);
                                                /* 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) {
-                                                       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) {
                                                                min_lpc_order = 1;
                                                        }