1

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.

Ichigo Kurosaki
  • 3,765
  • 8
  • 41
  • 56

1 Answers1

1

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).

Community
  • 1
  • 1
bonnyz
  • 13,458
  • 5
  • 46
  • 70
  • I have set 11025 because the incoming audio is of 11 KHz,, also i have tried with different standard frequencies and buffer size.. but quality is not improving – Ichigo Kurosaki Jan 30 '15 at 06:15