Mercurial > libavcodec.hg
comparison ra288.c @ 7503:d85a0a151344 libavcodec
Flip (by making buf[i] -> buf[size-i-1]) two buffers: {sp,gain}_block. This
needs duplicating a few loops, but now the code is clearer.
author | vitor |
---|---|
date | Wed, 06 Aug 2008 02:44:59 +0000 |
parents | 50e0b25882cd |
children | c75c3adf11bc |
comparison
equal
deleted
inserted
replaced
7502:d5c528384f13 | 7503:d85a0a151344 |
---|---|
68 static void decode(RA288Context *ractx, float gain, int cb_coef) | 68 static void decode(RA288Context *ractx, float gain, int cb_coef) |
69 { | 69 { |
70 int i, j; | 70 int i, j; |
71 double sumsum; | 71 double sumsum; |
72 float sum, buffer[5]; | 72 float sum, buffer[5]; |
73 | 73 float *block = ractx->sp_block + 36; // Current block |
74 memmove(ractx->sp_block + 5, ractx->sp_block, 36*sizeof(*ractx->sp_block)); | 74 |
75 | 75 memmove(ractx->sp_block, ractx->sp_block + 5, 36*sizeof(*ractx->sp_block)); |
76 for (i=4; i >= 0; i--) | 76 |
77 ractx->sp_block[i] = -scalar_product_float(ractx->sp_block + i + 1, | 77 for (i=0; i < 5; i++) { |
78 ractx->sp_lpc, 36); | 78 block[i] = 0.; |
79 for (j=0; j < 36; j++) | |
80 block[i] -= block[i-1-j]*ractx->sp_lpc[j]; | |
81 } | |
79 | 82 |
80 /* block 46 of G.728 spec */ | 83 /* block 46 of G.728 spec */ |
81 sum = 32. - scalar_product_float(ractx->gain_lpc, ractx->gain_block, 10); | 84 sum = 32.; |
85 for (i=0; i < 10; i++) | |
86 sum -= ractx->gain_block[9-i] * ractx->gain_lpc[i]; | |
82 | 87 |
83 /* block 47 of G.728 spec */ | 88 /* block 47 of G.728 spec */ |
84 sum = av_clipf(sum, 0, 60); | 89 sum = av_clipf(sum, 0, 60); |
85 | 90 |
86 /* block 48 of G.728 spec */ | 91 /* block 48 of G.728 spec */ |
92 sum = scalar_product_float(buffer, buffer, 5) / 5; | 97 sum = scalar_product_float(buffer, buffer, 5) / 5; |
93 | 98 |
94 sum = FFMAX(sum, 1); | 99 sum = FFMAX(sum, 1); |
95 | 100 |
96 /* shift and store */ | 101 /* shift and store */ |
97 memmove(ractx->gain_block, ractx->gain_block - 1, | 102 memmove(ractx->gain_block, ractx->gain_block + 1, |
98 10 * sizeof(*ractx->gain_block)); | 103 9 * sizeof(*ractx->gain_block)); |
99 | 104 |
100 *ractx->gain_block = 10 * log10(sum) - 32; | 105 ractx->gain_block[9] = 10 * log10(sum) - 32; |
101 | 106 |
102 for (i=1; i < 5; i++) | 107 for (i=1; i < 5; i++) |
103 for (j=i-1; j >= 0; j--) | 108 for (j=i-1; j >= 0; j--) |
104 buffer[i] -= ractx->sp_lpc[i-j-1] * buffer[j]; | 109 buffer[i] -= ractx->sp_lpc[i-j-1] * buffer[j]; |
105 | 110 |
106 /* output */ | 111 /* output */ |
107 for (i=0; i < 5; i++) | 112 for (i=0; i < 5; i++) |
108 ractx->sp_block[4-i] = | 113 block[i] = av_clipf(block[i] + buffer[i], -4095, 4095); |
109 av_clipf(ractx->sp_block[4-i] + buffer[i], -4095, 4095); | |
110 } | 114 } |
111 | 115 |
112 /** | 116 /** |
113 * Converts autocorrelation coefficients to LPC coefficients using the | 117 * Converts autocorrelation coefficients to LPC coefficients using the |
114 * Levinson-Durbin algorithm. See blocks 37 and 50 of the G.728 specification. | 118 * Levinson-Durbin algorithm. See blocks 37 and 50 of the G.728 specification. |
154 | 158 |
155 } | 159 } |
156 | 160 |
157 /** | 161 /** |
158 * Hybrid window filtering. See blocks 36 and 49 of the G.728 specification. | 162 * Hybrid window filtering. See blocks 36 and 49 of the G.728 specification. |
159 * | |
160 * @note This function is slightly different from that described in the spec. | |
161 * It expects in[0] to be the newest sample and in[n-1] to be the oldest | |
162 * one stored. The spec has in the more ordinary way (in[0] the oldest | |
163 * and in[n-1] the newest). | |
164 * | 163 * |
165 * @param order the order of the filter | 164 * @param order the order of the filter |
166 * @param n the length of the input | 165 * @param n the length of the input |
167 * @param non_rec the number of non-recursive samples | 166 * @param non_rec the number of non-recursive samples |
168 * @param out the filter output | 167 * @param out the filter output |
182 float buffer2[order + 1]; | 181 float buffer2[order + 1]; |
183 float work[order + n + non_rec]; | 182 float work[order + n + non_rec]; |
184 | 183 |
185 /* update history */ | 184 /* update history */ |
186 memmove(hist, hist + n, (order + non_rec)*sizeof(*hist)); | 185 memmove(hist, hist + n, (order + non_rec)*sizeof(*hist)); |
187 | 186 memcpy (hist + order + non_rec, in, n * sizeof(*hist)); |
188 for (i=0; i < n; i++) | |
189 hist[order + non_rec + i] = in[n-i-1]; | |
190 | 187 |
191 colmult(work, window, hist, order + n + non_rec); | 188 colmult(work, window, hist, order + n + non_rec); |
192 | 189 |
193 convolve(buffer1, work + order , n , order); | 190 convolve(buffer1, work + order , n , order); |
194 convolve(buffer2, work + order + n, non_rec, order); | 191 convolve(buffer2, work + order + n, non_rec, order); |
208 static void backward_filter(RA288Context *ractx) | 205 static void backward_filter(RA288Context *ractx) |
209 { | 206 { |
210 float temp1[37]; // RTMP in the spec | 207 float temp1[37]; // RTMP in the spec |
211 float temp2[11]; // GPTPMP in the spec | 208 float temp2[11]; // GPTPMP in the spec |
212 | 209 |
213 do_hybrid_window(36, 40, 35, ractx->sp_block, temp1, ractx->sp_hist, | 210 do_hybrid_window(36, 40, 35, ractx->sp_block+1, temp1, ractx->sp_hist, |
214 ractx->sp_rec, syn_window); | 211 ractx->sp_rec, syn_window); |
215 | 212 |
216 if (!eval_lpc_coeffs(temp1, ractx->sp_lpc, 36)) | 213 if (!eval_lpc_coeffs(temp1, ractx->sp_lpc, 36)) |
217 colmult(ractx->sp_lpc, ractx->sp_lpc, syn_bw_tab, 36); | 214 colmult(ractx->sp_lpc, ractx->sp_lpc, syn_bw_tab, 36); |
218 | 215 |
219 do_hybrid_window(10, 8, 20, ractx->gain_block, temp2, ractx->gain_hist, | 216 do_hybrid_window(10, 8, 20, ractx->gain_block+2, temp2, ractx->gain_hist, |
220 ractx->gain_rec, gain_window); | 217 ractx->gain_rec, gain_window); |
221 | 218 |
222 if (!eval_lpc_coeffs(temp2, ractx->gain_lpc, 10)) | 219 if (!eval_lpc_coeffs(temp2, ractx->gain_lpc, 10)) |
223 colmult(ractx->gain_lpc, ractx->gain_lpc, gain_bw_tab, 10); | 220 colmult(ractx->gain_lpc, ractx->gain_lpc, gain_bw_tab, 10); |
224 } | 221 } |
246 int cb_coef = get_bits(&gb, 6 + (i&1)); | 243 int cb_coef = get_bits(&gb, 6 + (i&1)); |
247 | 244 |
248 decode(ractx, gain, cb_coef); | 245 decode(ractx, gain, cb_coef); |
249 | 246 |
250 for (j=0; j < 5; j++) | 247 for (j=0; j < 5; j++) |
251 *(out++) = 8 * ractx->sp_block[4 - j]; | 248 *(out++) = 8 * ractx->sp_block[36 + j]; |
252 | 249 |
253 if ((i & 7) == 3) | 250 if ((i & 7) == 3) |
254 backward_filter(ractx); | 251 backward_filter(ractx); |
255 } | 252 } |
256 | 253 |