AcousticEchoCanceler on Samsung devices not working

2.7k views Asked by At

I have AcousticEchoCanceler working for VoIP calls for every other device type I've tried, but not on any Samsung device. The device reports AcousticEchoCanceler being available but it simply does nothing.

What I've got:

  • acousticEchoCanceler.setEnabled(true);
  • audioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
  • Audio session ID passed to AudioTrack
  • Sample rate: 16k
  • Tried both mono and stereo recording
  • <uses-permission android:name="android.permission.RECORD_AUDIO"/>
  • <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS"/>

Has anyone got AcousticEchoCanceler to work on a Samsung device?

3

There are 3 answers

0
Kervala On

I had the same issue recently. The most important part for me was to use audioManager.setMode(AudioManager.MODE_IN_COMMUNICATION) before creating the AudioRecord.

Next the AudioRecord was created with :

mAudioRecord = new AudioRecord(MediaRecorder.AudioSource.VOICE_COMMUNICATION, mSamplingRate, AudioFormat.CHANNEL_IN_MONO, AudioFormat.ENCODING_PCM_16BIT, audioRecordBufferSize);

And finally create and enable the NS and AEC :

mNoiseSuppressor = NoiseSuppressor.create(mAudioRecord.getAudioSessionId());
if (mNoiseSuppressor != null) {
    int res = mNoiseSuppressor.setEnabled(true);
}

mAcousticEchoCanceler = AcousticEchoCanceler.create(mAudioRecord.getAudioSessionId());
if (mAcousticEchoCanceler != null) {
    int res = mAcousticEchoCanceler.setEnabled(true);
}

The AudioTrack doesn't need to be associated to same Audio session ID than AudioTrack (I suppose it should be done automatically).

4
Harminder Singh On

Try these lines:

if (AcousticEchoCanceler.isAvailable() && WebRtcAudioUtils.isAcousticEchoCancelerSupported()) {
                WebRtcAudioUtils.setWebRtcBasedAcousticEchoCanceler(true);
                WebRtcAudioUtils.useWebRtcBasedAcousticEchoCanceler();
            }
1
Thingy On

I had tried this code a few years ago and remember that it worked. Can't say how it will fare with the latest devices.

int audioSource = MediaRecorder.AudioSource.VOICE_COMMUNICATION;
int sampleFreq = 16000;
int numChannels = 1;
int numBytesPerSample = 2;
int channelConfig = numChannels == 1 ? AudioFormat.CHANNEL_IN_MONO : AudioFormat.CHANNEL_IN_STEREO;
int audioFormat = numBytesPerSample == 2 ? AudioFormat.ENCODING_PCM_16BIT : AudioFormat.ENCODING_PCM_8BIT;
int bufSize = AudioRecord.getMinBufferSize(sampleFreq, channelConfig, audioFormat);
if (bufSize == AudioRecord.ERROR_BAD_VALUE || bufSize == AudioRecord.ERROR) {
        return;
}

AudioRecord audioInRecord   = new AudioRecord(audioSource, sampleFreq, 
                channelConfig, audioFormat, bufSize);
if (audioInRecord.getState() != AudioRecord.STATE_INITIALIZED) {
    return;
}

boolean aecAvailable = AcousticEchoCanceler.isAvailable();
if (aecAvailable) {
    AcousticEchoCanceler instance;
    if((instance = AcousticEchoCanceler.create(audioInRecord.getAudioSessionId())) != null) {
        instance.setEnabled(true);
        Log.d(TAG, "AEC enabled");
    } else {
        Log.d(TAG, "AEC disabled");
    }
}