Multimedia - Echo Cancellation

Materials

  • AmebaPro2 [ AMB82 MINI ] x 1
  • 3.5mm TRS/TRRS breakout x 1 (e.g., Adafruit 2791 / Sparkfun 11570)
  • Adafruit PDM Microphone Breakout x 1 [Optional]

Example

Introduction

This example shows how to use the Acoustic Echo Cancellation (AEC) audio effect of the Ameba board. The AEC algorithm can remove feedback when the Ameba Pro 2 board is both playing back audio as well as recording audio simultaneously.

Procedure

Connect the audio jack to the Ameba board as shown in the diagram.

1

Alternatively, connect the audio jack, potentiometers, and PDM Microphone as shown in the diagram below if you would like to use a digital microphone.

1

Open the example in “File” -> “Examples” -> “AmebaMultimedia” -> “Audio” -> “EchoCancellation”.

1

In the highlighted code snippet, fill in the “ssid” with your WiFi network SSID and “pass” with the network password.

1

Compile the code and upload it to Ameba.
After pressing the Reset button, wait for the Ameba Pro 2 board to connect to the WiFi network.
This example requires opening two VLC player windows, one for RTP audio streaming to the Ameba Pro 2 board, and one for RTSP audio streaming from the Ameba Pro 2 board.

RTP Audio Stream

On a computer connected to the same WiFi network, open VLC media player, and go to “Media” -> “Stream”.

1

Using the add button, add the audio file you would like to stream to the Ameba board, and click the stream button.

1

In the new window that appears, click on next to move to the destination setup page. In the dropdown menu, select “RTP Audio/Video Profile” and click on the add button next to it.

1

In the new tab that appears, enter the IP address of the Ameba Pro 2 board in the address field. Ensure that the base port uses the default value of 5004. Click on the next button.

1

For transcoding options, ensure that “Activate Transcoding” is checked. If you already have a profile created for the Ameba Pro 2, select the existing profile, and skip the next section showing how to create a profile. Otherwise, click on the highlighted button to create a new profile for the Ameba Pro 2 Board.

1

In the new window that appears, give a suitable name for the new transcoding profile. Ensure that “RAW” is selected in the “Encapsulation” tab.

1

Ensure that “Video” and “Subtitle” are disabled in the “Video codec” and “Subtitles” tabs.

1

1

In the “Audio codec” tab, ensure that “Audio” is enabled. Select “MPEG 4 Audio (AAC)” for the codec, and 1 for the number of channels. For the sample rate, this value should be the same as the AudioSetting configuration for the Ameba Pro 2, which is 8000 Hz by default for this example. Click on the create button, ensure that the new profile is selected, and click on the next button.

1

In the next window, click on the stream button, and VLC will begin streaming the audio file to Ameba Pro 2 using RTP.
Plug in a pair of wired earbuds into the audio jack, and you should hear the audio streamed from the computer. You can use the buttons in VLC to control the playback.

RTSP Audio Stream

On a computer connected to the same WiFi network, open VLC media player, and go to “Media” -> “Open Network Stream”.

1

Since RTSP is used as the streaming protocol, key in “rtsp://{IPaddress}:{port}” as the Network URL in VLC media player, replacing {IPaddress} with the IP address of your Ameba Pro2 board, and {port} with the RTSP port shown in Serial Monitor. The default RTSP port number is 554.

1

Next, click “Play” to start RTSP streaming. You should be able to hear sounds picked up by the onboard microphone replayed through computer.

Testing AEC algorithm

While both RTP and RTSP audio streams are ongoing, adjust the speaker output such that the on-board microphone on the Ameba Pro 2 board can pick up the sounds generated by the speaker, as shown in the image.

1

When the AEC algorithm is operating normally, from the RTSP audio streamed output on the computer, you should not be able to hear any audio streamed to the Ameba Pro 2 board over RTP.
To compare the effectiveness of the AEC algorithm, comment out “audio.configMicAEC(1);” in the code, recompile, reupload and test using two VLC windows again. The audio feedback from the speaker to the microphone should be obvious from the RTSP stream on the computer.

Code Reference

The AEC algorithm is limited to 8 kHz and 16 kHz sample rates. The strength level of the AEC effect can be adjusted with the second argument of configMicAEC, with 0 being the weakest and 17 being the strongest.

Please confirm that QQ communication software is installed