Real time audio playback in android device causes Echo

For iOS (iPhone, iPad & iPod), Android, Windows Phone, etc. App and Hardware talk
Post Reply New Topic
RELATED
PRODUCTS

Post

Hi
I'm happy that after lots of hopelessness and wasting my time and asking qs on stackoverflow and finding no sound guru to get an answer,i found this forum and i'm positive that i will get an answer.
I am trying to receive audio from head set's mic and playback the audio in real time to the Headphones using AudioTrack.I have implemented required code but the problem is that there is a disturbing Echo. I'm not using speakers and i'm using headphones. So,whats causing this echo? I used device's echocanceller which introduced in API level 11 and echo decreased but didn't go away.Im aware of audio latency in android devices but i can't understand how the delay may cause echo while i'm using headphones.Please guide me to the right direction.
PS: http://stackoverflow.com/questions/1580 ... -real-timelink to my question in stackoverflow.
Last edited by drplasma on Thu Apr 04, 2013 8:44 am, edited 1 time in total.

Post

If you have echo in your output and you're using headphones, then you've done something wrong and crossed wires somewhere in your code. You don't need echo cancellation if you're using headphones, the two streams should never cross unless you tell them to do so. I've never seen this, neither with AudioTrack nor OpenSL ES. What mic source are you using? if you're using the default, try using
AudioSource.VOICE_RECOGNITION as it doesn't use auto-gain or any of the other crap vendors turn on for phone calls.

BTW, if you're targeting higher API levels anyway, don't bother with AudioTrack, use OpenSL. It has better latency and Google have said this is the real-time API they're focusing on going forward.

Also, which devices have you tested this on?

Post

I already tested both MIC/VOICE_RECOGNITION etc but no success.Here is the link to my source code:
http://pastebin.com/z2VDEGN9
The recording to disk is optional. Sound is recorded to a buffer and then read to audiotrack. What am i doing wrong?Could you please give me some resources for code examples and new low latency implementations? Is OpenSL ES really faster?
PS: please note that echo exists even if DSP is disabled.

Post

Well, I can't tell what's wrong looking at an entire finished class (especially that it doesn't show the actual dsp handler), but you should be able to do a simple test by running something like

Code: Select all

your_audio_thread_run()
{
 declare audio buffer
 create AudioRecord
 create AudioTrack
 start both

 while(1)
 {
   capture mic to buffer
   write buffer to output track
 }
}
if you still get echo in this basic setup, there's something wrong with your device/firmware.

The only other thing I can think of is if you're using "phone headphones" to test with (the kind that have a mic built in), you might be picking up sound from the headphones through the little mic that's meant to pick up your voice. (could also be electronic crosstalk if the wires aren't well shielded.)
Last edited by SingleCell on Thu Apr 04, 2013 10:35 am, edited 1 time in total.

Post

Sorry for the very long code.actually im doing what you proposed and thanks for taking time and explaining it to me. You are right. Im using that kind of headphones and the echo might be because of that.I must check it out

Post

SingleCell wrote:Well, I can't tell what's wrong looking at an entire finished class (especially that it doesn't show the actual dsp handler), but you should be able to do a simple test by running something like

Code: Select all

your_audio_thread_run()
{
 declare audio buffer
 create AudioRecord
 create AudioTrack
 start both

 while(1)
 {
   capture mic to buffer
   write buffer to output track
 }
}
if you still get echo in this basic setup, there's something wrong with your device/firmware.

The only other thing I can think of is if you're using "phone headphones" to test with (the kind that have a mic built in), you might be picking up sound from the headphones through the little mic that's meant to pick up your voice. (could also be electronic crosstalk if the wires aren't well shielded.)
1.I detached the headset mic and soldered to a 3meteres wire but the problem still persists
2.The issue is much noticeable only on my Samsung galaxy SII with stock 4.1 android But on my Samsung galaxy note the echo is not very noticeable.
3.Whenever i use earbuds without any external mic which will route input to internal device mic,the echo is completely gone.
4.I tested apps on market(eg microphone, hearing aid apps)the problem persists.

Post

If it only happens when you use a heaset with a mic, then it's definitely crosstalk.

Are you amplifying the mic signal a LOT by any chance?

Post

SingleCell wrote:If it only happens when you use a heaset with a mic, then it's definitely crosstalk.

Are you amplifying the mic signal a LOT by any chance?
As far as im aware, there is no native mic input amplification option in android API.I have not attatched any preamplifiers or amplifiers to mic in.The sound volume is 50 percents and no more.So the issue might be with the phone audio cirute.You may reproduce the problem by installing microphone app from android market and see it for your self.None of such apps recomended using headsets.they all recomended using headphones+mobile mic. No one mentioned using headsets.
Do you know some forums with knowledges regarding mobile sound systems?

Post Reply

Return to “Mobile Apps and Hardware”