4

I working on an android app which records audio. For best audio quality it is better to use a buffer of shorts while reading?

//aRecorder.read(shortBuffer, 0, shortBuffer.length);
aRecorder.read(byteBuffer, 0, byteBuffer.length);

Using short[] isn't the same as using byte[] and considering a sample from 2 bytes(byteBuf[i] and byteBuf[i+1])? If I use short[], I must convert it anyway to ByteBuffer to write it on a file.

I'm asking this because I want to know if I switch to buffer of shorts, my recordings will be more accurate? For example, shortBuffer[0] contains the same information as byteBuffer[0] and byteBuffer[1] ?

The recordings could be in 16 bits PCM or 8 bits PCM (User can choose the sample rate, nr of channels, PCM 16 or 8, etc)

I must mention that the output file will be in WAV format.

1 Answer 1

5

There is no difference between using a Short or Byte buffer, it is just two representations of the same underlying data.

The only difference I can think of is that you are limiting your options on how to access the data during recording, since in short your minimum data representation would be 16 bit (short size) but then again you can just xAnd any part of the short object to get one of its bytes.

if you are doing a real time audio processing of any kind you better use byte to easy data minipulation.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, I will proceed further with byte array since I managed to apply gain on it during recording and to calculate the max amplitude at each recording callback. Switching to short would involve to modify my gain algorithm which however gave me a lot of headaches.
@AlexandruCircus : Were you able to calculate max value from AudioRecord using byte array. Most of the working examples where using short array. Would be glad if you could help me calculate max from byte array (while recodring audio using AudioRecord). TIA.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.