I have a basic audiorecord-audiotrack, udp packets voice chat between two android devices. It works, but I have a bad echo. I\'m trying to remove the echo using Speex ported
UPDATE: Regarding crash - This is due to mis-use of JNI. You can't treat jshortarray as a C pointer. You need to call the relevant JNI functions to convert it to a C pointer (GetShortArrayElements and so on).
Regarding echo canceler - you currently use the internal buffer, which is about 2 frames, and that might not be enough for you. Android's context-switching is not like on a PC, and you might get 4 consecutive playback frames -> 4 consecutive recorded frames -> and so on. So you lose frames that way.
Also, Android audio streaming has higher latency than a PC, so the 2-frame buffer isn't enough. You need to implement your own buffering and play with the amount of frames by which you delay, so the echo canceler sees the echo after the playback inside the boundaries of its filter length.
Other than that, the best way to analyze and debug the echo canceler is: 1. Actually understand how it works on a high level and what are the requirements - not a rocket science, you can find everything on the official Speex docs. 2. Use the provided echo_diagnostic tool, and examine the streams in a tool such as Audacity to see where it went wrong.
The Speex AEC works pretty well when used correctly, and I've already done 3 different projects using it, so it's just a matter of correcting your implementation.