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

libavcodec/celp_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 "celp_filters.h"
00027 
00028 void ff_celp_convolve_circ(
00029         int16_t* fc_out,
00030         const int16_t* fc_in,
00031         const int16_t* filter,
00032         int len)
00033 {
00034     int i, k;
00035 
00036     memset(fc_out, 0, len * sizeof(int16_t));
00037 
00038     /* Since there are few pulses over an entire subframe (i.e. almost
00039        all fc_in[i] are zero) it is faster to loop over fc_in first. */
00040     for(i=0; i<len; i++)
00041     {
00042         if(fc_in[i])
00043         {
00044             for(k=0; k<i; k++)
00045                 fc_out[k] += (fc_in[i] * filter[len + k - i]) >> 15;
00046 
00047             for(k=i; k<len; k++)
00048                 fc_out[k] += (fc_in[i] * filter[      k - i]) >> 15;
00049         }
00050     }
00051 }
00052 
00053 int ff_celp_lp_synthesis_filter(
00054         int16_t *out,
00055         const int16_t* filter_coeffs,
00056         const int16_t* in,
00057         int buffer_length,
00058         int filter_length,
00059         int stop_on_overflow,
00060         int rounder)
00061 {
00062     int i,n;
00063 
00064     // These two lines are to avoid a -1 subtraction in the main loop
00065     filter_length++;
00066     filter_coeffs--;
00067 
00068     for(n=0; n<buffer_length; n++)
00069     {
00070         int sum = rounder;
00071         for(i=1; i<filter_length; i++)
00072             sum -= filter_coeffs[i] * out[n-i];
00073 
00074         sum = (sum >> 12) + in[n];
00075 
00076         if(sum + 0x8000 > 0xFFFFU)
00077         {
00078             if(stop_on_overflow)
00079                 return 1;
00080             sum = (sum >> 31) ^ 32767;
00081         }
00082         out[n] = sum;
00083     }
00084 
00085     return 0;
00086 }
00087 
00088 void ff_celp_lp_synthesis_filterf(
00089         float *out,
00090         const float* filter_coeffs,
00091         const float* in,
00092         int buffer_length,
00093         int filter_length)
00094 {
00095     int i,n;
00096 
00097     // These two lines are to avoid a -1 subtraction in the main loop
00098     filter_length++;
00099     filter_coeffs--;
00100 
00101     for(n=0; n<buffer_length; n++)
00102     {
00103         out[n] = in[n];
00104         for(i=1; i<filter_length; i++)
00105             out[n] -= filter_coeffs[i] * out[n-i];
00106     }
00107 }

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