I am playing sound with the help of AudioTrack in my APP but i want to play sound in specific speaker/ear means left speaker or right speaker or both speaker.
Follow
AudioTrack
uses raw PCM samples to play sounds. The PCM samples are played in the following order (the first sample is played by the left speaker and the second sample is played by the right speaker):
LRLRLRLRLR
So you have to modify your samples array that you pass to AudioTrack
.
This could help too.
In your case just do the following:
// only play sound on left
for(int i = 0; i < count; i += 2){
short sample = (short)(Math.sin(2 * Math.PI * i / (44100.0 / freqHz)) * 0x7FFF);
samples[i + 0] = sample;
samples[i + 1] = 0;
}
// only play sound on right
for(int i = 0; i < count; i += 2){
short sample = (short)(Math.sin(2 * Math.PI * i / (44100.0 / freqHz)) * 0x7FFF);
samples[i + 0] = 0;
samples[i + 1] = sample;
}