I am working on a project related to audio processing.
I take a piece of audio from a file, and then I would like to process it. The problem is that I get the audio data as an array of bytes, and my processing is in a double array (and later in a complex array ...).
My question is, how can I correctly convert the byte array that I get for a double array?
Here is my input code:
AudioFormat format = new AudioFormat(8000, 16, 1, true, true);
AudioInputStream in = AudioSystem.getAudioInputStream(WAVfile);
AudioInputStream din = null;
AudioFormat decodedFormat = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED,
8000,
16,
1,
2,
8000,
true);
din = AudioSystem.getAudioInputStream(decodedFormat, in);
TargetDataLine fileLine = AudioSystem.getTargetDataLine(decodedFormat);
fileLine .open(format);
fileLine .start();
int numBytesRead;
byte[] targetData = new byte[256];
while (true) {
numBytesRead = din.read(targetData, 0, targetData.length);
if (numBytesRead == -1) {
break;
}
double[] convertedData;
processAudio(convertedData);
}
So far, I have studied different answers to different questions around this site and others. I tried using ByteBuffer and bit conversion, but both of them did not give me results that seem correct (the other member in my team did the same in a single Python file, so I have a link that the results should be approximately ...
? ? targetData 32 , TargerData? convertData?
.