[xiph-cvs] cvs commit: speex/libspeex sb_celp.c testenc.c

Jean-Marc Valin jm at xiph.org
Tue Oct 7 21:37:24 PDT 2003



jm          03/10/08 00:37:23

  Modified:    libspeex sb_celp.c testenc.c
  Log:
  fixed-point: signal scaling... again

Revision  Changes    Path
1.130     +36 -18    speex/libspeex/sb_celp.c

Index: sb_celp.c
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/sb_celp.c,v
retrieving revision 1.129
retrieving revision 1.130
diff -u -r1.129 -r1.130
--- sb_celp.c	8 Oct 2003 04:33:36 -0000	1.129
+++ sb_celp.c	8 Oct 2003 04:37:23 -0000	1.130
@@ -43,6 +43,8 @@
 #include "ltp.h"
 #include "misc.h"
 
+#include <stdio.h>
+
 #ifndef M_PI
 #define M_PI           3.14159265358979323846  /* pi */
 #endif
@@ -252,6 +254,11 @@
    /* Encode the narrowband part*/
    speex_encode(st->st_low, st->x0d, bits);
 
+   for (i=0;i<st->frame_size;i++)
+      st->x0d[i] *= SIG_SCALING;
+   for (i=0;i<st->frame_size;i++)
+      st->x1d[i] *= SIG_SCALING;
+
    /* High-band buffering / sync with low band */
    for (i=0;i<st->windowSize-st->frame_size;i++)
       st->high[i] = st->high[st->frame_size+i];
@@ -277,7 +284,7 @@
 
    /* Start encoding the high-band */
    for (i=0;i<st->windowSize;i++)
-      st->buf[i] = st->high[i] * st->window[i];
+      st->buf[i] = st->high[i] * st->window[i] / SIG_SCALING;
 
    /* Compute auto-correlation */
    _spx_autocorr(st->buf, st->autocorr, st->lpcSize+1, st->windowSize);
@@ -336,8 +343,9 @@
 
       for (i=0;i<st->frame_size;i++)
       {
-         e_low  += st->x0d[i]* st->x0d[i];
-         e_high += st->high[i]* st->high[i];
+         /*FIXME: Are the two signals (low, high) in sync? */
+         e_low  += st->x0d[i]* st->x0d[i] / (SIG_SCALING*SIG_SCALING);
+         e_high += st->high[i]* st->high[i] / (SIG_SCALING*SIG_SCALING);
       }
       ratio = log((1+e_high)/(1+e_low));
       speex_encoder_ctl(st->st_low, SPEEX_GET_RELATIVE_QUALITY, &st->relative_quality);
@@ -420,7 +428,7 @@
       fir_mem_up(st->high, h1, st->y1, st->full_frame_size, QMF_ORDER, st->g1_mem, stack);
 
       for (i=0;i<st->full_frame_size;i++)
-         in[i]=2*(st->y0[i]-st->y1[i]);
+         in[i]=2*(st->y0[i]-st->y1[i]) / SIG_SCALING;
 #endif
 
       if (dtx)
@@ -510,13 +518,13 @@
       fir_mem2(sp, st->interp_qlpc, exc, st->subframeSize, st->lpcSize, st->mem_sp2);
       /* Compute energy of low-band and high-band excitation */
       for (i=0;i<st->subframeSize;i++)
-         eh+=sqr(exc[i]);
+         eh+=sqr(exc[i]/SIG_SCALING);
 
       if (!SUBMODE(innovation_quant)) {/* 1 for spectral folding excitation, 0 for stochastic */
          float g;
          /*speex_bits_pack(bits, 1, 1);*/
          for (i=0;i<st->subframeSize;i++)
-            el+=sqr(low_innov[offset+i]);
+            el+=sqr(low_innov[offset+i]/SIG_SCALING);
 
          /* Gain to use if we want to use the low-band excitation for high-band */
          g=eh/(.01+el);
@@ -542,7 +550,7 @@
          float gc, scale, scale_1;
 
          for (i=0;i<st->subframeSize;i++)
-            el+=sqr(low_exc[offset+i]);
+            el+=sqr(low_exc[offset+i]/SIG_SCALING);
          /*speex_bits_pack(bits, 0, 1);*/
 
          gc = sqrt(1+eh)*filter_ratio/sqrt((1+el)*st->subframeSize);
@@ -561,7 +569,7 @@
 
          for (i=0;i<st->subframeSize;i++)
             exc[i]=0;
-         exc[0]=1;
+         exc[0]=SIG_SCALING;
          syn_percep_zero(exc, st->interp_qlpc, st->bw_lpc1, st->bw_lpc2, syn_resp, st->subframeSize, st->lpcSize, stack);
          
          /* Reset excitation */
@@ -591,8 +599,12 @@
 
 
          for (i=0;i<st->subframeSize;i++)
-            target[i]*=scale_1;
-         
+            target[i]*=scale_1/SIG_SCALING;
+
+         FLOAT_SIGNAL;
+         for (i=0;i<st->subframeSize;i++)
+            syn_resp[i]/=SIG_SCALING;
+
          /* Reset excitation */
          for (i=0;i<st->subframeSize;i++)
             innov[i]=0;
@@ -604,7 +616,7 @@
          /*print_vec(target, st->subframeSize, "after");*/
 
          for (i=0;i<st->subframeSize;i++)
-            exc[i] += innov[i]*scale;
+            exc[i] += innov[i]*scale*SIG_SCALING;
 
          if (SUBMODE(double_codebook)) {
             char *tmp_stack=stack;
@@ -617,11 +629,15 @@
                                       SUBMODE(innovation_params), st->lpcSize, st->subframeSize, 
                                       innov2, syn_resp, bits, tmp_stack, (st->complexity+1)>>1);
             for (i=0;i<st->subframeSize;i++)
-               innov2[i]*=scale*(1/2.5);
+               innov2[i]*=scale*(1/2.5)*SIG_SCALING;
             for (i=0;i<st->subframeSize;i++)
                exc[i] += innov2[i];
          }
 
+         FIXED_SIGNAL;
+         for (i=0;i<st->subframeSize;i++)
+            syn_resp[i]/=SIG_SCALING;
+
       }
 
          /*Keep the previous memory*/
@@ -642,7 +658,7 @@
    fir_mem_up(st->high, h1, st->y1, st->full_frame_size, QMF_ORDER, st->g1_mem, stack);
 
    for (i=0;i<st->full_frame_size;i++)
-      in[i]=2*(st->y0[i]-st->y1[i]);
+      in[i]=2*(st->y0[i]-st->y1[i]) / SIG_SCALING;
 #endif
    for (i=0;i<st->lpcSize;i++)
       st->old_lsp[i] = st->lsp[i];
@@ -829,6 +845,9 @@
    /* Decode the low-band */
    ret = speex_decode(st->st_low, bits, st->x0d);
 
+   for (i=0;i<st->frame_size;i++)
+      st->x0d[i] *= SIG_SCALING;
+
    speex_decoder_ctl(st->st_low, SPEEX_GET_DTX_STATUS, &dtx);
 
    /* If error decoding the narrowband part, propagate error */
@@ -889,7 +908,7 @@
       fir_mem_up(st->high, h1, st->y1, st->full_frame_size, QMF_ORDER, st->g1_mem, stack);
 
       for (i=0;i<st->full_frame_size;i++)
-         out[i]=2*(st->y0[i]-st->y1[i]);
+         out[i]=2*(st->y0[i]-st->y1[i]) / SIG_SCALING;
 
       return 0;
 
@@ -991,7 +1010,7 @@
          int quant;
 
          for (i=0;i<st->subframeSize;i++)
-            el+=sqr(low_innov[offset+i]);
+            el+=sqr(low_innov[offset+i]/SIG_SCALING);
          quant = speex_bits_unpack_unsigned(bits, 5);
          g= exp(((float)quant-10)/8.0);
          
@@ -1006,14 +1025,13 @@
          float gc, scale;
          int qgc = speex_bits_unpack_unsigned(bits, 4);
          for (i=0;i<st->subframeSize;i++)
-            el+=sqr(low_exc[offset+i]);
+            el+=sqr(low_exc[offset+i]/SIG_SCALING);
 
 
          gc = exp((1/3.7)*qgc-2);
 
          scale = gc*sqrt(1+el)/filter_ratio;
 
-
          SUBMODE(innovation_unquant)(exc, SUBMODE(innovation_params), st->subframeSize, 
                                 bits, stack);
          for (i=0;i<st->subframeSize;i++)
@@ -1058,7 +1076,7 @@
    fir_mem_up(st->high, h1, st->y1, st->full_frame_size, QMF_ORDER, st->g1_mem, stack);
 
    for (i=0;i<st->full_frame_size;i++)
-      out[i]=2*(st->y0[i]-st->y1[i]);
+      out[i]=2*(st->y0[i]-st->y1[i]) / SIG_SCALING;
 
    for (i=0;i<st->lpcSize;i++)
       st->old_qlsp[i] = st->qlsp[i];

<p><p>1.47      +1 -1      speex/libspeex/testenc.c

Index: testenc.c
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/testenc.c,v
retrieving revision 1.46
retrieving revision 1.47
diff -u -r1.46 -r1.47
--- testenc.c	8 Oct 2003 04:27:51 -0000	1.46
+++ testenc.c	8 Oct 2003 04:37:23 -0000	1.47
@@ -46,7 +46,7 @@
    speex_decoder_ctl(dec, SPEEX_SET_ENH, &tmp);
    tmp=0;
    speex_encoder_ctl(st, SPEEX_SET_VBR, &tmp);
-   tmp=4;
+   tmp=10;
    speex_encoder_ctl(st, SPEEX_SET_QUALITY, &tmp);
    tmp=5;
    speex_encoder_ctl(st, SPEEX_SET_COMPLEXITY, &tmp);

<p><p>--- >8 ----
List archives:  http://www.xiph.org/archives/
Ogg project homepage: http://www.xiph.org/ogg/
To unsubscribe from this list, send a message to 'cvs-request at xiph.org'
containing only the word 'unsubscribe' in the body.  No subject is needed.
Unsubscribe messages sent to the list will be ignored/filtered.



More information about the commits mailing list