Mercurial > libavcodec.hg
comparison acelp_filters.c @ 6772:695f4ab2db4c libavcodec
various filters for ACELP-based codecs
author | voroshil |
---|---|
date | Sun, 11 May 2008 03:42:53 +0000 |
parents | |
children | 1f02f929b9ff |
comparison
equal
deleted
inserted
replaced
6771:7613bea3ee92 | 6772:695f4ab2db4c |
---|---|
1 /* | |
2 * various filters for ACELP-based codecs | |
3 * | |
4 * Copyright (c) 2008 Vladimir Voroshilov | |
5 * | |
6 * This file is part of FFmpeg. | |
7 * | |
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. | |
12 * | |
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. | |
17 * | |
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 | |
21 */ | |
22 | |
23 #include <inttypes.h> | |
24 | |
25 #include "avcodec.h" | |
26 #include "acelp_filters.h" | |
27 #define FRAC_BITS 13 | |
28 #include "mathops.h" | |
29 | |
30 void ff_acelp_convolve_circ( | |
31 int16_t* fc_out, | |
32 const int16_t* fc_in, | |
33 const int16_t* filter, | |
34 int subframe_size) | |
35 { | |
36 int i, k; | |
37 | |
38 memset(fc_out, 0, subframe_size * sizeof(int16_t)); | |
39 | |
40 /* Since there are few pulses over entire subframe (i.e. almost all | |
41 fc_in[i] are zero, in case of G.729D the buffer contains two non-zero | |
42 samples before the call to ff_acelp_enhance_harmonics, and (due to | |
43 pitch_delay bounded to [20; 143]) a maximum four non-zero samples | |
44 for a total of 40 after the call to it), it is faster to swap two loops | |
45 and process non-zero samples only. This will reduce the number of | |
46 multiplications from 40*40 to 4*40 for G.729D */ | |
47 for(i=0; i<subframe_size; i++) | |
48 { | |
49 if(fc_in[i]) | |
50 { | |
51 for(k=0; k<i; k++) | |
52 fc_out[k] += (fc_in[i] * filter[subframe_size + k - i]) >> 15; | |
53 | |
54 for(k=i; k<subframe_size; k++) | |
55 fc_out[k] += (fc_in[i] * filter[k - i]) >> 15; | |
56 } | |
57 } | |
58 } | |
59 | |
60 int ff_acelp_lp_synthesis_filter( | |
61 int16_t *out, | |
62 const int16_t* filter_coeffs, | |
63 const int16_t* in, | |
64 int buffer_length, | |
65 int filter_length, | |
66 int stop_on_overflow) | |
67 { | |
68 int i,n; | |
69 | |
70 for(n=0; n<buffer_length; n++) | |
71 { | |
72 int sum = 0x800; | |
73 for(i=1; i<filter_length; i++) | |
74 sum -= filter_coeffs[i] * out[n-i]; | |
75 | |
76 sum = (sum >> 12) + in[n]; | |
77 | |
78 /* Check for overflow */ | |
79 if(sum + 0x8000 > 0xFFFFU) | |
80 { | |
81 if(stop_on_overflow) | |
82 return 1; | |
83 sum = (sum >> 31) ^ 32767; | |
84 } | |
85 out[n] = sum; | |
86 } | |
87 | |
88 return 0; | |
89 } | |
90 | |
91 void ff_acelp_weighted_filter( | |
92 int16_t *out, | |
93 const int16_t* in, | |
94 const int16_t *weight_pow, | |
95 int filter_length) | |
96 { | |
97 int n; | |
98 for(n=0; n<filter_length; n++) | |
99 out[n] = (in[n] * weight_pow[n] + 0x4000) >> 15; /* (3.12) = (0.15) * (3.12) with rounding */ | |
100 } | |
101 | |
102 void ff_acelp_high_pass_filter( | |
103 int16_t* out, | |
104 int hpf_f[2], | |
105 const int16_t* in, | |
106 int length) | |
107 { | |
108 int i; | |
109 int tmp; | |
110 | |
111 for(i=0; i<length; i++) | |
112 { | |
113 tmp = MULL(hpf_f[0], 15836); /* (14.13) = (13.13) * (1.13) */ | |
114 tmp += MULL(hpf_f[1], -7667); /* (13.13) = (13.13) * (0.13) */ | |
115 tmp += 7699 * (in[i] - 2*in[i-1] + in[i-2]); /* (14.13) = (0.13) * (14.0) */ | |
116 | |
117 /* Multiplication by 2 with rounding can cause short type | |
118 overflow, thus clipping is required. */ | |
119 | |
120 out[i] = av_clip_int16((tmp + 0x800) >> 12); /* (15.0) = 2 * (13.13) = (14.13) */ | |
121 | |
122 hpf_f[1] = hpf_f[0]; | |
123 hpf_f[0] = tmp; | |
124 } | |
125 } |