2 * various filters for ACELP-based codecs
4 * Copyright (c) 2008 Vladimir Voroshilov
6 * This file is part of FFmpeg.
8 * FFmpeg is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * FFmpeg is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with FFmpeg; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
26 #include "celp_filters.h"
28 void ff_celp_convolve_circ(int16_t* fc_out,
30 const int16_t* filter,
35 memset(fc_out, 0, len * sizeof(int16_t));
37 /* Since there are few pulses over an entire subframe (i.e. almost
38 all fc_in[i] are zero) it is faster to loop over fc_in first. */
39 for (i = 0; i < len; i++) {
41 for (k = 0; k < i; k++)
42 fc_out[k] += (fc_in[i] * filter[len + k - i]) >> 15;
44 for (k = i; k < len; k++)
45 fc_out[k] += (fc_in[i] * filter[ k - i]) >> 15;
50 void ff_celp_circ_addf(float *out, const float *in,
51 const float *lagged, int lag, float fac, int n)
54 for (k = 0; k < lag; k++)
55 out[k] = in[k] + fac * lagged[n + k - lag];
57 out[k] = in[k] + fac * lagged[ k - lag];
60 int ff_celp_lp_synthesis_filter(int16_t *out,
61 const int16_t* filter_coeffs,
70 for (n = 0; n < buffer_length; n++) {
72 for (i = 1; i <= filter_length; i++)
73 sum -= filter_coeffs[i-1] * out[n-i];
75 sum = (sum >> 12) + in[n];
77 if (sum + 0x8000 > 0xFFFFU) {
80 sum = (sum >> 31) ^ 32767;
88 void ff_celp_lp_synthesis_filterf(float *out,
89 const float* filter_coeffs,
96 for (n = 0; n < buffer_length; n++) {
98 for (i = 1; i <= filter_length; i++)
99 out[n] -= filter_coeffs[i-1] * out[n-i];
103 void ff_celp_lp_zero_synthesis_filterf(float *out,
104 const float* filter_coeffs,
111 for (n = 0; n < buffer_length; n++) {
113 for (i = 1; i <= filter_length; i++)
114 out[n] += filter_coeffs[i-1] * in[n-i];