ESP-Audio-Codec Component

[中文]

Note

This document is automatically translated using AI. Please excuse any detailed errors. The official English version is still in progress.

Overview

For an introduction and performance description of the ESP-Audio-Codec component, please refer to ESP-Audio-Codec.

Codec Comparison

The table below compares the features of the Codecs supported by ESP-Audio-Codec:

Common Audio Codec Feature Comparison

Codec

Features

Typical Bitrate Range (kbps)

Applicable Scenarios

AAC (Advanced Audio Coding)

Lossy compression, better sound quality than MP3, more efficient at the same bitrate; widely supported.

96 – 320 (commonly used for stereo 128–256)

Online music, video streaming (YouTube, Apple Music, radio).

MP3

The most popular lossy compression format, excellent compatibility, but less efficient than AAC/Opus.

128 – 320 (as low as 64 can also be used)

Music download, traditional players, car audio.

AMR-NB / AMR-WB

Optimized for voice, clear voice at low bitrates; NB (8kHz), WB (16kHz).

AMR-NB: 4.75 – 12.2; AMR-WB: 6.6 – 23.85

Mobile communication (2G/3G phone calls), VoIP, voice messages.

ADPCM

Simple compression, low latency, limited sound quality; not very efficient.

Commonly 16 – 64

Early voice storage, embedded devices, simple audio transmission sensitive to latency.

G.711 (A-law / μ-law)

Waveform coding, fixed at 64 kbps, near-telephone quality; extremely low latency.

Fixed at 64

Landline phones, VoIP (such as SIP), call centers.

OPUS

Low latency, high sound quality, supports narrowband to full band, strong adaptability; open source and free.

6 – 510 (common voice 16–32, music 64–128)

Real-time voice (VoIP, conference), music streaming, game voice, WebRTC.

Vorbis

Open source lossy compression, good sound quality, better compression rate than MP3; gradually being replaced by Opus.

64 – 320 (commonly used 128–192)

Open source streaming media (OGG container), some games and applications.

FLAC

Lossless compression, retains original sound quality, compression rate about 40–60%.

700 – 1100 (CD quality, depends on content)

High fidelity music storage, music download (Hi-Res music).

ALAC

Apple’s lossless compression, similar to FLAC, limited ecosystem.

700 – 1100 (similar to FLAC)

Apple Music lossless audio, iTunes, iOS/macOS ecosystem.

SBC

Simple, low power consumption, default encoding for Bluetooth A2DP, average sound quality.

192 – 320 (commonly used 256)

Bluetooth headphones, Bluetooth speakers.

LC3

Inherits from SBC, used for Bluetooth LE Audio; low power consumption, better sound quality than SBC, low latency.

16 – 160 (commonly used 96–128)

Bluetooth LE Audio (TWS headphones, hearing aids), IoT audio.

Usage

Encoder Usage Example

  • For detailed usage, please refer to: audio_encoder_test.c

  • If you need to use a custom encoder, please follow the steps below:

    1. Implement the custom encoder interface, for details, see: struct esp_audio_enc_ops_t

    2. Define a custom audio encoder type in the enumeration esp_audio_type_t, the definition range is between ESP_AUDIO_TYPE_CUSTOMIZED and ESP_AUDIO_TYPE_CUSTOMIZED_MAX, for details, see: enum esp_audio_type_t

    3. If you want to override the default encoder, there is no need to define a custom audio encoder type, you can directly use the existing encoder type

    4. Register the custom encoder, for details, see: esp_audio_enc_register()

Decoder Usage Example

  • For detailed usage, please refer to: audio_decoder_test.c

  • If you need to use a custom decoder, please follow the steps below:

    1. Implement the custom decoder interface, for details, see: struct esp_audio_dec_ops_t

    2. Define a custom audio decoder type in the enumeration esp_audio_type_t, the definition range is between ESP_AUDIO_TYPE_CUSTOMIZED and ESP_AUDIO_TYPE_CUSTOMIZED_MAX, for details, see: enum esp_audio_type_t

    3. If you want to override the default decoder, there is no need to define a custom audio decoder type, you can directly use the existing decoder type

    4. Register the custom decoder, for details, see: esp_audio_dec_register()

Simple Decoder Usage Example

  • For detailed usage, please refer to: simple_decoder_test.c

  • If you need to use a custom simple decoder, please follow the steps below:

    1. Implement the custom simple decoder interface, for details, see: struct esp_audio_simple_dec_reg_info_t

    2. Define a custom simple audio decoder type in the enumeration esp_audio_simple_dec_type_t, the definition range is between ESP_AUDIO_SIMPLE_DEC_TYPE_CUSTOM and ESP_AUDIO_SIMPLE_DEC_TYPE_CUSTOM_MAX, for details, see: enum esp_audio_simple_dec_type_t

    3. If you want to override the default decoder, there is no need to define a custom audio decoder type, you can directly use the existing decoder type

    4. Register the custom simple decoder, for details, see: esp_audio_simple_dec_register()