Browse code

Simplify implementation and use of dec2()

Originally committed as revision 13498 to svn://svn.ffmpeg.org/ffmpeg/trunk

Vitor Sessak authored on 2008/05/29 03:59:09
Showing 1 changed files
... ...
@@ -289,20 +289,29 @@ static int eq(const int16_t *in, int *target)
289 289
     return retval;
290 290
 }
291 291
 
292
-static int dec2(int16_t *decsp, const int *data, const int *inp,
293
-                 int f, const int *inp2, int a)
292
+static int dec2(RA144Context *ractx, int16_t *decsp, int block_num,
293
+                int copynew, int f)
294 294
 {
295 295
     int work[10];
296
+    int a = block_num + 1;
296 297
     int b = NBLOCKS - a;
297 298
     int x;
298 299
 
300
+    // Interpolate block coefficients from the this frame forth block and
301
+    // last frame forth block
299 302
     for (x=0; x<30; x++)
300
-        decsp[x] = (a * inp[x] + b * inp2[x]) >> 2;
301
-
302
-    if (eq(decsp, work))
303
-        return dec1(decsp, data, inp, f);
304
-    else
303
+        decsp[x] = (a * ractx->lpc_coef[x] + b * ractx->lpc_coef_old[x])>> 2;
304
+
305
+    if (eq(decsp, work)) {
306
+        // The interpolated coefficients are unstable, copy either new or old
307
+        // coefficients
308
+        if (copynew)
309
+            return dec1(decsp, ractx->lpc_refl, ractx->lpc_coef, f);
310
+        else
311
+            return dec1(decsp, ractx->lpc_refl_old, ractx->lpc_coef_old, f);
312
+    } else {
305 313
         return rms(work, f);
314
+    }
306 315
 }
307 316
 
308 317
 /* Uncompress one block (20 bytes -> 160*2 bytes) */
... ...
@@ -337,13 +346,9 @@ static int ra144_decode_frame(AVCodecContext * avctx,
337 337
     energy = decodeval[get_bits(&gb, 5) << 1]; // Useless table entries?
338 338
     a = t_sqrt(energy*ractx->old_energy) >> 12;
339 339
 
340
-    gbuf1[0] = dec2(gbuf2[0], ractx->lpc_refl_old, ractx->lpc_coef_old, ractx->old_energy, ractx->lpc_coef, 3);
341
-    if (ractx->old_energy < energy) {
342
-        gbuf1[1] = dec2(gbuf2[1], ractx->lpc_refl, ractx->lpc_coef, a, ractx->lpc_coef_old, 2);
343
-    } else {
344
-        gbuf1[1] = dec2(gbuf2[1], ractx->lpc_refl_old, ractx->lpc_coef_old, a, ractx->lpc_coef, 2);
345
-    }
346
-    gbuf1[2] = dec2(gbuf2[2], ractx->lpc_refl, ractx->lpc_coef, energy, ractx->lpc_coef_old, 3);
340
+    gbuf1[0] = dec2(ractx, gbuf2[0], 0, 0, ractx->old_energy);
341
+    gbuf1[1] = dec2(ractx, gbuf2[1], 1, energy > ractx->old_energy, a);
342
+    gbuf1[2] = dec2(ractx, gbuf2[2], 2, 1, energy);
347 343
     gbuf1[3] = dec1(gbuf2[3], ractx->lpc_refl, ractx->lpc_coef, energy);
348 344
 
349 345
     /* do output */