[FFmpeg-devel] [PATCH] broaden ff_set_fixed_vector

Ronald S. Bultje rsbultje
Wed Jan 27 00:38:32 CET 2010


Hi,

$subj. Useful for single-pulse excitation bits in WMAVoice.

Ronald
-------------- next part --------------
Index: libavcodec/acelp_vectors.c
===================================================================
--- libavcodec/acelp_vectors.c	(revision 21350)
+++ libavcodec/acelp_vectors.c	(working copy)
@@ -169,10 +169,12 @@
         const int pos1   = gray_decode[fixed_index[2*i+1] & mask] + i;
         const int pos2   = gray_decode[fixed_index[2*i  ] & mask] + i;
         const float sign = (fixed_index[2*i+1] & (1 << bits)) ? -1.0 : 1.0;
-        fixed_sparse->x[2*i+1] = pos1;
-        fixed_sparse->x[2*i  ] = pos2;
-        fixed_sparse->y[2*i+1] = sign;
-        fixed_sparse->y[2*i  ] = pos2 < pos1 ? -sign : sign;
+        fixed_sparse->pulses[2*i+1].x = pos1;
+        fixed_sparse->pulses[2*i  ].x = pos2;
+        fixed_sparse->pulses[2*i+1].single = 0;
+        fixed_sparse->pulses[2*i  ].single = 0;
+        fixed_sparse->pulses[2*i+1].y = sign;
+        fixed_sparse->pulses[2*i  ].y = pos2 < pos1 ? -sign : sign;
     }
 }
 
@@ -243,8 +245,8 @@
     int i;
 
     for (i=0; i < in->n; i++) {
-        int x   = in->x[i];
-        float y = in->y[i] * scale;
+        int x   = in->pulses[i].x;
+        float y = in->pulses[i].y * scale;
         out[x] += y;
 
         x += in->pitch_lag;
@@ -261,7 +263,7 @@
     int i;
 
     for (i=0; i < in->n; i++) {
-        int x  = in->x[i];
+        int x  = in->pulses[i].x;
         out[x] = 0.0;
 
         x += in->pitch_lag;
Index: libavcodec/acelp_vectors.h
===================================================================
--- libavcodec/acelp_vectors.h	(revision 21350)
+++ libavcodec/acelp_vectors.h	(working copy)
@@ -28,8 +28,11 @@
 /** Sparse representation for the algebraic codebook (fixed) vector */
 typedef struct {
     int      n;
-    int      x[10];
-    float    y[10];
+    struct {
+        unsigned int single:1;
+        unsigned int x:31;
+        float        y;
+    } pulses[10];
     int      pitch_lag;
     float    pitch_fac;
 } AMRFixed;
Index: libavcodec/sipr.c
===================================================================
--- libavcodec/sipr.c	(revision 21350)
+++ libavcodec/sipr.c	(working copy)
@@ -285,8 +285,8 @@
 
     memset(out, 0, length*sizeof(float));
     for (i = 0; i < pulses->n; i++)
-        for (j = pulses->x[i]; j < length; j++)
-            out[j] += pulses->y[i] * shape[j - pulses->x[i]];
+        for (j = pulses->pulses[i].x; j < length; j++)
+            out[j] += pulses->pulses[i].y * shape[j - pulses->pulses[i].x];
 }
 
 /**
@@ -335,21 +335,21 @@
     switch (mode) {
     case MODE_6k5:
         for (i = 0; i < 3; i++) {
-            fixed_sparse->x[i] = 3 * (pulses[i] & 0xf) + i;
-            fixed_sparse->y[i] = pulses[i] & 0x10 ? -1 : 1;
+            fixed_sparse->pulses[i].x = 3 * (pulses[i] & 0xf) + i;
+            fixed_sparse->pulses[i].y = pulses[i] & 0x10 ? -1 : 1;
         }
         fixed_sparse->n = 3;
         break;
     case MODE_8k5:
         for (i = 0; i < 3; i++) {
-            fixed_sparse->x[2*i    ] = 3 * ((pulses[i] >> 4) & 0xf) + i;
-            fixed_sparse->x[2*i + 1] = 3 * ( pulses[i]       & 0xf) + i;
+            fixed_sparse->pulses[2*i    ].x = 3 * ((pulses[i] >> 4) & 0xf) + i;
+            fixed_sparse->pulses[2*i + 1].x = 3 * ( pulses[i]       & 0xf) + i;
 
-            fixed_sparse->y[2*i    ] = (pulses[i] & 0x100) ? -1.0: 1.0;
+            fixed_sparse->pulses[2*i    ].y = (pulses[i] & 0x100) ? -1.0: 1.0;
 
-            fixed_sparse->y[2*i + 1] =
-                (fixed_sparse->x[2*i + 1] < fixed_sparse->x[2*i]) ?
-                -fixed_sparse->y[2*i    ] : fixed_sparse->y[2*i];
+            fixed_sparse->pulses[2*i + 1].y =
+                (fixed_sparse->pulses[2*i + 1].x < fixed_sparse->pulses[2*i].x) ?
+                -fixed_sparse->pulses[2*i    ].y : fixed_sparse->pulses[2*i].y;
         }
 
         fixed_sparse->n = 6;
@@ -363,8 +363,8 @@
             for (i = 0; i < 3; i++) {
                 int index = (val & 0x7) * 6 + 4 - i*2;
 
-                fixed_sparse->y[i] = (offset + index) & 0x3 ? -1 : 1;
-                fixed_sparse->x[i] = index;
+                fixed_sparse->pulses[i].y = (offset + index) & 0x3 ? -1 : 1;
+                fixed_sparse->pulses[i].x = index;
 
                 val >>= 3;
             }
@@ -372,11 +372,11 @@
         } else {
             int pulse_subset = (pulses[0] >> 8) & 1;
 
-            fixed_sparse->x[0] = ((pulses[0] >> 4) & 15) * 3 + pulse_subset;
-            fixed_sparse->x[1] = ( pulses[0]       & 15) * 3 + pulse_subset + 1;
+            fixed_sparse->pulses[0].x = ((pulses[0] >> 4) & 15) * 3 + pulse_subset;
+            fixed_sparse->pulses[1].x = ( pulses[0]       & 15) * 3 + pulse_subset + 1;
 
-            fixed_sparse->y[0] = pulses[0] & 0x200 ? -1 : 1;
-            fixed_sparse->y[1] = -fixed_sparse->y[0];
+            fixed_sparse->pulses[0].y = pulses[0] & 0x200 ? -1 : 1;
+            fixed_sparse->pulses[1].y = -fixed_sparse->pulses[0].y;
             fixed_sparse->n = 2;
         }
         break;



More information about the ffmpeg-devel mailing list