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 The MathWorks, Inc.
Before you start with this example, we recommend that you complete the Getting Started with Android™ Devices example.
To run the model, download and install:
Headphones with in-line microphone (recommended)
To demonstrate the addition of echo and reverberation effects to the audio signal, the example uses a Simulink® model, androidAudioEffects.
The model is divided into these areas based on the functionality of the blocks in each area:
Echo and Reverb Algorithm
Audio Capture block accepts an audio signal from the microphone of the Android™ device.
Echo and Reverb Algorithm
Echo Subsystem is active when the expression
Mode == 1 evaluates to
Reverb Subsystem is active when the expression
Mode == 2 evaluates to
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 System 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
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.
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.
1. Open the androidAudioEffects 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
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.
1. On the Simulink® model toolbar, click Deploy to Hardware. 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, right-click the
Variant Subsystem block, select Variant > Active choice > REVERB_CONTROLLER (Reverb Subsystem), and then deploy the model again. You will hear the reverb of your voice through the speaker of the device.