Mercurial > libavcodec.hg
annotate celp_filters.c @ 8325:0b905a126bc9 libavcodec
Make register_avcodec() call avcodec_init().
This avoids the possibility to use a registered codec without first
initializing libavcodec, which resulted in unexpected behavior.
author | stefano |
---|---|
date | Sun, 14 Dec 2008 20:04:00 +0000 |
parents | 4c95f44c4c23 |
children | 1e2c96617886 |
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 |
611a21e4b01b
Split off celp_filters.[ch] from acelp_filters.[ch] for the QCELP decoder.
diego
parents:
diff
changeset
|
28 void ff_celp_convolve_circ( |
611a21e4b01b
Split off celp_filters.[ch] from acelp_filters.[ch] for the QCELP decoder.
diego
parents:
diff
changeset
|
29 int16_t* fc_out, |
611a21e4b01b
Split off celp_filters.[ch] from acelp_filters.[ch] for the QCELP decoder.
diego
parents:
diff
changeset
|
30 const int16_t* fc_in, |
611a21e4b01b
Split off celp_filters.[ch] from acelp_filters.[ch] for the QCELP decoder.
diego
parents:
diff
changeset
|
31 const int16_t* filter, |
611a21e4b01b
Split off celp_filters.[ch] from acelp_filters.[ch] for the QCELP decoder.
diego
parents:
diff
changeset
|
32 int len) |
611a21e4b01b
Split off celp_filters.[ch] from acelp_filters.[ch] for the QCELP decoder.
diego
parents:
diff
changeset
|
33 { |
611a21e4b01b
Split off celp_filters.[ch] from acelp_filters.[ch] for the QCELP decoder.
diego
parents:
diff
changeset
|
34 int i, k; |
611a21e4b01b
Split off celp_filters.[ch] from acelp_filters.[ch] for the QCELP decoder.
diego
parents:
diff
changeset
|
35 |
611a21e4b01b
Split off celp_filters.[ch] from acelp_filters.[ch] for the QCELP decoder.
diego
parents:
diff
changeset
|
36 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
|
37 |
611a21e4b01b
Split off celp_filters.[ch] from acelp_filters.[ch] for the QCELP decoder.
diego
parents:
diff
changeset
|
38 /* 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
|
39 all fc_in[i] are zero) it is faster to loop over fc_in first. */ |
611a21e4b01b
Split off celp_filters.[ch] from acelp_filters.[ch] for the QCELP decoder.
diego
parents:
diff
changeset
|
40 for(i=0; i<len; i++) |
611a21e4b01b
Split off celp_filters.[ch] from acelp_filters.[ch] for the QCELP decoder.
diego
parents:
diff
changeset
|
41 { |
611a21e4b01b
Split off celp_filters.[ch] from acelp_filters.[ch] for the QCELP decoder.
diego
parents:
diff
changeset
|
42 if(fc_in[i]) |
611a21e4b01b
Split off celp_filters.[ch] from acelp_filters.[ch] for the QCELP decoder.
diego
parents:
diff
changeset
|
43 { |
611a21e4b01b
Split off celp_filters.[ch] from acelp_filters.[ch] for the QCELP decoder.
diego
parents:
diff
changeset
|
44 for(k=0; k<i; k++) |
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[len + 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 for(k=i; k<len; k++) |
611a21e4b01b
Split off celp_filters.[ch] from acelp_filters.[ch] for the QCELP decoder.
diego
parents:
diff
changeset
|
48 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
|
49 } |
611a21e4b01b
Split off celp_filters.[ch] from acelp_filters.[ch] for the QCELP decoder.
diego
parents:
diff
changeset
|
50 } |
611a21e4b01b
Split off celp_filters.[ch] from acelp_filters.[ch] for the QCELP decoder.
diego
parents:
diff
changeset
|
51 } |
611a21e4b01b
Split off celp_filters.[ch] from acelp_filters.[ch] for the QCELP decoder.
diego
parents:
diff
changeset
|
52 |
611a21e4b01b
Split off celp_filters.[ch] from acelp_filters.[ch] for the QCELP decoder.
diego
parents:
diff
changeset
|
53 int ff_celp_lp_synthesis_filter( |
611a21e4b01b
Split off celp_filters.[ch] from acelp_filters.[ch] for the QCELP decoder.
diego
parents:
diff
changeset
|
54 int16_t *out, |
611a21e4b01b
Split off celp_filters.[ch] from acelp_filters.[ch] for the QCELP decoder.
diego
parents:
diff
changeset
|
55 const int16_t* filter_coeffs, |
611a21e4b01b
Split off celp_filters.[ch] from acelp_filters.[ch] for the QCELP decoder.
diego
parents:
diff
changeset
|
56 const int16_t* in, |
611a21e4b01b
Split off celp_filters.[ch] from acelp_filters.[ch] for the QCELP decoder.
diego
parents:
diff
changeset
|
57 int buffer_length, |
611a21e4b01b
Split off celp_filters.[ch] from acelp_filters.[ch] for the QCELP decoder.
diego
parents:
diff
changeset
|
58 int filter_length, |
611a21e4b01b
Split off celp_filters.[ch] from acelp_filters.[ch] for the QCELP decoder.
diego
parents:
diff
changeset
|
59 int stop_on_overflow, |
611a21e4b01b
Split off celp_filters.[ch] from acelp_filters.[ch] for the QCELP decoder.
diego
parents:
diff
changeset
|
60 int rounder) |
611a21e4b01b
Split off celp_filters.[ch] from acelp_filters.[ch] for the QCELP decoder.
diego
parents:
diff
changeset
|
61 { |
611a21e4b01b
Split off celp_filters.[ch] from acelp_filters.[ch] for the QCELP decoder.
diego
parents:
diff
changeset
|
62 int i,n; |
611a21e4b01b
Split off celp_filters.[ch] from acelp_filters.[ch] for the QCELP decoder.
diego
parents:
diff
changeset
|
63 |
611a21e4b01b
Split off celp_filters.[ch] from acelp_filters.[ch] for the QCELP decoder.
diego
parents:
diff
changeset
|
64 // These two lines are to avoid a -1 subtraction in the main loop |
611a21e4b01b
Split off celp_filters.[ch] from acelp_filters.[ch] for the QCELP decoder.
diego
parents:
diff
changeset
|
65 filter_length++; |
611a21e4b01b
Split off celp_filters.[ch] from acelp_filters.[ch] for the QCELP decoder.
diego
parents:
diff
changeset
|
66 filter_coeffs--; |
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 for(n=0; n<buffer_length; n++) |
611a21e4b01b
Split off celp_filters.[ch] from acelp_filters.[ch] for the QCELP decoder.
diego
parents:
diff
changeset
|
69 { |
611a21e4b01b
Split off celp_filters.[ch] from acelp_filters.[ch] for the QCELP decoder.
diego
parents:
diff
changeset
|
70 int sum = rounder; |
611a21e4b01b
Split off celp_filters.[ch] from acelp_filters.[ch] for the QCELP decoder.
diego
parents:
diff
changeset
|
71 for(i=1; i<filter_length; i++) |
611a21e4b01b
Split off celp_filters.[ch] from acelp_filters.[ch] for the QCELP decoder.
diego
parents:
diff
changeset
|
72 sum -= filter_coeffs[i] * out[n-i]; |
611a21e4b01b
Split off celp_filters.[ch] from acelp_filters.[ch] for the QCELP decoder.
diego
parents:
diff
changeset
|
73 |
611a21e4b01b
Split off celp_filters.[ch] from acelp_filters.[ch] for the QCELP decoder.
diego
parents:
diff
changeset
|
74 sum = (sum >> 12) + in[n]; |
611a21e4b01b
Split off celp_filters.[ch] from acelp_filters.[ch] for the QCELP decoder.
diego
parents:
diff
changeset
|
75 |
611a21e4b01b
Split off celp_filters.[ch] from acelp_filters.[ch] for the QCELP decoder.
diego
parents:
diff
changeset
|
76 if(sum + 0x8000 > 0xFFFFU) |
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 if(stop_on_overflow) |
611a21e4b01b
Split off celp_filters.[ch] from acelp_filters.[ch] for the QCELP decoder.
diego
parents:
diff
changeset
|
79 return 1; |
611a21e4b01b
Split off celp_filters.[ch] from acelp_filters.[ch] for the QCELP decoder.
diego
parents:
diff
changeset
|
80 sum = (sum >> 31) ^ 32767; |
611a21e4b01b
Split off celp_filters.[ch] from acelp_filters.[ch] for the QCELP decoder.
diego
parents:
diff
changeset
|
81 } |
611a21e4b01b
Split off celp_filters.[ch] from acelp_filters.[ch] for the QCELP decoder.
diego
parents:
diff
changeset
|
82 out[n] = sum; |
611a21e4b01b
Split off celp_filters.[ch] from acelp_filters.[ch] for the QCELP decoder.
diego
parents:
diff
changeset
|
83 } |
611a21e4b01b
Split off celp_filters.[ch] from acelp_filters.[ch] for the QCELP decoder.
diego
parents:
diff
changeset
|
84 |
611a21e4b01b
Split off celp_filters.[ch] from acelp_filters.[ch] for the QCELP decoder.
diego
parents:
diff
changeset
|
85 return 0; |
611a21e4b01b
Split off celp_filters.[ch] from acelp_filters.[ch] for the QCELP decoder.
diego
parents:
diff
changeset
|
86 } |
8091 | 87 |
88 void ff_celp_lp_synthesis_filterf( | |
89 float *out, | |
90 const float* filter_coeffs, | |
91 const float* in, | |
92 int buffer_length, | |
93 int filter_length) | |
94 { | |
95 int i,n; | |
96 | |
97 // These two lines are to avoid a -1 subtraction in the main loop | |
98 filter_length++; | |
99 filter_coeffs--; | |
100 | |
101 for(n=0; n<buffer_length; n++) | |
102 { | |
103 out[n] = in[n]; | |
104 for(i=1; i<filter_length; i++) | |
105 out[n] += filter_coeffs[i] * out[n-i]; | |
106 } | |
107 } |