I want to convert a byte array (byte[]
) to float array (float[]
) in Java.
I read some examples but when I convert back again, to compare that the result is same that original signal, it is not the same.
So how can I perform this process?
EDIT:
I do this:
ByteArrayInputStream bas = new ByteArrayInputStream(data);
DataInputStream ds = new DataInputStream(bas);
float[] data_proc = new float[numbytes / 4];
for (int i = 0; i < data_proc.length; i++) {
try {
data_proc[i] = ds.readFloat();
} catch (IOException e) {
e.printStackTrace();
}
}
ByteArrayOutputStream bas2 = new ByteArrayOutputStream();
DataOutputStream ds2 = new DataOutputStream(bas2);
for(int i=0;i<data_proc.length;i++){
try {
ds2.writeFloat(data_proc[i]);
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
byte telo[] = bas2.toByteArray();
But when i compare two .pcm files not are equals.