Skip to content

Commit 70c58a1

Browse files
committed
feat(esp_capture): Update esp-sr to v2.1.5
1 parent 76d6d28 commit 70c58a1

File tree

4 files changed

+53
-32
lines changed

4 files changed

+53
-32
lines changed

packages/esp_capture/CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
# Changelog
2+
3+
## v0.7.1
4+
5+
### Features
6+
7+
- Updated esp-sr dependency to v2.1.5
8+
19
## v0.7.0
210

311
### Features

packages/esp_capture/idf_component.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version: "0.7.0"
1+
version: "0.7.1"
22
description: Espressif Capture is a module for capture media stream from camera and microphone
33
url: https://github.com/espressif/esp-gmf/tree/main/packages/esp_capture
44
documentation: "https://github.com/espressif/esp-gmf/blob/main/packages/esp_capture/README.md"
@@ -24,7 +24,7 @@ dependencies:
2424
espressif/esp_codec_dev:
2525
version: "^1.3"
2626
espressif/esp-sr:
27-
version: "1.9.5"
27+
version: "2.1.5"
2828
espressif/esp_video:
2929
require: public
3030
version: "^1.0"

packages/esp_capture/impl/capture_audio_src/capture_audio_aec_src.c

Lines changed: 38 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
typedef struct {
2525
esp_capture_audio_src_if_t base;
26+
const char *mic_layout;
2627
uint8_t channel;
2728
uint8_t channel_mask;
2829
esp_codec_dev_handle_t handle;
@@ -37,8 +38,9 @@ typedef struct {
3738
uint8_t open : 1;
3839
uint8_t in_quit : 1;
3940
uint8_t stopping : 1;
40-
const esp_afe_sr_iface_t *aec_if;
41-
esp_afe_sr_data_t *aec_data;
41+
const esp_afe_sr_iface_t *afe_handle;
42+
esp_afe_sr_data_t *afe_data;
43+
srmodel_list_t *models;
4244
} audio_aec_src_t;
4345

4446
static int cal_frame_length(esp_capture_audio_info_t *info)
@@ -49,23 +51,23 @@ static int cal_frame_length(esp_capture_audio_info_t *info)
4951

5052
static esp_capture_err_t open_afe(audio_aec_src_t *src)
5153
{
52-
afe_config_t afe_config = AFE_CONFIG_DEFAULT();
53-
afe_config.vad_init = false;
54-
afe_config.wakenet_init = false;
55-
afe_config.afe_perferred_core = 1;
56-
afe_config.afe_perferred_priority = 20;
57-
// afe_config.memory_alloc_mode = AFE_MEMORY_ALLOC_MORE_INTERNAL;
58-
afe_config.pcm_config.mic_num = 1;
59-
afe_config.pcm_config.ref_num = 1;
60-
afe_config.pcm_config.total_ch_num = 1 + 1;
61-
afe_config.aec_init = true;
62-
afe_config.se_init = false;
63-
afe_config.pcm_config.sample_rate = src->info.sample_rate;
64-
afe_config.voice_communication_init = true;
65-
src->aec_if = &ESP_AFE_VC_HANDLE;
66-
src->aec_data = src->aec_if->create_from_config(&afe_config);
67-
if (src->aec_data == NULL) {
68-
return ESP_CAPTURE_ERR_NO_MEM;
54+
src->models = esp_srmodel_init("model");
55+
if (src->models == NULL) {
56+
ESP_LOGW(TAG, "No model to load");
57+
}
58+
59+
afe_config_t *afe_config = afe_config_init(src->mic_layout, src->models, AFE_TYPE_SR, AFE_MODE_LOW_COST);
60+
61+
src->afe_handle = esp_afe_handle_from_config(afe_config);
62+
if (src->afe_handle == NULL) {
63+
ESP_LOGE(TAG, "Failed to create AFE handle");
64+
return ESP_CAPTURE_ERR_NOT_SUPPORTED;
65+
}
66+
67+
src->afe_data = src->afe_handle->create_from_config(afe_config);
68+
if (src->afe_data == NULL) {
69+
ESP_LOGE(TAG, "Failed to create AFE data");
70+
return ESP_CAPTURE_ERR_NOT_SUPPORTED;
6971
}
7072
return ESP_CAPTURE_ERR_OK;
7173
}
@@ -120,7 +122,7 @@ static void audio_aec_src_buffer_in_thread(void *arg)
120122
ESP_LOGE(TAG, "Fail to read data %d", ret);
121123
break;
122124
}
123-
ret = src->aec_if->feed(src->aec_data, (int16_t *)feed_data);
125+
ret = src->afe_handle->feed(src->afe_data, (int16_t *)feed_data);
124126
if (ret < 0) {
125127
ESP_LOGE(TAG, "Fail to feed data %d", ret);
126128
break;
@@ -154,7 +156,7 @@ static esp_capture_err_t audio_aec_src_start(esp_capture_audio_src_if_t *h)
154156
ESP_LOGE(TAG, "Failed to open AFE");
155157
return ESP_CAPTURE_ERR_NOT_SUPPORTED;
156158
}
157-
int audio_chunksize = src->aec_if->get_feed_chunksize(src->aec_data);
159+
int audio_chunksize = src->afe_handle->get_feed_chunksize(src->afe_data);
158160
src->cache_size = audio_chunksize * (16 / 8);
159161

160162
src->cached_frame = capture_calloc(1, src->cache_size * 2);
@@ -200,7 +202,7 @@ static esp_capture_err_t audio_aec_src_read_frame(esp_capture_audio_src_if_t *h,
200202
}
201203
src->cache_fill = 0;
202204
src->cached_read_pos = 0;
203-
afe_fetch_result_t *res = src->aec_if->fetch(src->aec_data);
205+
afe_fetch_result_t *res = src->afe_handle->fetch(src->afe_data);
204206
if (res->ret_value != ESP_OK) {
205207
ESP_LOGE(TAG, "Fail to read from AEC");
206208
return ESP_CAPTURE_ERR_INTERNAL;
@@ -221,15 +223,20 @@ static esp_capture_err_t audio_aec_src_stop(esp_capture_audio_src_if_t *h)
221223
audio_aec_src_t *src = (audio_aec_src_t *)h;
222224
if (src->in_quit == false) {
223225
// fetch once
224-
src->aec_if->fetch(src->aec_data);
226+
src->afe_handle->fetch(src->afe_data);
225227
src->stopping = true;
226228
while (src->in_quit == false) {
227229
capture_sleep(10);
228230
}
229231
}
230-
if (src->aec_data) {
231-
src->aec_if->destroy(src->aec_data);
232-
src->aec_data = NULL;
232+
233+
if (src->models) {
234+
esp_srmodel_deinit(src->models);
235+
src->models = NULL;
236+
}
237+
if (src->afe_data) {
238+
src->afe_handle->destroy(src->afe_data);
239+
src->afe_data = NULL;
233240
}
234241
if (src->cached_frame) {
235242
capture_free(src->cached_frame);
@@ -263,6 +270,11 @@ esp_capture_audio_src_if_t *esp_capture_new_audio_aec_src(esp_capture_audio_aec_
263270
src->handle = cfg->record_handle;
264271
src->channel = cfg->channel ? cfg->channel : 2;
265272
src->channel_mask = cfg->channel_mask;
273+
if (cfg->mic_layout == NULL) {
274+
cfg->mic_layout = "MR";
275+
} else {
276+
src->mic_layout = cfg->mic_layout;
277+
}
266278
return &src->base;
267279
}
268280

packages/esp_capture/include/impl/esp_capture_audio_aec_src.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,11 @@ extern "C" {
3535
* @brief Audio with AEC source configuration
3636
*/
3737
typedef struct {
38-
void *record_handle; /*!< Record handle of `esp_codec_dev` */
39-
uint8_t channel; /*!< Audio channel */
40-
uint8_t channel_mask; /*!< Bit mask to select which channels to process
41-
(e.g. 0x1 for left channel, 0x2 for right channel) */
38+
const char *mic_layout; /*!< Mic data layout, e.g. "MR", "RMNM"" */
39+
void *record_handle; /*!< Record handle of `esp_codec_dev` */
40+
uint8_t channel; /*!< Audio channel */
41+
uint8_t channel_mask; /*!< Bit mask to select which channels to process
42+
(e.g. 0x1 for left channel, 0x2 for right channel) */
4243
} esp_capture_audio_aec_src_cfg_t;
4344

4445
/**

0 commit comments

Comments
 (0)