Parametric Audio Equalizer
This example shows how to use the ALSA Audio Playback block from the BeagleBone® Black block library to implement a parametric audio equalizer algorithm on BeagleBone Black hardware.
Parametric equalizers are used to adjust the frequency response of audio systems. For example, a parametric equalizer can be used to compensate for biases with specific speakers that have peaks and dips at different frequencies.
In this example, you will implement a parametric audio equalizer with a Simulink® model and then run that model on BeagleBone Black hardware. The parametric equalizer algorithm in this example provides three second-order (bi-quadratic) filters whose coefficients can be adjusted to achieve a desired frequency response. A graphical user interface (GUI) is used in simulation to dynamically adjust filter coefficients and explore behavior.
The following sections will describe how the parametric equalizer algorithm is specified, how the performance can be assessed through simulation, and how the model is run on BeagleBone Black hardware. You will also learn how the ALSA Audio Playback block is used to output audio signals.
We recommend completing Get Started with Embedded Coder Support Package for BeagleBone Black Hardware example.
To run this example you need the following hardware:
BeagleBone Black hardware
Headphones or speakers
An external USB audio card, HDMI monitor with sound playback capability or an audio cape
Task 1 - Identify Audio Playback Device
The ALSA Audio Capture / Playback Simulink® blocks in the BeagleBone Black Simulink library enables you to capture and playback audio from an ALSA compatible sound card. The BeagleBone Black hardware has no built-in sound capture capability. The audio output is routed to the HDMI interface by default. Note that audio over HDMI is enabled only for resolutions 1920x1080@24 and 1280x720@60 (Reference). You can alternatively use an external USB audio card or and audio cape for sound capture and playback. In this example, we use an external USB sound card attached directly to the USB host port of the BeagleBone Black hardware.
1. In order to find the available audio playback devices on your hardware, execute the following on the MATLAB® prompt:
bbone = beaglebone_black; system(bbone, 'aplay -l')
You will see an output similar to the following:
ans = **** List of PLAYBACK Hardware Devices **** card 0: Black [TI BeagleBone Black], device 0: HDMI nxp-hdmi-hifi-0  Subdevices: 1/1 Subdevice #0: subdevice #0 card 1: Set [C-Media USB Headphone Set], device 0: USB Audio [USB Audio] Subdevices: 0/1 Subdevice #0: subdevice #0
Each ALSA playback device has a card number and a device number. In the example output above, there are two sound cards: card 0 - TI BeagleBone Black and card 1 - C-Media USB Headphone Set. Each sound card has a single device, device 0.
2. Test the audio playback through card 1 - C-Media USB Headphone Set by executing the following on the MATLAB prompt:
system(bbone, 'cat /dev/urandom | aplay -d 3 -D plughw:1,0')
The command above sends random audio samples to plughw:1,0 audio device for a duration of 3 seconds. The plughw is an ALSA plug-in that does necessary sample rate and format conversions before sending audio samples to the actual hardware device corresponding to the card 1, device 0. You should hear white noise through headphones or speakers attached to the sound card being tested while executing this command.
Task 2 - Configure and Run the Parametric Equalizer Model
In this task, you will configure and run the parametric equalizer model on BeagleBone Black hardware.
1. Open the
beaglebone_audioequalizer Simulink model.
2. In the model, make sure that the Simulation mode on the toolbar is set to External.
3. In the Simulink model, double-click on the Signal From Workspace block. The block outputs the samples of the signal called audioSignal at a rate of 44100 samples per second. The audioSignal is read from a wave file called guitartune.wav in the model InitFcn callback.
4. In the Simulink model, double-click on the ALSA Audio Playback block. This block sends the processed audio signal to an audio device on the BeagleBone Black hardware. Enter the name of the desired audio playback device in the Device name edit box:
In the example above, plughw:1,0 audio device is used. The numbers in plughw:1,0 represent the card number and the device number respectively. If you want to send audio to HDMI interface, use plughw:0,0.
5. In the model, click the Run button on the toolbar to run the model on the hardware.
Task 3 - Change the Frequency Response of the Parametric Equalizer
1. When model starts running on BeagleBone Black hardware, you will hear audio from the speakers/headphones connected to the sound card.
2. A GUI displaying the frequency response of the audio equalizer will appear as shown in the picture below:
3. Click and drag the markers or lines in the Three Band Equalizer GUI to specify the desired filter response characteristics. Note the change in audio output as the frequency response of the equalizer changes.
4. Press the Stop button on the model to stop model execution.
Other Things to Try
Change the volume of the sound sent to speakers/headphones by tuning the Gain parameter in the 'Sum left & right channels and to single* subsystem in the Simulink model.
Find out audio capture devices available on your hardware (Hint: execute 'arecord -l' command on your BeagleBone Black hardware).