00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include <inttypes.h>
00024
00025 #include "avcodec.h"
00026 #define FRAC_BITS 14
00027 #include "mathops.h"
00028 #include "lsp.h"
00029 #include "celp_math.h"
00030
00031 void ff_acelp_reorder_lsf(int16_t* lsfq, int lsfq_min_distance, int lsfq_min, int lsfq_max, int lp_order)
00032 {
00033 int i, j;
00034
00035
00036
00037 for(i=0; i<lp_order-1; i++)
00038 for(j=i; j>=0 && lsfq[j] > lsfq[j+1]; j--)
00039 FFSWAP(int16_t, lsfq[j], lsfq[j+1]);
00040
00041 for(i=0; i<lp_order; i++)
00042 {
00043 lsfq[i] = FFMAX(lsfq[i], lsfq_min);
00044 lsfq_min = lsfq[i] + lsfq_min_distance;
00045 }
00046 lsfq[lp_order-1] = FFMIN(lsfq[lp_order-1], lsfq_max);
00047 }
00048
00049 void ff_acelp_lsf2lsp(int16_t *lsp, const int16_t *lsf, int lp_order)
00050 {
00051 int i;
00052
00053
00054 for(i=0; i<lp_order; i++)
00055
00056 lsp[i] = ff_cos(lsf[i] * 20861 >> 15);
00057 }
00058
00064 static void lsp2poly(int* f, const int16_t* lsp, int lp_half_order)
00065 {
00066 int i, j;
00067
00068 f[0] = 0x400000;
00069 f[1] = -lsp[0] << 8;
00070
00071 for(i=2; i<=lp_half_order; i++)
00072 {
00073 f[i] = f[i-2];
00074 for(j=i; j>1; j--)
00075 f[j] -= MULL(f[j-1], lsp[2*i-2], FRAC_BITS) - f[j-2];
00076
00077 f[1] -= lsp[2*i-2] << 8;
00078 }
00079 }
00080
00081 void ff_acelp_lsp2lpc(int16_t* lp, const int16_t* lsp, int lp_half_order)
00082 {
00083 int i;
00084 int f1[lp_half_order+1];
00085 int f2[lp_half_order+1];
00086
00087 lsp2poly(f1, lsp , lp_half_order);
00088 lsp2poly(f2, lsp+1, lp_half_order);
00089
00090
00091 lp[0] = 4096;
00092 for(i=1; i<lp_half_order+1; i++)
00093 {
00094 int ff1 = f1[i] + f1[i-1];
00095 int ff2 = f2[i] - f2[i-1];
00096
00097 ff1 += 1 << 10;
00098 lp[i] = (ff1 + ff2) >> 11;
00099 lp[(lp_half_order << 1) + 1 - i] = (ff1 - ff2) >> 11;
00100 }
00101 }
00102
00103 void ff_acelp_lp_decode(int16_t* lp_1st, int16_t* lp_2nd, const int16_t* lsp_2nd, const int16_t* lsp_prev, int lp_order)
00104 {
00105 int16_t lsp_1st[lp_order];
00106 int i;
00107
00108
00109 for(i=0; i<lp_order; i++)
00110 #ifdef G729_BITEXACT
00111 lsp_1st[i] = (lsp_2nd[i] >> 1) + (lsp_prev[i] >> 1);
00112 #else
00113 lsp_1st[i] = (lsp_2nd[i] + lsp_prev[i]) >> 1;
00114 #endif
00115
00116 ff_acelp_lsp2lpc(lp_1st, lsp_1st, lp_order >> 1);
00117
00118
00119 ff_acelp_lsp2lpc(lp_2nd, lsp_2nd, lp_order >> 1);
00120 }