annotate celp_filters.c @ 10013:454cb6aa43a3 libavcodec

Correct the sign of the arithmetic in ff_celp_lp_zero_synthesis_filterf() Patch by Colin McQuillan ( m.niloc googlemail com )
author superdump
date Mon, 03 Aug 2009 17:15:01 +0000
parents 24952f1a8979
children d35904b4fe3f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8049
611a21e4b01b Split off celp_filters.[ch] from acelp_filters.[ch] for the QCELP decoder.
diego
parents:
diff changeset
1 /*
611a21e4b01b Split off celp_filters.[ch] from acelp_filters.[ch] for the QCELP decoder.
diego
parents:
diff changeset
2 * various filters for ACELP-based codecs
611a21e4b01b Split off celp_filters.[ch] from acelp_filters.[ch] for the QCELP decoder.
diego
parents:
diff changeset
3 *
611a21e4b01b Split off celp_filters.[ch] from acelp_filters.[ch] for the QCELP decoder.
diego
parents:
diff changeset
4 * Copyright (c) 2008 Vladimir Voroshilov
611a21e4b01b Split off celp_filters.[ch] from acelp_filters.[ch] for the QCELP decoder.
diego
parents:
diff changeset
5 *
611a21e4b01b Split off celp_filters.[ch] from acelp_filters.[ch] for the QCELP decoder.
diego
parents:
diff changeset
6 * This file is part of FFmpeg.
611a21e4b01b Split off celp_filters.[ch] from acelp_filters.[ch] for the QCELP decoder.
diego
parents:
diff changeset
7 *
611a21e4b01b Split off celp_filters.[ch] from acelp_filters.[ch] for the QCELP decoder.
diego
parents:
diff changeset
8 * FFmpeg is free software; you can redistribute it and/or
611a21e4b01b Split off celp_filters.[ch] from acelp_filters.[ch] for the QCELP decoder.
diego
parents:
diff changeset
9 * modify it under the terms of the GNU Lesser General Public
611a21e4b01b Split off celp_filters.[ch] from acelp_filters.[ch] for the QCELP decoder.
diego
parents:
diff changeset
10 * License as published by the Free Software Foundation; either
611a21e4b01b Split off celp_filters.[ch] from acelp_filters.[ch] for the QCELP decoder.
diego
parents:
diff changeset
11 * version 2.1 of the License, or (at your option) any later version.
611a21e4b01b Split off celp_filters.[ch] from acelp_filters.[ch] for the QCELP decoder.
diego
parents:
diff changeset
12 *
611a21e4b01b Split off celp_filters.[ch] from acelp_filters.[ch] for the QCELP decoder.
diego
parents:
diff changeset
13 * FFmpeg is distributed in the hope that it will be useful,
611a21e4b01b Split off celp_filters.[ch] from acelp_filters.[ch] for the QCELP decoder.
diego
parents:
diff changeset
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
611a21e4b01b Split off celp_filters.[ch] from acelp_filters.[ch] for the QCELP decoder.
diego
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
611a21e4b01b Split off celp_filters.[ch] from acelp_filters.[ch] for the QCELP decoder.
diego
parents:
diff changeset
16 * Lesser General Public License for more details.
611a21e4b01b Split off celp_filters.[ch] from acelp_filters.[ch] for the QCELP decoder.
diego
parents:
diff changeset
17 *
611a21e4b01b Split off celp_filters.[ch] from acelp_filters.[ch] for the QCELP decoder.
diego
parents:
diff changeset
18 * You should have received a copy of the GNU Lesser General Public
611a21e4b01b Split off celp_filters.[ch] from acelp_filters.[ch] for the QCELP decoder.
diego
parents:
diff changeset
19 * License along with FFmpeg; if not, write to the Free Software
611a21e4b01b Split off celp_filters.[ch] from acelp_filters.[ch] for the QCELP decoder.
diego
parents:
diff changeset
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
611a21e4b01b Split off celp_filters.[ch] from acelp_filters.[ch] for the QCELP decoder.
diego
parents:
diff changeset
21 */
611a21e4b01b Split off celp_filters.[ch] from acelp_filters.[ch] for the QCELP decoder.
diego
parents:
diff changeset
22
611a21e4b01b Split off celp_filters.[ch] from acelp_filters.[ch] for the QCELP decoder.
diego
parents:
diff changeset
23 #include <inttypes.h>
611a21e4b01b Split off celp_filters.[ch] from acelp_filters.[ch] for the QCELP decoder.
diego
parents:
diff changeset
24
611a21e4b01b Split off celp_filters.[ch] from acelp_filters.[ch] for the QCELP decoder.
diego
parents:
diff changeset
25 #include "avcodec.h"
611a21e4b01b Split off celp_filters.[ch] from acelp_filters.[ch] for the QCELP decoder.
diego
parents:
diff changeset
26 #include "celp_filters.h"
611a21e4b01b Split off celp_filters.[ch] from acelp_filters.[ch] for the QCELP decoder.
diego
parents:
diff changeset
27
10003
24952f1a8979 cosmetics: K&R coding style
diego
parents: 9509
diff changeset
28 void ff_celp_convolve_circ(int16_t* fc_out,
24952f1a8979 cosmetics: K&R coding style
diego
parents: 9509
diff changeset
29 const int16_t* fc_in,
24952f1a8979 cosmetics: K&R coding style
diego
parents: 9509
diff changeset
30 const int16_t* filter,
24952f1a8979 cosmetics: K&R coding style
diego
parents: 9509
diff changeset
31 int len)
8049
611a21e4b01b Split off celp_filters.[ch] from acelp_filters.[ch] for the QCELP decoder.
diego
parents:
diff changeset
32 {
611a21e4b01b Split off celp_filters.[ch] from acelp_filters.[ch] for the QCELP decoder.
diego
parents:
diff changeset
33 int i, k;
611a21e4b01b Split off celp_filters.[ch] from acelp_filters.[ch] for the QCELP decoder.
diego
parents:
diff changeset
34
611a21e4b01b Split off celp_filters.[ch] from acelp_filters.[ch] for the QCELP decoder.
diego
parents:
diff changeset
35 memset(fc_out, 0, len * sizeof(int16_t));
611a21e4b01b Split off celp_filters.[ch] from acelp_filters.[ch] for the QCELP decoder.
diego
parents:
diff changeset
36
611a21e4b01b Split off celp_filters.[ch] from acelp_filters.[ch] for the QCELP decoder.
diego
parents:
diff changeset
37 /* Since there are few pulses over an entire subframe (i.e. almost
611a21e4b01b Split off celp_filters.[ch] from acelp_filters.[ch] for the QCELP decoder.
diego
parents:
diff changeset
38 all fc_in[i] are zero) it is faster to loop over fc_in first. */
10003
24952f1a8979 cosmetics: K&R coding style
diego
parents: 9509
diff changeset
39 for (i = 0; i < len; i++) {
24952f1a8979 cosmetics: K&R coding style
diego
parents: 9509
diff changeset
40 if (fc_in[i]) {
24952f1a8979 cosmetics: K&R coding style
diego
parents: 9509
diff changeset
41 for (k = 0; k < i; k++)
8049
611a21e4b01b Split off celp_filters.[ch] from acelp_filters.[ch] for the QCELP decoder.
diego
parents:
diff changeset
42 fc_out[k] += (fc_in[i] * filter[len + k - i]) >> 15;
611a21e4b01b Split off celp_filters.[ch] from acelp_filters.[ch] for the QCELP decoder.
diego
parents:
diff changeset
43
10003
24952f1a8979 cosmetics: K&R coding style
diego
parents: 9509
diff changeset
44 for (k = i; k < len; k++)
8049
611a21e4b01b Split off celp_filters.[ch] from acelp_filters.[ch] for the QCELP decoder.
diego
parents:
diff changeset
45 fc_out[k] += (fc_in[i] * filter[ k - i]) >> 15;
611a21e4b01b Split off celp_filters.[ch] from acelp_filters.[ch] for the QCELP decoder.
diego
parents:
diff changeset
46 }
611a21e4b01b Split off celp_filters.[ch] from acelp_filters.[ch] for the QCELP decoder.
diego
parents:
diff changeset
47 }
611a21e4b01b Split off celp_filters.[ch] from acelp_filters.[ch] for the QCELP decoder.
diego
parents:
diff changeset
48 }
611a21e4b01b Split off celp_filters.[ch] from acelp_filters.[ch] for the QCELP decoder.
diego
parents:
diff changeset
49
10003
24952f1a8979 cosmetics: K&R coding style
diego
parents: 9509
diff changeset
50 int ff_celp_lp_synthesis_filter(int16_t *out,
24952f1a8979 cosmetics: K&R coding style
diego
parents: 9509
diff changeset
51 const int16_t* filter_coeffs,
24952f1a8979 cosmetics: K&R coding style
diego
parents: 9509
diff changeset
52 const int16_t* in,
24952f1a8979 cosmetics: K&R coding style
diego
parents: 9509
diff changeset
53 int buffer_length,
24952f1a8979 cosmetics: K&R coding style
diego
parents: 9509
diff changeset
54 int filter_length,
24952f1a8979 cosmetics: K&R coding style
diego
parents: 9509
diff changeset
55 int stop_on_overflow,
24952f1a8979 cosmetics: K&R coding style
diego
parents: 9509
diff changeset
56 int rounder)
8049
611a21e4b01b Split off celp_filters.[ch] from acelp_filters.[ch] for the QCELP decoder.
diego
parents:
diff changeset
57 {
611a21e4b01b Split off celp_filters.[ch] from acelp_filters.[ch] for the QCELP decoder.
diego
parents:
diff changeset
58 int i,n;
611a21e4b01b Split off celp_filters.[ch] from acelp_filters.[ch] for the QCELP decoder.
diego
parents:
diff changeset
59
9447
d7554a5e3fd7 [COSMETIC] Correct a minor nit. Should be clearer now.
reynaldo
parents: 9446
diff changeset
60 // Avoids a +1 in the inner loop.
8049
611a21e4b01b Split off celp_filters.[ch] from acelp_filters.[ch] for the QCELP decoder.
diego
parents:
diff changeset
61 filter_length++;
611a21e4b01b Split off celp_filters.[ch] from acelp_filters.[ch] for the QCELP decoder.
diego
parents:
diff changeset
62
10003
24952f1a8979 cosmetics: K&R coding style
diego
parents: 9509
diff changeset
63 for (n = 0; n < buffer_length; n++) {
8049
611a21e4b01b Split off celp_filters.[ch] from acelp_filters.[ch] for the QCELP decoder.
diego
parents:
diff changeset
64 int sum = rounder;
10003
24952f1a8979 cosmetics: K&R coding style
diego
parents: 9509
diff changeset
65 for (i = 1; i < filter_length; i++)
9446
1a3865d1b049 Fix possibly harmful outbound addressing. Patch by Kenan Gillet.
reynaldo
parents: 9017
diff changeset
66 sum -= filter_coeffs[i-1] * out[n-i];
8049
611a21e4b01b Split off celp_filters.[ch] from acelp_filters.[ch] for the QCELP decoder.
diego
parents:
diff changeset
67
611a21e4b01b Split off celp_filters.[ch] from acelp_filters.[ch] for the QCELP decoder.
diego
parents:
diff changeset
68 sum = (sum >> 12) + in[n];
611a21e4b01b Split off celp_filters.[ch] from acelp_filters.[ch] for the QCELP decoder.
diego
parents:
diff changeset
69
10003
24952f1a8979 cosmetics: K&R coding style
diego
parents: 9509
diff changeset
70 if (sum + 0x8000 > 0xFFFFU) {
24952f1a8979 cosmetics: K&R coding style
diego
parents: 9509
diff changeset
71 if (stop_on_overflow)
8049
611a21e4b01b Split off celp_filters.[ch] from acelp_filters.[ch] for the QCELP decoder.
diego
parents:
diff changeset
72 return 1;
611a21e4b01b Split off celp_filters.[ch] from acelp_filters.[ch] for the QCELP decoder.
diego
parents:
diff changeset
73 sum = (sum >> 31) ^ 32767;
611a21e4b01b Split off celp_filters.[ch] from acelp_filters.[ch] for the QCELP decoder.
diego
parents:
diff changeset
74 }
611a21e4b01b Split off celp_filters.[ch] from acelp_filters.[ch] for the QCELP decoder.
diego
parents:
diff changeset
75 out[n] = sum;
611a21e4b01b Split off celp_filters.[ch] from acelp_filters.[ch] for the QCELP decoder.
diego
parents:
diff changeset
76 }
611a21e4b01b Split off celp_filters.[ch] from acelp_filters.[ch] for the QCELP decoder.
diego
parents:
diff changeset
77
611a21e4b01b Split off celp_filters.[ch] from acelp_filters.[ch] for the QCELP decoder.
diego
parents:
diff changeset
78 return 0;
611a21e4b01b Split off celp_filters.[ch] from acelp_filters.[ch] for the QCELP decoder.
diego
parents:
diff changeset
79 }
8091
4c95f44c4c23 Add a LPC filter
vitor
parents: 8049
diff changeset
80
10003
24952f1a8979 cosmetics: K&R coding style
diego
parents: 9509
diff changeset
81 void ff_celp_lp_synthesis_filterf(float *out,
24952f1a8979 cosmetics: K&R coding style
diego
parents: 9509
diff changeset
82 const float* filter_coeffs,
24952f1a8979 cosmetics: K&R coding style
diego
parents: 9509
diff changeset
83 const float* in,
24952f1a8979 cosmetics: K&R coding style
diego
parents: 9509
diff changeset
84 int buffer_length,
24952f1a8979 cosmetics: K&R coding style
diego
parents: 9509
diff changeset
85 int filter_length)
8091
4c95f44c4c23 Add a LPC filter
vitor
parents: 8049
diff changeset
86 {
4c95f44c4c23 Add a LPC filter
vitor
parents: 8049
diff changeset
87 int i,n;
4c95f44c4c23 Add a LPC filter
vitor
parents: 8049
diff changeset
88
9447
d7554a5e3fd7 [COSMETIC] Correct a minor nit. Should be clearer now.
reynaldo
parents: 9446
diff changeset
89 // Avoids a +1 in the inner loop.
8091
4c95f44c4c23 Add a LPC filter
vitor
parents: 8049
diff changeset
90 filter_length++;
4c95f44c4c23 Add a LPC filter
vitor
parents: 8049
diff changeset
91
10003
24952f1a8979 cosmetics: K&R coding style
diego
parents: 9509
diff changeset
92 for (n = 0; n < buffer_length; n++) {
8091
4c95f44c4c23 Add a LPC filter
vitor
parents: 8049
diff changeset
93 out[n] = in[n];
10003
24952f1a8979 cosmetics: K&R coding style
diego
parents: 9509
diff changeset
94 for (i = 1; i < filter_length; i++)
9446
1a3865d1b049 Fix possibly harmful outbound addressing. Patch by Kenan Gillet.
reynaldo
parents: 9017
diff changeset
95 out[n] -= filter_coeffs[i-1] * out[n-i];
8091
4c95f44c4c23 Add a LPC filter
vitor
parents: 8049
diff changeset
96 }
4c95f44c4c23 Add a LPC filter
vitor
parents: 8049
diff changeset
97 }
9509
2838045383c5 Add LP zero synthesis filter. Patch by Kenan Gillet.
reynaldo
parents: 9447
diff changeset
98
10003
24952f1a8979 cosmetics: K&R coding style
diego
parents: 9509
diff changeset
99 void ff_celp_lp_zero_synthesis_filterf(float *out,
24952f1a8979 cosmetics: K&R coding style
diego
parents: 9509
diff changeset
100 const float* filter_coeffs,
24952f1a8979 cosmetics: K&R coding style
diego
parents: 9509
diff changeset
101 const float* in,
24952f1a8979 cosmetics: K&R coding style
diego
parents: 9509
diff changeset
102 int buffer_length,
24952f1a8979 cosmetics: K&R coding style
diego
parents: 9509
diff changeset
103 int filter_length)
9509
2838045383c5 Add LP zero synthesis filter. Patch by Kenan Gillet.
reynaldo
parents: 9447
diff changeset
104 {
2838045383c5 Add LP zero synthesis filter. Patch by Kenan Gillet.
reynaldo
parents: 9447
diff changeset
105 int i,n;
2838045383c5 Add LP zero synthesis filter. Patch by Kenan Gillet.
reynaldo
parents: 9447
diff changeset
106
2838045383c5 Add LP zero synthesis filter. Patch by Kenan Gillet.
reynaldo
parents: 9447
diff changeset
107 // Avoids a +1 in the inner loop.
2838045383c5 Add LP zero synthesis filter. Patch by Kenan Gillet.
reynaldo
parents: 9447
diff changeset
108 filter_length++;
2838045383c5 Add LP zero synthesis filter. Patch by Kenan Gillet.
reynaldo
parents: 9447
diff changeset
109
10003
24952f1a8979 cosmetics: K&R coding style
diego
parents: 9509
diff changeset
110 for (n = 0; n < buffer_length; n++) {
9509
2838045383c5 Add LP zero synthesis filter. Patch by Kenan Gillet.
reynaldo
parents: 9447
diff changeset
111 out[n] = in[n];
10003
24952f1a8979 cosmetics: K&R coding style
diego
parents: 9509
diff changeset
112 for (i = 1; i < filter_length; i++)
10013
454cb6aa43a3 Correct the sign of the arithmetic in ff_celp_lp_zero_synthesis_filterf()
superdump
parents: 10003
diff changeset
113 out[n] += filter_coeffs[i-1] * in[n-i];
9509
2838045383c5 Add LP zero synthesis filter. Patch by Kenan Gillet.
reynaldo
parents: 9447
diff changeset
114 }
2838045383c5 Add LP zero synthesis filter. Patch by Kenan Gillet.
reynaldo
parents: 9447
diff changeset
115 }