I'm not that good at Java, so please keep it pretty simple. I will, however, try to understand everything that you publish. Here is my problem.
I wrote code to record sound from an external microphone and saved it in .wav. The storage of this file is important for archiving purposes. I need to make FFT saved sound.
My approach to this is loading a wav file as a byte array and transforming it with a problem: 1. There the heading is how I need to get rid, but I have to do it 2. I got an array of bytes, but most, if not all the FFT algorithms that I found on the Internet and tried to patch in my design work with complex / two double arrays.
I tried to work around both of these problems and finally was able to build my FFT array in a graph when I found out that it just returns me "0". The .wav file is fine, I can play it without a problem. I thought that maybe converting bytes to doubles was a problem for me, so here is my approach to this (I know this is not very)
byte ByteArray[] = Files.readAllBytes(wav_path);
String s = new String(ByteArray);
double[] DoubleArray = toDouble(ByteArray);
boolean exp = false;
int i = 0;
int pow = 0;
while (!exp) {
pow = (int) Math.pow(2, i);
if (pow > ByteArray.length) {
exp = true;
} else {
i++;
}
}
System.out.println(pow);
double[] Filledup = new double[pow];
for (int j = 0; j < DoubleArray.length; j++) {
Filledup[j] = DoubleArray[j];
System.out.println(DoubleArray[j]);
}
for (int k = DoubleArray.length; k < Filledup.length; k++) {
Filledup[k] = 0;
}
This is the function I use to convert a byte array to a double array:
public static double[] toDouble(byte[] byteArray) {
ByteBuffer byteBuffer = ByteBuffer.wrap(byteArray);
double[] doubles = new double[byteArray.length / 8];
for (int i = 0; i < doubles.length; i++) {
doubles[i] = byteBuffer.getDouble(i * 8);
}
return doubles;
}
, , . , 2 , ( 2 ^ n ). , , - . , ( , ).
: 44100 , 16 .
FFT, .
, :
...
-2.0311904060823147E236
-1.3309975624948503E241
1.630738286366793E-260
1.0682002560745842E-255
-5.961832069690704E197
-1.1476447092561027E164
-1.1008407401197794E217
-8.109566204271759E298
-1.6104556241572942E265
-2.2081172620352248E130
NaN
3.643749694745671E-217
-3.9085815506127892E202
-4.0747557114875874E149
...
, - , - , , . , : ?