Remove svn $Id$ header.
[platform/upstream/libvorbis.git] / lib / smallft.c
index dcbd72c..6d528af 100644 (file)
@@ -1,20 +1,18 @@
 /********************************************************************
  *                                                                  *
- * THIS FILE IS PART OF THE Ogg Vorbis SOFTWARE CODEC SOURCE CODE.  *
- * USE, DISTRIBUTION AND REPRODUCTION OF THIS SOURCE IS GOVERNED BY *
- * THE GNU PUBLIC LICENSE 2, WHICH IS INCLUDED WITH THIS SOURCE.    *
- * PLEASE READ THESE TERMS DISTRIBUTING.                            *
+ * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE.   *
+ * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS     *
+ * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
+ * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING.       *
  *                                                                  *
- * THE OggSQUISH SOURCE CODE IS (C) COPYRIGHT 1994-2000             *
- * by Monty <monty@xiph.org> and The XIPHOPHORUS Company            *
- * http://www.xiph.org/                                             *
+ * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2009             *
+ * by the Xiph.Org Foundation http://www.xiph.org/                  *
  *                                                                  *
  ********************************************************************
 
  function: *unnormalized* fft transform
- last mod: $Id: smallft.c,v 1.7 2000/02/09 22:04:16 xiphmont Exp $
 
-********************************************************************/
+ ********************************************************************/
 
 /* FFT implementation from OggSquish, minus cosine transforms,
  * minus all but radix 2/4 case.  In Vorbis we only need this
 #include <string.h>
 #include <math.h>
 #include "smallft.h"
+#include "os.h"
+#include "misc.h"
 
-static void drfti1(int n, double *wa, int *ifac){
+static void drfti1(int n, float *wa, int *ifac){
   static int ntryh[4] = { 4,2,3,5 };
-  static double tpi = 6.28318530717958647692528676655900577;
-  double arg,argh,argld,fi;
+  static float tpi = 6.28318530717958648f;
+  float arg,argh,argld,fi;
   int ntry=0,i,j=-1;
   int k1, l1, l2, ib;
   int ld, ii, ip, is, nq, nr;
@@ -90,13 +90,13 @@ static void drfti1(int n, double *wa, int *ifac){
     for (j=0;j<ipm;j++){
       ld+=l1;
       i=is;
-      argld=(double)ld*argh;
-      fi=0.;
+      argld=(float)ld*argh;
+      fi=0.f;
       for (ii=2;ii<ido;ii+=2){
-       fi+=1.;
-       arg=fi*argld;
-       wa[i++]=cos(arg);
-       wa[i++]=sin(arg);
+        fi+=1.f;
+        arg=fi*argld;
+        wa[i++]=cos(arg);
+        wa[i++]=sin(arg);
       }
       is+=ido;
     }
@@ -104,15 +104,15 @@ static void drfti1(int n, double *wa, int *ifac){
   }
 }
 
-static void fdrffti(int n, double *wsave, int *ifac){
+static void fdrffti(int n, float *wsave, int *ifac){
 
   if (n == 1) return;
   drfti1(n, wsave+n, ifac);
 }
 
-static void dradf2(int ido,int l1,double *cc,double *ch,double *wa1){
+static void dradf2(int ido,int l1,float *cc,float *ch,float *wa1){
   int i,k;
-  double ti2,tr2;
+  float ti2,tr2;
   int t0,t1,t2,t3,t4,t5,t6;
 
   t1=0;
@@ -124,7 +124,7 @@ static void dradf2(int ido,int l1,double *cc,double *ch,double *wa1){
     t1+=ido;
     t2+=ido;
   }
-    
+
   if(ido<2)return;
   if(ido==2)goto L105;
 
@@ -165,13 +165,13 @@ static void dradf2(int ido,int l1,double *cc,double *ch,double *wa1){
   }
 }
 
-static void dradf4(int ido,int l1,double *cc,double *ch,double *wa1,
-           double *wa2,double *wa3){
-  static double hsqt2 = .70710678118654752440084436210485;
+static void dradf4(int ido,int l1,float *cc,float *ch,float *wa1,
+            float *wa2,float *wa3){
+  static float hsqt2 = .70710678118654752f;
   int i,k,t0,t1,t2,t3,t4,t5,t6;
-  double ci2,ci3,ci4,cr2,cr3,cr4,ti1,ti2,ti3,ti4,tr1,tr2,tr3,tr4;
+  float ci2,ci3,ci4,cr2,cr3,cr4,ti1,ti2,ti3,ti4,tr1,tr2,tr3,tr4;
   t0=l1*ido;
-  
+
   t1=t0;
   t4=t1<<1;
   t2=t1+(t1<<1);
@@ -243,7 +243,7 @@ static void dradf4(int ido,int l1,double *cc,double *ch,double *wa1,
   if(ido&1)return;
 
  L105:
-  
+
   t2=(t1=t0+ido-1)+(t0<<1);
   t3=ido<<2;
   t4=ido;
@@ -267,18 +267,18 @@ static void dradf4(int ido,int l1,double *cc,double *ch,double *wa1,
   }
 }
 
-static void dradfg(int ido,int ip,int l1,int idl1,double *cc,double *c1,
-                          double *c2,double *ch,double *ch2,double *wa){
+static void dradfg(int ido,int ip,int l1,int idl1,float *cc,float *c1,
+                          float *c2,float *ch,float *ch2,float *wa){
 
-  static double tpi=6.28318530717958647692528676655900577;
+  static float tpi=6.283185307179586f;
   int idij,ipph,i,j,k,l,ic,ik,is;
   int t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10;
-  double dc2,ai1,ai2,ar1,ar2,ds2;
+  float dc2,ai1,ai2,ar1,ar2,ds2;
   int nbd;
-  double dcp,arg,dsp,ar1h,ar2h;
+  float dcp,arg,dsp,ar1h,ar2h;
   int idp2,ipp2;
-  
-  arg=tpi/(double)ip;
+
+  arg=tpi/(float)ip;
   dcp=cos(arg);
   dsp=sin(arg);
   ipph=(ip+1)>>1;
@@ -404,8 +404,8 @@ L119:
     }
   }
 
-  ar1=1.;
-  ai1=0.;
+  ar1=1.f;
+  ai1=0.f;
   t1=0;
   t2=ipp2*idl1;
   t3=(ip-1)*idl1;
@@ -569,7 +569,7 @@ L119:
   }
 }
 
-static void drftf1(int n,double *c,double *ch,double *wa,int *ifac){
+static void drftf1(int n,float *c,float *ch,float *wa,int *ifac){
   int i,k1,l1,l2;
   int na,kh,nf;
   int ip,iw,ido,idl1,ix2,ix3;
@@ -630,12 +630,12 @@ static void drftf1(int n,double *c,double *ch,double *wa,int *ifac){
   for(i=0;i<n;i++)c[i]=ch[i];
 }
 
-static void dradb2(int ido,int l1,double *cc,double *ch,double *wa1){
+static void dradb2(int ido,int l1,float *cc,float *ch,float *wa1){
   int i,k,t0,t1,t2,t3,t4,t5,t6;
-  double ti2,tr2;
+  float ti2,tr2;
 
   t0=l1*ido;
-  
+
   t1=0;
   t2=0;
   t3=(ido<<1)-1;
@@ -682,12 +682,12 @@ L105:
   }
 }
 
-static void dradb3(int ido,int l1,double *cc,double *ch,double *wa1,
-                          double *wa2){
-  static double taur = -.5;
-  static double taui = .86602540378443864676372317075293618;
+static void dradb3(int ido,int l1,float *cc,float *ch,float *wa1,
+                          float *wa2){
+  static float taur = -.5f;
+  static float taui = .8660254037844386f;
   int i,k,t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10;
-  double ci2,ci3,di2,di3,cr2,cr3,dr2,dr3,ti2,tr2;
+  float ci2,ci3,di2,di3,cr2,cr3,dr2,dr3,ti2,tr2;
   t0=l1*ido;
 
   t1=0;
@@ -745,13 +745,13 @@ static void dradb3(int ido,int l1,double *cc,double *ch,double *wa1,
   }
 }
 
-static void dradb4(int ido,int l1,double *cc,double *ch,double *wa1,
-                         double *wa2,double *wa3){
-  static double sqrt2=1.4142135623730950488016887242097;
+static void dradb4(int ido,int l1,float *cc,float *ch,float *wa1,
+                          float *wa2,float *wa3){
+  static float sqrt2=1.414213562373095f;
   int i,k,t0,t1,t2,t3,t4,t5,t6,t7,t8;
-  double ci2,ci3,ci4,cr2,cr3,cr4,ti1,ti2,ti3,ti4,tr1,tr2,tr3,tr4;
+  float ci2,ci3,ci4,cr2,cr3,cr4,ti1,ti2,ti3,ti4,tr1,tr2,tr3,tr4;
   t0=l1*ido;
-  
+
   t1=0;
   t2=ido<<2;
   t3=0;
@@ -760,7 +760,7 @@ static void dradb4(int ido,int l1,double *cc,double *ch,double *wa1,
     t4=t3+t6;
     t5=t1;
     tr3=cc[t4-1]+cc[t4-1];
-    tr4=cc[t4]+cc[t4]; 
+    tr4=cc[t4]+cc[t4];
     tr1=cc[t3]-cc[(t4+=t6)-1];
     tr2=cc[t3]+cc[t4-1];
     ch[t5]=tr2+tr3;
@@ -836,26 +836,26 @@ static void dradb4(int ido,int l1,double *cc,double *ch,double *wa1,
   }
 }
 
-static void dradbg(int ido,int ip,int l1,int idl1,double *cc,double *c1,
-            double *c2,double *ch,double *ch2,double *wa){
-  static double tpi=6.28318530717958647692528676655900577;
+static void dradbg(int ido,int ip,int l1,int idl1,float *cc,float *c1,
+            float *c2,float *ch,float *ch2,float *wa){
+  static float tpi=6.283185307179586f;
   int idij,ipph,i,j,k,l,ik,is,t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,
       t11,t12;
-  double dc2,ai1,ai2,ar1,ar2,ds2;
+  float dc2,ai1,ai2,ar1,ar2,ds2;
   int nbd;
-  double dcp,arg,dsp,ar1h,ar2h;
+  float dcp,arg,dsp,ar1h,ar2h;
   int ipp2;
 
   t10=ip*ido;
   t0=l1*ido;
-  arg=tpi/(double)ip;
+  arg=tpi/(float)ip;
   dcp=cos(arg);
   dsp=sin(arg);
   nbd=(ido-1)>>1;
   ipp2=ip;
   ipph=(ip+1)>>1;
   if(ido<l1)goto L103;
-  
+
   t1=0;
   t2=0;
   for(k=0;k<l1;k++){
@@ -975,8 +975,8 @@ static void dradbg(int ido,int ip,int l1,int idl1,double *cc,double *c1,
   }
 
 L116:
-  ar1=1.;
-  ai1=0.;
+  ar1=1.f;
+  ai1=0.f;
   t1=0;
   t9=(t2=ipp2*idl1);
   t3=(ip-1)*idl1;
@@ -1150,7 +1150,7 @@ L132:
   }
 }
 
-static void drftb1(int n, double *c, double *ch, double *wa, int *ifac){
+static void drftb1(int n, float *c, float *ch, float *wa, int *ifac){
   int i,k1,l1,l2;
   int na;
   int nf,ip,iw,ix2,ix3,ido,idl1;
@@ -1228,27 +1228,27 @@ static void drftb1(int n, double *c, double *ch, double *wa, int *ifac){
   for(i=0;i<n;i++)c[i]=ch[i];
 }
 
-void drft_forward(drft_lookup *l,double *data){
+void drft_forward(drft_lookup *l,float *data){
   if(l->n==1)return;
   drftf1(l->n,data,l->trigcache,l->trigcache+l->n,l->splitcache);
 }
 
-void drft_backward(drft_lookup *l,double *data){
+void drft_backward(drft_lookup *l,float *data){
   if (l->n==1)return;
   drftb1(l->n,data,l->trigcache,l->trigcache+l->n,l->splitcache);
 }
 
 void drft_init(drft_lookup *l,int n){
   l->n=n;
-  l->trigcache=calloc(3*n,sizeof(double));
-  l->splitcache=calloc(32,sizeof(int));
+  l->trigcache=_ogg_calloc(3*n,sizeof(*l->trigcache));
+  l->splitcache=_ogg_calloc(32,sizeof(*l->splitcache));
   fdrffti(n, l->trigcache, l->splitcache);
 }
 
 void drft_clear(drft_lookup *l){
   if(l){
-    if(l->trigcache)free(l->trigcache);
-    if(l->splitcache)free(l->splitcache);
-    memset(l,0,sizeof(drft_lookup));
+    if(l->trigcache)_ogg_free(l->trigcache);
+    if(l->splitcache)_ogg_free(l->splitcache);
+    memset(l,0,sizeof(*l));
   }
 }