26 #define LPC_USE_DOUBLE
42 c = 2.0 / (
len - 1.0);
73 for(j=0; j<lag; j+=2){
74 double sum0 = 1.0, sum1 = 1.0;
98 int max_shift,
int zero_shift)
106 qmax = (1 << (precision - 1)) - 1;
110 for(
i=0;
i<order;
i++) {
115 if(cmax * (1 << max_shift) < 1.0) {
117 memset(lpc_out, 0,
sizeof(
int32_t) * order);
123 while((cmax * (1 << sh) > qmax) && (sh > min_shift)) {
129 if(sh == 0 && cmax > qmax) {
130 double scale = ((double)qmax) / cmax;
131 for(
i=0;
i<order;
i++) {
138 for(
i=0;
i<order;
i++) {
139 error -= lpc_in[
i] * (1 << sh);
151 for(
i=max_order-1;
i>=min_order-1;
i--) {
161 const int32_t *samples,
int order,
double *
ref)
165 s->lpc_apply_welch_window(samples,
s->blocksize,
s->windowed_samples);
166 s->lpc_compute_autocorr(
s->windowed_samples,
s->blocksize, order, autoc);
173 int order,
double *
ref)
176 double signal = 0.0f, avg_err = 0.0f;
178 const double a = 0.5f,
b = 1.0f -
a;
181 for (
i = 0;
i <=
len / 2;
i++) {
183 s->windowed_samples[
i] =
weight*samples[
i];
187 s->lpc_compute_autocorr(
s->windowed_samples,
len, order, autoc);
190 for (
i = 0;
i < order;
i++)
191 avg_err = (avg_err +
error[
i])/2.0f;
192 return signal/avg_err;
202 const int32_t *samples,
int blocksize,
int min_order,
203 int max_order,
int precision,
206 int omethod,
int min_shift,
int max_shift,
int zero_shift)
219 if (blocksize !=
s->blocksize || max_order !=
s->max_order ||
220 lpc_type !=
s->lpc_type) {
229 s->lpc_apply_welch_window(samples, blocksize,
s->windowed_samples);
231 s->lpc_compute_autocorr(
s->windowed_samples, blocksize, max_order, autoc);
235 for(
i=0;
i<max_order;
i++)
247 for(j=0; j<max_order; j++)
248 m[0].
coeff[max_order-1][j] = -lpc[max_order-1][j];
254 for(
i=max_order;
i<blocksize;
i++){
255 for(j=0; j<=max_order; j++)
256 var[j]= samples[
i-j];
259 double eval, inv, rinv;
261 eval= (512>>
pass) +
fabs(eval - var[0]);
264 for(j=0; j<=max_order; j++)
275 for(
i=0;
i<max_order;
i++){
276 for(j=0; j<max_order; j++)
278 ref[
i]= sqrt(m[(
pass-1)&1].variance[
i] /
weight) * (blocksize - max_order) / 4000;
280 for(
i=max_order-1;
i>0;
i--)
284 opt_order = max_order;
290 min_shift, max_shift, zero_shift);
292 for(
i=min_order-1;
i<max_order;
i++) {
294 min_shift, max_shift, zero_shift);
304 s->blocksize = blocksize;
305 s->max_order = max_order;
306 s->lpc_type = lpc_type;
309 sizeof(*
s->windowed_samples));
310 if (!
s->windowed_buffer)
312 s->windowed_samples =
s->windowed_buffer +
FFALIGN(max_order, 4);
simple assert() macros that are a bit more flexible than ISO C assert().
#define av_assert2(cond)
assert() equivalent, that does lie in speed critical code.
#define av_assert0(cond)
assert() equivalent, that is always enabled.
common internal and external API header
static __device__ float fabs(float a)
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
static int weight(int i, int blen, int offset)
av_cold void avpriv_init_lls(LLSModel *m, int indep_count)
void avpriv_solve_lls(LLSModel *m, double threshold, unsigned short min_order)
static int estimate_best_order(double *ref, int min_order, int max_order)
static void quantize_lpc_coefs(double *lpc_in, int order, int precision, int32_t *lpc_out, int *shift, int min_shift, int max_shift, int zero_shift)
Quantize LPC coefficients.
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.
double ff_lpc_calc_ref_coefs_f(LPCContext *s, const float *samples, int len, int order, double *ref)
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 min_shift, 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...
int ff_lpc_calc_ref_coefs(LPCContext *s, const int32_t *samples, int order, double *ref)
av_cold int ff_lpc_init(LPCContext *s, int blocksize, int max_order, enum FFLPCType lpc_type)
Initialize LPCContext.
FFLPCType
LPC analysis type.
@ FF_LPC_TYPE_CHOLESKY
Cholesky factorization.
@ FF_LPC_TYPE_FIXED
fixed LPC coefficients
@ FF_LPC_TYPE_LEVINSON
Levinson-Durbin recursion.
static int AAC_RENAME() compute_lpc_coefs(const LPC_TYPE *autoc, int max_order, LPC_TYPE *lpc, int lpc_stride, int fail, int normalize)
Levinson-Durbin recursion.
static void compute_ref_coefs(const LPC_TYPE *autoc, int max_order, LPC_TYPE *ref, LPC_TYPE *error)
Schur recursion.
#define LOCAL_ALIGNED(a, t, v,...)
static int shift(int a, int b)
Linear least squares model.
void(* update_lls)(struct LLSModel *m, const double *var)
Take the outer-product of var[] with itself, and add to the covariance matrix.
double(* evaluate_lls)(struct LLSModel *m, const double *var, int order)
Inner product of var[] and the LPC coefs.
static void error(const char *err)
static int ref[MAX_W *MAX_W]
static const double coeff[2][5]
av_cold void ff_lpc_init_x86(LPCContext *c)