Audio Codec

Swadesh Kelkar
7 min readJan 7, 2022

--

Photo by Amin Asbaghipour on Unsplash

A codec is a device or computer program that can encode or decode a digital stream of data or a signal for communication over a network. The term CODEC has been formed from the two words COder and DECoder. Codec can be for audio or video type of content. In this blog, we will see audio codec.

Audio systems are generally meant for a full duplex media flow. For this purpose, ADC and DAC are available in one package called an audio codec. An audio codec, whether hardware or emulated in software, converts analog audio signals into digital signals for transmission or encodes them for storage in a digital format. Later, the decoder side of a codec can be used to decompress and convert the digital data into an analog signal. An example of a device with a codec might be a recording/playback device. CODECs are responsible for changing the sound that a microphone picks up and converting it to a stream of 0s and 1s for transmission (analog-to-digital conversion), or in a more common vernacular, “data streaming“ if the digital signal is transmitted. codecs are also used for encoding, compressing, decoding, and decompressing video as well.

One common application for CODECs is with Digital Signal Processors (DSPs) in audio electronics devices. CODECs convert sound (using the ADC) to digital signals for a processor to compress and store and for playback, the stored digital data is decompressed and converted to analog signals via the DAC. The analog signal reaches the human ear by converting the analog signal into a transmissible sound via a pulse width modulator and a speaker, for example.

VS1063 IC

VS1063 Block Diagram (Source)

An example of audio codec is the VS1063 IC. VS1063 is an easy-to-use, versatile encoder, decoder and codec for a multitude of audio formats. VS1063a contains a high-performance, proprietary low-power DSP core VS_DSP4 , ROM memories, 16 KiB instruction RAM and up to 80 KiB data RAM for user applications running simultaneously with any built-in decoder, serial control and input data interfaces, up to 12 general purpose I/O pins, a UART, as well as a high-quality stereo ADC, and a variablesample-rate stereo DAC, followed by an earphone amplifier and a common voltage buffer.

Uncompressed Audio:

This is a type of audio that has no compression applied to it. The sound in uncompressed audio files remains the same as when it was recorded. Examples include PCM, AIFF and WAV formats.

Audio Compression & Codec

The purpose of using an audio codec is to effectively reduce the size of an audio file without affecting the quality of the sound. This helps in storing the high-quality audio signal using the minimum amount of space. The quality is restored by decoding the compressed file with the same codec before playback. The process not only reduces storage space but also decreases the bandwidth requirement for transmission of an audio signal.

There are two basic categories of audio compression.

Lossless audio

This is a compression technique that decompresses audio files back to their original data amount. Lossless compression algorithms reduce the size of the audio without compromising the quality or fidelity of the sound. Lossless methods can provide high degrees of digital compression, but there is no loss in size or sound quality. Upon decoding audio compressed with a lossless codec such as FLAC or ALAC, the result is identical in every way to the original sound, down to the bit. Lossless compression is ideal in professional audio settings where complete files are needed.

Lossy audio

This is a compression technique that does not decompress audio files to their original data amount. Lossy methods provide high degrees of digital compression, which results in smaller files. Lossy codecs take advantage of the fact that the human ear is not a perfect interpreter of audio, and of the fact that the human brain can pluck the important information out of imperfect or noisy audio. They strip away audio frequencies that aren’t used much, tolerate loss of precision in the decoded output, and use other methods to lose audio content, quality, and fidelity to produce smaller encoded media. Upon decoding, the output is, to varying degrees, still understandable. The specific codec used — and the compression configuration selected — determine how close to the original, uncompressed audio signal the output seems to be when heard by the human ear.

Because of the differences in how lossy codecs work compared to lossless ones, especially the fact that lossless ones have to be much more conservative with their compression, lossy codecs nearly always result in significantly smaller compressed audio than lossless codecs do.

Generally speaking, the most common reasons to choose lossless audio are because you require archival-quality storage, or because the audio samples will be remixed and recompressed, and you wish to avoid the amplification of artifacts in the audio due to recompression. For real-time streaming of audio, a lossy codec is usually required in order to ensure the flow of data can keep up with the audio playback rate regardless of network performance.

Common Codec Formats

The list below denotes the audio codec formats most commonly used and the compression type they use.

WAV
WAV, or Waveform Audio Format, is an uncompressed audio format that’s great to use if you want to get the original recorded material without losing sound quality. WAV files are ideal for shorter sound bites because their uncompressed form means they’re large files, making them difficult to stream. This is especially true in cases with limited bandwidth. The audio in these files is crisp, and the sound is good over Bluetooth.

AIFF
Originally created by Apple, Audio Interchange File Format, or AIFF, is an audio file that’s completely uncompressed and can be played on both Macs and PCs. AIFF is identical to CD-quality audio, but its large files increase download time and take up significant space, making the format less than ideal for portable devices. Streaming is possible in AIFF, but it’s not commonly used.

DSD
Direct Stream Digital is an uncompressed, high-resolution audio format. These files encode sound using pulse-density modulation. They are very large, with a sample rate as much as 64 times that of a regular audio CD, so they require top-of-the-line audio systems.

PCM
Pulse-Code Modulation, used for CDs and DVDs, captures analogue waveforms and turns them into digital bits. Until DSD, this was thought to be the closest you could get to capturing complete analogue audio quality.

MP3
MP3, or Moving Picture Experts Group Layer-3 Audio, is one of the most popular audio codecs. MP3 files use lossy compression, which compacts audio drastically. In some cases, MP3 files can be 10 times smaller than WAV files. This compression method is versatile and works on nearly all playback devices.

AAC
Advanced Audio Coding or AAC files (also known as MPEG-4 AAC), take up very little space and are good for streaming, especially over mobile devices. AAC files aren’t helpful if you need a near-replica of the original recording, because bits are discarded.Requiring less than 1 MB per minute of music and sounding better than MP3 at the same bitrate, the AAC format is used by iTunes/Apple Music, YouTube and Android.

Ogg Vorbis
Ogg Vorbis is an open-source and patent-free audio codec that’s great for streaming over the internet without compromising speed. Ogg Vorbis provides impressive sound at lower bit rates than other lossy formats. It is used by Spotify. The only downside of Ogg Vorbis is that it compresses audio and discards data for smaller file sizes.

FLAC
FLAC, or Free Lossless Audio Codec, delivers CD-quality audio in a file size smaller than an actual CD. It’’s also a nonproprietary, open-source codec that’s great for software developers who want to use lossless audio. Though FLAC files are easily accessible, they can be six times larger than MP3 files, so they take longer to download. This format is not compatible with all devices and software, but it sounds great over Bluetooth and streaming.

ALAC
ALAC, or Apple Lossless Audio Codec, sounds identical to original recorded audio, but it’s compressed to a smaller size without discarding bits. ALAC works primarily with Apple products, which makes the format a bit limited for folks without iOS devices. It also takes a longer time to download than lossy formats do, but it sounds great over Bluetooth. It’s possible to stream with ALAC, but this codec isn’t commonly used because of its incompatibility with non-Apple devices.

WMA
WMA, or Windows Media Audio, is available in lossy and lossless WMA formats, which gives listeners some choice. Generally, WMA files are smaller than their uncompressed counterparts, and similar in functionality to MP3s and FLAC files. Though WMA offers versatility, it’s not compatible with all devices, especially Apple devices. It’s possible to stream audio in WMA format, but major streaming providers do not use it. Fortunately, for the average listener, this format sounds good over Bluetooth. Only critical ears would hear a difference in quality.

Conclusion

We can clearly see that audio codecs play a very big and important role in the transmission and playback of the audio. Depending on the desired use case, for example artists prefer to use lossless codecs, one can choose the type of audio codec from the various ones available.

Contributors

Yuvraj Kathar
Swadesh Kelkar
Akshay Khare
Adwait Kamathe
Chinmay Kanchanwar

--

--