Hi,
I am writing an application which receives the audio from network. the audio is alaw (8000Hz, 8bit).
My problem is that AudioFormat is ENCODING_PCM_16BIT doesn't support ENCODING_PCM_8BIT.
The received data is in sizes of 256 and 384.
I need to convert my received samples from byte to short.
I have tried but all i get is noise.
This is what i do:
byte[] buffer = new byte[1024];
track = new AudioTrack(AudioManager.STREAM_MUSIC, 8000, AudioFormat.CHANNEL_OUT_MONO, AudioFormat.ENCODING_PCM_16BIT, buffer.length, AudioTrack.MODE_STREAM);
track.play();
//receives audio stream from network
private void onAudio(AudioTrack track, byte[] userData) {
track.write(userData, 0, userData.length); // -> noise
}
I also tried converting to short[] using following code:
short[] shortOut = new short[buffer.length / 2];
ByteBuffer byteBuffer = ByteBuffer.wrap(byteArray);
byteBuffer.order(ByteOrder.LITTLE_ENDIAN).asShortBuffer().get(shortOut);
track.write(shortOut , 0, shortOut .length); // -> noise
Can any one please help me?
Thanks.
I am writing an application which receives the audio from network. the audio is alaw (8000Hz, 8bit).
My problem is that AudioFormat is ENCODING_PCM_16BIT doesn't support ENCODING_PCM_8BIT.
The received data is in sizes of 256 and 384.
I need to convert my received samples from byte to short.
I have tried but all i get is noise.
This is what i do:
byte[] buffer = new byte[1024];
track = new AudioTrack(AudioManager.STREAM_MUSIC, 8000, AudioFormat.CHANNEL_OUT_MONO, AudioFormat.ENCODING_PCM_16BIT, buffer.length, AudioTrack.MODE_STREAM);
track.play();
//receives audio stream from network
private void onAudio(AudioTrack track, byte[] userData) {
track.write(userData, 0, userData.length); // -> noise
}
I also tried converting to short[] using following code:
short[] shortOut = new short[buffer.length / 2];
ByteBuffer byteBuffer = ByteBuffer.wrap(byteArray);
byteBuffer.order(ByteOrder.LITTLE_ENDIAN).asShortBuffer().get(shortOut);
track.write(shortOut , 0, shortOut .length); // -> noise
Can any one please help me?
Thanks.