I'm developing an android application. What I need to do is reading a per recorded audio file. Audio file has been recorded and saved as .pcm file. I use this code to read the .pcm file.
public double[] readPCM() {
double[] result = null;
try {
File file = new File(Environment.getExternalStorageDirectory().getPath() + "/recording.pcm");
InputStream in = new FileInputStream(file);
int bufferSize = (int) (file.length()/2);
result = new double[bufferSize];
DataInputStream is = new DataInputStream(in);
for (int i = 0; i < bufferSize; i++) {
result[i] = is.readShort() / 32768.0;
}
} catch (FileNotFoundException e) {
Log.i("File not found", "" + e);
} catch (IOException e) {
e.printStackTrace();
}
return result;
}
I want to know is this code correct because in this code bufferSize is fileLength/2. It is confusing me. Please explain it to me. By the way it does return a double array with values. this code works fine but I want to make sure this works exactly. Thank you in advance.