00001
00022 #ifndef AVCODEC_LPC_H
00023 #define AVCODEC_LPC_H
00024
00025 #include <stdint.h>
00026 #include "dsputil.h"
00027
00028 #define ORDER_METHOD_EST 0
00029 #define ORDER_METHOD_2LEVEL 1
00030 #define ORDER_METHOD_4LEVEL 2
00031 #define ORDER_METHOD_8LEVEL 3
00032 #define ORDER_METHOD_SEARCH 4
00033 #define ORDER_METHOD_LOG 5
00034
00035 #define MIN_LPC_ORDER 1
00036 #define MAX_LPC_ORDER 32
00037
00041 enum FFLPCType {
00042 FF_LPC_TYPE_DEFAULT = -1,
00043 FF_LPC_TYPE_NONE = 0,
00044 FF_LPC_TYPE_FIXED = 1,
00045 FF_LPC_TYPE_LEVINSON = 2,
00046 FF_LPC_TYPE_CHOLESKY = 3,
00047 FF_LPC_TYPE_NB ,
00048 };
00049
00050 typedef struct LPCContext {
00051 int blocksize;
00052 int max_order;
00053 enum FFLPCType lpc_type;
00054 double *windowed_samples;
00055
00064 void (*lpc_apply_welch_window)(const int32_t *data, int len,
00065 double *w_data);
00079 void (*lpc_compute_autocorr)(const double *data, int len, int lag,
00080 double *autoc);
00081 } LPCContext;
00082
00083
00087 int ff_lpc_calc_coefs(LPCContext *s,
00088 const int32_t *samples, int blocksize, int min_order,
00089 int max_order, int precision,
00090 int32_t coefs[][MAX_LPC_ORDER], int *shift,
00091 enum FFLPCType lpc_type, int lpc_passes,
00092 int omethod, int max_shift, int zero_shift);
00093
00097 int ff_lpc_init(LPCContext *s, int blocksize, int max_order,
00098 enum FFLPCType lpc_type);
00099 void ff_lpc_init_x86(LPCContext *s);
00100
00104 void ff_lpc_end(LPCContext *s);
00105
00106 #ifdef LPC_USE_DOUBLE
00107 #define LPC_TYPE double
00108 #else
00109 #define LPC_TYPE float
00110 #endif
00111
00116 static inline int compute_lpc_coefs(const LPC_TYPE *autoc, int max_order,
00117 LPC_TYPE *lpc, int lpc_stride, int fail,
00118 int normalize)
00119 {
00120 int i, j;
00121 LPC_TYPE err;
00122 LPC_TYPE *lpc_last = lpc;
00123
00124 if (normalize)
00125 err = *autoc++;
00126
00127 if (fail && (autoc[max_order - 1] == 0 || err <= 0))
00128 return -1;
00129
00130 for(i=0; i<max_order; i++) {
00131 LPC_TYPE r = -autoc[i];
00132
00133 if (normalize) {
00134 for(j=0; j<i; j++)
00135 r -= lpc_last[j] * autoc[i-j-1];
00136
00137 r /= err;
00138 err *= 1.0 - (r * r);
00139 }
00140
00141 lpc[i] = r;
00142
00143 for(j=0; j < (i+1)>>1; j++) {
00144 LPC_TYPE f = lpc_last[ j];
00145 LPC_TYPE b = lpc_last[i-1-j];
00146 lpc[ j] = f + r * b;
00147 lpc[i-1-j] = b + r * f;
00148 }
00149
00150 if (fail && err < 0)
00151 return -1;
00152
00153 lpc_last = lpc;
00154 lpc += lpc_stride;
00155 }
00156
00157 return 0;
00158 }
00159
00160 #endif