24 #define LPC_USE_DOUBLE
43 c = 2.0 / (len - 1.0);
50 w_data[-i-1] = data[-i-1] * w;
51 w_data[+i ] = data[+i ] * w;
64 for(j=0; j<lag; j+=2){
65 double sum0 = 1.0, sum1 = 1.0;
67 sum0 += data[i] * data[i-j];
68 sum1 += data[i] * data[i-j-1];
76 for(i=j-1; i<
len; i+=2){
77 sum += data[i ] * data[i-j ]
78 + data[i+1] * data[i-j+1];
88 int32_t *lpc_out,
int *shift,
int max_shift,
int zero_shift)
96 qmax = (1 << (precision - 1)) - 1;
100 for(i=0; i<order; i++) {
101 cmax=
FFMAX(cmax, fabs(lpc_in[i]));
105 if(cmax * (1 << max_shift) < 1.0) {
107 memset(lpc_out, 0,
sizeof(int32_t) * order);
113 while((cmax * (1 << sh) > qmax) && (sh > 0)) {
119 if(sh == 0 && cmax > qmax) {
120 double scale = ((double)qmax) / cmax;
121 for(i=0; i<order; i++) {
128 for(i=0; i<order; i++) {
129 error -= lpc_in[i] * (1 << sh);
130 lpc_out[i] = av_clip(
lrintf(error), -qmax, qmax);
141 for(i=max_order-1; i>=min_order-1; i--) {
157 const int32_t *
samples,
int blocksize,
int min_order,
158 int max_order,
int precision,
161 int omethod,
int max_shift,
int zero_shift)
163 double autoc[MAX_LPC_ORDER+1];
169 assert(max_order >=
MIN_LPC_ORDER && max_order <= MAX_LPC_ORDER &&
188 for(i=0; i<max_order; i++)
189 ref[i] = fabs(lpc[i][i]);
192 double var[MAX_LPC_ORDER+1],
av_uninit(weight);
194 for(pass=0; pass<lpc_passes; pass++){
198 for(i=max_order; i<blocksize; i++){
199 for(j=0; j<=max_order; j++)
200 var[j]= samples[i-j];
203 double eval, inv, rinv;
205 eval= (512>>
pass) + fabs(eval - var[0]);
208 for(j=0; j<=max_order; j++)
219 for(i=0; i<max_order; i++){
220 for(j=0; j<max_order; j++)
221 lpc[i][j]=-m[(pass-1)&1].
coeff[i][j];
222 ref[i]= sqrt(m[(pass-1)&1].variance[i] / weight) * (blocksize - max_order) / 4000;
224 for(i=max_order-1; i>0; i--)
225 ref[i] = ref[i-1] - ref[i];
227 opt_order = max_order;
232 quantize_lpc_coefs(lpc[i], i+1, precision, coefs[i], &shift[i], max_shift, zero_shift);
234 for(i=min_order-1; i<max_order; i++) {
235 quantize_lpc_coefs(lpc[i], i+1, precision, coefs[i], &shift[i], max_shift, zero_shift);
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
Linear least squares model.
int ff_lpc_calc_coefs(LPCContext *s, const int32_t *samples, int blocksize, int min_order, int max_order, int precision, int32_t coefs[][MAX_LPC_ORDER], int *shift, enum FFLPCType lpc_type, int lpc_passes, int omethod, int max_shift, int zero_shift)
Calculate LPC coefficients for multiple orders.
static void lpc_compute_autocorr_c(const double *data, int len, int lag, double *autoc)
Calculate autocorrelation data from audio samples A Welch window function is applied before calculati...
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
double coeff[MAX_VARS][MAX_VARS]
void av_solve_lls(LLSModel *m, double threshold, int min_order)
static int estimate_best_order(double *ref, int min_order, int max_order)
av_cold void ff_lpc_end(LPCContext *s)
Uninitialize LPCContext.
static void lpc_apply_welch_window_c(const int32_t *data, int len, double *w_data)
Apply Welch window function to audio block.
static av_always_inline av_const long int lrintf(float x)
static void quantize_lpc_coefs(double *lpc_in, int order, int precision, int32_t *lpc_out, int *shift, int max_shift, int zero_shift)
Quantize LPC coefficients.
static int compute_lpc_coefs(const LPC_TYPE *autoc, int max_order, LPC_TYPE *lpc, int lpc_stride, int fail, int normalize)
Levinson-Durbin recursion.
Levinson-Durbin recursion.
#define ORDER_METHOD_EST
LPC utility code Copyright (c) 2006 Justin Ruggles justin.ruggles@gmail.com
void av_init_lls(LLSModel *m, int indep_count)
double * windowed_samples
av_cold int ff_lpc_init(LPCContext *s, int blocksize, int max_order, enum FFLPCType lpc_type)
Initialize LPCContext.
static const uint16_t scale[4]
double av_evaluate_lls(LLSModel *m, double *param, int order)
FFLPCType
LPC analysis type.
void av_update_lls(LLSModel *m, double *var, double decay)
void(* lpc_compute_autocorr)(const double *data, int len, int lag, double *autoc)
Perform autocorrelation on input samples with delay of 0 to lag.
void(* lpc_apply_welch_window)(const int32_t *data, int len, double *w_data)
Apply a Welch window to an array of input samples.
void ff_lpc_init_x86(LPCContext *s)