androidwebrtcaec

Proper way to use WebRtcAecm functions


I am trying to understand how to properly use two WebRtcAecm functions. It seems there are the two main functions that are used for echo cancellation on mobile.

The first one is WebRtcAecm_BufferFarend:

int32_t WebRtcAecm_BufferFarend(void* aecmInst,
                            const int16_t* farend,
                            int16_t nrOfSamples);

I guess this is where we pass in the audio data that we receive from the remote end. Do we keep calling this method as we continue to receive audio packets? Also, does the function make a copy of the passed-in buffer so that we could reuse the same buffer for the next packet?

The other function is WebRtcAecm_Process:

int32_t WebRtcAecm_Process(void* aecmInst,
                       const int16_t* nearendNoisy,
                       const int16_t* nearendClean,
                       int16_t* out,
                       int16_t nrOfSamples,
                       int16_t msInSndCardBuf);

In a code snippet on the Internet, I saw that the same pointer was being used for nearendNoisy and nearendClean. Shouldn't nearendClean parameter be null if we don't do any noise suppression?

Finally, is there any issue in calling these two methods in two different threads? Our remote audio receiver code is in one thread and our microphone listener code is in another thread.

Thank you in advance for your help.


Solution

  • I've post a project on github which will show you exactly how to call these functions.

    nearendClean can be set to NULL indeed, and I always set it to NULL, cus' my NS is after AECM procession.

    Holp I helped :)