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;
30 static private final float cPI3_8=0.38268343236508977175f;
31 static private final float cPI2_8=0.70710678118654752441f;
32 static private final float cPI1_8=0.92387953251128675613f;
44 trig=new float[n+n/4];
47 log2n=(int)Math.rint(Math.log(n)/Math.log(2));
58 for(int i=0;i<n/4;i++){
59 trig[AE+i*2]=(float)Math.cos((Math.PI/n)*(4*i));
60 trig[AO+i*2]=(float)-Math.sin((Math.PI/n)*(4*i));
61 trig[BE+i*2]=(float)Math.cos((Math.PI/(2*n))*(2*i+1));
62 trig[BO+i*2]=(float)Math.sin((Math.PI/(2*n))*(2*i+1));
64 for(int i=0;i<n/8;i++){
65 trig[CE+i*2]=(float)Math.cos((Math.PI/n)*(4*i+2));
66 trig[CO+i*2]=(float)-Math.sin((Math.PI/n)*(4*i+2));
70 int mask=(1<<(log2n-1))-1;
72 for(int i=0;i<n/8;i++){
74 for(int j=0;msb>>>j!=0;j++)
75 if(((msb>>>j)&i)!=0)acc|=1<<j;
76 bitrev[i*2]=((~acc)&mask);
77 // bitrev[i*2]=((~acc)&mask)-1;
87 void forward(float[] in, float[] out){
90 float[] _x=new float[1024];
91 float[] _w=new float[1024];
93 synchronized void backward(float[] in, float[] out){
94 if(_x.length<n/2){_x=new float[n/2];}
95 if(_w.length<n/2){_w=new float[n/2];}
111 x[xO++]=-in[inO+2]*trig[A+1] - in[inO]*trig[A];
112 x[xO++]= in[inO]*trig[A+1] - in[inO+2]*trig[A];
120 x[xO++]=in[inO]*trig[A+1] + in[inO+2]*trig[A];
121 x[xO++]=in[inO]*trig[A] - in[inO+2]*trig[A+1];
126 float[] xxx=mdct_kernel(x,w,n,n2,n4,n8);
134 int o3=n4+n2,o4=o3-1;
136 for(int i=0;i<n4;i++){
137 float temp1= (xxx[xx] * trig[B+1] - xxx[xx+1] * trig[B]);
138 float temp2=-(xxx[xx] * trig[B] + xxx[xx+1] * trig[B+1]);
154 private float[] mdct_kernel(float[] x, float[] w,
155 int n, int n2, int n4, int n8){
164 float x0=x[xA] - x[xB];
166 w[w2+i]=x[xA++]+x[xB++];
171 w[i++]= x0 * trig[A] + x1 * trig[A+1];
172 w[i]= x1 * trig[A] - x0 * trig[A+1];
174 w[w2+i]=x[xA++]+x[xB++];
181 for(int i=0;i<log2n-3;i++){
189 for(int r=0;r<(k0>>>2);r++){
192 float AEv= trig[A],wA;
193 float AOv= trig[A+1],wB;
197 for(int s=0;s<(2<<i);s++){
201 wA =w[++w1] -w[++w2];
204 x[w2] =wA*AEv - wB*AOv;
205 x[w2-1]=wB*AEv + wA*AOv;
227 for(int i=0;i<n8;i++){
228 int t1=bitrev[bit++];
229 int t2=bitrev[bit++];
231 float wA=w[t1]-w[t2+1];
232 float wB=w[t1-1]+w[t2];
233 float wC=w[t1]+w[t2+1];
234 float wD=w[t1-1]-w[t2];
236 float wACE=wA* trig[C];
237 float wBCE=wB* trig[C++];
238 float wACO=wA* trig[C];
239 float wBCO=wB* trig[C++];
241 x[x1++]=( wC+wACO+wBCE)*.5f;
242 x[x2--]=(-wD+wBCO-wACE)*.5f;
243 x[x1++]=( wD+wBCO-wACE)*.5f;
244 x[x2--]=( wC-wACO-wBCE)*.5f;