Skip to content

Commit 3b55cff

Browse files
committed
Merge branch 'feature/gmf_loader' into 'main'
gmf_loader: Add loader of gmf io & elements See merge request adf/multimedia/esp-gmf!63
2 parents fd54a2a + e087ba1 commit 3b55cff

File tree

68 files changed

+4024
-598
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+4024
-598
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ Advanced components are encapsulation modules in ESP-GMF that target specific ap
4141
| Component Name | Function | Dependent Components |
4242
| :------------: | :------------: | :------------ |
4343
| [esp_audio_simple_player](./packages/esp_audio_simple_player) | Simple audio player | - `gmf_audio`<br>- `gmf_io` |
44+
| [gmf_loader](./packages/gmf_loader) | Set up the given GMF pool using the configuration selected via `Kconfig` | - `gmf_core`<br>- `gmf_io`<br>- `gmf_audio`<br>- `gmf_ai_audio`<br>- `esp_codec_dev`<br>- `esp_audio_codec` |
4445

4546
# ESP-GMF Usage Guide
4647

README_CN.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ ESP-GMF 各个模块以组件的形式存在,组件又按功能分为**原子
4141
| 组件名称 | 功能 | 依赖的组件 |
4242
| :------------: | :------------:|:------------ |
4343
| [esp_audio_simple_player](./packages/esp_audio_simple_player) | 简单的音频播放器 | - `gmf_audio`<br>- `gmf_io` |
44+
| [gmf_loader](./packages/gmf_loader) | 使用 `Kconfig` 选择的配置<br>设置给定的 GMF Pool | - `gmf_core`<br>- `gmf_io`<br>- `gmf_audio`<br>- `gmf_ai_audio`<br>- `esp_codec_dev`<br>- `esp_audio_codec` |
4445

4546
# ESP-GMF 使用说明
4647

elements/gmf_ai_audio/CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## *Unreleased*
4+
5+
### Features
6+
7+
- Add API `esp_gmf_afe_set_event_cb` to set AFE element event callback
8+
39
## v0.6.2
410

511
### Features
@@ -16,4 +22,4 @@
1622

1723
### Features
1824

19-
- Initial version of GMF AI Audio Elements
25+
- Initial version of GMF AI Audio Elements

elements/gmf_ai_audio/examples/aec_rec/main/idf_component.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@ dependencies:
1212
version: "^0.6"
1313
espressif/gmf_ai_audio:
1414
override_path: ../../../../gmf_ai_audio
15-
15+
espressif/gmf_loader:
16+
version: "^0.6"

elements/gmf_ai_audio/examples/aec_rec/main/main.c

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,26 @@
77
#include <stdio.h>
88
#include <string.h>
99

10+
#include "esp_err.h"
11+
#include "esp_log.h"
12+
13+
#include "esp_codec_dev.h"
1014
#include "esp_gmf_err.h"
15+
#include "esp_gmf_io_codec_dev.h"
1116
#include "esp_gmf_obj.h"
1217
#include "esp_gmf_payload.h"
1318
#include "esp_gmf_port.h"
14-
15-
#include "esp_err.h"
16-
#include "esp_log.h"
17-
1819
#include "esp_gmf_aec.h"
1920
#include "esp_gmf_element.h"
2021
#include "esp_gmf_pipeline.h"
2122
#include "esp_gmf_pool.h"
2223
#include "esp_gmf_setup_peripheral.h"
23-
#include "esp_gmf_setup_pool.h"
2424
#include "esp_gmf_rate_cvt.h"
2525
#include "esp_gmf_bit_cvt.h"
2626
#include "esp_gmf_ch_cvt.h"
2727
#include "esp_gmf_audio_helper.h"
2828
#include "cli.h"
29+
#include "gmf_loader_setup_defaults.h"
2930

3031
#define BOARD_LYRAT_MINI (0)
3132
#define BOARD_KORVO_2 (1)
@@ -127,20 +128,7 @@ void app_main(void)
127128

128129
esp_gmf_pool_handle_t pool = NULL;
129130
esp_gmf_pool_init(&pool);
130-
pool_register_io(pool);
131-
pool_register_audio_codecs(pool);
132-
pool_register_audio_effects(pool);
133-
pool_register_codec_dev_io(pool, play_dev, record_dev);
134-
135-
esp_gmf_element_handle_t gmf_aec_handle = NULL;
136-
esp_gmf_aec_cfg_t gmf_aec_cfg = {
137-
.filter_len = 4,
138-
.type = AFE_TYPE_VC,
139-
.mode = AFE_MODE_HIGH_PERF,
140-
.input_format = INPUT_CH_ALLOCATION,
141-
};
142-
esp_gmf_aec_init(&gmf_aec_cfg, &gmf_aec_handle);
143-
esp_gmf_pool_register_element(pool, gmf_aec_handle, NULL);
131+
gmf_loader_setup_all_defaults(pool);
144132

145133
ESP_GMF_POOL_SHOW_ITEMS(pool);
146134
esp_gmf_pipeline_handle_t read_pipe = NULL;
@@ -155,6 +143,8 @@ void app_main(void)
155143
ESP_LOGE(TAG, "There is no pipeline");
156144
return;
157145
}
146+
esp_gmf_io_codec_dev_set_dev(ESP_GMF_PIPELINE_GET_IN_INSTANCE(read_pipe), record_dev);
147+
158148
esp_gmf_port_handle_t out_port = NEW_ESP_GMF_PORT_OUT_BYTE(pcm_buf_acq_write, pcm_buf_release_write, NULL, NULL, 1024, portMAX_DELAY);
159149
esp_gmf_element_register_out_port(read_pipe->last_el, out_port);
160150
esp_gmf_obj_handle_t rate_cvt = NULL;
@@ -188,6 +178,8 @@ void app_main(void)
188178
ESP_LOGE(TAG, "There is no play pipeline");
189179
return;
190180
}
181+
esp_gmf_io_codec_dev_set_dev(ESP_GMF_PIPELINE_GET_OUT_INSTANCE(play_pipe), play_dev);
182+
191183
esp_gmf_obj_handle_t bit_cvt = NULL;
192184
esp_gmf_pipeline_get_el_by_name(play_pipe, "bit_cvt", &bit_cvt);
193185
esp_gmf_bit_cvt_set_dest_bits(bit_cvt, DAC_I2S_BITS);
@@ -226,11 +218,11 @@ void app_main(void)
226218
}
227219
heap_caps_free(pcm_buffer);
228220

229-
pool_unregister_audio_codecs();
230221
esp_gmf_task_deinit(read_task);
231222
esp_gmf_task_deinit(play_task);
232223
esp_gmf_pipeline_destroy(read_pipe);
233224
esp_gmf_pipeline_destroy(play_pipe);
225+
gmf_loader_teardown_all_defaults(pool);
234226
esp_gmf_pool_deinit(pool);
235227
esp_gmf_teardown_periph_codec(play_dev, record_dev);
236228
esp_gmf_teardown_periph_i2c(0);

elements/gmf_ai_audio/examples/common/gmf_setup/esp_gmf_setup_peripheral.c

Lines changed: 7 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
#include "esp_log.h"
88
#include "driver/sdmmc_host.h"
99
#include "vfs_fat_internal.h"
10-
#include "esp_wifi.h"
1110
#include "esp_event.h"
1211
#include "nvs_flash.h"
1312
#include "esp_gmf_oal_mem.h"
@@ -25,9 +24,11 @@
2524
#include "esp_codec_dev_defaults.h"
2625
#endif /* USE_ESP_GMF_ESP_CODEC_DEV_IO */
2726

28-
#define WIFI_CONNECTED_BIT BIT0
29-
#define WIFI_FAIL_BIT BIT1
30-
#define WIFI_RECONNECT_RETRIES 30
27+
typedef enum {
28+
I2S_CREATE_MODE_TX_ONLY = 0,
29+
I2S_CREATE_MODE_RX_ONLY = 1,
30+
I2S_CREATE_MODE_TX_AND_RX = 2,
31+
} i2s_create_mode_t;
3132

3233
#ifdef USE_ESP_GMF_ESP_CODEC_DEV_IO
3334
i2s_chan_handle_t rx_handle = NULL;
@@ -43,22 +44,8 @@ const audio_codec_if_t *out_codec_if = NULL;
4344
const audio_codec_gpio_if_t *gpio_if = NULL;
4445
#endif /* USE_ESP_GMF_ESP_CODEC_DEV_IO */
4546

46-
#ifndef CONFIG_EXAMPLE_ESP_GMF_WIFI
47-
#define CONFIG_EXAMPLE_ESP_GMF_WIFI_SSID "****"
48-
#define CONFIG_EXAMPLE_ESP_GMF_WIFI_PASS "****"
49-
#endif /* CONFIG_EXAMPLE_ESP_GMF_WIFI */
50-
51-
typedef enum {
52-
I2S_CREATE_MODE_TX_ONLY = 0,
53-
I2S_CREATE_MODE_RX_ONLY = 1,
54-
I2S_CREATE_MODE_TX_AND_RX = 2,
55-
} i2s_create_mode_t;
56-
57-
static const char *TAG = "SETUP_PERIPH";
58-
static esp_netif_t *s_esp_gmf_setup_sta_netif;
59-
static EventGroupHandle_t s_wifi_event_group;
60-
static int s_retry_num = 0;
61-
i2c_master_bus_handle_t i2c_handle = NULL;
47+
static const char *TAG = "SETUP_PERIPH";
48+
i2c_master_bus_handle_t i2c_handle = NULL;
6249

6350
#ifdef USE_ESP_GMF_ESP_CODEC_DEV_IO
6451
static esp_err_t setup_periph_i2s_tx_init(esp_gmf_setup_periph_aud_info *aud_info)
@@ -342,92 +329,6 @@ void esp_gmf_teardown_periph_sdmmc(void *card)
342329
esp_vfs_fat_sdcard_unmount("/sdcard", card);
343330
}
344331

345-
static void event_handler(void *arg, esp_event_base_t event_base,
346-
int32_t event_id, void *event_data)
347-
{
348-
if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_START) {
349-
esp_wifi_connect();
350-
} else if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_DISCONNECTED) {
351-
if (s_retry_num < WIFI_RECONNECT_RETRIES) {
352-
esp_wifi_connect();
353-
s_retry_num++;
354-
ESP_LOGI(TAG, "Retry to connect to the AP");
355-
} else {
356-
xEventGroupSetBits(s_wifi_event_group, WIFI_FAIL_BIT);
357-
}
358-
ESP_LOGI(TAG, "connect to the AP fail");
359-
} else if (event_base == IP_EVENT && event_id == IP_EVENT_STA_GOT_IP) {
360-
ip_event_got_ip_t *event = (ip_event_got_ip_t *)event_data;
361-
ESP_LOGI(TAG, "got ip:" IPSTR, IP2STR(&event->ip_info.ip));
362-
s_retry_num = 0;
363-
xEventGroupSetBits(s_wifi_event_group, WIFI_CONNECTED_BIT);
364-
}
365-
}
366-
367-
void esp_gmf_setup_periph_wifi(void)
368-
{
369-
esp_err_t ret = nvs_flash_init();
370-
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
371-
ESP_ERROR_CHECK(nvs_flash_erase());
372-
ret = nvs_flash_init();
373-
}
374-
ESP_ERROR_CHECK(ret);
375-
s_wifi_event_group = xEventGroupCreate();
376-
ESP_ERROR_CHECK(esp_netif_init());
377-
ESP_ERROR_CHECK(esp_event_loop_create_default());
378-
s_esp_gmf_setup_sta_netif = esp_netif_create_default_wifi_sta();
379-
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
380-
ESP_ERROR_CHECK(esp_wifi_init(&cfg));
381-
esp_event_handler_instance_t instance_any_id;
382-
esp_event_handler_instance_t instance_got_ip;
383-
ESP_ERROR_CHECK(esp_event_handler_instance_register(WIFI_EVENT,
384-
ESP_EVENT_ANY_ID,
385-
&event_handler,
386-
NULL,
387-
&instance_any_id));
388-
ESP_ERROR_CHECK(esp_event_handler_instance_register(IP_EVENT,
389-
IP_EVENT_STA_GOT_IP,
390-
&event_handler,
391-
NULL,
392-
&instance_got_ip));
393-
wifi_config_t wifi_config = {
394-
.sta = {
395-
.ssid = CONFIG_EXAMPLE_ESP_GMF_WIFI_SSID,
396-
.password = CONFIG_EXAMPLE_ESP_GMF_WIFI_PASS,
397-
},
398-
};
399-
ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA));
400-
ESP_ERROR_CHECK(esp_wifi_set_config(WIFI_IF_STA, &wifi_config));
401-
ESP_ERROR_CHECK(esp_wifi_start());
402-
ESP_LOGI(TAG, "wifi_init_sta finished.");
403-
EventBits_t bits = xEventGroupWaitBits(s_wifi_event_group,
404-
WIFI_CONNECTED_BIT | WIFI_FAIL_BIT, pdFALSE, pdFALSE, portMAX_DELAY);
405-
if (bits & WIFI_CONNECTED_BIT) {
406-
ESP_LOGI(TAG, "connected to ap SSID:%s password:%s",
407-
CONFIG_EXAMPLE_ESP_GMF_WIFI_SSID, CONFIG_EXAMPLE_ESP_GMF_WIFI_PASS);
408-
} else if (bits & WIFI_FAIL_BIT) {
409-
ESP_LOGI(TAG, "Failed to connect to SSID:%s, password:%s",
410-
CONFIG_EXAMPLE_ESP_GMF_WIFI_SSID, CONFIG_EXAMPLE_ESP_GMF_WIFI_PASS);
411-
} else {
412-
ESP_LOGE(TAG, "UNEXPECTED EVENT");
413-
}
414-
}
415-
416-
void esp_gmf_teardown_periph_wifi(void)
417-
{
418-
esp_wifi_disconnect();
419-
esp_err_t err = esp_wifi_stop();
420-
if (err == ESP_ERR_WIFI_NOT_INIT) {
421-
ESP_LOGE(TAG, "WIFI stop got an error");
422-
return;
423-
}
424-
ESP_ERROR_CHECK(esp_wifi_deinit());
425-
esp_event_loop_delete_default();
426-
ESP_ERROR_CHECK(esp_wifi_clear_default_wifi_driver_and_handlers(s_esp_gmf_setup_sta_netif));
427-
esp_netif_destroy(s_esp_gmf_setup_sta_netif);
428-
s_esp_gmf_setup_sta_netif = NULL;
429-
}
430-
431332
void esp_gmf_setup_periph_i2c(int port)
432333
{
433334
i2c_master_bus_config_t i2c_config = {

0 commit comments

Comments
 (0)