00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
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_buffer;
00055 double *windowed_samples;
00056
00065 void (*lpc_apply_welch_window)(const int32_t *data, int len,
00066 double *w_data);
00080 void (*lpc_compute_autocorr)(const double *data, int len, int lag,
00081 double *autoc);
00082 } LPCContext;
00083
00084
00088 int ff_lpc_calc_coefs(LPCContext *s,
00089 const int32_t *samples, int blocksize, int min_order,
00090 int max_order, int precision,
00091 int32_t coefs[][MAX_LPC_ORDER], int *shift,
00092 enum FFLPCType lpc_type, int lpc_passes,
00093 int omethod, int max_shift, int zero_shift);
00094
00098 int ff_lpc_init(LPCContext *s, int blocksize, int max_order,
00099 enum FFLPCType lpc_type);
00100 void ff_lpc_init_x86(LPCContext *s);
00101
00105 void ff_lpc_end(LPCContext *s);
00106
00107 #ifdef LPC_USE_DOUBLE
00108 #define LPC_TYPE double
00109 #else
00110 #define LPC_TYPE float
00111 #endif
00112
00117 static inline int compute_lpc_coefs(const LPC_TYPE *autoc, int max_order,
00118 LPC_TYPE *lpc, int lpc_stride, int fail,
00119 int normalize)
00120 {
00121 int i, j;
00122 LPC_TYPE err;
00123 LPC_TYPE *lpc_last = lpc;
00124
00125 if (normalize)
00126 err = *autoc++;
00127
00128 if (fail && (autoc[max_order - 1] == 0 || err <= 0))
00129 return -1;
00130
00131 for(i=0; i<max_order; i++) {
00132 LPC_TYPE r = -autoc[i];
00133
00134 if (normalize) {
00135 for(j=0; j<i; j++)
00136 r -= lpc_last[j] * autoc[i-j-1];
00137
00138 r /= err;
00139 err *= 1.0 - (r * r);
00140 }
00141
00142 lpc[i] = r;
00143
00144 for(j=0; j < (i+1)>>1; j++) {
00145 LPC_TYPE f = lpc_last[ j];
00146 LPC_TYPE b = lpc_last[i-1-j];
00147 lpc[ j] = f + r * b;
00148 lpc[i-1-j] = b + r * f;
00149 }
00150
00151 if (fail && err < 0)
00152 return -1;
00153
00154 lpc_last = lpc;
00155 lpc += lpc_stride;
00156 }
00157
00158 return 0;
00159 }
00160
00161 #endif