comparison ra288.c @ 7448:b15534513059 libavcodec

Cosmetics: rename loop counter vars to i,j
author vitor
date Tue, 29 Jul 2008 18:20:49 +0000
parents a8b985890c34
children 18fc253b4991
comparison
equal deleted inserted replaced
7447:16737361e9ab 7448:b15534513059
59 *tgt++ = *m1++ * *m2++; 59 *tgt++ = *m1++ * *m2++;
60 } 60 }
61 61
62 static void decode(RA288Context *ractx, float gain, int cb_coef) 62 static void decode(RA288Context *ractx, float gain, int cb_coef)
63 { 63 {
64 int x, y; 64 int i, j;
65 double sumsum; 65 double sumsum;
66 float sum, buffer[5]; 66 float sum, buffer[5];
67 67
68 memmove(ractx->sp_block + 5, ractx->sp_block, 36*sizeof(*ractx->sp_block)); 68 memmove(ractx->sp_block + 5, ractx->sp_block, 36*sizeof(*ractx->sp_block));
69 69
70 for (x=4; x >= 0; x--) 70 for (i=4; i >= 0; i--)
71 ractx->sp_block[x] = -scalar_product_float(ractx->sp_block + x + 1, 71 ractx->sp_block[i] = -scalar_product_float(ractx->sp_block + i + 1,
72 ractx->sp_lpc, 36); 72 ractx->sp_lpc, 36);
73 73
74 /* block 46 of G.728 spec */ 74 /* block 46 of G.728 spec */
75 sum = 32. - scalar_product_float(ractx->gain_lpc, ractx->gain_block, 10); 75 sum = 32. - scalar_product_float(ractx->gain_lpc, ractx->gain_block, 10);
76 76
78 sum = av_clipf(sum, 0, 60); 78 sum = av_clipf(sum, 0, 60);
79 79
80 /* block 48 of G.728 spec */ 80 /* block 48 of G.728 spec */
81 sumsum = exp(sum * 0.1151292546497) * gain; /* pow(10.0,sum/20)*gain */ 81 sumsum = exp(sum * 0.1151292546497) * gain; /* pow(10.0,sum/20)*gain */
82 82
83 for (x=0; x < 5; x++) 83 for (i=0; i < 5; i++)
84 buffer[x] = codetable[cb_coef][x] * sumsum; 84 buffer[i] = codetable[cb_coef][i] * sumsum;
85 85
86 sum = scalar_product_float(buffer, buffer, 5) / 5; 86 sum = scalar_product_float(buffer, buffer, 5) / 5;
87 87
88 sum = FFMAX(sum, 1); 88 sum = FFMAX(sum, 1);
89 89
91 memmove(ractx->gain_block, ractx->gain_block - 1, 91 memmove(ractx->gain_block, ractx->gain_block - 1,
92 10 * sizeof(*ractx->gain_block)); 92 10 * sizeof(*ractx->gain_block));
93 93
94 *ractx->gain_block = 10 * log10(sum) - 32; 94 *ractx->gain_block = 10 * log10(sum) - 32;
95 95
96 for (x=1; x < 5; x++) 96 for (i=1; i < 5; i++)
97 for (y=x-1; y >= 0; y--) 97 for (j=i-1; j >= 0; j--)
98 buffer[x] -= ractx->sp_lpc[x-y-1] * buffer[y]; 98 buffer[i] -= ractx->sp_lpc[i-j-1] * buffer[j];
99 99
100 /* output */ 100 /* output */
101 for (x=0; x < 5; x++) 101 for (i=0; i < 5; i++)
102 ractx->sp_block[4-x] = 102 ractx->sp_block[4-i] =
103 av_clipf(ractx->sp_block[4-x] + buffer[x], -4095, 4095); 103 av_clipf(ractx->sp_block[4-i] + buffer[i], -4095, 4095);
104 } 104 }
105 105
106 /** 106 /**
107 * Converts autocorrelation coefficients to LPC coefficients using the 107 * Converts autocorrelation coefficients to LPC coefficients using the
108 * Levinson-Durbin algorithm. See blocks 37 and 50 of the G.728 specification. 108 * Levinson-Durbin algorithm. See blocks 37 and 50 of the G.728 specification.
109 * 109 *
110 * @return 0 if success, -1 if fail 110 * @return 0 if success, -1 if fail
111 */ 111 */
112 static int eval_lpc_coeffs(const float *in, float *tgt, int n) 112 static int eval_lpc_coeffs(const float *in, float *tgt, int n)
113 { 113 {
114 int x, y; 114 int i, j;
115 double f0, f1, f2; 115 double f0, f1, f2;
116 116
117 if (in[n] == 0) 117 if (in[n] == 0)
118 return -1; 118 return -1;
119 119
120 if ((f0 = *in) <= 0) 120 if ((f0 = *in) <= 0)
121 return -1; 121 return -1;
122 122
123 in--; // To avoid a -1 subtraction in the inner loop 123 in--; // To avoid a -1 subtraction in the inner loop
124 124
125 for (x=1; x <= n; x++) { 125 for (i=1; i <= n; i++) {
126 f1 = in[x+1]; 126 f1 = in[i+1];
127 127
128 for (y=0; y < x - 1; y++) 128 for (j=0; j < i - 1; j++)
129 f1 += in[x-y]*tgt[y]; 129 f1 += in[i-j]*tgt[j];
130 130
131 tgt[x-1] = f2 = -f1/f0; 131 tgt[i-1] = f2 = -f1/f0;
132 for (y=0; y < x >> 1; y++) { 132 for (j=0; j < i >> 1; j++) {
133 float temp = tgt[y] + tgt[x-y-2]*f2; 133 float temp = tgt[j] + tgt[i-j-2]*f2;
134 tgt[x-y-2] += tgt[y]*f2; 134 tgt[i-j-2] += tgt[j]*f2;
135 tgt[y] = temp; 135 tgt[j] = temp;
136 } 136 }
137 if ((f0 += f1*f2) < 0) 137 if ((f0 += f1*f2) < 0)
138 return -1; 138 return -1;
139 } 139 }
140 140
169 */ 169 */
170 static void do_hybrid_window(int order, int n, int non_rec, const float *in, 170 static void do_hybrid_window(int order, int n, int non_rec, const float *in,
171 float *out, float *hist, float *out2, 171 float *out, float *hist, float *out2,
172 const float *window) 172 const float *window)
173 { 173 {
174 unsigned int x; 174 unsigned int i;
175 float buffer1[order + 1]; 175 float buffer1[order + 1];
176 float buffer2[order + 1]; 176 float buffer2[order + 1];
177 float work[order + n + non_rec]; 177 float work[order + n + non_rec];
178 178
179 /* update history */ 179 /* update history */
180 memmove(hist, hist + n, (order + non_rec)*sizeof(*hist)); 180 memmove(hist, hist + n, (order + non_rec)*sizeof(*hist));
181 181
182 for (x=0; x < n; x++) 182 for (i=0; i < n; i++)
183 hist[order + non_rec + x] = in[n-x-1]; 183 hist[order + non_rec + i] = in[n-i-1];
184 184
185 colmult(work, window, hist, order + n + non_rec); 185 colmult(work, window, hist, order + n + non_rec);
186 186
187 prodsum(buffer1, work + order , n , order); 187 prodsum(buffer1, work + order , n , order);
188 prodsum(buffer2, work + order + n, non_rec, order); 188 prodsum(buffer2, work + order + n, non_rec, order);
189 189
190 for (x=0; x <= order; x++) { 190 for (i=0; i <= order; i++) {
191 out2[x] = out2[x] * 0.5625 + buffer1[x]; 191 out2[i] = out2[i] * 0.5625 + buffer1[i];
192 out [x] = out2[x] + buffer2[x]; 192 out [i] = out2[i] + buffer2[i];
193 } 193 }
194 194
195 /* Multiply by the white noise correcting factor (WNCF) */ 195 /* Multiply by the white noise correcting factor (WNCF) */
196 *out *= 257./256.; 196 *out *= 257./256.;
197 } 197 }
220 static int ra288_decode_frame(AVCodecContext * avctx, void *data, 220 static int ra288_decode_frame(AVCodecContext * avctx, void *data,
221 int *data_size, const uint8_t * buf, 221 int *data_size, const uint8_t * buf,
222 int buf_size) 222 int buf_size)
223 { 223 {
224 int16_t *out = data; 224 int16_t *out = data;
225 int x, y; 225 int i, j;
226 RA288Context *ractx = avctx->priv_data; 226 RA288Context *ractx = avctx->priv_data;
227 GetBitContext gb; 227 GetBitContext gb;
228 228
229 if (buf_size < avctx->block_align) { 229 if (buf_size < avctx->block_align) {
230 av_log(avctx, AV_LOG_ERROR, 230 av_log(avctx, AV_LOG_ERROR,
233 return 0; 233 return 0;
234 } 234 }
235 235
236 init_get_bits(&gb, buf, avctx->block_align * 8); 236 init_get_bits(&gb, buf, avctx->block_align * 8);
237 237
238 for (x=0; x < 32; x++) { 238 for (i=0; i < 32; i++) {
239 float gain = amptable[get_bits(&gb, 3)]; 239 float gain = amptable[get_bits(&gb, 3)];
240 int cb_coef = get_bits(&gb, 6 + (x&1)); 240 int cb_coef = get_bits(&gb, 6 + (i&1));
241 241
242 decode(ractx, gain, cb_coef); 242 decode(ractx, gain, cb_coef);
243 243
244 for (y=0; y < 5; y++) 244 for (j=0; j < 5; j++)
245 *(out++) = 8 * ractx->sp_block[4 - y]; 245 *(out++) = 8 * ractx->sp_block[4 - j];
246 246
247 if ((x & 7) == 3) 247 if ((i & 7) == 3)
248 backward_filter(ractx); 248 backward_filter(ractx);
249 } 249 }
250 250
251 *data_size = (char *)out - (char *)data; 251 *data_size = (char *)out - (char *)data;
252 return avctx->block_align; 252 return avctx->block_align;