2 * Copyright (C) 2000 ymnk, JCraft,Inc.
4 * Written by: 2000 ymnk<ymnk@jcraft.com>
7 * Monty <monty@xiph.org> and
8 * The XIPHOPHORUS Company http://www.xiph.org/ .
9 * JOrbis has been based on their awesome works, Vorbis codec.
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Library General Public License
13 * as published by the Free Software Foundation; either version 2 of
14 * the License, or (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Library General Public License for more details.
21 * You should have received a copy of the GNU Library General Public
22 * License along with this program; if not, write to the Free Software
23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 package com.jcraft.jorbis;
33 void backward(float[] data){
34 //System.err.println("Drft.backward");
36 drftb1(n,data,trigcache,trigcache,n,splitcache);
40 //System.err.println("Drft.init");
42 trigcache=new float[3*n];
43 splitcache=new int[32];
44 fdrffti(n, trigcache, splitcache);
48 //System.err.println("Drft.clear");
49 if(trigcache!=null)trigcache=null;
50 if(splitcache!=null)splitcache=null;
51 // memset(l,0,sizeof(drft_lookup));
54 static int[] ntryh = { 4,2,3,5 };
55 static float tpi = 6.28318530717958647692528676655900577f;
56 static float hsqt2 = .70710678118654752440084436210485f;
57 static float taui = .86602540378443864676372317075293618f;
58 static float taur = -.5f;
59 static float sqrt2 = 1.4142135623730950488016887242097f;
61 static void drfti1(int n, float[] wa, int index, int[] ifac){
62 float arg,argh,argld,fi;
65 int ld, ii, ip, is, nq, nr;
118 for (k1=0;k1<nfm1;k1++){
128 argld=(float)ld*argh;
130 for (ii=2;ii<ido;ii+=2){
133 wa[index+i++]=(float)Math.cos(arg);
134 wa[index+i++]=(float)Math.sin(arg);
145 static void fdrffti(int n, float[] wsave, int[] ifac){
146 //System.err.println("fdrffti: n="+n);
148 drfti1(n, wsave, n, ifac);
151 static void dradf2(int ido,int l1,float[] cc, float[] ch, float[] wa1, int index){
154 int t0,t1,t2,t3,t4,t5,t6;
160 ch[t1<<1]=cc[t1]+cc[t2];
161 ch[(t1<<1)+t3-1]=cc[t1]-cc[t2];
181 tr2=wa1[index+i-2]*cc[t3-1]+wa1[index+i-1]*cc[t3];
182 ti2=wa1[index+i-2]*cc[t3]-wa1[index+i-1]*cc[t3-1];
185 ch[t6-1]=cc[t5-1]+tr2;
186 ch[t4-1]=cc[t5-1]-tr2;
205 static void dradf4(int ido,int l1,float[] cc, float[] ch,
206 float[] wa1, int index1,
207 float[] wa2, int index2,
208 float[] wa3, int index3){
209 int i,k,t0,t1,t2,t3,t4,t5,t6;
210 float ci2,ci3,ci4,cr2,cr3,cr4,ti1,ti2,ti3,ti4,tr1,tr2,tr3,tr4;
222 ch[t5=t3<<2]=tr1+tr2;
223 ch[(ido<<2)+t5-1]=tr2-tr1;
224 ch[(t5+=(ido<<1))-1]=cc[t3]-cc[t4];
225 ch[t5]=cc[t2]-cc[t1];
246 cr2=wa1[index1+i-2]*cc[t3-1]+wa1[index1+i-1]*cc[t3];
247 ci2=wa1[index1+i-2]*cc[t3]-wa1[index1+i-1]*cc[t3-1];
249 cr3=wa2[index2+i-2]*cc[t3-1]+wa2[index2+i-1]*cc[t3];
250 ci3=wa2[index2+i-2]*cc[t3]-wa2[index2+i-1]*cc[t3-1];
252 cr4=wa3[index3+i-2]*cc[t3-1]+wa3[index3+i-1]*cc[t3];
253 ci4=wa3[index3+i-2]*cc[t3]-wa3[index3+i-1]*cc[t3-1];
279 if((ido&1)!=0)return;
282 t2=(t1=t0+ido-1)+(t0<<1);
289 ti1=-hsqt2*(cc[t1]+cc[t2]);
290 tr1=hsqt2*(cc[t1]-cc[t2]);
292 ch[t4-1]=tr1+cc[t6-1];
293 ch[t4+t5-1]=cc[t6-1]-tr1;
295 ch[t4]=ti1-cc[t1+t0];
296 ch[t4+t5]=ti1+cc[t1+t0];
305 static void dradfg(int ido,int ip,int l1,int idl1,float[] cc,float[] c1,
306 float[] c2, float[] ch, float[] ch2, float[] wa, int index){
307 int idij,ipph,i,j,k,l,ic,ik,is;
308 int t0,t1,t2=0,t3,t4,t5,t6,t7,t8,t9,t10;
309 float dc2,ai1,ai2,ar1,ar2,ds2;
311 float dcp=0,arg,dsp=0,ar1h,ar2h;
315 dcp=(float)Math.cos(arg);
316 dsp=(float)Math.sin(arg);
332 for(ik=0;ik<idl1;ik++)ch2[ik]=c2[ik];
358 ch[t3-1]=wa[index+idij-1]*c1[t3-1]+wa[index+idij]*c1[t3];
359 ch[t3]=wa[index+idij-1]*c1[t3]-wa[index+idij]*c1[t3-1];
376 ch[t3-1]=wa[index+idij-1]*c1[t3-1]+wa[index+idij]*c1[t3];
377 ch[t3]=wa[index+idij-1]*c1[t3]-wa[index+idij]*c1[t3-1];
400 c1[t5-1]=ch[t5-1]+ch[t6-1];
401 c1[t6-1]=ch[t5]-ch[t6];
402 c1[t5]=ch[t5]+ch[t6];
403 c1[t6]=ch[t6-1]-ch[t5-1];
420 c1[t5-1]=ch[t5-1]+ch[t6-1];
421 c1[t6-1]=ch[t5]-ch[t6];
422 c1[t5]=ch[t5]+ch[t6];
423 c1[t6]=ch[t6-1]-ch[t5-1];
431 for(ik=0;ik<idl1;ik++)c2[ik]=ch2[ik];
443 c1[t3]=ch[t3]+ch[t4];
444 c1[t4]=ch[t4]-ch[t3];
456 ar1h=dcp*ar1-dsp*ai1;
464 for(ik=0;ik<idl1;ik++){
465 ch2[t4++]=c2[ik]+ar1*c2[t7++];
466 ch2[t5++]=ai1*c2[t6++];
480 ar2h=dc2*ar2-ds2*ai2;
488 for(ik=0;ik<idl1;ik++){
489 ch2[t6++]+=ar2*c2[t8++];
490 ch2[t7++]+=ai2*c2[t9++];
498 for(ik=0;ik<idl1;ik++)ch2[ik]+=c2[t2++];
511 for(i=0;i<ido;i++)cc[t4++]=ch[t3++];
573 cc[i+t7-1]=ch[i+t8-1]+ch[i+t9-1];
574 cc[ic+t6-1]=ch[i+t8-1]-ch[i+t9-1];
575 cc[i+t7]=ch[i+t8]+ch[i+t9];
576 cc[ic+t6]=ch[i+t9]-ch[i+t8];
601 cc[t7-1]=ch[t8-1]+ch[t9-1];
602 cc[t6-1]=ch[t8-1]-ch[t9-1];
603 cc[t7]=ch[t8]+ch[t9];
604 cc[t6]=ch[t9]-ch[t8];
617 static void drftf1(int n,float[] c, float[] ch, float[] wa, int[] ifac){
620 int ip,iw,ido,idl1,ix2,ix3;
627 for(k1=0;k1<nf;k1++){
648 dradf4(ido,l1,ch,c,wa,iw-1,wa,ix2-1,wa,ix3-1);
650 dradf4(ido,l1,c,ch,wa,iw-1,wa,ix2-1,wa,ix3-1);
662 dradf2(ido,l1,c,ch,wa, iw-1);
666 dradf2(ido,l1,ch,c,wa, iw-1);
673 dradfg(ido,ip,l1,idl1,c,c,c,ch,ch,wa,iw-1);
678 dradfg(ido,ip,l1,idl1,ch,ch,ch,c,c,wa,iw-1);
687 for(i=0;i<n;i++)c[i]=ch[i];
690 static void dradb2(int ido,int l1,float[] cc,float[] ch,float[] wa1, int index){
691 int i,k,t0,t1,t2,t3,t4,t5,t6;
700 ch[t1]=cc[t2]+cc[t3+t2];
701 ch[t1+t0]=cc[t2]-cc[t3+t2];
718 ch[t3-1]=cc[t4-1]+cc[t5-1];
719 tr2=cc[t4-1]-cc[t5-1];
720 ch[t3]=cc[t4]-cc[t5];
722 ch[t6-1]=wa1[index+i-2]*tr2-wa1[index+i-1]*ti2;
723 ch[t6]=wa1[index+i-2]*ti2+wa1[index+i-1]*tr2;
727 if((ido%2)==1)return;
733 ch[t1]=cc[t2]+cc[t2];
734 ch[t1+t0]=-(cc[t2+1]+cc[t2+1]);
740 static void dradb3(int ido,int l1,float[] cc,float[] ch,
741 float[] wa1, int index1,
742 float[] wa2, int index2){
743 int i,k,t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10;
744 float ci2,ci3,di2,di3,cr2,cr3,dr2,dr3,ti2,tr2;
753 tr2=cc[t3-1]+cc[t3-1];
754 cr2=cc[t5]+(taur*tr2);
756 ci3=taui*(cc[t3]+cc[t3]);
781 tr2=cc[t5-1]+cc[t6-1];
782 cr2=cc[t7-1]+(taur*tr2);
783 ch[t8-1]=cc[t7-1]+tr2;
785 ci2=cc[t7]+(taur*ti2);
787 cr3=taui*(cc[t5-1]-cc[t6-1]);
788 ci3=taui*(cc[t5]+cc[t6]);
793 ch[t9-1]=wa1[index1+i-2]*dr2-wa1[index1+i-1]*di2;
794 ch[t9]=wa1[index1+i-2]*di2+wa1[index1+i-1]*dr2;
795 ch[t10-1]=wa2[index2+i-2]*dr3-wa2[index2+i-1]*di3;
796 ch[t10]=wa2[index2+i-2]*di3+wa2[index2+i-1]*dr3;
802 static void dradb4(int ido,int l1,float[] cc,float[] ch,
803 float[] wa1, int index1,
804 float[] wa2, int index2,
805 float[] wa3, int index3){
806 int i,k,t0,t1,t2,t3,t4,t5,t6,t7,t8;
807 float ci2,ci3,ci4,cr2,cr3,cr4,ti1,ti2,ti3,ti4,tr1,tr2,tr3,tr4;
817 tr3=cc[t4-1]+cc[t4-1];
819 tr1=cc[t3]-cc[(t4+=t6)-1];
833 t5=(t4=(t3=(t2=t1<<2)+t6))+t6;
845 tr1=cc[t2-1]-cc[t5-1];
846 tr2=cc[t2-1]+cc[t5-1];
847 ti4=cc[t3-1]-cc[t4-1];
848 tr3=cc[t3-1]+cc[t4-1];
858 ch[(t8=t7+t0)-1]=wa1[index1+i-2]*cr2-wa1[index1+i-1]*ci2;
859 ch[t8]=wa1[index1+i-2]*ci2+wa1[index1+i-1]*cr2;
860 ch[(t8+=t0)-1]=wa2[index2+i-2]*cr3-wa2[index2+i-1]*ci3;
861 ch[t8]=wa2[index2+i-2]*ci3+wa2[index2+i-1]*cr3;
862 ch[(t8+=t0)-1]=wa3[index3+i-2]*cr4-wa3[index3+i-1]*ci4;
863 ch[t8]=wa3[index3+i-2]*ci4+wa3[index3+i-1]*cr4;
867 if(ido%2 == 1)return;
878 tr1=cc[t1-1]-cc[t4-1];
879 tr2=cc[t1-1]+cc[t4-1];
881 ch[t5+=t0]=sqrt2*(tr1-ti1);
883 ch[t5+=t0]=-sqrt2*(tr1+ti1);
891 static void dradbg(int ido,int ip,int l1,int idl1,float[] cc,float[] c1,
892 float[] c2,float[] ch,float[] ch2,float[] wa, int index ){
894 int idij,ipph=0,i,j,k,l,ik,is,t0=0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10=0,
896 float dc2,ai1,ai2,ar1,ar2,ds2;
898 float dcp=0,arg,dsp=0,ar1h,ar2h;
909 dcp=(float)Math.cos(arg);
910 dsp=(float)Math.sin(arg);
956 ch[t3]=cc[t6-1]+cc[t6-1];
957 ch[t4]=cc[t6]+cc[t6];
994 ch[t5-1]=cc[t9-1]+cc[t11-1];
995 ch[t6-1]=cc[t9-1]-cc[t11-1];
996 ch[t5]=cc[t9]-cc[t11];
997 ch[t6]=cc[t9]+cc[t11];
1010 for(j=1;j<ipph;j++){
1018 for(i=2;i<ido;i+=2){
1028 ch[t5-1]=cc[t11-1]+cc[t12-1];
1029 ch[t6-1]=cc[t11-1]-cc[t12-1];
1030 ch[t5]=cc[t11]-cc[t12];
1031 ch[t6]=cc[t11]+cc[t12];
1045 for(l=1;l<ipph;l++){
1049 ar1h=dcp*ar1-dsp*ai1;
1050 ai1=dcp*ai1+dsp*ar1;
1057 for(ik=0;ik<idl1;ik++){
1058 c2[t4++]=ch2[t6++]+ar1*ch2[t7++];
1059 c2[t5++]=ai1*ch2[t8++];
1068 for(j=2;j<ipph;j++){
1071 ar2h=dc2*ar2-ds2*ai2;
1072 ai2=dc2*ai2+ds2*ar2;
1078 for(ik=0;ik<idl1;ik++){
1079 c2[t4++]+=ar2*ch2[t11++];
1080 c2[t5++]+=ai2*ch2[t12++];
1086 for(j=1;j<ipph;j++){
1089 for(ik=0;ik<idl1;ik++)ch2[ik]+=ch2[t2++];
1094 for(j=1;j<ipph;j++){
1100 ch[t3]=c1[t3]-c1[t4];
1101 ch[t4]=c1[t3]+c1[t4];
1118 for(j=1;j<ipph;j++){
1126 for(i=2;i<ido;i+=2){
1129 ch[t5-1]=c1[t5-1]-c1[t6];
1130 ch[t6-1]=c1[t5-1]+c1[t6];
1131 ch[t5]=c1[t5]+c1[t6-1];
1132 ch[t6]=c1[t5]-c1[t6-1];
1143 for(j=1;j<ipph;j++){
1148 for(i=2;i<ido;i+=2){
1154 ch[t5-1]=c1[t5-1]-c1[t6];
1155 ch[t6-1]=c1[t5-1]+c1[t6];
1156 ch[t5]=c1[t5]+c1[t6-1];
1157 ch[t6]=c1[t5]-c1[t6-1];
1166 for(ik=0;ik<idl1;ik++)c2[ik]=ch2[ik];
1189 for(i=2;i<ido;i+=2){
1194 c1[t3-1]=wa[index+idij-1]*ch[t3-1]-wa[index+idij]*ch[t3];
1195 c1[t3]=wa[index+idij-1]*ch[t3]+wa[index+idij]*ch[t3-1];
1212 for(i=2;i<ido;i+=2){
1215 c1[t3-1]=wa[index+idij-1]*ch[t3-1]-wa[index+idij]*ch[t3];
1216 c1[t3]=wa[index+idij-1]*ch[t3]+wa[index+idij]*ch[t3-1];
1226 static void drftb1(int n, float[] c, float[] ch, float[] wa, int index, int[] ifac){
1229 int nf,ip=0,iw,ix2,ix3,ido=0,idl1=0;
1236 for(k1=0;k1<nf;k1++){
1253 dradb4(ido,l1,ch,c,wa,index+iw-1,wa,index+ix2-1,wa,index+ix3-1);
1255 dradb4(ido,l1,c,ch,wa,index+iw-1,wa,index+ix2-1,wa,index+ix3-1);
1266 dradb2(ido,l1,ch,c,wa,index+iw-1);
1268 dradb2(ido,l1,c,ch,wa,index+iw-1);
1281 dradb3(ido,l1,ch,c,wa,index+iw-1,wa,index+ix2-1);
1283 dradb3(ido,l1,c,ch,wa,index+iw-1,wa,index+ix2-1);
1288 // The radix five case can be translated later.....
1289 // if(ip!=5)goto L112;
1295 // dradb5(ido,l1,ch,c,wa+iw-1,wa+ix2-1,wa+ix3-1,wa+ix4-1);
1297 // dradb5(ido,l1,c,ch,wa+iw-1,wa+ix2-1,wa+ix3-1,wa+ix4-1);
1302 dradbg(ido,ip,l1,idl1,ch,ch,ch,c,c,wa,index+iw-1);
1304 dradbg(ido,ip,l1,idl1,c,c,c,ch,ch,wa,index+iw-1);
1315 for(i=0;i<n;i++)c[i]=ch[i];