Hi all, I am intend to decode the sound data from my wave file to int format for further analysis. But i m stucked with the decode code. Hereby wish to have your advise.

I have made a case. Please correct my concept and code where i have done wrong that cause the error in my code.

If
- my sound data of one sample is 1234H (in hexa for easier representation)
- i have byte array abData[] that hold my sound data
- Data is stored as arrangement below: abData[i+1] ... abData[i]

In big Endian: 34 12
Left-shift abData[i] by 8 bits

In little Endian: 12 34
Left-shift abData[i+1] by 8 bits

The sound data should be obtained after abData[i+1] + abData[i]

boolean isBigEndian = audioFormat.isBigEndian();

//this array is the value of the signal at time, assume that i have n sample
int x[] = new int[n];

//convert each pair of byte values from the byte array to an Endian value
for (int i = 0; i < n*2; i+=2) {
int b1 = abData[i];
int b2 = abData[i + 1];

int value;

//Store the data based on the original Endian encoding format
if (isBigEndian) value = (b1 << 8) + b2;
else value = b1 + (b2 << 8);
x[i/2] = value;
}



I have do according my concept... but the result still wrong...

Below is the 1st 10th results i got from both Java and MATLAB after simulate the program with a 300 Hz sine wave audio file:

Java:
-173
-779
-1128
-1219
-1819
-2161
-2244
-2835
-3165
-3233

MATLAB: (I use wavread function to retrieve the sound data directly, the data is reliable.)
-0.1272
-0.1363
-0.1451
-0.1537
-0.1620
-0.1699
-0.1776
-0.1850
-0.1920

Please advise again.

Thanks a lot!!