Libav
|
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 00038 00042 int ff_lpc_calc_coefs(DSPContext *s, 00043 const int32_t *samples, int blocksize, int min_order, 00044 int max_order, int precision, 00045 int32_t coefs[][MAX_LPC_ORDER], int *shift, int use_lpc, 00046 int omethod, int max_shift, int zero_shift); 00047 00048 void ff_lpc_compute_autocorr(const int32_t *data, int len, int lag, 00049 double *autoc); 00050 00051 #ifdef LPC_USE_DOUBLE 00052 #define LPC_TYPE double 00053 #else 00054 #define LPC_TYPE float 00055 #endif 00056 00061 static inline int compute_lpc_coefs(const LPC_TYPE *autoc, int max_order, 00062 LPC_TYPE *lpc, int lpc_stride, int fail, 00063 int normalize) 00064 { 00065 int i, j; 00066 LPC_TYPE err; 00067 LPC_TYPE *lpc_last = lpc; 00068 00069 if (normalize) 00070 err = *autoc++; 00071 00072 if (fail && (autoc[max_order - 1] == 0 || err <= 0)) 00073 return -1; 00074 00075 for(i=0; i<max_order; i++) { 00076 LPC_TYPE r = -autoc[i]; 00077 00078 if (normalize) { 00079 for(j=0; j<i; j++) 00080 r -= lpc_last[j] * autoc[i-j-1]; 00081 00082 r /= err; 00083 err *= 1.0 - (r * r); 00084 } 00085 00086 lpc[i] = r; 00087 00088 for(j=0; j < (i+1)>>1; j++) { 00089 LPC_TYPE f = lpc_last[ j]; 00090 LPC_TYPE b = lpc_last[i-1-j]; 00091 lpc[ j] = f + r * b; 00092 lpc[i-1-j] = b + r * f; 00093 } 00094 00095 if (fail && err < 0) 00096 return -1; 00097 00098 lpc_last = lpc; 00099 lpc += lpc_stride; 00100 } 00101 00102 return 0; 00103 } 00104 00105 #endif /* AVCODEC_LPC_H */