Main Content

Add Echo and Reverberation Effects to an Audio Signal on an Android Device

This example shows how to create an application to add echo and reverberation effects to an audio signal captured from the microphone of an Android® device. The application displays an audio visualizer that is synchronized with the audio as it is played. The application also has sliders that enable you to control various parameters of the audio signal.

Copyright(C) 2018-2023 The MathWorks, Inc.

Prerequisite

Before you start with this example, we recommend that you complete the Getting Started with Android Devices example.

Required Hardware

  • Android device

  • Headphones with in-line microphone (recommended)

  • USB cable

Description of Simulink Model

Open the androidAudioEffects Simulink® model.

The Simulink model is divided into these areas based on the functionality of the blocks in each area:

  • Audio Input

  • Echo and Reverb Algorithm

  • Data Visualizer

  • Audio Playback

Audio Input

The Audio Capture block accepts an audio signal from the microphone of the Android device.

Echo and Reverb Algorithm

The Variant Subsystem contains two child subsystems, Echo Subsystem and Reverb Subsystem.

The Echo Subsystem is active when the expression Mode == 1 evaluates to true. The Reverb Subsystem is active when the expression Mode == 2 evaluates to true.

To choose which subsystem to activate, either the Echo Subsystem or Reverb Subsystem, right-click the Variant Subsystem block. Select Variant > Active choice, and then select a subsystem to be activated.

  • Echo Subsystem: In this subsystem, a MATLAB Function block implements an echo algorithm by using the echo function of the Audio Toolbox™. The function uses four parameters to generate an echo effect. When the model is running on the Android device, you can tune these parameters to modify the echo effect.

   Parameter      | Description                                  | Measurement Unit
 _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
   Delay/s        | Delay applied to audio signal                | Seconds
   Gain/dB        | Linear gain of the delayed audio signal      | Decibels
   Feedback Level | Feedback gain applied to delay line          | Single-precision value
   Wet/Dry Mix    | Ratio of wet audio added to dry audio signal | Single-precision value
  • Reverb Subsystem: In this subsystem, a MATLAB Function block implements a reverb algorithm by using the reverberator function of the Audio Toolbox. The function uses seven parameters to generate a reverb effect. When the model is running on the Android device, you can tune these parameters to modify the reverb effect.

   Parameter              | Description                                   | Measurement Unit
 _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
   Pre-delay/s            | Time between hearing direct audio signal      |
                          |and the first early reflection                 | Seconds
   Highcut frequency/Hz   | Cutoff frequency for the lowpass filter       |
                          | at the front of the reverberator structure    | Hertz
   Diffusion              | Density of reverb tail                        | Single-precision value
   Decay factor           | Decay factor of reverb tail                   | Single-precision value
   High Frequency Damping | Attenuation of high frequencies in the        |
                          | reverberation output                          | Single-precision value
   Wet/Dry Mix            | Ratio of wet signal added to dry audio signal | Single-precision value
   Gain/dB                | Linear gain of the delayed audio signal       | Decibels

Data Visualizer

The Discrete Transfer Function Estimator (DSP System Toolbox) block computes the response of the audio visualizer to various frequency ranges of the audio signal. This block estimates the frequency response by using Welch's method. The response changes as you tune the echo and reverb properties.

Audio Playback

The Mute & channel selector subsystem creates Bypass and Mute buttons on the device screen. You can toggle between the original and the processed audio by clicking the Bypass button. You can mute the audio by clicking the Mute button.

The block plays the audio on the speaker of the device.

Step 1: Configure Simulink Model

1. Open the androidAudioEffects Simulink model.

2. In the Modeling tab of the toolstrip, select Model Settings.

3. In the Configuration Parameters dialog box, select Hardware Implementation. Verify that the Hardware board parameter is set to Android Device.

4. From the Groups list under Target hardware resources, select Device options.

5. From the Device list, select your Android device. If your device is not listed, click Refresh.

Note: If your device is not listed even after clicking Refresh, ensure that you have enabled the USB debugging option on your device. To enable USB debugging, enter androidhwsetup in the MATLAB® Command Window and follow the onscreen instructions.

Step 2: Deploy Simulink Model on Android Device

1. On the Hardware tab of the Simulink model, in the Mode section, select Run on board and then click Build, Deploy & Start. This action builds, downloads, and runs the model on the Android device. The application continues to run even if the device is disconnected from the computer.

The UI of the application contains:

   Elements          | Description
 _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
   Audio Visualizer  | Visual representation of the audio signal that shows the change
                     | in amplitude over a certain amount of time.
                     | The amplitude of the signal is measured on the y-axis, whereas
                     | time is measured on the x-axis.
   Sliders           | Tunable parameters to modify the echo and reverberation effect
                     | added to the audio signal.
   Bypass            | Hear the original audio signal.
   Mute              | Mute the audio signal.

2. Hold the microphone close to your mouth and start speaking. You can hear the echo of your voice through the speaker of the device. We recommend you use a headset to reduce the feedback loop between the microphone and speaker.

3. Change the values of the tunable parameters by dragging the sliders on the device screen. Speak into the microphone again, and observe the changes in the generated echo.

4. To add a reverberation effect to your voice, in the MATLAB Command Window, execute this command. This command changes the Mode of the Variant_Subsystem to point to the Reverb_Subsystem.

Mode = AudioEffectsController.Reverb

Deploy the model again. You will hear the reverb of your voice through the speaker of the device.

See Also