ac3dec: simplify zero-bit mantissa dithering by calculating it
[ffmpeg-lucabe.git] / libavcodec / celp_filters.c
blobcd475533a55e47fe0016b8ed3f8312a6ccc89454
1 /*
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
23 #include <inttypes.h>
25 #include "avcodec.h"
26 #include "celp_filters.h"
28 void ff_celp_convolve_circ(int16_t* fc_out,
29 const int16_t* fc_in,
30 const int16_t* filter,
31 int len)
33 int i, k;
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++) {
40 if (fc_in[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 int ff_celp_lp_synthesis_filter(int16_t *out,
51 const int16_t* filter_coeffs,
52 const int16_t* in,
53 int buffer_length,
54 int filter_length,
55 int stop_on_overflow,
56 int rounder)
58 int i,n;
60 // Avoids a +1 in the inner loop.
61 filter_length++;
63 for (n = 0; n < buffer_length; n++) {
64 int sum = rounder;
65 for (i = 1; i < filter_length; i++)
66 sum -= filter_coeffs[i-1] * out[n-i];
68 sum = (sum >> 12) + in[n];
70 if (sum + 0x8000 > 0xFFFFU) {
71 if (stop_on_overflow)
72 return 1;
73 sum = (sum >> 31) ^ 32767;
75 out[n] = sum;
78 return 0;
81 void ff_celp_lp_synthesis_filterf(float *out,
82 const float* filter_coeffs,
83 const float* in,
84 int buffer_length,
85 int filter_length)
87 int i,n;
89 // Avoids a +1 in the inner loop.
90 filter_length++;
92 for (n = 0; n < buffer_length; n++) {
93 out[n] = in[n];
94 for (i = 1; i < filter_length; i++)
95 out[n] -= filter_coeffs[i-1] * out[n-i];
99 void ff_celp_lp_zero_synthesis_filterf(float *out,
100 const float* filter_coeffs,
101 const float* in,
102 int buffer_length,
103 int filter_length)
105 int i,n;
107 // Avoids a +1 in the inner loop.
108 filter_length++;
110 for (n = 0; n < buffer_length; n++) {
111 out[n] = in[n];
112 for (i = 1; i < filter_length; i++)
113 out[n] += filter_coeffs[i-1] * in[n-i];