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

libavcodec/acelp_filters.c

Go to the documentation of this file.
00001 /*
00002  * various filters 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 #include "acelp_filters.h"
00027 
00028 const int16_t ff_acelp_interp_filter[61] =
00029 { /* (0.15) */
00030   29443, 28346, 25207, 20449, 14701,  8693,
00031    3143, -1352, -4402, -5865, -5850, -4673,
00032   -2783,  -672,  1211,  2536,  3130,  2991,
00033    2259,  1170,     0, -1001, -1652, -1868,
00034   -1666, -1147,  -464,   218,   756,  1060,
00035    1099,   904,   550,   135,  -245,  -514,
00036    -634,  -602,  -451,  -231,     0,   191,
00037     308,   340,   296,   198,    78,   -36,
00038    -120,  -163,  -165,  -132,   -79,   -19,
00039      34,    73,    91,    89,    70,    38,
00040       0,
00041 };
00042 
00043 void ff_acelp_interpolate(
00044         int16_t* out,
00045         const int16_t* in,
00046         const int16_t* filter_coeffs,
00047         int precision,
00048         int frac_pos,
00049         int filter_length,
00050         int length)
00051 {
00052     int n, i;
00053 
00054     assert(pitch_delay_frac >= 0 && pitch_delay_frac < precision);
00055 
00056     for(n=0; n<length; n++)
00057     {
00058         int idx = 0;
00059         int v = 0x4000;
00060 
00061         for(i=0; i<filter_length;)
00062         {
00063 
00064             /* The reference G.729 and AMR fixed point code performs clipping after
00065                each of the two following accumulations.
00066                Since clipping affects only the synthetic OVERFLOW test without
00067                causing an int type overflow, it was moved outside the loop. */
00068 
00069             /*  R(x):=ac_v[-k+x]
00070                 v += R(n-i)*ff_acelp_interp_filter(t+6i)
00071                 v += R(n+i+1)*ff_acelp_interp_filter(6-t+6i) */
00072 
00073             v += in[n + i] * filter_coeffs[idx + frac_pos];
00074             idx += precision;
00075             i++;
00076             v += in[n - i] * filter_coeffs[idx - frac_pos];
00077         }
00078         if(av_clip_int16(v>>15) != (v>>15))
00079             av_log(NULL, AV_LOG_WARNING, "overflow that would need cliping in ff_acelp_interpolate()\n");
00080         out[n] = v >> 15;
00081     }
00082 }
00083 
00084 
00085 void ff_acelp_high_pass_filter(
00086         int16_t* out,
00087         int hpf_f[2],
00088         const int16_t* in,
00089         int length)
00090 {
00091     int i;
00092     int tmp;
00093 
00094     for(i=0; i<length; i++)
00095     {
00096         tmp =  (hpf_f[0]* 15836LL)>>13;
00097         tmp += (hpf_f[1]* -7667LL)>>13;
00098         tmp += 7699 * (in[i] - 2*in[i-1] + in[i-2]);
00099 
00100         /* With "+0x800" rounding, clipping is needed
00101            for ALGTHM and SPEECH tests. */
00102         out[i] = av_clip_int16((tmp + 0x800) >> 12);
00103 
00104         hpf_f[1] = hpf_f[0];
00105         hpf_f[0] = tmp;
00106     }
00107 }

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