[xiph-commits] r12343 - trunk/speex/libspeex

jm at svn.xiph.org jm at svn.xiph.org
Thu Jan 18 02:38:08 PST 2007


Author: jm
Date: 2007-01-18 02:38:06 -0800 (Thu, 18 Jan 2007)
New Revision: 12343

Modified:
   trunk/speex/libspeex/resample.c
Log:
fixed the alignment of the sinc and removed the if() from the main loop. 
Upsampling seems to work good.


Modified: trunk/speex/libspeex/resample.c
===================================================================
--- trunk/speex/libspeex/resample.c	2007-01-18 00:33:01 UTC (rev 12342)
+++ trunk/speex/libspeex/resample.c	2007-01-18 10:38:06 UTC (rev 12343)
@@ -1,33 +1,33 @@
 /* Copyright (C) 2007 Jean-Marc Valin
       
    File: resample.c
-   Resample code
+   Resampling code
 
-      Redistribution and use in source and binary forms, with or without
-      modification, are permitted provided that the following conditions are
+   Redistribution and use in source and binary forms, with or without
+   modification, are permitted provided that the following conditions are
    met:
 
-      1. Redistributions of source code must retain the above copyright notice,
-      this list of conditions and the following disclaimer.
+   1. Redistributions of source code must retain the above copyright notice,
+   this list of conditions and the following disclaimer.
 
-      2. Redistributions in binary form must reproduce the above copyright
-      notice, this list of conditions and the following disclaimer in the
-      documentation and/or other materials provided with the distribution.
+   2. Redistributions in binary form must reproduce the above copyright
+   notice, this list of conditions and the following disclaimer in the
+   documentation and/or other materials provided with the distribution.
 
-      3. The name of the author may not be used to endorse or promote products
-      derived from this software without specific prior written permission.
+   3. The name of the author may not be used to endorse or promote products
+   derived from this software without specific prior written permission.
 
-      THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
-      IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
-      OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-      DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
-      INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-      (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-      SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-      HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
-      STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
-      ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
-      POSSIBILITY OF SUCH DAMAGE.
+   THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+   IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+   OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+   DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
+   INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+   (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+   SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+   HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+   STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+   ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+   POSSIBILITY OF SUCH DAMAGE.
 */
 
 #include "misc.h"
@@ -82,10 +82,12 @@
 
 static float sinc(float x, int N)
 {
+   //fprintf (stderr, "%f ", x);
    if (fabs(x)<1e-6)
       return 1;
    else if (fabs(x) > .5f*N)
       return 0;
+   /*FIXME: Can it really be any slower than this? */
    return sin(M_PI*x)/(M_PI*x) * (.5+.5*cos(2*x*M_PI/N));
 }
 
@@ -98,13 +100,16 @@
    {
       int j;
       float sum=0;
-      for (j=0;j<N;j++)
+      /* Do the memory part */
+      for (j=0;st->last_sample-N+1+j < 0;j++)
       {
-         if (st->last_sample-N+1+j < 0)
-            sum += st->mem[st->last_sample+j]*sinc((j-N/2)-((float)st->samp_frac_num)/st->den_rate, N);
-         else
-            sum += in[st->last_sample-N+1+j]*sinc((j-N/2)-((float)st->samp_frac_num)/st->den_rate, N);
+         sum += st->mem[st->last_sample+j]*sinc((j-N/2+1)-((float)st->samp_frac_num)/st->den_rate, N);
       }
+      /* Do the new part */
+      for (;j<N;j++)
+      {
+         sum += in[st->last_sample-N+1+j]*sinc((j-N/2+1)-((float)st->samp_frac_num)/st->den_rate, N);
+      }
       out[out_sample++] = sum;
       
       st->last_sample += st->num_rate/st->den_rate;
@@ -153,6 +158,7 @@
          out[i]=fout[i];
       fwrite(out, sizeof(short), out_num, stdout);
    }
+   speex_resampler_destroy(st);
    speex_free(in);
    speex_free(out);
    speex_free(fin);



More information about the commits mailing list