comparison ra288.c @ 7412:51da3d8200d0 libavcodec

Give the context variables of ra288 a better name: s/glob/ractx/
author vitor
date Sat, 26 Jul 2008 14:31:47 +0000
parents d41948bf80a1
children d018af0d20a1
comparison
equal deleted inserted replaced
7411:d41948bf80a1 7412:51da3d8200d0
47 47
48 return res; 48 return res;
49 } 49 }
50 50
51 /* Decode and produce output */ 51 /* Decode and produce output */
52 static void decode(RA288Context *glob, float gain, int cb_coef) 52 static void decode(RA288Context *ractx, float gain, int cb_coef)
53 { 53 {
54 int x, y; 54 int x, y;
55 double sumsum; 55 double sumsum;
56 float sum, buffer[5]; 56 float sum, buffer[5];
57 57
58 memmove(glob->sb + 5, glob->sb, 36 * sizeof(*glob->sb)); 58 memmove(ractx->sb + 5, ractx->sb, 36 * sizeof(*ractx->sb));
59 59
60 for (x=4; x >= 0; x--) 60 for (x=4; x >= 0; x--)
61 glob->sb[x] = -scalar_product_float(glob->sb + x + 1, glob->pr1, 36); 61 ractx->sb[x] = -scalar_product_float(ractx->sb + x + 1, ractx->pr1, 36);
62 62
63 /* convert log and do rms */ 63 /* convert log and do rms */
64 sum = 32. - scalar_product_float(glob->pr2, glob->lhist, 10); 64 sum = 32. - scalar_product_float(ractx->pr2, ractx->lhist, 10);
65 65
66 sum = av_clipf(sum, 0, 60); 66 sum = av_clipf(sum, 0, 60);
67 67
68 sumsum = exp(sum * 0.1151292546497) * gain; /* pow(10.0,sum/20)*f */ 68 sumsum = exp(sum * 0.1151292546497) * gain; /* pow(10.0,sum/20)*f */
69 69
73 sum = scalar_product_float(buffer, buffer, 5) / 5; 73 sum = scalar_product_float(buffer, buffer, 5) / 5;
74 74
75 sum = FFMAX(sum, 1); 75 sum = FFMAX(sum, 1);
76 76
77 /* shift and store */ 77 /* shift and store */
78 memmove(glob->lhist, glob->lhist - 1, 10 * sizeof(*glob->lhist)); 78 memmove(ractx->lhist, ractx->lhist - 1, 10 * sizeof(*ractx->lhist));
79 79
80 *glob->lhist = glob->history[glob->phase] = 10 * log10(sum) - 32; 80 *ractx->lhist = ractx->history[ractx->phase] = 10 * log10(sum) - 32;
81 81
82 for (x=1; x < 5; x++) 82 for (x=1; x < 5; x++)
83 for (y=x-1; y >= 0; y--) 83 for (y=x-1; y >= 0; y--)
84 buffer[x] -= glob->pr1[x-y-1] * buffer[y]; 84 buffer[x] -= ractx->pr1[x-y-1] * buffer[y];
85 85
86 /* output */ 86 /* output */
87 for (x=0; x < 5; x++) { 87 for (x=0; x < 5; x++) {
88 glob->output[glob->phase*5+x] = glob->sb[4-x] = 88 ractx->output[ractx->phase*5+x] = ractx->sb[4-x] =
89 av_clipf(glob->sb[4-x] + buffer[x], -4095, 4095); 89 av_clipf(ractx->sb[4-x] + buffer[x], -4095, 4095);
90 } 90 }
91 } 91 }
92 92
93 /* column multiply */ 93 /* column multiply */
94 static void colmult(float *tgt, const float *m1, const float *m2, int n) 94 static void colmult(float *tgt, const float *m1, const float *m2, int n)
185 } 185 }
186 186
187 /** 187 /**
188 * Backward synthesis filter. Find the LPC coefficients from past speech data. 188 * Backward synthesis filter. Find the LPC coefficients from past speech data.
189 */ 189 */
190 static void backward_filter(RA288Context *glob) 190 static void backward_filter(RA288Context *ractx)
191 { 191 {
192 float buffer1[40], temp1[37]; 192 float buffer1[40], temp1[37];
193 float buffer2[8], temp2[11]; 193 float buffer2[8], temp2[11];
194 194
195 memcpy(buffer1 , glob->output + 20, 20*sizeof(*buffer1)); 195 memcpy(buffer1 , ractx->output + 20, 20*sizeof(*buffer1));
196 memcpy(buffer1 + 20, glob->output , 20*sizeof(*buffer1)); 196 memcpy(buffer1 + 20, ractx->output , 20*sizeof(*buffer1));
197 197
198 do_hybrid_window(36, 40, 35, buffer1, temp1, glob->st1a, glob->st1b, 198 do_hybrid_window(36, 40, 35, buffer1, temp1, ractx->st1a, ractx->st1b,
199 syn_window); 199 syn_window);
200 200
201 if (!eval_lpc_coeffs(temp1, glob->st1, 36)) 201 if (!eval_lpc_coeffs(temp1, ractx->st1, 36))
202 colmult(glob->pr1, glob->st1, syn_bw_tab, 36); 202 colmult(ractx->pr1, ractx->st1, syn_bw_tab, 36);
203 203
204 memcpy(buffer2 , glob->history + 4, 4*sizeof(*buffer2)); 204 memcpy(buffer2 , ractx->history + 4, 4*sizeof(*buffer2));
205 memcpy(buffer2 + 4, glob->history , 4*sizeof(*buffer2)); 205 memcpy(buffer2 + 4, ractx->history , 4*sizeof(*buffer2));
206 206
207 do_hybrid_window(10, 8, 20, buffer2, temp2, glob->st2a, glob->st2b, 207 do_hybrid_window(10, 8, 20, buffer2, temp2, ractx->st2a, ractx->st2b,
208 gain_window); 208 gain_window);
209 209
210 if (!eval_lpc_coeffs(temp2, glob->st2, 10)) 210 if (!eval_lpc_coeffs(temp2, ractx->st2, 10))
211 colmult(glob->pr2, glob->st2, gain_bw_tab, 10); 211 colmult(ractx->pr2, ractx->st2, gain_bw_tab, 10);
212 } 212 }
213 213
214 /* Decode a block (celp) */ 214 /* Decode a block (celp) */
215 static int ra288_decode_frame(AVCodecContext * avctx, void *data, 215 static int ra288_decode_frame(AVCodecContext * avctx, void *data,
216 int *data_size, const uint8_t * buf, 216 int *data_size, const uint8_t * buf,
217 int buf_size) 217 int buf_size)
218 { 218 {
219 int16_t *out = data; 219 int16_t *out = data;
220 int x, y; 220 int x, y;
221 RA288Context *glob = avctx->priv_data; 221 RA288Context *ractx = avctx->priv_data;
222 GetBitContext gb; 222 GetBitContext gb;
223 223
224 if (buf_size < avctx->block_align) { 224 if (buf_size < avctx->block_align) {
225 av_log(avctx, AV_LOG_ERROR, 225 av_log(avctx, AV_LOG_ERROR,
226 "Error! Input buffer is too small [%d<%d]\n", 226 "Error! Input buffer is too small [%d<%d]\n",
231 init_get_bits(&gb, buf, avctx->block_align * 8); 231 init_get_bits(&gb, buf, avctx->block_align * 8);
232 232
233 for (x=0; x < 32; x++) { 233 for (x=0; x < 32; x++) {
234 float gain = amptable[get_bits(&gb, 3)]; 234 float gain = amptable[get_bits(&gb, 3)];
235 int cb_coef = get_bits(&gb, 6 + (x&1)); 235 int cb_coef = get_bits(&gb, 6 + (x&1));
236 glob->phase = x & 7; 236 ractx->phase = x & 7;
237 decode(glob, gain, cb_coef); 237 decode(ractx, gain, cb_coef);
238 238
239 for (y=0; y < 5; y++) 239 for (y=0; y < 5; y++)
240 *(out++) = 8 * glob->output[glob->phase*5 + y]; 240 *(out++) = 8 * ractx->output[ractx->phase*5 + y];
241 241
242 if (glob->phase == 3) 242 if (ractx->phase == 3)
243 backward_filter(glob); 243 backward_filter(ractx);
244 } 244 }
245 245
246 *data_size = (char *)out - (char *)data; 246 *data_size = (char *)out - (char *)data;
247 return avctx->block_align; 247 return avctx->block_align;
248 } 248 }