[FFmpeg-soc] [soc]: r350 - in qcelp: qcelpdata.h qcelpdec.c

reynaldo subversion at mplayerhq.hu
Sun Jul 8 19:18:16 CEST 2007


Author: reynaldo
Date: Sun Jul  8 19:18:16 2007
New Revision: 350

Log:
- Decoding of gain parameters (WIP)
- Codebook gain sanity checks, completes wrong packet detection code


Modified:
   qcelp/qcelpdata.h
   qcelp/qcelpdec.c

Modified: qcelp/qcelpdata.h
==============================================================================
--- qcelp/qcelpdata.h	(original)
+++ qcelp/qcelpdata.h	Sun Jul  8 19:18:16 2007
@@ -24,6 +24,8 @@
  * QCELP decoder
  */
 
+#define FXQ(v)  (roundf(16384.0*v)/16384.0)
+
 typedef enum
 {
     RATE_FULL   = 0,
@@ -309,6 +311,24 @@ static const qcelp_fvector qcelp_lspvq5[
 {.0486,.1050},{.1675,.1019},{.0880,.0278},{.2214,.0202},
 {.0539,.1564},{.1142,.0533},{.0984,.0391},{.2130,.1089}};
 
+/**
+ * Gain parameters
+ * TIA/EIA/IS-733 2.4.6.2.1-(1 through 3)
+ */
+
+#define QCELP_CBSIGN2GS(a) ((a) == 0? 1:-1)
+#define QCELP_CBGAIN2G0(a) (a*4)
+
+static const float qcelp_g12ga[]={
+   1.000,   1.125,   1.250,   1.375,   1.625,  1.750,  2.000,  2.250,
+   2.500,   2.875,   3.125,   3.500,   4.000,  4.500,  5.000,  5.625,
+   6.250,   7.125,   8.000,   8.875,  10.000, 11.250, 12.625, 14.125,
+  15.875,  17.750,  20.000,  22.375,  25.125, 28.125, 31.625, 35.500,
+  39.750,  44.625,  50.125,  56.250,  63.125, 70.750, 79.375, 89.125,
+ 100.000, 112.250, 125.875, 141.250, 158.500,177.875,199.500,223.875,
+ 251.250, 281.875, 316.250, 354.875, 398.125,446.625,501.125,563.375,
+ 631.000, 708.000, 794.375, 891.250,1000.000};
+
 /* rest is currently unused */
 
 static const int   qcelp_cumulative_gainloss[]={0,1,2,6};

Modified: qcelp/qcelpdec.c
==============================================================================
--- qcelp/qcelpdec.c	(original)
+++ qcelp/qcelpdec.c	Sun Jul  8 19:18:16 2007
@@ -86,18 +86,52 @@ static int qcelp_decode_close(AVCodecCon
  *
  * For details see TIA/EIA/IS-733 2.4.3.2.6.2-2
  */
-void qcelp_lspv2lspf(const uint8_t *lspv, float *lspf)
+void qcelp_lspv2lspf(const uint8_t *lspv, float *lspf, qcelp_packet_rate rate)
 {
-    lspf[0]=        qcelp_lspvq1[lspv[0]].x;
-    lspf[1]=lspf[0]+qcelp_lspvq1[lspv[0]].y;
-    lspf[2]=lspf[1]+qcelp_lspvq2[lspv[1]].x;
-    lspf[3]=lspf[2]+qcelp_lspvq2[lspv[1]].y;
-    lspf[4]=lspf[3]+qcelp_lspvq3[lspv[2]].x;
-    lspf[5]=lspf[4]+qcelp_lspvq3[lspv[2]].y;
-    lspf[6]=lspf[5]+qcelp_lspvq4[lspv[3]].x;
-    lspf[7]=lspf[6]+qcelp_lspvq4[lspv[3]].y;
-    lspf[8]=lspf[7]+qcelp_lspvq5[lspv[4]].x;
-    lspf[9]=lspf[8]+qcelp_lspvq5[lspv[4]].y;
+    /* FIXME a loop is wanted here */
+    /* WIP implement rate 1/8 handling */
+    switch(rate)
+    {
+        case RATE_FULL:
+        case RATE_HALF:
+        case RATE_QUARTER:
+            lspf[0]=        qcelp_lspvq1[lspv[0]].x;
+            lspf[1]=lspf[0]+qcelp_lspvq1[lspv[0]].y;
+            lspf[2]=lspf[1]+qcelp_lspvq2[lspv[1]].x;
+            lspf[3]=lspf[2]+qcelp_lspvq2[lspv[1]].y;
+            lspf[4]=lspf[3]+qcelp_lspvq3[lspv[2]].x;
+            lspf[5]=lspf[4]+qcelp_lspvq3[lspv[2]].y;
+            lspf[6]=lspf[5]+qcelp_lspvq4[lspv[3]].x;
+            lspf[7]=lspf[6]+qcelp_lspvq4[lspv[3]].y;
+            lspf[8]=lspf[7]+qcelp_lspvq5[lspv[4]].x;
+            lspf[9]=lspf[8]+qcelp_lspvq5[lspv[4]].y;
+            break;
+        case RATE_OCTAVE:
+            break;
+    }
+}
+
+/**
+ * TIA/EIA/IS-733 2.4.6.2.2
+ */
+void qcelp_cbgain2g(const uint8_t *cbgain, int *g0, int *gs, int *g1, float *ga, qcelp_packet_rate rate)
+{
+    int i;
+    /* FIXME need better gX varnames */
+    /* WIP right now only decodes rate 1/4 */
+    switch(rate)
+    {
+        case RATE_QUARTER:
+            for(i=0; i<5; i++)
+                g0[i]=g1[i]=QCELP_CBGAIN2G0(cbgain[i]);
+                gs[i]=1;
+                ga[i]=qcelp_g12ga[g1[i]];
+            break;
+        case RATE_FULL:
+        case RATE_HALF:
+        case RATE_OCTAVE:
+            break;
+    }
 }
 
 static int qcelp_decode_frame(AVCodecContext *avctx, void *data,
@@ -107,10 +141,10 @@ static int qcelp_decode_frame(AVCodecCon
     const QCELPBitmap *order = NULL;
     int16_t  *outbuffer = data;
     int8_t   samples;
-    int      n;
+    int      n, is_ifq = 0;
     uint16_t first16 = 0; /*!< needed for rate 1/8 peculiarities */
-    int      is_ifq = 0;
-    float    qtzd_lspf[10];
+    float    qtzd_lspf[10], ga[16];
+    int      g0[16], gs[16], g1[16];
 
     init_get_bits(&q->gb, buf, buf_size*8);
 
@@ -184,13 +218,21 @@ static int qcelp_decode_frame(AVCodecCon
         is_ifq=1;
 
     /**
+     * Preliminary decoding of frame's transmission codes
+     */
+
+    qcelp_lspv2lspf(q->frame->data + QCELP_LSPV0_POS, qtzd_lspf,
+                    q->frame->rate);
+    qcelp_cbgain2g (q->frame->data + QCELP_CBGAIN0_POS, g0, gs, g1, ga,
+                    q->frame->rate);
+
+    /**
      * Check for badly received packets
      * TIA/EIA/IS-733 2.4.8.7.3
      */
 
     if(q->frame->rate != RATE_OCTAVE)
     {
-        qcelp_lspv2lspf(q->frame->data + QCELP_LSPV0_POS, qtzd_lspf);
 
         /* check for outbound LSP freqs and codebook gain params */
         if(q->frame->rate != RATE_QUARTER)
@@ -214,6 +256,12 @@ static int qcelp_decode_frame(AVCodecCon
                     is_ifq=1;
             }
             /* codebook gain sanity check */
+            for(n=0; !is_ifq && n<4; n++)
+            {
+                if(FFABS(g0[n+1]-g0[n]) > 40) is_ifq=1;
+                /* FIXME: spec with typing errors here? */
+                if(n<3 && FFABS(g0[n+2] - 2*g0[n+1] + g0[n]) > 48) is_ifq=1;
+            }
 
         }
     }



More information about the FFmpeg-soc mailing list