Main Content

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.

Introduction

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.

Prerequisites

We recommend completingGetting Started with Embedded Coder Support Package for BeagleBone Black Hardwareexample.

Required Products

  • DSP System Toolbox™

Required Hardware

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 theBeagleBone Black Simulink libraryenables you to capture and playback audio from anALSAcompatible 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:卡0 - TI BeagleBone黑色and卡1 - C-Media USBHeadphone Set. Each sound card has a single device,device 0.

2.Test the audio playback through卡1 - C-Media USBHeadphone Setby 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 toplughw:1,0audio device for a duration of 3 seconds. Theplughwis an ALSA plug-in that does necessary sample rate and format conversions before sending audio samples to the actual hardware device corresponding to thecard 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 theParametric Audio Equalizermodel.

2.In the model, make sure that theSimulation modeon the toolbar is set toExternal.

3.In the Simulink model, double-click on the Signal From Workspace block. The block outputs the samples of the signal calledaudioSignalat a rate of 44100 samples per second. TheaudioSignalis read from a wave file calledguitartune.wavin the modelInitFcncallback.

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 theDevice nameedit box:

In the example above,plughw:1,0audio device is used. The numbers inplughw:1,0represent the card number and the device number respectively. If you want to send audio to HDMI interface, useplughw:0,0.

5.In the model, click theRunbutton 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.单击并拖动标记或线的三个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 theGainparameter 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).

Summary

This example showed a Simulink model of a parametric audio equalizer. Using External mode, equalizer settings were changed in real-time as the model executed on BeagleBone Black hardware.