examples/SFExamples/oggvorbiscodec94/src/libvorbis/lib/smallft.c

00001 /********************************************************************
00002  *                                                                  *
00003  * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE.   *
00004  * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS     *
00005  * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
00006  * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING.       *
00007  *                                                                  *
00008  * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2002             *
00009  * by the XIPHOPHORUS Company http://www.xiph.org/                  *
00010  *                                                                  *
00011  ********************************************************************
00012 
00013  function: *unnormalized* fft transform
00014  last mod: $Id: smallft.c 7573 2004-08-16 01:26:52Z conrad $
00015 
00016  ********************************************************************/
00017 
00018 /* FFT implementation from OggSquish, minus cosine transforms,
00019  * minus all but radix 2/4 case.  In Vorbis we only need this
00020  * cut-down version.
00021  *
00022  * To do more than just power-of-two sized vectors, see the full
00023  * version I wrote for NetLib.
00024  *
00025  * Note that the packing is a little strange; rather than the FFT r/i
00026  * packing following R_0, I_n, R_1, I_1, R_2, I_2 ... R_n-1, I_n-1,
00027  * it follows R_0, R_1, I_1, R_2, I_2 ... R_n-1, I_n-1, I_n like the
00028  * FORTRAN version
00029  */
00030 
00031 #include <stdlib.h>
00032 #include <string.h>
00033 #include <math.h>
00034 #include "smallft.h"
00035 #include "os.h"
00036 #include "misc.h"
00037 
00038 static void drfti1(int n, float *wa, int *ifac){
00039   static int ntryh[4] = { 4,2,3,5 };
00040   static float tpi = 6.28318530717958648f;
00041   float arg,argh,argld,fi;
00042   int ntry=0,i,j=-1;
00043   int k1, l1, l2, ib;
00044   int ld, ii, ip, is, nq, nr;
00045   int ido, ipm, nfm1;
00046   int nl=n;
00047   int nf=0;
00048 
00049  L101:
00050   j++;
00051   if (j < 4)
00052     ntry=ntryh[j];
00053   else
00054     ntry+=2;
00055 
00056  L104:
00057   nq=nl/ntry;
00058   nr=nl-ntry*nq;
00059   if (nr!=0) goto L101;
00060 
00061   nf++;
00062   ifac[nf+1]=ntry;
00063   nl=nq;
00064   if(ntry!=2)goto L107;
00065   if(nf==1)goto L107;
00066 
00067   for (i=1;i<nf;i++){
00068     ib=nf-i+1;
00069     ifac[ib+1]=ifac[ib];
00070   }
00071   ifac[2] = 2;
00072 
00073  L107:
00074   if(nl!=1)goto L104;
00075   ifac[0]=n;
00076   ifac[1]=nf;
00077   argh=tpi/n;
00078   is=0;
00079   nfm1=nf-1;
00080   l1=1;
00081 
00082   if(nfm1==0)return;
00083 
00084   for (k1=0;k1<nfm1;k1++){
00085     ip=ifac[k1+2];
00086     ld=0;
00087     l2=l1*ip;
00088     ido=n/l2;
00089     ipm=ip-1;
00090 
00091     for (j=0;j<ipm;j++){
00092       ld+=l1;
00093       i=is;
00094       argld=(float)ld*argh;
00095       fi=0.f;
00096       for (ii=2;ii<ido;ii+=2){
00097         fi+=1.f;
00098         arg=fi*argld;
00099         wa[i++]=cos(arg);
00100         wa[i++]=sin(arg);
00101       }
00102       is+=ido;
00103     }
00104     l1=l2;
00105   }
00106 }
00107 
00108 static void fdrffti(int n, float *wsave, int *ifac){
00109 
00110   if (n == 1) return;
00111   drfti1(n, wsave+n, ifac);
00112 }
00113 
00114 static void dradf2(int ido,int l1,float *cc,float *ch,float *wa1){
00115   int i,k;
00116   float ti2,tr2;
00117   int t0,t1,t2,t3,t4,t5,t6;
00118 
00119   t1=0;
00120   t0=(t2=l1*ido);
00121   t3=ido<<1;
00122   for(k=0;k<l1;k++){
00123     ch[t1<<1]=cc[t1]+cc[t2];
00124     ch[(t1<<1)+t3-1]=cc[t1]-cc[t2];
00125     t1+=ido;
00126     t2+=ido;
00127   }
00128     
00129   if(ido<2)return;
00130   if(ido==2)goto L105;
00131 
00132   t1=0;
00133   t2=t0;
00134   for(k=0;k<l1;k++){
00135     t3=t2;
00136     t4=(t1<<1)+(ido<<1);
00137     t5=t1;
00138     t6=t1+t1;
00139     for(i=2;i<ido;i+=2){
00140       t3+=2;
00141       t4-=2;
00142       t5+=2;
00143       t6+=2;
00144       tr2=wa1[i-2]*cc[t3-1]+wa1[i-1]*cc[t3];
00145       ti2=wa1[i-2]*cc[t3]-wa1[i-1]*cc[t3-1];
00146       ch[t6]=cc[t5]+ti2;
00147       ch[t4]=ti2-cc[t5];
00148       ch[t6-1]=cc[t5-1]+tr2;
00149       ch[t4-1]=cc[t5-1]-tr2;
00150     }
00151     t1+=ido;
00152     t2+=ido;
00153   }
00154 
00155   if(ido%2==1)return;
00156 
00157  L105:
00158   t3=(t2=(t1=ido)-1);
00159   t2+=t0;
00160   for(k=0;k<l1;k++){
00161     ch[t1]=-cc[t2];
00162     ch[t1-1]=cc[t3];
00163     t1+=ido<<1;
00164     t2+=ido;
00165     t3+=ido;
00166   }
00167 }
00168 
00169 static void dradf4(int ido,int l1,float *cc,float *ch,float *wa1,
00170             float *wa2,float *wa3){
00171   static float hsqt2 = .70710678118654752f;
00172   int i,k,t0,t1,t2,t3,t4,t5,t6;
00173   float ci2,ci3,ci4,cr2,cr3,cr4,ti1,ti2,ti3,ti4,tr1,tr2,tr3,tr4;
00174   t0=l1*ido;
00175   
00176   t1=t0;
00177   t4=t1<<1;
00178   t2=t1+(t1<<1);
00179   t3=0;
00180 
00181   for(k=0;k<l1;k++){
00182     tr1=cc[t1]+cc[t2];
00183     tr2=cc[t3]+cc[t4];
00184 
00185     ch[t5=t3<<2]=tr1+tr2;
00186     ch[(ido<<2)+t5-1]=tr2-tr1;
00187     ch[(t5+=(ido<<1))-1]=cc[t3]-cc[t4];
00188     ch[t5]=cc[t2]-cc[t1];
00189 
00190     t1+=ido;
00191     t2+=ido;
00192     t3+=ido;
00193     t4+=ido;
00194   }
00195 
00196   if(ido<2)return;
00197   if(ido==2)goto L105;
00198 
00199 
00200   t1=0;
00201   for(k=0;k<l1;k++){
00202     t2=t1;
00203     t4=t1<<2;
00204     t5=(t6=ido<<1)+t4;
00205     for(i=2;i<ido;i+=2){
00206       t3=(t2+=2);
00207       t4+=2;
00208       t5-=2;
00209 
00210       t3+=t0;
00211       cr2=wa1[i-2]*cc[t3-1]+wa1[i-1]*cc[t3];
00212       ci2=wa1[i-2]*cc[t3]-wa1[i-1]*cc[t3-1];
00213       t3+=t0;
00214       cr3=wa2[i-2]*cc[t3-1]+wa2[i-1]*cc[t3];
00215       ci3=wa2[i-2]*cc[t3]-wa2[i-1]*cc[t3-1];
00216       t3+=t0;
00217       cr4=wa3[i-2]*cc[t3-1]+wa3[i-1]*cc[t3];
00218       ci4=wa3[i-2]*cc[t3]-wa3[i-1]*cc[t3-1];
00219 
00220       tr1=cr2+cr4;
00221       tr4=cr4-cr2;
00222       ti1=ci2+ci4;
00223       ti4=ci2-ci4;
00224 
00225       ti2=cc[t2]+ci3;
00226       ti3=cc[t2]-ci3;
00227       tr2=cc[t2-1]+cr3;
00228       tr3=cc[t2-1]-cr3;
00229 
00230       ch[t4-1]=tr1+tr2;
00231       ch[t4]=ti1+ti2;
00232 
00233       ch[t5-1]=tr3-ti4;
00234       ch[t5]=tr4-ti3;
00235 
00236       ch[t4+t6-1]=ti4+tr3;
00237       ch[t4+t6]=tr4+ti3;
00238 
00239       ch[t5+t6-1]=tr2-tr1;
00240       ch[t5+t6]=ti1-ti2;
00241     }
00242     t1+=ido;
00243   }
00244   if(ido&1)return;
00245 
00246  L105:
00247   
00248   t2=(t1=t0+ido-1)+(t0<<1);
00249   t3=ido<<2;
00250   t4=ido;
00251   t5=ido<<1;
00252   t6=ido;
00253 
00254   for(k=0;k<l1;k++){
00255     ti1=-hsqt2*(cc[t1]+cc[t2]);
00256     tr1=hsqt2*(cc[t1]-cc[t2]);
00257 
00258     ch[t4-1]=tr1+cc[t6-1];
00259     ch[t4+t5-1]=cc[t6-1]-tr1;
00260 
00261     ch[t4]=ti1-cc[t1+t0];
00262     ch[t4+t5]=ti1+cc[t1+t0];
00263 
00264     t1+=ido;
00265     t2+=ido;
00266     t4+=t3;
00267     t6+=ido;
00268   }
00269 }
00270 
00271 static void dradfg(int ido,int ip,int l1,int idl1,float *cc,float *c1,
00272                           float *c2,float *ch,float *ch2,float *wa){
00273 
00274   static float tpi=6.283185307179586f;
00275   int idij,ipph,i,j,k,l,ic,ik,is;
00276   int t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10;
00277   float dc2,ai1,ai2,ar1,ar2,ds2;
00278   int nbd;
00279   float dcp,arg,dsp,ar1h,ar2h;
00280   int idp2,ipp2;
00281   
00282   arg=tpi/(float)ip;
00283   dcp=cos(arg);
00284   dsp=sin(arg);
00285   ipph=(ip+1)>>1;
00286   ipp2=ip;
00287   idp2=ido;
00288   nbd=(ido-1)>>1;
00289   t0=l1*ido;
00290   t10=ip*ido;
00291 
00292   if(ido==1)goto L119;
00293   for(ik=0;ik<idl1;ik++)ch2[ik]=c2[ik];
00294 
00295   t1=0;
00296   for(j=1;j<ip;j++){
00297     t1+=t0;
00298     t2=t1;
00299     for(k=0;k<l1;k++){
00300       ch[t2]=c1[t2];
00301       t2+=ido;
00302     }
00303   }
00304 
00305   is=-ido;
00306   t1=0;
00307   if(nbd>l1){
00308     for(j=1;j<ip;j++){
00309       t1+=t0;
00310       is+=ido;
00311       t2= -ido+t1;
00312       for(k=0;k<l1;k++){
00313         idij=is-1;
00314         t2+=ido;
00315         t3=t2;
00316         for(i=2;i<ido;i+=2){
00317           idij+=2;
00318           t3+=2;
00319           ch[t3-1]=wa[idij-1]*c1[t3-1]+wa[idij]*c1[t3];
00320           ch[t3]=wa[idij-1]*c1[t3]-wa[idij]*c1[t3-1];
00321         }
00322       }
00323     }
00324   }else{
00325 
00326     for(j=1;j<ip;j++){
00327       is+=ido;
00328       idij=is-1;
00329       t1+=t0;
00330       t2=t1;
00331       for(i=2;i<ido;i+=2){
00332         idij+=2;
00333         t2+=2;
00334         t3=t2;
00335         for(k=0;k<l1;k++){
00336           ch[t3-1]=wa[idij-1]*c1[t3-1]+wa[idij]*c1[t3];
00337           ch[t3]=wa[idij-1]*c1[t3]-wa[idij]*c1[t3-1];
00338           t3+=ido;
00339         }
00340       }
00341     }
00342   }
00343 
00344   t1=0;
00345   t2=ipp2*t0;
00346   if(nbd<l1){
00347     for(j=1;j<ipph;j++){
00348       t1+=t0;
00349       t2-=t0;
00350       t3=t1;
00351       t4=t2;
00352       for(i=2;i<ido;i+=2){
00353         t3+=2;
00354         t4+=2;
00355         t5=t3-ido;
00356         t6=t4-ido;
00357         for(k=0;k<l1;k++){
00358           t5+=ido;
00359           t6+=ido;
00360           c1[t5-1]=ch[t5-1]+ch[t6-1];
00361           c1[t6-1]=ch[t5]-ch[t6];
00362           c1[t5]=ch[t5]+ch[t6];
00363           c1[t6]=ch[t6-1]-ch[t5-1];
00364         }
00365       }
00366     }
00367   }else{
00368     for(j=1;j<ipph;j++){
00369       t1+=t0;
00370       t2-=t0;
00371       t3=t1;
00372       t4=t2;
00373       for(k=0;k<l1;k++){
00374         t5=t3;
00375         t6=t4;
00376         for(i=2;i<ido;i+=2){
00377           t5+=2;
00378           t6+=2;
00379           c1[t5-1]=ch[t5-1]+ch[t6-1];
00380           c1[t6-1]=ch[t5]-ch[t6];
00381           c1[t5]=ch[t5]+ch[t6];
00382           c1[t6]=ch[t6-1]-ch[t5-1];
00383         }
00384         t3+=ido;
00385         t4+=ido;
00386       }
00387     }
00388   }
00389 
00390 L119:
00391   for(ik=0;ik<idl1;ik++)c2[ik]=ch2[ik];
00392 
00393   t1=0;
00394   t2=ipp2*idl1;
00395   for(j=1;j<ipph;j++){
00396     t1+=t0;
00397     t2-=t0;
00398     t3=t1-ido;
00399     t4=t2-ido;
00400     for(k=0;k<l1;k++){
00401       t3+=ido;
00402       t4+=ido;
00403       c1[t3]=ch[t3]+ch[t4];
00404       c1[t4]=ch[t4]-ch[t3];
00405     }
00406   }
00407 
00408   ar1=1.f;
00409   ai1=0.f;
00410   t1=0;
00411   t2=ipp2*idl1;
00412   t3=(ip-1)*idl1;
00413   for(l=1;l<ipph;l++){
00414     t1+=idl1;
00415     t2-=idl1;
00416     ar1h=dcp*ar1-dsp*ai1;
00417     ai1=dcp*ai1+dsp*ar1;
00418     ar1=ar1h;
00419     t4=t1;
00420     t5=t2;
00421     t6=t3;
00422     t7=idl1;
00423 
00424     for(ik=0;ik<idl1;ik++){
00425       ch2[t4++]=c2[ik]+ar1*c2[t7++];
00426       ch2[t5++]=ai1*c2[t6++];
00427     }
00428 
00429     dc2=ar1;
00430     ds2=ai1;
00431     ar2=ar1;
00432     ai2=ai1;
00433 
00434     t4=idl1;
00435     t5=(ipp2-1)*idl1;
00436     for(j=2;j<ipph;j++){
00437       t4+=idl1;
00438       t5-=idl1;
00439 
00440       ar2h=dc2*ar2-ds2*ai2;
00441       ai2=dc2*ai2+ds2*ar2;
00442       ar2=ar2h;
00443 
00444       t6=t1;
00445       t7=t2;
00446       t8=t4;
00447       t9=t5;
00448       for(ik=0;ik<idl1;ik++){
00449         ch2[t6++]+=ar2*c2[t8++];
00450         ch2[t7++]+=ai2*c2[t9++];
00451       }
00452     }
00453   }
00454 
00455   t1=0;
00456   for(j=1;j<ipph;j++){
00457     t1+=idl1;
00458     t2=t1;
00459     for(ik=0;ik<idl1;ik++)ch2[ik]+=c2[t2++];
00460   }
00461 
00462   if(ido<l1)goto L132;
00463 
00464   t1=0;
00465   t2=0;
00466   for(k=0;k<l1;k++){
00467     t3=t1;
00468     t4=t2;
00469     for(i=0;i<ido;i++)cc[t4++]=ch[t3++];
00470     t1+=ido;
00471     t2+=t10;
00472   }
00473 
00474   goto L135;
00475 
00476  L132:
00477   for(i=0;i<ido;i++){
00478     t1=i;
00479     t2=i;
00480     for(k=0;k<l1;k++){
00481       cc[t2]=ch[t1];
00482       t1+=ido;
00483       t2+=t10;
00484     }
00485   }
00486 
00487  L135:
00488   t1=0;
00489   t2=ido<<1;
00490   t3=0;
00491   t4=ipp2*t0;
00492   for(j=1;j<ipph;j++){
00493 
00494     t1+=t2;
00495     t3+=t0;
00496     t4-=t0;
00497 
00498     t5=t1;
00499     t6=t3;
00500     t7=t4;
00501 
00502     for(k=0;k<l1;k++){
00503       cc[t5-1]=ch[t6];
00504       cc[t5]=ch[t7];
00505       t5+=t10;
00506       t6+=ido;
00507       t7+=ido;
00508     }
00509   }
00510 
00511   if(ido==1)return;
00512   if(nbd<l1)goto L141;
00513 
00514   t1=-ido;
00515   t3=0;
00516   t4=0;
00517   t5=ipp2*t0;
00518   for(j=1;j<ipph;j++){
00519     t1+=t2;
00520     t3+=t2;
00521     t4+=t0;
00522     t5-=t0;
00523     t6=t1;
00524     t7=t3;
00525     t8=t4;
00526     t9=t5;
00527     for(k=0;k<l1;k++){
00528       for(i=2;i<ido;i+=2){
00529         ic=idp2-i;
00530         cc[i+t7-1]=ch[i+t8-1]+ch[i+t9-1];
00531         cc[ic+t6-1]=ch[i+t8-1]-ch[i+t9-1];
00532         cc[i+t7]=ch[i+t8]+ch[i+t9];
00533         cc[ic+t6]=ch[i+t9]-ch[i+t8];
00534       }
00535       t6+=t10;
00536       t7+=t10;
00537       t8+=ido;
00538       t9+=ido;
00539     }
00540   }
00541   return;
00542 
00543  L141:
00544 
00545   t1=-ido;
00546   t3=0;
00547   t4=0;
00548   t5=ipp2*t0;
00549   for(j=1;j<ipph;j++){
00550     t1+=t2;
00551     t3+=t2;
00552     t4+=t0;
00553     t5-=t0;
00554     for(i=2;i<ido;i+=2){
00555       t6=idp2+t1-i;
00556       t7=i+t3;
00557       t8=i+t4;
00558       t9=i+t5;
00559       for(k=0;k<l1;k++){
00560         cc[t7-1]=ch[t8-1]+ch[t9-1];
00561         cc[t6-1]=ch[t8-1]-ch[t9-1];
00562         cc[t7]=ch[t8]+ch[t9];
00563         cc[t6]=ch[t9]-ch[t8];
00564         t6+=t10;
00565         t7+=t10;
00566         t8+=ido;
00567         t9+=ido;
00568       }
00569     }
00570   }
00571 }
00572 
00573 static void drftf1(int n,float *c,float *ch,float *wa,int *ifac){
00574   int i,k1,l1,l2;
00575   int na,kh,nf;
00576   int ip,iw,ido,idl1,ix2,ix3;
00577 
00578   nf=ifac[1];
00579   na=1;
00580   l2=n;
00581   iw=n;
00582 
00583   for(k1=0;k1<nf;k1++){
00584     kh=nf-k1;
00585     ip=ifac[kh+1];
00586     l1=l2/ip;
00587     ido=n/l2;
00588     idl1=ido*l1;
00589     iw-=(ip-1)*ido;
00590     na=1-na;
00591 
00592     if(ip!=4)goto L102;
00593 
00594     ix2=iw+ido;
00595     ix3=ix2+ido;
00596     if(na!=0)
00597       dradf4(ido,l1,ch,c,wa+iw-1,wa+ix2-1,wa+ix3-1);
00598     else
00599       dradf4(ido,l1,c,ch,wa+iw-1,wa+ix2-1,wa+ix3-1);
00600     goto L110;
00601 
00602  L102:
00603     if(ip!=2)goto L104;
00604     if(na!=0)goto L103;
00605 
00606     dradf2(ido,l1,c,ch,wa+iw-1);
00607     goto L110;
00608 
00609   L103:
00610     dradf2(ido,l1,ch,c,wa+iw-1);
00611     goto L110;
00612 
00613   L104:
00614     if(ido==1)na=1-na;
00615     if(na!=0)goto L109;
00616 
00617     dradfg(ido,ip,l1,idl1,c,c,c,ch,ch,wa+iw-1);
00618     na=1;
00619     goto L110;
00620 
00621   L109:
00622     dradfg(ido,ip,l1,idl1,ch,ch,ch,c,c,wa+iw-1);
00623     na=0;
00624 
00625   L110:
00626     l2=l1;
00627   }
00628 
00629   if(na==1)return;
00630 
00631   for(i=0;i<n;i++)c[i]=ch[i];
00632 }
00633 
00634 static void dradb2(int ido,int l1,float *cc,float *ch,float *wa1){
00635   int i,k,t0,t1,t2,t3,t4,t5,t6;
00636   float ti2,tr2;
00637 
00638   t0=l1*ido;
00639   
00640   t1=0;
00641   t2=0;
00642   t3=(ido<<1)-1;
00643   for(k=0;k<l1;k++){
00644     ch[t1]=cc[t2]+cc[t3+t2];
00645     ch[t1+t0]=cc[t2]-cc[t3+t2];
00646     t2=(t1+=ido)<<1;
00647   }
00648 
00649   if(ido<2)return;
00650   if(ido==2)goto L105;
00651 
00652   t1=0;
00653   t2=0;
00654   for(k=0;k<l1;k++){
00655     t3=t1;
00656     t5=(t4=t2)+(ido<<1);
00657     t6=t0+t1;
00658     for(i=2;i<ido;i+=2){
00659       t3+=2;
00660       t4+=2;
00661       t5-=2;
00662       t6+=2;
00663       ch[t3-1]=cc[t4-1]+cc[t5-1];
00664       tr2=cc[t4-1]-cc[t5-1];
00665       ch[t3]=cc[t4]-cc[t5];
00666       ti2=cc[t4]+cc[t5];
00667       ch[t6-1]=wa1[i-2]*tr2-wa1[i-1]*ti2;
00668       ch[t6]=wa1[i-2]*ti2+wa1[i-1]*tr2;
00669     }
00670     t2=(t1+=ido)<<1;
00671   }
00672 
00673   if(ido%2==1)return;
00674 
00675 L105:
00676   t1=ido-1;
00677   t2=ido-1;
00678   for(k=0;k<l1;k++){
00679     ch[t1]=cc[t2]+cc[t2];
00680     ch[t1+t0]=-(cc[t2+1]+cc[t2+1]);
00681     t1+=ido;
00682     t2+=ido<<1;
00683   }
00684 }
00685 
00686 static void dradb3(int ido,int l1,float *cc,float *ch,float *wa1,
00687                           float *wa2){
00688   static float taur = -.5f;
00689   static float taui = .8660254037844386f;
00690   int i,k,t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10;
00691   float ci2,ci3,di2,di3,cr2,cr3,dr2,dr3,ti2,tr2;
00692   t0=l1*ido;
00693 
00694   t1=0;
00695   t2=t0<<1;
00696   t3=ido<<1;
00697   t4=ido+(ido<<1);
00698   t5=0;
00699   for(k=0;k<l1;k++){
00700     tr2=cc[t3-1]+cc[t3-1];
00701     cr2=cc[t5]+(taur*tr2);
00702     ch[t1]=cc[t5]+tr2;
00703     ci3=taui*(cc[t3]+cc[t3]);
00704     ch[t1+t0]=cr2-ci3;
00705     ch[t1+t2]=cr2+ci3;
00706     t1+=ido;
00707     t3+=t4;
00708     t5+=t4;
00709   }
00710 
00711   if(ido==1)return;
00712 
00713   t1=0;
00714   t3=ido<<1;
00715   for(k=0;k<l1;k++){
00716     t7=t1+(t1<<1);
00717     t6=(t5=t7+t3);
00718     t8=t1;
00719     t10=(t9=t1+t0)+t0;
00720 
00721     for(i=2;i<ido;i+=2){
00722       t5+=2;
00723       t6-=2;
00724       t7+=2;
00725       t8+=2;
00726       t9+=2;
00727       t10+=2;
00728       tr2=cc[t5-1]+cc[t6-1];
00729       cr2=cc[t7-1]+(taur*tr2);
00730       ch[t8-1]=cc[t7-1]+tr2;
00731       ti2=cc[t5]-cc[t6];
00732       ci2=cc[t7]+(taur*ti2);
00733       ch[t8]=cc[t7]+ti2;
00734       cr3=taui*(cc[t5-1]-cc[t6-1]);
00735       ci3=taui*(cc[t5]+cc[t6]);
00736       dr2=cr2-ci3;
00737       dr3=cr2+ci3;
00738       di2=ci2+cr3;
00739       di3=ci2-cr3;
00740       ch[t9-1]=wa1[i-2]*dr2-wa1[i-1]*di2;
00741       ch[t9]=wa1[i-2]*di2+wa1[i-1]*dr2;
00742       ch[t10-1]=wa2[i-2]*dr3-wa2[i-1]*di3;
00743       ch[t10]=wa2[i-2]*di3+wa2[i-1]*dr3;
00744     }
00745     t1+=ido;
00746   }
00747 }
00748 
00749 static void dradb4(int ido,int l1,float *cc,float *ch,float *wa1,
00750                           float *wa2,float *wa3){
00751   static float sqrt2=1.414213562373095f;
00752   int i,k,t0,t1,t2,t3,t4,t5,t6,t7,t8;
00753   float ci2,ci3,ci4,cr2,cr3,cr4,ti1,ti2,ti3,ti4,tr1,tr2,tr3,tr4;
00754   t0=l1*ido;
00755   
00756   t1=0;
00757   t2=ido<<2;
00758   t3=0;
00759   t6=ido<<1;
00760   for(k=0;k<l1;k++){
00761     t4=t3+t6;
00762     t5=t1;
00763     tr3=cc[t4-1]+cc[t4-1];
00764     tr4=cc[t4]+cc[t4]; 
00765     tr1=cc[t3]-cc[(t4+=t6)-1];
00766     tr2=cc[t3]+cc[t4-1];
00767     ch[t5]=tr2+tr3;
00768     ch[t5+=t0]=tr1-tr4;
00769     ch[t5+=t0]=tr2-tr3;
00770     ch[t5+=t0]=tr1+tr4;
00771     t1+=ido;
00772     t3+=t2;
00773   }
00774 
00775   if(ido<2)return;
00776   if(ido==2)goto L105;
00777 
00778   t1=0;
00779   for(k=0;k<l1;k++){
00780     t5=(t4=(t3=(t2=t1<<2)+t6))+t6;
00781     t7=t1;
00782     for(i=2;i<ido;i+=2){
00783       t2+=2;
00784       t3+=2;
00785       t4-=2;
00786       t5-=2;
00787       t7+=2;
00788       ti1=cc[t2]+cc[t5];
00789       ti2=cc[t2]-cc[t5];
00790       ti3=cc[t3]-cc[t4];
00791       tr4=cc[t3]+cc[t4];
00792       tr1=cc[t2-1]-cc[t5-1];
00793       tr2=cc[t2-1]+cc[t5-1];
00794       ti4=cc[t3-1]-cc[t4-1];
00795       tr3=cc[t3-1]+cc[t4-1];
00796       ch[t7-1]=tr2+tr3;
00797       cr3=tr2-tr3;
00798       ch[t7]=ti2+ti3;
00799       ci3=ti2-ti3;
00800       cr2=tr1-tr4;
00801       cr4=tr1+tr4;
00802       ci2=ti1+ti4;
00803       ci4=ti1-ti4;
00804 
00805       ch[(t8=t7+t0)-1]=wa1[i-2]*cr2-wa1[i-1]*ci2;
00806       ch[t8]=wa1[i-2]*ci2+wa1[i-1]*cr2;
00807       ch[(t8+=t0)-1]=wa2[i-2]*cr3-wa2[i-1]*ci3;
00808       ch[t8]=wa2[i-2]*ci3+wa2[i-1]*cr3;
00809       ch[(t8+=t0)-1]=wa3[i-2]*cr4-wa3[i-1]*ci4;
00810       ch[t8]=wa3[i-2]*ci4+wa3[i-1]*cr4;
00811     }
00812     t1+=ido;
00813   }
00814 
00815   if(ido%2 == 1)return;
00816 
00817  L105:
00818 
00819   t1=ido;
00820   t2=ido<<2;
00821   t3=ido-1;
00822   t4=ido+(ido<<1);
00823   for(k=0;k<l1;k++){
00824     t5=t3;
00825     ti1=cc[t1]+cc[t4];
00826     ti2=cc[t4]-cc[t1];
00827     tr1=cc[t1-1]-cc[t4-1];
00828     tr2=cc[t1-1]+cc[t4-1];
00829     ch[t5]=tr2+tr2;
00830     ch[t5+=t0]=sqrt2*(tr1-ti1);
00831     ch[t5+=t0]=ti2+ti2;
00832     ch[t5+=t0]=-sqrt2*(tr1+ti1);
00833 
00834     t3+=ido;
00835     t1+=t2;
00836     t4+=t2;
00837   }
00838 }
00839 
00840 static void dradbg(int ido,int ip,int l1,int idl1,float *cc,float *c1,
00841             float *c2,float *ch,float *ch2,float *wa){
00842   static float tpi=6.283185307179586f;
00843   int idij,ipph,i,j,k,l,ik,is,t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,
00844       t11,t12;
00845   float dc2,ai1,ai2,ar1,ar2,ds2;
00846   int nbd;
00847   float dcp,arg,dsp,ar1h,ar2h;
00848   int ipp2;
00849 
00850   t10=ip*ido;
00851   t0=l1*ido;
00852   arg=tpi/(float)ip;
00853   dcp=cos(arg);
00854   dsp=sin(arg);
00855   nbd=(ido-1)>>1;
00856   ipp2=ip;
00857   ipph=(ip+1)>>1;
00858   if(ido<l1)goto L103;
00859   
00860   t1=0;
00861   t2=0;
00862   for(k=0;k<l1;k++){
00863     t3=t1;
00864     t4=t2;
00865     for(i=0;i<ido;i++){
00866       ch[t3]=cc[t4];
00867       t3++;
00868       t4++;
00869     }
00870     t1+=ido;
00871     t2+=t10;
00872   }
00873   goto L106;
00874 
00875  L103:
00876   t1=0;
00877   for(i=0;i<ido;i++){
00878     t2=t1;
00879     t3=t1;
00880     for(k=0;k<l1;k++){
00881       ch[t2]=cc[t3];
00882       t2+=ido;
00883       t3+=t10;
00884     }
00885     t1++;
00886   }
00887 
00888  L106:
00889   t1=0;
00890   t2=ipp2*t0;
00891   t7=(t5=ido<<1);
00892   for(j=1;j<ipph;j++){
00893     t1+=t0;
00894     t2-=t0;
00895     t3=t1;
00896     t4=t2;
00897     t6=t5;
00898     for(k=0;k<l1;k++){
00899       ch[t3]=cc[t6-1]+cc[t6-1];
00900       ch[t4]=cc[t6]+cc[t6];
00901       t3+=ido;
00902       t4+=ido;
00903       t6+=t10;
00904     }
00905     t5+=t7;
00906   }
00907 
00908   if (ido == 1)goto L116;
00909   if(nbd<l1)goto L112;
00910 
00911   t1=0;
00912   t2=ipp2*t0;
00913   t7=0;
00914   for(j=1;j<ipph;j++){
00915     t1+=t0;
00916     t2-=t0;
00917     t3=t1;
00918     t4=t2;
00919 
00920     t7+=(ido<<1);
00921     t8=t7;
00922     for(k=0;k<l1;k++){
00923       t5=t3;
00924       t6=t4;
00925       t9=t8;
00926       t11=t8;
00927       for(i=2;i<ido;i+=2){
00928         t5+=2;
00929         t6+=2;
00930         t9+=2;
00931         t11-=2;
00932         ch[t5-1]=cc[t9-1]+cc[t11-1];
00933         ch[t6-1]=cc[t9-1]-cc[t11-1];
00934         ch[t5]=cc[t9]-cc[t11];
00935         ch[t6]=cc[t9]+cc[t11];
00936       }
00937       t3+=ido;
00938       t4+=ido;
00939       t8+=t10;
00940     }
00941   }
00942   goto L116;
00943 
00944  L112:
00945   t1=0;
00946   t2=ipp2*t0;
00947   t7=0;
00948   for(j=1;j<ipph;j++){
00949     t1+=t0;
00950     t2-=t0;
00951     t3=t1;
00952     t4=t2;
00953     t7+=(ido<<1);
00954     t8=t7;
00955     t9=t7;
00956     for(i=2;i<ido;i+=2){
00957       t3+=2;
00958       t4+=2;
00959       t8+=2;
00960       t9-=2;
00961       t5=t3;
00962       t6=t4;
00963       t11=t8;
00964       t12=t9;
00965       for(k=0;k<l1;k++){
00966         ch[t5-1]=cc[t11-1]+cc[t12-1];
00967         ch[t6-1]=cc[t11-1]-cc[t12-1];
00968         ch[t5]=cc[t11]-cc[t12];
00969         ch[t6]=cc[t11]+cc[t12];
00970         t5+=ido;
00971         t6+=ido;
00972         t11+=t10;
00973         t12+=t10;
00974       }
00975     }
00976   }
00977 
00978 L116:
00979   ar1=1.f;
00980   ai1=0.f;
00981   t1=0;
00982   t9=(t2=ipp2*idl1);
00983   t3=(ip-1)*idl1;
00984   for(l=1;l<ipph;l++){
00985     t1+=idl1;
00986     t2-=idl1;
00987 
00988     ar1h=dcp*ar1-dsp*ai1;
00989     ai1=dcp*ai1+dsp*ar1;
00990     ar1=ar1h;
00991     t4=t1;
00992     t5=t2;
00993     t6=0;
00994     t7=idl1;
00995     t8=t3;
00996     for(ik=0;ik<idl1;ik++){
00997       c2[t4++]=ch2[t6++]+ar1*ch2[t7++];
00998       c2[t5++]=ai1*ch2[t8++];
00999     }
01000     dc2=ar1;
01001     ds2=ai1;
01002     ar2=ar1;
01003     ai2=ai1;
01004 
01005     t6=idl1;
01006     t7=t9-idl1;
01007     for(j=2;j<ipph;j++){
01008       t6+=idl1;
01009       t7-=idl1;
01010       ar2h=dc2*ar2-ds2*ai2;
01011       ai2=dc2*ai2+ds2*ar2;
01012       ar2=ar2h;
01013       t4=t1;
01014       t5=t2;
01015       t11=t6;
01016       t12=t7;
01017       for(ik=0;ik<idl1;ik++){
01018         c2[t4++]+=ar2*ch2[t11++];
01019         c2[t5++]+=ai2*ch2[t12++];
01020       }
01021     }
01022   }
01023 
01024   t1=0;
01025   for(j=1;j<ipph;j++){
01026     t1+=idl1;
01027     t2=t1;
01028     for(ik=0;ik<idl1;ik++)ch2[ik]+=ch2[t2++];
01029   }
01030 
01031   t1=0;
01032   t2=ipp2*t0;
01033   for(j=1;j<ipph;j++){
01034     t1+=t0;
01035     t2-=t0;
01036     t3=t1;
01037     t4=t2;
01038     for(k=0;k<l1;k++){
01039       ch[t3]=c1[t3]-c1[t4];
01040       ch[t4]=c1[t3]+c1[t4];
01041       t3+=ido;
01042       t4+=ido;
01043     }
01044   }
01045 
01046   if(ido==1)goto L132;
01047   if(nbd<l1)goto L128;
01048 
01049   t1=0;
01050   t2=ipp2*t0;
01051   for(j=1;j<ipph;j++){
01052     t1+=t0;
01053     t2-=t0;
01054     t3=t1;
01055     t4=t2;
01056     for(k=0;k<l1;k++){
01057       t5=t3;
01058       t6=t4;
01059       for(i=2;i<ido;i+=2){
01060         t5+=2;
01061         t6+=2;
01062         ch[t5-1]=c1[t5-1]-c1[t6];
01063         ch[t6-1]=c1[t5-1]+c1[t6];
01064         ch[t5]=c1[t5]+c1[t6-1];
01065         ch[t6]=c1[t5]-c1[t6-1];
01066       }
01067       t3+=ido;
01068       t4+=ido;
01069     }
01070   }
01071   goto L132;
01072 
01073  L128:
01074   t1=0;
01075   t2=ipp2*t0;
01076   for(j=1;j<ipph;j++){
01077     t1+=t0;
01078     t2-=t0;
01079     t3=t1;
01080     t4=t2;
01081     for(i=2;i<ido;i+=2){
01082       t3+=2;
01083       t4+=2;
01084       t5=t3;
01085       t6=t4;
01086       for(k=0;k<l1;k++){
01087         ch[t5-1]=c1[t5-1]-c1[t6];
01088         ch[t6-1]=c1[t5-1]+c1[t6];
01089         ch[t5]=c1[t5]+c1[t6-1];
01090         ch[t6]=c1[t5]-c1[t6-1];
01091         t5+=ido;
01092         t6+=ido;
01093       }
01094     }
01095   }
01096 
01097 L132:
01098   if(ido==1)return;
01099 
01100   for(ik=0;ik<idl1;ik++)c2[ik]=ch2[ik];
01101 
01102   t1=0;
01103   for(j=1;j<ip;j++){
01104     t2=(t1+=t0);
01105     for(k=0;k<l1;k++){
01106       c1[t2]=ch[t2];
01107       t2+=ido;
01108     }
01109   }
01110 
01111   if(nbd>l1)goto L139;
01112 
01113   is= -ido-1;
01114   t1=0;
01115   for(j=1;j<ip;j++){
01116     is+=ido;
01117     t1+=t0;
01118     idij=is;
01119     t2=t1;
01120     for(i=2;i<ido;i+=2){
01121       t2+=2;
01122       idij+=2;
01123       t3=t2;
01124       for(k=0;k<l1;k++){
01125         c1[t3-1]=wa[idij-1]*ch[t3-1]-wa[idij]*ch[t3];
01126         c1[t3]=wa[idij-1]*ch[t3]+wa[idij]*ch[t3-1];
01127         t3+=ido;
01128       }
01129     }
01130   }
01131   return;
01132 
01133  L139:
01134   is= -ido-1;
01135   t1=0;
01136   for(j=1;j<ip;j++){
01137     is+=ido;
01138     t1+=t0;
01139     t2=t1;
01140     for(k=0;k<l1;k++){
01141       idij=is;
01142       t3=t2;
01143       for(i=2;i<ido;i+=2){
01144         idij+=2;
01145         t3+=2;
01146         c1[t3-1]=wa[idij-1]*ch[t3-1]-wa[idij]*ch[t3];
01147         c1[t3]=wa[idij-1]*ch[t3]+wa[idij]*ch[t3-1];
01148       }
01149       t2+=ido;
01150     }
01151   }
01152 }
01153 
01154 static void drftb1(int n, float *c, float *ch, float *wa, int *ifac){
01155   int i,k1,l1,l2;
01156   int na;
01157   int nf,ip,iw,ix2,ix3,ido,idl1;
01158 
01159   nf=ifac[1];
01160   na=0;
01161   l1=1;
01162   iw=1;
01163 
01164   for(k1=0;k1<nf;k1++){
01165     ip=ifac[k1 + 2];
01166     l2=ip*l1;
01167     ido=n/l2;
01168     idl1=ido*l1;
01169     if(ip!=4)goto L103;
01170     ix2=iw+ido;
01171     ix3=ix2+ido;
01172 
01173     if(na!=0)
01174       dradb4(ido,l1,ch,c,wa+iw-1,wa+ix2-1,wa+ix3-1);
01175     else
01176       dradb4(ido,l1,c,ch,wa+iw-1,wa+ix2-1,wa+ix3-1);
01177     na=1-na;
01178     goto L115;
01179 
01180   L103:
01181     if(ip!=2)goto L106;
01182 
01183     if(na!=0)
01184       dradb2(ido,l1,ch,c,wa+iw-1);
01185     else
01186       dradb2(ido,l1,c,ch,wa+iw-1);
01187     na=1-na;
01188     goto L115;
01189 
01190   L106:
01191     if(ip!=3)goto L109;
01192 
01193     ix2=iw+ido;
01194     if(na!=0)
01195       dradb3(ido,l1,ch,c,wa+iw-1,wa+ix2-1);
01196     else
01197       dradb3(ido,l1,c,ch,wa+iw-1,wa+ix2-1);
01198     na=1-na;
01199     goto L115;
01200 
01201   L109:
01202 /*    The radix five case can be translated later..... */
01203 /*    if(ip!=5)goto L112;
01204 
01205     ix2=iw+ido;
01206     ix3=ix2+ido;
01207     ix4=ix3+ido;
01208     if(na!=0)
01209       dradb5(ido,l1,ch,c,wa+iw-1,wa+ix2-1,wa+ix3-1,wa+ix4-1);
01210     else
01211       dradb5(ido,l1,c,ch,wa+iw-1,wa+ix2-1,wa+ix3-1,wa+ix4-1);
01212     na=1-na;
01213     goto L115;
01214 
01215   L112:*/
01216     if(na!=0)
01217       dradbg(ido,ip,l1,idl1,ch,ch,ch,c,c,wa+iw-1);
01218     else
01219       dradbg(ido,ip,l1,idl1,c,c,c,ch,ch,wa+iw-1);
01220     if(ido==1)na=1-na;
01221 
01222   L115:
01223     l1=l2;
01224     iw+=(ip-1)*ido;
01225   }
01226 
01227   if(na==0)return;
01228 
01229   for(i=0;i<n;i++)c[i]=ch[i];
01230 }
01231 
01232 void drft_forward(drft_lookup *l,float *data){
01233   if(l->n==1)return;
01234   drftf1(l->n,data,l->trigcache,l->trigcache+l->n,l->splitcache);
01235 }
01236 
01237 void drft_backward(drft_lookup *l,float *data){
01238   if (l->n==1)return;
01239   drftb1(l->n,data,l->trigcache,l->trigcache+l->n,l->splitcache);
01240 }
01241 
01242 void drft_init(drft_lookup *l,int n){
01243   l->n=n;
01244   l->trigcache=(float*)_ogg_calloc(3*n,sizeof(*l->trigcache));
01245   l->splitcache=(int*)_ogg_calloc(32,sizeof(*l->splitcache));
01246   fdrffti(n, l->trigcache, l->splitcache);
01247 }
01248 
01249 void drft_clear(drft_lookup *l){
01250   if(l){
01251     if(l->trigcache)_ogg_free(l->trigcache);
01252     if(l->splitcache)_ogg_free(l->splitcache);
01253     memset(l,0,sizeof(*l));
01254   }
01255 }

Generated by  doxygen 1.6.2