summaryrefslogtreecommitdiff
path: root/songdbj/de/jarnbjo/vorbis/MdctFloat.java
diff options
context:
space:
mode:
Diffstat (limited to 'songdbj/de/jarnbjo/vorbis/MdctFloat.java')
-rw-r--r--songdbj/de/jarnbjo/vorbis/MdctFloat.java321
1 files changed, 0 insertions, 321 deletions
diff --git a/songdbj/de/jarnbjo/vorbis/MdctFloat.java b/songdbj/de/jarnbjo/vorbis/MdctFloat.java
deleted file mode 100644
index 4f354b259b..0000000000
--- a/songdbj/de/jarnbjo/vorbis/MdctFloat.java
+++ /dev/null
@@ -1,321 +0,0 @@
1/*
2 * $ProjectName$
3 * $ProjectRevision$
4 * -----------------------------------------------------------
5 * $Id$
6 * -----------------------------------------------------------
7 *
8 * $Author$
9 *
10 * Description:
11 *
12 * Copyright 2002-2003 Tor-Einar Jarnbjo
13 * -----------------------------------------------------------
14 *
15 * Change History
16 * -----------------------------------------------------------
17 * $Log$
18 * Revision 1.1 2005/07/11 15:42:36 hcl
19 * Songdb java version, source. only 1.5 compatible
20 *
21 * Revision 1.2 2004/09/21 12:09:45 shred
22 * *** empty log message ***
23 *
24 * Revision 1.1.1.1 2004/04/04 22:09:12 shred
25 * First Import
26 *
27 * Revision 1.3 2003/04/10 19:49:04 jarnbjo
28 * no message
29 *
30 * Revision 1.2 2003/03/16 01:11:12 jarnbjo
31 * no message
32 *
33 *
34 */
35
36package de.jarnbjo.vorbis;
37
38class MdctFloat {
39 static private final float cPI3_8=0.38268343236508977175f;
40 static private final float cPI2_8=0.70710678118654752441f;
41 static private final float cPI1_8=0.92387953251128675613f;
42
43 private int n;
44 private int log2n;
45
46 private float[] trig;
47 private int[] bitrev;
48
49 private float[] equalizer;
50
51 private float scale;
52
53 private int itmp1, itmp2, itmp3, itmp4, itmp5, itmp6, itmp7, itmp8, itmp9;
54 private float dtmp1, dtmp2, dtmp3, dtmp4, dtmp5, dtmp6, dtmp7, dtmp8, dtmp9;
55
56 protected MdctFloat(int n) {
57 bitrev=new int[n/4];
58 trig=new float[n+n/4];
59
60 int n2=n>>>1;
61 log2n=(int)Math.rint(Math.log(n)/Math.log(2));
62 this.n=n;
63
64 int AE=0;
65 int AO=1;
66 int BE=AE+n/2;
67 int BO=BE+1;
68 int CE=BE+n/2;
69 int CO=CE+1;
70 // trig lookups...
71 for(int i=0;i<n/4;i++){
72 trig[AE+i*2]=(float)Math.cos((Math.PI/n)*(4*i));
73 trig[AO+i*2]=(float)-Math.sin((Math.PI/n)*(4*i));
74 trig[BE+i*2]=(float)Math.cos((Math.PI/(2*n))*(2*i+1));
75 trig[BO+i*2]=(float)Math.sin((Math.PI/(2*n))*(2*i+1));
76 }
77 for(int i=0;i<n/8;i++){
78 trig[CE+i*2]=(float)Math.cos((Math.PI/n)*(4*i+2));
79 trig[CO+i*2]=(float)-Math.sin((Math.PI/n)*(4*i+2));
80 }
81
82 {
83 int mask=(1<<(log2n-1))-1;
84 int msb=1<<(log2n-2);
85 for(int i=0;i<n/8;i++){
86 int acc=0;
87 for(int j=0;msb>>>j!=0;j++)
88 if(((msb>>>j)&i)!=0)acc|=1<<j;
89 bitrev[i*2]=((~acc)&mask);
90// bitrev[i*2]=((~acc)&mask)-1;
91 bitrev[i*2+1]=acc;
92 }
93 }
94 scale=4.f/n;
95 }
96
97 //void clear(){
98 //}
99
100 //void forward(float[] in, float[] out){
101 //}
102
103 private float[] _x=new float[1024];
104 private float[] _w=new float[1024];
105
106 protected void setEqualizer(float[] equalizer) {
107 this.equalizer=equalizer;
108 }
109
110 protected float[] getEqualizer() {
111 return equalizer;
112 }
113
114 protected synchronized void imdct(final float[] frq, final float[] window, final int[] pcm) {//, float[] out){
115
116 float[] in=frq;//, out=buf;
117 if(_x.length<n/2){_x=new float[n/2];}
118 if(_w.length<n/2){_w=new float[n/2];}
119 final float[] x=_x;
120 final float[] w=_w;
121 int n2=n>>1;
122 int n4=n>>2;
123 int n8=n>>3;
124
125 if(equalizer!=null) {
126 for(int i=0; i<n; i++) {
127 frq[i]*=equalizer[i];
128 }
129 }
130
131 // rotate + step 1
132 {
133 int inO=-1;
134 int xO=0;
135 int A=n2;
136
137 int i;
138 for(i=0;i<n8;i++) {
139 dtmp1=in[inO+=2];
140 dtmp2=in[inO+=2];
141 dtmp3=trig[--A];
142 dtmp4=trig[--A];
143 x[xO++]=-dtmp2*dtmp3 - dtmp1*dtmp4;
144 x[xO++]= dtmp1*dtmp3 - dtmp2*dtmp4;
145 //A-=2;
146 //x[xO++]=-in[inO+2]*trig[A+1] - in[inO]*trig[A];
147 //x[xO++]= in[inO]*trig[A+1] - in[inO+2]*trig[A];
148 //inO+=4;
149 }
150
151 inO=n2;//-4;
152
153 for(i=0;i<n8;i++) {
154 dtmp1=in[inO-=2];
155 dtmp2=in[inO-=2];
156 dtmp3=trig[--A];
157 dtmp4=trig[--A];
158 x[xO++]=dtmp2*dtmp3 + dtmp1*dtmp4;
159 x[xO++]=dtmp2*dtmp4 - dtmp1*dtmp3;
160 //A-=2;
161 //x[xO++]=in[inO]*trig[A+1] + in[inO+2]*trig[A];
162 //x[xO++]=in[inO]*trig[A] - in[inO+2]*trig[A+1];
163 //inO-=4;
164 }
165 }
166
167 float[] xxx=kernel(x,w,n,n2,n4,n8);
168 int xx=0;
169
170 // step 8
171
172 {
173 int B=n2;
174 int o1=n4,o2=o1-1;
175 int o3=n4+n2,o4=o3-1;
176
177 for(int i=0;i<n4;i++){
178 dtmp1=xxx[xx++];
179 dtmp2=xxx[xx++];
180 dtmp3=trig[B++];
181 dtmp4=trig[B++];
182
183 float temp1= (dtmp1* dtmp4 - dtmp2 * dtmp3);
184 float temp2=-(dtmp1 * dtmp3 + dtmp2 * dtmp4);
185
186 /*
187 float temp1= (xxx[xx] * trig[B+1] - xxx[xx+1] * trig[B]);//*32767.0f;
188 float temp2=-(xxx[xx] * trig[B] + xxx[xx+1] * trig[B+1]);//*32767.0f;
189 */
190
191 //if(temp1>32767.0f) temp1=32767.0f;
192 //if(temp1<-32768.0f) temp1=-32768.0f;
193 //if(temp2>32767.0f) temp2=32767.0f;
194 //if(temp2<-32768.0f) temp2=-32768.0f;
195
196 pcm[o1]=(int)(-temp1*window[o1]);
197 pcm[o2]=(int)( temp1*window[o2]);
198 pcm[o3]=(int)( temp2*window[o3]);
199 pcm[o4]=(int)( temp2*window[o4]);
200
201 o1++;
202 o2--;
203 o3++;
204 o4--;
205 //xx+=2;
206 //B+=2;
207 }
208 }
209 }
210
211 private float[] kernel(float[] x, float[] w,
212 int n, int n2, int n4, int n8){
213 // step 2
214
215 int xA=n4;
216 int xB=0;
217 int w2=n4;
218 int A=n2;
219
220 for(int i=0;i<n4;){
221 float x0=x[xA] - x[xB];
222 float x1;
223 w[w2+i]=x[xA++]+x[xB++];
224
225 x1=x[xA]-x[xB];
226 A-=4;
227
228 w[i++]= x0 * trig[A] + x1 * trig[A+1];
229 w[i]= x1 * trig[A] - x0 * trig[A+1];
230
231 w[w2+i]=x[xA++]+x[xB++];
232 i++;
233 }
234
235 // step 3
236
237 {
238 for(int i=0;i<log2n-3;i++){
239 int k0=n>>>(i+2);
240 int k1=1<<(i+3);
241 int wbase=n2-2;
242
243 A=0;
244 float[] temp;
245
246 for(int r=0;r<(k0>>>2);r++){
247 int w1=wbase;
248 w2=w1-(k0>>1);
249 float AEv= trig[A],wA;
250 float AOv= trig[A+1],wB;
251 wbase-=2;
252
253 k0++;
254 for(int s=0;s<(2<<i);s++){
255 dtmp1=w[w1];
256 dtmp2=w[w2];
257 wB=dtmp1-dtmp2;
258 x[w1]=dtmp1+dtmp2;
259 dtmp1=w[++w1];
260 dtmp2=w[++w2];
261 wA=dtmp1-dtmp2;
262 x[w1]=dtmp1+dtmp2;
263 x[w2] =wA*AEv - wB*AOv;
264 x[w2-1]=wB*AEv + wA*AOv;
265
266 /*
267 wB =w[w1] -w[w2];
268 x[w1] =w[w1] +w[w2];
269
270 wA =w[++w1] -w[++w2];
271 x[w1] =w[w1] +w[w2];
272
273 x[w2] =wA*AEv - wB*AOv;
274 x[w2-1]=wB*AEv + wA*AOv;
275 */
276
277 w1-=k0;
278 w2-=k0;
279 }
280 k0--;
281 A+=k1;
282 }
283
284 temp=w;
285 w=x;
286 x=temp;
287 }
288 }
289
290 // step 4, 5, 6, 7
291 {
292 int C=n;
293 int bit=0;
294 int x1=0;
295 int x2=n2-1;
296
297 for(int i=0;i<n8;i++) {
298 int t1=bitrev[bit++];
299 int t2=bitrev[bit++];
300
301 float wA=w[t1]-w[t2+1];
302 float wB=w[t1-1]+w[t2];
303 float wC=w[t1]+w[t2+1];
304 float wD=w[t1-1]-w[t2];
305
306 float wACE=wA* trig[C];
307 float wBCE=wB* trig[C++];
308 float wACO=wA* trig[C];
309 float wBCO=wB* trig[C++];
310
311 x[x1++]=( wC+wACO+wBCE)*16383.0f;
312 x[x2--]=(-wD+wBCO-wACE)*16383.0f;
313 x[x1++]=( wD+wBCO-wACE)*16383.0f;
314 x[x2--]=( wC-wACO-wBCE)*16383.0f;
315 }
316 }
317 return x;
318 }
319
320}
321