mirror of
https://github.com/claunia/flac.git
synced 2025-12-16 18:54:26 +00:00
speed up FLAC__lpc_compute_autocorrelation()
This commit is contained in:
@@ -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[])
|
||||||
|
|||||||
Reference in New Issue
Block a user