Commit | Line | Data |
---|---|---|
2ba45a60 DM |
1 | /* |
2 | * various filters for CELP-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 | #ifndef AVCODEC_CELP_FILTERS_H | |
24 | #define AVCODEC_CELP_FILTERS_H | |
25 | ||
26 | #include <stdint.h> | |
27 | ||
28 | typedef struct CELPFContext { | |
29 | /** | |
30 | * LP synthesis filter. | |
31 | * @param[out] out pointer to output buffer | |
32 | * - the array out[-filter_length, -1] must | |
33 | * contain the previous result of this filter | |
34 | * @param filter_coeffs filter coefficients. | |
35 | * @param in input signal | |
36 | * @param buffer_length amount of data to process | |
37 | * @param filter_length filter length (10 for 10th order LP filter). Must be | |
38 | * greater than 4 and even. | |
39 | * | |
40 | * @note Output buffer must contain filter_length samples of past | |
41 | * speech data before pointer. | |
42 | * | |
43 | * Routine applies 1/A(z) filter to given speech data. | |
44 | */ | |
45 | void (*celp_lp_synthesis_filterf)(float *out, const float *filter_coeffs, | |
46 | const float *in, int buffer_length, | |
47 | int filter_length); | |
48 | ||
49 | /** | |
50 | * LP zero synthesis filter. | |
51 | * @param[out] out pointer to output buffer | |
52 | * @param filter_coeffs filter coefficients. | |
53 | * @param in input signal | |
54 | * - the array in[-filter_length, -1] must | |
55 | * contain the previous input of this filter | |
56 | * @param buffer_length amount of data to process (should be a multiple of eight) | |
57 | * @param filter_length filter length (10 for 10th order LP filter; | |
58 | * should be a multiple of two) | |
59 | * | |
60 | * @note Output buffer must contain filter_length samples of past | |
61 | * speech data before pointer. | |
62 | * | |
63 | * Routine applies A(z) filter to given speech data. | |
64 | */ | |
65 | void (*celp_lp_zero_synthesis_filterf)(float *out, const float *filter_coeffs, | |
66 | const float *in, int buffer_length, | |
67 | int filter_length); | |
68 | ||
69 | }CELPFContext; | |
70 | ||
71 | /** | |
72 | * Initialize CELPFContext. | |
73 | */ | |
74 | void ff_celp_filter_init(CELPFContext *c); | |
75 | void ff_celp_filter_init_mips(CELPFContext *c); | |
76 | ||
77 | /** | |
78 | * Circularly convolve fixed vector with a phase dispersion impulse | |
79 | * response filter (D.6.2 of G.729 and 6.1.5 of AMR). | |
80 | * @param fc_out vector with filter applied | |
81 | * @param fc_in source vector | |
82 | * @param filter phase filter coefficients | |
83 | * | |
84 | * fc_out[n] = sum(i,0,len-1){ fc_in[i] * filter[(len + n - i)%len] } | |
85 | * | |
86 | * @note fc_in and fc_out should not overlap! | |
87 | */ | |
88 | void ff_celp_convolve_circ(int16_t *fc_out, const int16_t *fc_in, | |
89 | const int16_t *filter, int len); | |
90 | ||
91 | /** | |
92 | * Add an array to a rotated array. | |
93 | * | |
94 | * out[k] = in[k] + fac * lagged[k-lag] with wrap-around | |
95 | * | |
96 | * @param out result vector | |
97 | * @param in samples to be added unfiltered | |
98 | * @param lagged samples to be rotated, multiplied and added | |
99 | * @param lag lagged vector delay in the range [0, n] | |
100 | * @param fac scalefactor for lagged samples | |
101 | * @param n number of samples | |
102 | */ | |
103 | void ff_celp_circ_addf(float *out, const float *in, | |
104 | const float *lagged, int lag, float fac, int n); | |
105 | ||
106 | /** | |
107 | * LP synthesis filter. | |
108 | * @param[out] out pointer to output buffer | |
109 | * @param filter_coeffs filter coefficients (-0x8000 <= (3.12) < 0x8000) | |
110 | * @param in input signal | |
111 | * @param buffer_length amount of data to process | |
112 | * @param filter_length filter length (10 for 10th order LP filter) | |
113 | * @param stop_on_overflow 1 - return immediately if overflow occurs | |
114 | * 0 - ignore overflows | |
115 | * @param shift the result is shifted right by this value | |
116 | * @param rounder the amount to add for rounding (usually 0x800 or 0xfff) | |
117 | * | |
118 | * @return 1 if overflow occurred, 0 - otherwise | |
119 | * | |
120 | * @note Output buffer must contain filter_length samples of past | |
121 | * speech data before pointer. | |
122 | * | |
123 | * Routine applies 1/A(z) filter to given speech data. | |
124 | */ | |
125 | int ff_celp_lp_synthesis_filter(int16_t *out, const int16_t *filter_coeffs, | |
126 | const int16_t *in, int buffer_length, | |
127 | int filter_length, int stop_on_overflow, | |
128 | int shift, int rounder); | |
129 | ||
130 | /** | |
131 | * LP synthesis filter. | |
132 | * @param[out] out pointer to output buffer | |
133 | * - the array out[-filter_length, -1] must | |
134 | * contain the previous result of this filter | |
135 | * @param filter_coeffs filter coefficients. | |
136 | * @param in input signal | |
137 | * @param buffer_length amount of data to process | |
138 | * @param filter_length filter length (10 for 10th order LP filter). Must be | |
139 | * greater than 4 and even. | |
140 | * | |
141 | * @note Output buffer must contain filter_length samples of past | |
142 | * speech data before pointer. | |
143 | * | |
144 | * Routine applies 1/A(z) filter to given speech data. | |
145 | */ | |
146 | void ff_celp_lp_synthesis_filterf(float *out, const float *filter_coeffs, | |
147 | const float *in, int buffer_length, | |
148 | int filter_length); | |
149 | ||
150 | /** | |
151 | * LP zero synthesis filter. | |
152 | * @param[out] out pointer to output buffer | |
153 | * @param filter_coeffs filter coefficients. | |
154 | * @param in input signal | |
155 | * - the array in[-filter_length, -1] must | |
156 | * contain the previous input of this filter | |
157 | * @param buffer_length amount of data to process | |
158 | * @param filter_length filter length (10 for 10th order LP filter) | |
159 | * | |
160 | * @note Output buffer must contain filter_length samples of past | |
161 | * speech data before pointer. | |
162 | * | |
163 | * Routine applies A(z) filter to given speech data. | |
164 | */ | |
165 | void ff_celp_lp_zero_synthesis_filterf(float *out, const float *filter_coeffs, | |
166 | const float *in, int buffer_length, | |
167 | int filter_length); | |
168 | ||
169 | #endif /* AVCODEC_CELP_FILTERS_H */ |