// fill the data array
for (int offset = 0; offset < FFT_LEN; offset++) {
int desiredSampleIndex = (baseAddress)+offset;
short signedSample = data[desiredSampleIndex];
double sample = ((double) signedSample) / (Short.MAX_VALUE);
amplitudeData[offset] = new Complex(sample,0);
}
// run fft
frequencyData = FFT.fft(amplitudeData);
if (shift < 0) {
// downshift
// calculate new 0
int newZero = SharedDSPFunctions.getSampleNumberByFrequency(FFT_LEN, shift*-1);
// shift new zero to zero
for(int i = 0; i < FFT_LEN/2; ++i) {
Complex value;
if (i + newZero < FFT_LEN/2) {
value = frequencyData[i+newZero];
} else {
value = new Complex(0,0);
}
frequencyData[i] = value;
frequencyData[FFT_LEN-i-1] = value;
}
} else {
// calculate where to put the old 0
int oldZero = SharedDSPFunctions.getSampleNumberByFrequency(FFT_LEN, shift);
// upshift
for(int i = FFT_LEN/2-1; i > 0 ; --i) {
Complex value;
if (i - oldZero > 0) {
value = frequencyData[i-oldZero];
} else {
value = new Complex(0,0);
}
frequencyData[i] = value;
frequencyData[FFT_LEN-i-1] = value;
}