Skip to content

Commit 6d4cbde

Browse files
committed
ID: [b90ff79a]
esp_audio_codec: 1. Support g711a, g711u, pcm, adpcm decoder in audio simple decoder 2. Add pcm decoder in esp_audio_codec 3. Fix a bug that dtx is not effect in opus 4. Complete error log in esp_audio_codec
1 parent 4610cd7 commit 6d4cbde

25 files changed

+154
-11
lines changed

esp_audio_codec/CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
# Changelog
22

3+
## v2.2.0
4+
5+
### Features
6+
7+
- Support g711a, g711u, pcm, adpcm decoder in audio simple decoder
8+
- Add pcm decoder in esp_audio_codec
9+
10+
### Bug Fixes
11+
12+
- Fix a bug that dtx is not effect in opus encoder
13+
- Complete error log in esp_audio_codec
14+
315
## v2.1.0
416

517
### Features

esp_audio_codec/Kconfig

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ menu "Audio Codec Configuration"
5858
default y
5959
help
6060
Enable this option to register ALAC decoder
61+
config AUDIO_DECODER_PCM_SUPPORT
62+
bool "Support PCM Decoder"
63+
default y
64+
help
65+
Enable this option to register PCM decoder
6166
endmenu
6267

6368
menu "Audio Simple Decoder Configuration"

esp_audio_codec/idf_component.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ description: Espressif audio encoder and decoder
55
issues: https://github.com/espressif/esp-adf/issues
66
repository: https://github.com/espressif/esp-adf-libs.git
77
url: https://github.com/espressif/esp-adf-libs/tree/master/esp_audio_codec
8-
version: 2.1.0
8+
version: 2.2.0

esp_audio_codec/include/decoder/esp_audio_dec.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ extern "C" {
5656
*/
5757
typedef struct {
5858
uint8_t *buffer; /*!< Input encoded data buffer */
59-
uint32_t len; /*!< Input encoded data size */
60-
uint32_t consumed; /*!< Input data consumed size */
59+
uint32_t len; /*!< Input data size to be decoded */
60+
uint32_t consumed; /*!< Consumed input data size (output) */
6161
} esp_audio_dec_in_raw_t;
6262

6363
/**

esp_audio_codec/include/decoder/esp_audio_dec_default.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include "esp_mp3_dec.h"
3636
#include "esp_opus_dec.h"
3737
#include "esp_vorbis_dec.h"
38+
#include "esp_pcm_dec.h"
3839

3940
#ifdef __cplusplus
4041
extern "C" {
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
/*
2+
* ESPRESSIF MIT License
3+
*
4+
* Copyright (c) 2025 <ESPRESSIF SYSTEMS (SHANGHAI) CO., LTD>
5+
*
6+
* Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case,
7+
* it is free of charge, to any person obtaining a copy of this software and associated
8+
* documentation files (the "Software"), to deal in the Software without restriction, including
9+
* without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
10+
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished
11+
* to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all copies or
14+
* substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
18+
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
19+
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
20+
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21+
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22+
*
23+
*/
24+
25+
#pragma once
26+
27+
#include "esp_audio_dec.h"
28+
29+
#ifdef __cplusplus
30+
extern "C" {
31+
#endif
32+
33+
/**
34+
* @brief Configuration for PCM decoder
35+
*
36+
*/
37+
typedef struct {
38+
int32_t sample_rate; /*!< The sample rate of audio */
39+
uint8_t channel; /*!< The channel num of audio */
40+
uint8_t bits_per_sample; /*!< The bits per sample of audio */
41+
} esp_pcm_dec_cfg_t;
42+
43+
/**
44+
* @brief Default decoder operations for PCM
45+
*/
46+
#define ESP_PCM_DEC_DEFAULT_OPS() { \
47+
.open = esp_pcm_dec_open, \
48+
.decode = esp_pcm_dec_decode, \
49+
.close = esp_pcm_dec_close, \
50+
}
51+
52+
/**
53+
* @brief Register PCM decoder library
54+
*
55+
* @note If user want to use decoder through decoder common API, need register it firstly.
56+
* Register can use either of following methods:
57+
* 1: Manually call `esp_pcm_dec_register`.
58+
* 2: Call `esp_audio_dec_register_default` and use menuconfig to enable it.
59+
* When user want to use PCM decoder only and not manage it by common part, no need to call this API,
60+
* And call `esp_pcm_dec_open`, `esp_pcm_dec_decode`, `esp_pcm_dec_close` instead.
61+
*
62+
* @return
63+
* - ESP_AUDIO_ERR_OK On success
64+
* - ESP_AUDIO_ERR_MEM_LACK Fail to allocate memory
65+
*/
66+
esp_audio_err_t esp_pcm_dec_register(void);
67+
68+
/**
69+
* @brief Open PCM decoder
70+
*
71+
* @param[in] cfg Pointer to `esp_pcm_dec_cfg_t`
72+
* @param[in] cfg_sz Set to sizeof(esp_pcm_dec_cfg_t)
73+
* @param[out] dec_handle The PCM decoder handle
74+
*
75+
* @return
76+
* - ESP_AUDIO_ERR_OK On success
77+
* - ESP_AUDIO_ERR_MEM_LACK Fail to allocate memory
78+
* - ESP_AUDIO_ERR_INVALID_PARAMETER Invalid parameter
79+
*/
80+
esp_audio_err_t esp_pcm_dec_open(void *cfg, uint32_t cfg_sz, void **dec_handle);
81+
82+
/**
83+
* @brief Decode raw data for PCM
84+
*
85+
* @param[in] dec_handle Decoder handle
86+
* @param[in,out] raw Raw data to be decoded
87+
* @param[in,out] frame Decoded PCM frame data
88+
* @param[out] dec_info Information of decoder
89+
*
90+
* @return
91+
* - ESP_AUDIO_ERR_OK On success
92+
* - ESP_AUDIO_ERR_INVALID_PARAMETER Invalid parameter
93+
* - ESP_AUDIO_ERR_BUFF_NOT_ENOUGH No enough frame buffer to hold output PCM frame data
94+
*/
95+
esp_audio_err_t esp_pcm_dec_decode(void *dec_handle, esp_audio_dec_in_raw_t *raw, esp_audio_dec_out_frame_t *frame,
96+
esp_audio_dec_info_t *dec_info);
97+
98+
/**
99+
* @brief Close decoder for PCM
100+
*
101+
* @param[in] dec_handle Decoder handle
102+
*
103+
* @return
104+
* - ESP_AUDIO_ERR_OK On success
105+
*/
106+
esp_audio_err_t esp_pcm_dec_close(void *dec_handle);
107+
108+
#ifdef __cplusplus
109+
}
110+
#endif

esp_audio_codec/include/encoder/impl/esp_opus_enc.h

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,21 +71,24 @@ typedef struct {
7171
int bits_per_sample; /*!< The bits per sample of OPUS audio.
7272
This must be 16 */
7373
int bitrate; /*!< Suggest bitrate(Kbps) range on mono stream :
74-
| frame_duration(ms)| 2.5 | 5 | 10 | 20 | 40 | 60 |
75-
| samplerate(Hz) | | | | | | |
76-
| 8000 | 50 - 128 | 40 - 128 | 20 - 128 | 20 - 128 | 20 - 128 | 20 - 128 |
77-
| 12000 | 60 - 192 | 50 - 192 | 30 - 192 | 20 - 192 | 20 - 192 | 20 - 192 |
78-
| 16000 | 70 - 256 | 60 - 256 | 50 - 256 | 20 - 256 | 20 - 256 | 20 - 256 |
79-
| 24000 | 70 - 384 | 60 - 384 | 60 - 384 | 60 - 384 | 50 - 384 | 60 - 384 |
80-
| 48000 | 80 - 510 | 80 - 510 | 80 - 510 | 70 - 510 | 70 - 510 | 70 - 510 |
74+
| frame_duration(ms)| 2.5 | 5 | 10 | 20 | 40 | 60 | 80 | 100 | 120 |
75+
| samplerate(Hz) | | | | | | | | | |
76+
| 8000 | 30 - 128 | 20 - 128 | 6 - 128 | 6 - 128 | 6 - 128 | 6 - 128 | 6 - 128 | 6 - 128 | 6 - 128 |
77+
| 12000 | 30 - 192 | 20 - 192 | 6 - 192 | 6 - 192 | 6 - 192 | 6 - 192 | 6 - 192 | 6 - 192 | 6 - 192 |
78+
| 16000 | 30 - 256 | 20 - 256 | 6 - 256 | 6 - 256 | 6 - 256 | 6 - 256 | 6 - 256 | 6 - 256 | 6 - 256 |
79+
| 24000 | 50 - 384 | 40 - 384 | 40 - 384 | 40 - 384 | 40 - 384 | 40 - 384 | 40 - 384 | 40 - 384 | 40 - 384 |
80+
| 48000 | 40 - 510 | 30 - 510 | 30 - 510 | 30 - 510 | 30 - 510 | 30 - 510 | 30 - 510 | 30 - 510 | 30 - 510 |
8181
Note : 1) This table shows the bitrate range corresponding to each samplerate and frame duration.
8282
2) The bitrate range of dual stream is the same that of mono. */
8383
esp_opus_enc_frame_duration_t frame_duration; /*!< The duration of one frame.
8484
This must be 2.5, 5, 10, 20, 40, 60, 80, 100, 120 ms. */
8585
esp_opus_enc_application_t application_mode; /*!< The application mode. */
8686
int complexity; /*!< Indicates the complexity of OPUS encoding. 0 is lowest. 10 is higest.*/
8787
bool enable_fec; /*!< Configures the encoder's use of inband forward error correction (FEC) */
88-
bool enable_dtx; /*!< Configures the encoder's use of discontinuous transmission (DTX) */
88+
bool enable_dtx; /*!< Configures the encoder's use of discontinuous transmission (DTX).
89+
DTX activation condition: 1) The sample_rate must be 8000, 12000 or 16000Hz
90+
2) The application_mode must set to `ESP_OPUS_ENC_APPLICATION_VOIP`
91+
3) The frame_duration must gather than 5ms */
8992
bool enable_vbr; /*!< Configures to enable or disable variable bitrate mode */
9093
} esp_opus_enc_config_t;
9194

esp_audio_codec/include/simple_dec/esp_audio_simple_dec.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ typedef enum {
5757
ESP_AUDIO_SIMPLE_DEC_TYPE_M4A = 7, /*!< Simple decoder for M4A */
5858
ESP_AUDIO_SIMPLE_DEC_TYPE_TS = 8, /*!< Simple decoder for TS */
5959
ESP_AUDIO_SIMPLE_DEC_TYPE_RAW_OPUS = 9, /*!< Simple decoder for OPUS (raw data with no extra header) */
60+
ESP_AUDIO_SIMPLE_DEC_TYPE_G711A = 10, /*!< Simple decoder for G711A */
61+
ESP_AUDIO_SIMPLE_DEC_TYPE_G711U = 11, /*!< Simple decoder for G711U */
62+
ESP_AUDIO_SIMPLE_DEC_TYPE_PCM = 12, /*!< Simple decoder for PCM */
63+
ESP_AUDIO_SIMPLE_DEC_TYPE_ADPCM = 13, /*!< Simple decoder for IMA-ADPCM */
6064
ESP_AUDIO_SIMPLE_DEC_TYPE_CUSTOM = 0x10, /*!< Customized simple decoder type start */
6165
} esp_audio_simple_dec_type_t;
6266

40.6 KB
Binary file not shown.
1.5 KB
Binary file not shown.

0 commit comments

Comments
 (0)