0

When I loaded .wav signal in matlab,the values ​​of samples are like this 0.001853466033936, 0.003706693649292 etc.

When I loaded same signal in Java with:

byte[] buffer = new byte[blockSize];
FileInputStream s = new FileInputStream(file);
s.read(buffer, 0, blockSize);

i have values like this: 73, 70...

I tried to convert to double and I never got the same result like in matlab.

I need this for Android!

Can someone help me? THANKS!

Avokado
  • 59
  • 1
  • 9

1 Answers1

1

Your java code is reading the file from the beginning. Look at the WAVE file format, the data is stored after the header.

You will need to write a wav file reader (or find an android compatible one) to parse the header, read the NumChannels, BitsPerSample etc, find the start of the data and read.

This is what MATLAB's wavread does (presumably this is what you are using?). You can see how it parses wav files, type edit wavread.

Have a look at this simple Java WAV File IO class. It may do all you need or at least get you started.

smn
  • 548
  • 2
  • 7