Sound

Sound output devices

Buzzers

The simplest output device for sound is a piezoelectric buzzer. Buzzers can produce simple tones for applications such as alarms or timers. Buzzers are inexpensive and can be controlled directly from a microcontroller. A simple square wave suffices to produce a sound. Buzzers have a resonant frequency, at this frequency they will produce the most sound. As implied by the name, piezoelectric buzzers are built around a piezoelectric crystal. This crystal will deform under influence of a voltage. Periodically reversing the voltage on this crystal will cause the crystal to vibrate, thus producing sound.

The downside of buzzers is that they produce low quality sound, which can be perceived as harsh and unpleasant by users. For this reason, modern devices tend to pursue more qualitative sound solutions. Still, the price point of piezoelectric buzzers is hard to beat, and they still find their use in many different applications.

Speakers

Speakers are high quality sound output devices. They are a specialized type of electromechanical actuator. Speakers work by using a coil to vibrate a magnet that is attached to a membrane. Sending a specific signal to the coil will cause the membrane to vibrate at that frequency, thus generating sound.

Speakers are characterized by a much broader frequency response than buzzers. That is to say, speakers will produce high quality sound at a broader range of frequencies, whereas buzzers tend to have a more narrow frequency range. Some speakers are designed to more or less cover the full audio spectrum of human hearing, these speakers are called full-range speakers. Other speakers are optimized to work in one specific range of frequencies, in this case multiple speakers are combined to cover the full audio spectrum. These speakers are sometimes called woofers (low tones), midrange speakers, or tweeters (high tones). Using specialized speakers results in the highest sound quality, though needless to say, this solution is more expensive. For the best sound output, the speaker enclosure should be optimized to match the properties of the speakers. However, this is a specialist subject. Finally, speakers have a characteristic impedance, measured in Ohms. Ideally, the impedance of speaker and amplifier should match. However, it is possible to attach a high impedance speaker (e.g. 8 Ohm) to a low impedance amplifier (e.g. 4 Ohm). The reverse is not possible.

Driver circuitry

Specialized circuitry is required to generate sound. This is done in three distinct steps. First, the digital sound files are decoded into raw audio data. Secondly, a digital-to-analog converter (DAC) is used to generate an analog signal that represents the sound. Finally, this analog signal is amplified and sent to the speaker. The rest of this section will discuss drivers for speakers, as buzzers are usually controlled directly.

Decoding data

First, the sound files need to be decoded from compressed audio file into a raw stream of numbers representing the audio signal. Optionally, transformations such as volume adjustment, balance adjustment, or equalization may also be applied. There are multiple ways to decode audio data. The first option is to decode the audio files in software. A reasonably powerful microcontroller is needed for this, and software decoding tends to be less energy-efficient. Microcontrollers with digital signal processing (DSP) extensions may be helpful for this, as these extensions allow audio processing algorithms to be performed more efficiently. The last option is to use a separate specialized CODEC chip, such as one of the devices from VLSI. This is the most energy-efficient solution, though a separate codec IC adds to the system cost.

Digital-to-Analog converter

Next, the decoded audio stream needs to be converted to an analog signal. This task is performed by a digital-to-analog converter (DAC). Some microcontrollers, such as those found in the Teensy boards, have a built-in DAC. In other cases, stand-alone DAC chip needs to be used. Most DACs that are intended for audio purposes can be interfaced using an I2S bus. I2S is an electrical bus standard intended for connecting digital audio devices together. Note that I2S is unrelated to I2C, they are different standards.

Amplifier

The final step is to take the low-power signal from the DAC, amplify it, and direct it to the speaker. In the past, analog amplifier circuits were generally for their sound quality. However, analog amps are inefficient; the theoretical maximum efficiency of a class-AB amplifier is less than 78%. In recent years, class-D amplifiers have risen to prominence. Class-D amplifiers are digital amplifiers. They work by rapidly switching the speaker coil on and off at a frequency that is much higher than can be perceived by human hearing. Class-D amplifiers are much more efficient than traditional amplifier circuits. This is because the transistors are turned either fully on or fully off, they do not operate in the inefficient linear region. The block diagram below illustrates the basic operating principle of class-D amps.

 

Finally, it should be noted that some chips combine multiple roles into a single device. For instance, the MAX98357A combines an I2S DAC and class-D amplifier into a single package. This IC can be connected directly to a Raspberry Pi to provide an end-to-end audio solution. For prototyping purposes, the DFPlayer Mini can also be used. This module combines a CODEC, DAC, and amplifier in a single package and can be controlled directly through serial commands.