• Main Page
  • Related Pages
  • Modules
  • Data Structures
  • Files
  • File List
  • Globals

libavcodec/lsp.c

Go to the documentation of this file.
00001 /*
00002  * LSP routines for ACELP-based codecs
00003  *
00004  * Copyright (c) 2008 Vladimir Voroshilov
00005  *
00006  * This file is part of FFmpeg.
00007  *
00008  * FFmpeg is free software; you can redistribute it and/or
00009  * modify it under the terms of the GNU Lesser General Public
00010  * License as published by the Free Software Foundation; either
00011  * version 2.1 of the License, or (at your option) any later version.
00012  *
00013  * FFmpeg is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016  * Lesser General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU Lesser General Public
00019  * License along with FFmpeg; if not, write to the Free Software
00020  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
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     /* sort lsfq in ascending order. float bubble agorithm,
00036        O(n) if data already sorted, O(n^2) - otherwise */
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);//Is warning required ?
00047 }
00048 
00049 void ff_acelp_lsf2lsp(int16_t *lsp, const int16_t *lsf, int lp_order)
00050 {
00051     int i;
00052 
00053     /* Convert LSF to LSP, lsp=cos(lsf) */
00054     for(i=0; i<lp_order; i++)
00055         // 20861 = 2.0 / PI in (0.15)
00056         lsp[i] = ff_cos(lsf[i] * 20861 >> 15); // divide by PI and (0,13) -> (0,14)
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;          // 1.0 in (3.22)
00069     f[1] = -lsp[0] << 8;      // *2 and (0.15) -> (3.22)
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]; // (3.22)
00085     int f2[lp_half_order+1]; // (3.22)
00086 
00087     lsp2poly(f1, lsp  , lp_half_order);
00088     lsp2poly(f2, lsp+1, lp_half_order);
00089 
00090     /* 3.2.6 of G.729, Equations 25 and  26*/
00091     lp[0] = 4096;
00092     for(i=1; i<lp_half_order+1; i++)
00093     {
00094         int ff1 = f1[i] + f1[i-1]; // (3.22)
00095         int ff2 = f2[i] - f2[i-1]; // (3.22)
00096 
00097         ff1 += 1 << 10; // for rounding
00098         lp[i]    = (ff1 + ff2) >> 11; // divide by 2 and (3.22) -> (3.12)
00099         lp[(lp_half_order << 1) + 1 - i] = (ff1 - ff2) >> 11; // divide by 2 and (3.22) -> (3.12)
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]; // (0.15)
00106     int i;
00107 
00108     /* LSP values for first subframe (3.2.5 of G.729, Equation 24)*/
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     /* LSP values for second subframe (3.2.5 of G.729)*/
00119     ff_acelp_lsp2lpc(lp_2nd, lsp_2nd, lp_order >> 1);
00120 }

Generated on Sat Feb 16 2013 09:23:12 for ffmpeg by  doxygen 1.7.1