Ichigo Kurosaki
Ichigo Kurosaki

Reputation: 3843

Decoding audio with Jspeex in android produces choppy/clipped sound

i am developing an android app, which plays live speex audio stream. So i used jspeex library .
The audio stream is 11khz,16 bit.
At android side i have done as follows:

SpeexDecoder decoder = new SpeexDecoder();
decoder.init(1, 11025,1, true);
decoder.processData(subdata, 0, subdata.length);
byte[] decoded_data =  new byte[decoder.getProcessedDataByteSize()];
int result= decoder.getProcessedData(decoded_data, 0);

When this decoded data is played by Audiotrack , some part of audio is clipped.
Also when decoder is set to nb-mode( first parameter set to 0) the sound quality is worse. I wonder there is any parameter configuration mistake in my code.
Any help, advice appreciated.
Thanks in advance.

Upvotes: 2

Views: 455

Answers (1)

bonnyz
bonnyz

Reputation: 13548

Sampling rate and buffer size should be set in an optimized way for the specific device. For example you can use AudioRecord.getMinBufferSize() to obtain the best size for your buffer:

   int sampleRate = 11025; //try also different standard sampleRate
   int bufferSize = AudioRecord.getMinBufferSize(sampleRate,
                        AudioFormat.CHANNEL_CONFIGURATION_MONO,
                        AudioFormat.ENCODING_PCM_16BIT);

If your Audiotrack has a buffer which is too small or too large you will experience audio glitch. I suggest you to take a look here and play around with these values (sampleRate and bufferSize).

Upvotes: 1

Related Questions