Digital audio and speech is ubiquitous in products ranging from specialized industrial embedded systems to consumer products such as headsets and car kits. Many of the applications require a processor to apply algorithms such as noise suppression, echo cancellation, and gain control to streams in real time to maximize audio quality. Most design teams probably associate such algorithms with implementation on specialized DSP-centric processors that are dedicated to the audio task. Today, however, microcontrollers (MCUs) that integrate DSP math capability – often referred to as digital signal controllers (DSCs) – can handle both the real-time audio algorithms and the remainder of the application requirements. We will examine some typical algorithms and consider how to implement these algorithms on mainstream MCUs and DSCs.
First, we will cover some typical audio-centric functions that might be used in communications applications such as phones, hands-free kits, intercoms, wireless radios, and others. Noise is a common problem in such applications, although suppression algorithms can greatly reduce the ambient noise captured along with the voice through a microphone (Figure 1). Noise sources might be machinery or even the fan noise from a PC.
Figure 1: Noise suppression algorithms can greatly reduce ambient noise captured along with voice by a microphone.
A noise suppression algorithm must typically execute in real time on a stream of data. Microchip offers such an algorithm for use with its dsPIC DSCs. The algorithm operates on speech data that is sampled at 8 kHz with 16-bit resolution. The algorithm sequentially processes 10 msec blocks of speech.
The primary DSP function in the noise suppression algorithm is a frequency-domain Fast Fourier Transform (FFT). The algorithm continuously updates a profile of the detected noise. It scales the signal in individual frequency bands, amplifying speech and quieting noise.
Microchip supplies the algorithm in a Noise Suppression Library. The algorithm is coded in assembly language for maximum performance, but high-level-language application code can access the functions via an application programming interface (API).
Acoustic echo cancellation
Echo cancellation is another handy algorithm that can improve audio quality especially across a wired or wireless communications link (Figure 2). When a microphone and speaker are close to one another, signals from the speaker to the microphone are propagated to the other end of the communication link creating an echo that at best is distracting and at worst renders the link useless.
Figure 2: Echo cancellation relies on a time-domain Finite Impulse Response (FIR) filter to eliminate echo in speech that is propagated over a communication link.
Microchip offers the Acoustic Echo Cancellation library to eliminate the echo phenomenon. The time-domain algorithm relies on an adaptive Finite Impulse Response (FIR) filter that is applied to audio from the far end of the communications link. Filter coefficients provide this adaptive capability, and are set using the Normalized Least Mean Square (NLMS) algorithm. That algorithm ensures that the filter closely models the actual acoustic path. Moreover, a nonlinear processor algorithm eliminates residual echo.
Similar to the noise-suppression algorithm, the Acoustic Echo Cancellation library is coded in assembly language and can process data in real time on a dsPIC processor. It provides greater than 40 dB cancellation and uses an 8-kHz sampling rate. It is also compatible with the G.167 ITU standard that is typically used in automotive hands-free applications.
Microchip offers several additional audio-centric libraries. For example, a Line Echo Cancellation library that is ITU G.168 compliant targets phone systems. A GUI-based Speech and Audio Fast Forward tool works with other libraries, such as the Noise Suppression library, to allow tuning of an application. An Automatic Gain Control Library allows easy adjustment of audio levels.
Digital signal controllers
Now we will discuss the type of processors you might use in audio applications. As mentioned above, the Microchip libraries are designed for the company's dsPIC DSCs. A DSC is essentially just an MCU that has added math hardware to enable DSP-centric applications. The ICs still integrate memory and a broad array of peripherals, just like typical MCUs.
Microchip was actually first to use the DSC term, although now virtually every MCU vendor has such products. The Microchip offerings include the dsPIC30F and dsPIC33F/E families. All of the products include a single-cycle hardware MAC (multiplier accumulator) – specifically, a 16x16-bit multiplier and a 40-bit accumulator. The DSCs also include a barrel shifter that can shift any number of bits in a single cycle. Together, the barrel shifter and the MAC enable real-time execution of DSP-centric algorithms. The block diagram in Figure 3 depicts the dsPIC30F architecture.
Figure 3: The dsPIC30F DSC includes a 16x16-bit multiplier and 40-bit accumulator, along with a barrel shifter to enable DSP-centric applications.
Select members of the DSPIC family add peripherals that are especially handy in audio and speech applications. For example, the dsPIC33FJ128GP804 DSC includes a 16-bit dual-channel digital-to-analog converter (DAC) that can be used to output audio. Moreover, the DSC includes a 10-bit Analog-to-digital converter (ADC) that supports as many as 13 channels for audio input. The ADC can capture more than a million samples per second. The 40 MIPS processor affords the performance headroom to implement both the application code and the audio algorithms.
DSC development boards
Design teams that want to experiment with the dsPIC technology have a number of development boards to choose from. Hotenda stocks a full range of Microchip Explorer development boards for both the DSP-centric DSCs and the company's broad selection of PIC MCUs. The Microchip DM24001-ND dsPIC Explorer board includes a dsPIC33FL256GP710 DSC and the Microchip DM24002-ND dsPIC Explorer board includes a dsPIC33FJ32GP204 DSC. Both also come with 16-bit PIC MCUs.
The Explorer boards are ideal for general experimentation, but Microchip also offers mezzanine PICtail boards targeted to specific applications that can be used together with the base Explorer board. The Audio PICtail plus development board includes a 16/24-bit codec, a headphone amplifier, and microphone and line-in inputs with adjustable gain. The Speech PICtail development board supports adaptive differential pulse code modulation (ADPCM).
With the math capabilities found in DSCs, combined in general with faster MCU microarchitectures, design teams can implement complex audio-based applications that not long ago would have required separate microprocessor and DSP ICs. Moreover, libraries such as those offered by Microchip can greatly accelerate the development process and allow the design team to work in a high-level language while enjoying the performance benefits of the assembly-coded algorithms. Getting started is easy given the relatively low-cost development boards and mezzanine modules designed specifically for audio applications.