kaeuser
kaeuser

Reputation: 31

Pre-processing compile-time constant arrays in Java 1.4

For a current project, my task is to optimize a DSP algorithm for a machine only capable of executing Java 1.4 bytecode. The algorithm requires a lot of computations of coefficients of e^(-2 * i * pi * n * k * C) for a frequency shift; in my case, k ranges from 0-10, and n ranges from 0-4095. C is a constant.

What i want to do in order to speed up the algorithm is to pre-compute these coefficients and, ideally, have that done at compile time.

Therefore, my question is:

can

private final static float[][] coefficientsReal = getCoefficientsReal();
private final static float[][] getCoefficientsReal(){
    float[][] coeffReal = new float[11][];
    for (int kk=0; kk<11;kk++){
        coeffReal[kk]= new float[4096];
        for (int nn = 0; nn < 4096; nn++){
             coeffReal[kk][nn] = Math.cos(-2 * (float)Math.PI * kk * nn * C);
        }
    }
    return coeffReal;
} 

which should be constant and known at compile time, be expressed in any way, so that all computations are executed at compile time? If not, what would be another way do do these computations before loading the class (note that static initializers are executed before the class is used, but still at runtime)? And, additionally, if it is not possible to compute that before, why?

Possible other options

I thought about other ways to solve the problem

So far, I have not figured out which way would be the best to go.

Thank you for answers on my first question here!

Upvotes: 3

Views: 191

Answers (0)

Related Questions