speed up FLAC__lpc_compute_autocorrelation()

This commit is contained in:
Josh Coalson
2001-05-10 19:29:41 +00:00
parent fc205cc00a
commit c0785cd274

View File

@@ -30,6 +30,8 @@
void FLAC__lpc_compute_autocorrelation(const real data[], unsigned data_len, unsigned lag, real autoc[]) void FLAC__lpc_compute_autocorrelation(const real data[], unsigned data_len, unsigned lag, real autoc[])
{ {
/* a readable, but slower, version */
#if 0
real d; real d;
unsigned i; unsigned i;
@@ -41,6 +43,31 @@ void FLAC__lpc_compute_autocorrelation(const real data[], unsigned data_len, uns
d += data[i] * data[i - lag]; d += data[i] * data[i - lag];
autoc[lag] = d; autoc[lag] = d;
} }
#endif
/*
* this version tends to run faster because of better data locality
* ('data_len' is usually much larger than 'lag')
*/
real d;
unsigned sample, coeff;
const unsigned limit = data_len - lag;
assert(lag > 0);
assert(lag <= data_len);
for(coeff = 0; coeff < lag; coeff++)
autoc[coeff] = 0.0;
for(sample = 0; sample <= limit; sample++){
d = data[sample];
for(coeff = 0; coeff < lag; coeff++)
autoc[coeff] += d * data[sample+coeff];
}
for(; sample < data_len; sample++){
d = data[sample];
for(coeff = 0; coeff < data_len - sample; coeff++)
autoc[coeff] += d * data[sample+coeff];
}
} }
void FLAC__lpc_compute_lp_coefficients(const real autoc[], unsigned max_order, real lp_coeff[][FLAC__MAX_LPC_ORDER], real error[]) void FLAC__lpc_compute_lp_coefficients(const real autoc[], unsigned max_order, real lp_coeff[][FLAC__MAX_LPC_ORDER], real error[])