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

Jean-Marc Valin jm at xiph.org
Tue Oct 22 19:56:46 PDT 2002



jm          02/10/22 22:56:46

  Modified:    libspeex filters.c filters.h sb_celp.c
  Log:
  Modified QMF filters so we don't calculate useless (zeros) values.

Revision  Changes    Path
1.22      +68 -11    speex/libspeex/filters.c

Index: filters.c
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/filters.c,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -r1.21 -r1.22
--- filters.c	21 Oct 2002 20:39:38 -0000	1.21
+++ filters.c	23 Oct 2002 02:56:46 -0000	1.22
@@ -215,37 +215,94 @@
    fir_mem2(y, awk2, y, N, ord, mem);
 }
 
-
-
-#if 1
 #define MAX_FILTER 100
 #define MAX_SIGNAL 1000
-void fir_mem(float *xx, float *aa, float *y, int N, int M, float *mem)
+
+#if 1
+void qmf_decomp(float *xx, float *aa, float *y1, float *y2, int N, int M, float *mem)
 {
-   int i,j;
+   int i,j,k,M2;
+   /* FIXME: this should be dynamic */
    float a[MAX_FILTER];
    float x[MAX_SIGNAL];
+   float *x2=x+M-1;
+   M2=M>>1;
    for (i=0;i<M;i++)
       a[M-i-1]=aa[i];
    for (i=0;i<M-1;i++)
       x[i]=mem[M-i-2];
    for (i=0;i<N;i++)
       x[i+M-1]=xx[i];
-   for (i=0;i<N;i++)
+   for (i=0,k=0;i<N;i+=2,k++)
    {
-      y[i]=0;
-      for (j=0;j<M;j++)
-         y[i]+=a[j]*x[i+j];
+      y1[k]=0;
+      y2[k]=0;
+      for (j=0;j<M2;j++)
+      {
+         y1[k]+=a[j]*(x[i+j]+x2[i-j]);
+         y2[k]-=a[j]*(x[i+j]-x2[i-j]);
+         j++;
+         y1[k]+=a[j]*(x[i+j]+x2[i-j]);
+         y2[k]+=a[j]*(x[i+j]-x2[i-j]);
+      }
    }
    for (i=0;i<M-1;i++)
      mem[i]=xx[N-i-1];
 }
 #else
-void fir_mem(float *xx, float *aa, float *y, int N, int M, float *mem)
+void qmf_decomp(float *xx, float *aa, float *bb, float *y1, float *y2, int N, int M, float *mem)
 {
-   fir_mem2(xx, aa, y, N, M-1, mem);
+   int i,j,k;
+   float a[MAX_FILTER];
+   float b[MAX_FILTER];
+   float x[MAX_SIGNAL];
+   for (i=0;i<M;i++)
+      a[M-i-1]=aa[i];
+   for (i=0;i<M;i++)
+      b[M-i-1]=bb[i];
+   for (i=0;i<M-1;i++)
+      x[i]=mem[M-i-2];
+   for (i=0;i<N;i++)
+      x[i+M-1]=xx[i];
+   for (i=0,k=0;i<N;i+=2,k++)
+   {
+      y1[k]=0;
+      for (j=0;j<M;j++)
+         y1[k]+=a[j]*x[i+j];
+      y2[k]=0;
+      for (j=0;j<M;j++)
+         y2[k]+=b[j]*x[i+j];
+   }
+   for (i=0;i<M-1;i++)
+     mem[i]=xx[N-i-1];
 }
 #endif
+
+void fir_decim_mem(float *xx, float *aa, float *y, int N, int M, float *mem)
+{
+   int i,j,M2;
+   float a[MAX_FILTER];
+   float x[MAX_SIGNAL];
+   M2=M>>1;
+   for (i=0;i<M;i++)
+      a[M-i-1]=aa[i];
+   for (i=0;i<M-1;i++)
+      x[i]=mem[M-i-2];
+   for (i=0;i<N;i++)
+      x[i+M-1]=xx[i];
+   for (i=0;i<N;i++)
+   {
+      y[i]=0;
+      for (j=1;j<M;j+=2)
+         y[i]+=a[j]*x[i+j];
+      i++;
+      y[i]=0;
+      for (j=0;j<M;j+=2)
+         y[i]+=a[j]*x[i+j];
+   }
+   for (i=0;i<M-1;i++)
+     mem[i]=xx[N-i-1];
+}
 
 void comb_filter(
 float *exc,          /*decoded excitation*/

<p><p>1.17      +4 -1      speex/libspeex/filters.h

Index: filters.h
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/filters.h,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- filters.h	21 Oct 2002 20:39:38 -0000	1.16
+++ filters.h	23 Oct 2002 02:56:46 -0000	1.17
@@ -33,6 +33,8 @@
 #ifndef FILTERS_H
 #define FILTERS_H
 
+void qmf_decomp(float *xx, float *aa, float *y1, float *y2, int N, int M, float *mem);
+
 void print_vec(float *vec, int len, char *name);
 
 void filter_mem2(float *x, float *num, float *den, float *y, int N, int ord, float *mem);
@@ -59,8 +61,9 @@
 
 
 
+
 /* FIR filter */
-void fir_mem(float *x, float *a, float *y, int N, int M, float *mem);
+void fir_decim_mem(float *x, float *a, float *y, int N, int M, float *mem);
 
 void syn_percep_zero(float *x, float *ak, float *awk1, float *awk2, float *y, int N, int ord, float *stack);
 

<p><p>1.76      +15 -12    speex/libspeex/sb_celp.c

Index: sb_celp.c
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/sb_celp.c,v
retrieving revision 1.75
retrieving revision 1.76
diff -u -r1.75 -r1.76
--- sb_celp.c	21 Oct 2002 20:39:38 -0000	1.75
+++ sb_celp.c	23 Oct 2002 02:56:46 -0000	1.76
@@ -276,16 +276,19 @@
    stack=st->stack;
 
    /* Compute the two sub-bands by filtering with h0 and h1*/
+#if 0
    fir_mem(in, h0, st->x0, st->full_frame_size, QMF_ORDER, st->h0_mem);
    fir_mem(in, h1, st->x1, st->full_frame_size, QMF_ORDER, st->h1_mem);
-
+   
    /* Down-sample x0 and x1 */
    for (i=0;i<st->frame_size;i++)
       st->x1d[i]=st->x1[i<<1];
 
    for (i=0;i<st->frame_size;i++)
       st->x0d[i]=st->x0[i<<1];
-
+#else
+   qmf_decomp(in, h0, st->x0d, st->x1d, st->full_frame_size, QMF_ORDER, st->h0_mem);
+#endif
    /* Encode the narrowband part*/
    nb_encode(st->st_low, st->x0d, bits);
 
@@ -361,8 +364,8 @@
          st->x1[(i<<1)+1]=0;
       }
       /* Reconstruct the original */
-      fir_mem(st->x0, h0, st->y0, st->full_frame_size, QMF_ORDER, st->g0_mem);
-      fir_mem(st->x1, h1, st->y1, st->full_frame_size, QMF_ORDER, st->g1_mem);
+      fir_decim_mem(st->x0, h0, st->y0, st->full_frame_size, QMF_ORDER, st->g0_mem);
+      fir_decim_mem(st->x1, h1, st->y1, st->full_frame_size, QMF_ORDER, st->g1_mem);
       for (i=0;i<st->full_frame_size;i++)
          in[i]=2*(st->y0[i]-st->y1[i]);
 #endif
@@ -627,8 +630,8 @@
       st->x1[(i<<1)+1]=0;
    }
    /* Reconstruct the original */
-   fir_mem(st->x0, h0, st->y0, st->full_frame_size, QMF_ORDER, st->g0_mem);
-   fir_mem(st->x1, h1, st->y1, st->full_frame_size, QMF_ORDER, st->g1_mem);
+   fir_decim_mem(st->x0, h0, st->y0, st->full_frame_size, QMF_ORDER, st->g0_mem);
+   fir_decim_mem(st->x1, h1, st->y1, st->full_frame_size, QMF_ORDER, st->g1_mem);
    for (i=0;i<st->full_frame_size;i++)
       in[i]=2*(st->y0[i]-st->y1[i]);
 #endif
@@ -739,8 +742,8 @@
       st->x1[(i<<1)+1]=0;
    }
    /* Reconstruct the original */
-   fir_mem(st->x0, h0, st->y0, st->full_frame_size, QMF_ORDER, st->g0_mem);
-   fir_mem(st->x1, h1, st->y1, st->full_frame_size, QMF_ORDER, st->g1_mem);
+   fir_decim_mem(st->x0, h0, st->y0, st->full_frame_size, QMF_ORDER, st->g0_mem);
+   fir_decim_mem(st->x1, h1, st->y1, st->full_frame_size, QMF_ORDER, st->g1_mem);
    for (i=0;i<st->full_frame_size;i++)
       out[i]=2*(st->y0[i]-st->y1[i]);
    
@@ -809,8 +812,8 @@
          st->x1[(i<<1)+1]=0;
       }
       /* Reconstruct the original */
-      fir_mem(st->x0, h0, st->y0, st->full_frame_size, QMF_ORDER, st->g0_mem);
-      fir_mem(st->x1, h1, st->y1, st->full_frame_size, QMF_ORDER, st->g1_mem);
+      fir_decim_mem(st->x0, h0, st->y0, st->full_frame_size, QMF_ORDER, st->g0_mem);
+      fir_decim_mem(st->x1, h1, st->y1, st->full_frame_size, QMF_ORDER, st->g1_mem);
       for (i=0;i<st->full_frame_size;i++)
          out[i]=2*(st->y0[i]-st->y1[i]);
 
@@ -928,8 +931,8 @@
       st->x1[(i<<1)+1]=0;
    }
    /* Reconstruct the original */
-   fir_mem(st->x0, h0, st->y0, st->full_frame_size, QMF_ORDER, st->g0_mem);
-   fir_mem(st->x1, h1, st->y1, st->full_frame_size, QMF_ORDER, st->g1_mem);
+   fir_decim_mem(st->x0, h0, st->y0, st->full_frame_size, QMF_ORDER, st->g0_mem);
+   fir_decim_mem(st->x1, h1, st->y1, st->full_frame_size, QMF_ORDER, st->g1_mem);
    for (i=0;i<st->full_frame_size;i++)
       out[i]=2*(st->y0[i]-st->y1[i]);
 

<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