What I am Trying to do : Reading .wav file in C(linux) ,forwarding buffer data through bluetooth rfcomm socket , receiving buffer in android and then giving buffer to Audio Track to play.(Need android application to play audio streaming) code :
1- C-code for rfcomm socket creation Ccode for rfcomm socket
2 - C-code for forwarding data
FILE *fp;
char buffer[1024];
fp = fopen("feelgood.wav","r"); //for audio track use reading .wav file
while(i=fread(buffer, sizeof(buffer),1, fp) > 0){
status=write(bluetooth_socket, buffer,strlen(buffer));
usleep(100000);
}
3- Android code for reading from socket is something like this:
//Audio Track initialization for Streaming
AudioTrack track = new AudioTrack(AudioManager.STREAM_MUSIC,44100,AudioFormat.CHANNEL_OUT_MONO,AudioFormat.ENCODING_PCM_8BIT,10000, AudioTrack.MODE_STREAM);
track.play();
//Receiving data from socket
byte[] buffer = new byte[1024];
int bytes;
bytes = socket.getInputStream().read(buffer);
track.write(buffer, 0,bytes);
Problem : Actually problem I am not getting why Audio track is not playing properly(hint of audio music with lot of noise is heard).How to listen noisefree audio on Android application part with this approach .Is there audio track implementation problem or buffer problem. Related question(Receive audio via Bluetooth in Android) but cannot follow a2dp approach on Android as sink.