google / oboe

Oboe is a C++ library that makes it easy to build high-performance audio apps on Android.
Apache License 2.0
3.69k stars 563 forks source link

AudioEffect AcousticEchoCanceler is not working with Oboe #951

Open banburubi opened 4 years ago

banburubi commented 4 years ago

Android version(s): 10 Android device(s): Google Pixle 3a Oboe version: 1.4.2 App name used for testing: Similar to LiveEffect

Short description In voice related application, I'm working on, I have a feedback loop and to avoid it I'm trying to apply Android AEC effect to Oboe Input stream. The acutal sample does not work: https://github.com/google/oboe/blob/master/docs/notes/effects.md

Steps to reproduce

In my case for AEC to be intialized properly I need to use such code in Java:

        int sampleRate = 48000;
        int channelConfig = AudioFormat.CHANNEL_IN_MONO;
        int audioFormat = AudioFormat.ENCODING_PCM_16BIT;

        int chunkSize = AudioRecord.getMinBufferSize(sampleRate, channelConfig, audioFormat);
        int bufferSize = chunkSize;

        int audioSource = MediaRecorder.AudioSource.MIC;
        record = new AudioRecord( audioSource,
                sampleRate,
                channelConfig,
                audioFormat,
                bufferSize );

        audioSessionId = record.getAudioSessionId(); //This session id is passed to Oboe through jni

a few strings below there is such an activation of AEC:

        if(AcousticEchoCanceler.isAvailable())
        {
            aec = AcousticEchoCanceler.create( sessionId );
            if(null != aec)
            {
                if ( !aec.getEnabled() )
                {
                    aec.setEnabled(true);
                }
            }
         }

Oboe stream is created later with session id from AudioRecord.

There are no errors, AEC is enabled and session id is set to Oboe Input stream. I'm still getting low-latency steam the only difference it is not Exclusive anymore (when session id is set).

I have also tried with NoiseSuppressor effect with the same result.

Expected behavior Echo and some noise should be removed if an effect is attached.

Actual behavior Does not work.

Looking forward to your feedback.

Thank you very much.

P.S. Probably these issues are related: https://github.com/google/oboe/issues/296 https://github.com/google/oboe/issues/898 https://github.com/google/oboe/issues/85

Best, Vladymyr.

philburk commented 4 years ago

Do not create an AudioRecord. Just allocate a sessionId.

AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
int audioSessionId = audioManager.generateAudioSessionId();
banburubi commented 4 years ago

Thank you veyr much for the reply.

philburk commented 4 years ago

I'm still getting low-latency steam the only difference it is not Exclusive anymore (when session id is set).

EXCLUSIVE streams are only supported on the new MMAP data path. Sessions and Effects are only supported on the Legacy data path. The Legacy data path will not use the FAST low-latency mixer when effects are enabled.

I will review this limitation with the team.

One way to achieve low latency with effects is to add your own effects above the OS.

banburubi commented 4 years ago

Thank you very much. It is clear. I will try to integrate AEC from WebRTC it is just a bit more time consuming from the development perspective.

Cova8bitdots commented 3 years ago

@philburk Hi, Is this issue not solved on low-latency audio thread yet? If not, are there any way to achieve to implement in Oboe-layer?

I'm working to create karaoke-live-streaming app on Android. There is problem when user does not use earphone( audio feedback happens )

philburk commented 3 years ago

I improved the Effects test in OboeTester. I then tested on a Pixel 3a running RQ1A. (11). I was able to get a low-latency input stream when I enabled the effect. I was using InputPreset=VoiceRec. If I selected VoiceCommunication then I did not get any input signal.