I am trying to record audio on Android. I have found different examples, but one thing I didn't understand.
Some people write shorts, other bytes.
Here is an example of converting short to bytes.
private byte[] short2byte(short[] sData) {
int shortArrsize = sData.length;
byte[] bytes = new byte[shortArrsize * 2];
for (int i = 0; i < shortArrsize; i++) {
bytes[i * 2] = (byte) (sData[i] & 0x00FF);
bytes[(i * 2) + 1] = (byte) (sData[i] >> 8);
sData[i] = 0;
}
return bytes;
}
What is the purpose of doing that ? Why not to write shorts directly to file, as far as we are using PCM 16bit.
Please explain this matter from the audio perspective.
Thanks