2 * various filters for CELP-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 #ifndef AVCODEC_CELP_FILTERS_H
24 #define AVCODEC_CELP_FILTERS_H
28 typedef struct CELPFContext
{
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.
40 * @note Output buffer must contain filter_length samples of past
41 * speech data before pointer.
43 * Routine applies 1/A(z) filter to given speech data.
45 void (*celp_lp_synthesis_filterf
)(float *out
, const float *filter_coeffs
,
46 const float *in
, int buffer_length
,
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)
60 * @note Output buffer must contain filter_length samples of past
61 * speech data before pointer.
63 * Routine applies A(z) filter to given speech data.
65 void (*celp_lp_zero_synthesis_filterf
)(float *out
, const float *filter_coeffs
,
66 const float *in
, int buffer_length
,
72 * Initialize CELPFContext.
74 void ff_celp_filter_init(CELPFContext
*c
);
75 void ff_celp_filter_init_mips(CELPFContext
*c
);
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
84 * fc_out[n] = sum(i,0,len-1){ fc_in[i] * filter[(len + n - i)%len] }
86 * @note fc_in and fc_out should not overlap!
88 void ff_celp_convolve_circ(int16_t *fc_out
, const int16_t *fc_in
,
89 const int16_t *filter
, int len
);
92 * Add an array to a rotated array.
94 * out[k] = in[k] + fac * lagged[k-lag] with wrap-around
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
103 void ff_celp_circ_addf(float *out
, const float *in
,
104 const float *lagged
, int lag
, float fac
, int n
);
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)
118 * @return 1 if overflow occurred, 0 - otherwise
120 * @note Output buffer must contain filter_length samples of past
121 * speech data before pointer.
123 * Routine applies 1/A(z) filter to given speech data.
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
);
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.
141 * @note Output buffer must contain filter_length samples of past
142 * speech data before pointer.
144 * Routine applies 1/A(z) filter to given speech data.
146 void ff_celp_lp_synthesis_filterf(float *out
, const float *filter_coeffs
,
147 const float *in
, int buffer_length
,
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)
160 * @note Output buffer must contain filter_length samples of past
161 * speech data before pointer.
163 * Routine applies A(z) filter to given speech data.
165 void ff_celp_lp_zero_synthesis_filterf(float *out
, const float *filter_coeffs
,
166 const float *in
, int buffer_length
,
169 #endif /* AVCODEC_CELP_FILTERS_H */