Skip to content

Commit 912ae6d

Browse files
committed
Merge branch 'bugfix/fix_sdcard_play_fail' into 'main'
bugfix(basic_examples): Fixed play_sdcard_music play fail due to format not set See merge request adf/multimedia/esp-gmf!118
2 parents cbfd5bc + 6941f0a commit 912ae6d

File tree

5 files changed

+60
-15
lines changed

5 files changed

+60
-15
lines changed

gmf_examples/CHANGELOG.md

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

3+
## v0.7.1
4+
5+
### Bug Fixes
6+
7+
- Fixed `pipeline_play_sdcard_music` example playback fail due to format not set
8+
- Fixed examples codec device setting mismatch with process output
9+
310
## v0.7.0
411

512
### Features

gmf_examples/basic_examples/pipeline_play_embed_music/main/play_embed_music.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,16 @@ void app_main(void)
4242
ESP_GMF_MEM_SHOW(TAG);
4343
int ret;
4444
ESP_LOGI(TAG, "[ 1 ] Mount peripheral");
45-
esp_gmf_app_setup_codec_dev(NULL);
45+
// Configuration of codec to be aligned with audio pipeline output
46+
esp_gmf_app_codec_info_t codec_info = ESP_GMF_APP_CODEC_INFO_DEFAULT();
47+
codec_info.play_info.sample_rate = CONFIG_GMF_AUDIO_EFFECT_RATE_CVT_DEST_RATE;
48+
codec_info.play_info.channel = CONFIG_GMF_AUDIO_EFFECT_CH_CVT_DEST_CH;
49+
codec_info.play_info.bits_per_sample = CONFIG_GMF_AUDIO_EFFECT_BIT_CVT_DEST_BITS;
50+
codec_info.record_info = codec_info.play_info;
51+
esp_gmf_app_setup_codec_dev(&codec_info);
52+
53+
// Set default output volume range from [0, 100]
54+
esp_codec_dev_set_out_vol((esp_codec_dev_handle_t)esp_gmf_app_get_playback_handle() , 80);
4655

4756
ESP_LOGI(TAG, "[ 2 ] Register all the elements and set audio information to play codec device");
4857
esp_gmf_pool_handle_t pool = NULL;

gmf_examples/basic_examples/pipeline_play_sdcard_music/main/play_sdcard_music.c

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@
2121

2222
static const char *TAG = "PLAY_SDCARD_MUSIC";
2323

24-
#define PIPELINE_BLOCK_BIT BIT(0)
24+
#define PIPELINE_BLOCK_BIT BIT(0)
25+
#define DEFAULT_PLAY_URL "/sdcard/test.mp3"
2526

26-
esp_err_t _pipeline_event(esp_gmf_event_pkt_t *event, void *ctx)
27+
esp_gmf_err_t _pipeline_event(esp_gmf_event_pkt_t *event, void *ctx)
2728
{
2829
ESP_LOGI(TAG, "CB: RECV Pipeline EVT: el: %s-%p, type: %x, sub: %s, payload: %p, size: %d, %p",
2930
"OBJ_GET_TAG(event->from)", event->from, event->type, esp_gmf_event_get_state_str(event->sub),
@@ -33,15 +34,27 @@ esp_err_t _pipeline_event(esp_gmf_event_pkt_t *event, void *ctx)
3334
|| (event->sub == ESP_GMF_EVENT_STATE_ERROR)) {
3435
xEventGroupSetBits((EventGroupHandle_t)ctx, PIPELINE_BLOCK_BIT);
3536
}
36-
return 0;
37+
return ESP_GMF_ERR_OK;
3738
}
3839

3940
void app_main(void)
4041
{
4142
esp_log_level_set("*", ESP_LOG_INFO);
4243
int ret;
44+
45+
// Configuration of codec to be aligned with audio pipeline output
46+
esp_gmf_app_codec_info_t codec_info = ESP_GMF_APP_CODEC_INFO_DEFAULT();
47+
codec_info.play_info.sample_rate = CONFIG_GMF_AUDIO_EFFECT_RATE_CVT_DEST_RATE;
48+
codec_info.play_info.channel = CONFIG_GMF_AUDIO_EFFECT_CH_CVT_DEST_CH;
49+
codec_info.play_info.bits_per_sample = CONFIG_GMF_AUDIO_EFFECT_BIT_CVT_DEST_BITS;
50+
codec_info.record_info = codec_info.play_info;
51+
esp_gmf_app_setup_codec_dev(&codec_info);
52+
53+
// Set default output volume range from [0, 100]
54+
esp_codec_dev_set_out_vol((esp_codec_dev_handle_t)esp_gmf_app_get_playback_handle() , 80);
55+
4356
ESP_LOGI(TAG, "[ 1 ] Mount sdcard");
44-
esp_gmf_app_setup_codec_dev(NULL);
57+
4558
void *sdcard_handle = NULL;
4659
esp_gmf_app_setup_sdcard(&sdcard_handle);
4760

@@ -54,19 +67,21 @@ void app_main(void)
5467

5568
ESP_LOGI(TAG, "[ 3 ] Create audio pipeline");
5669
esp_gmf_pipeline_handle_t pipe = NULL;
57-
const char *name[] = {"aud_dec", "aud_rate_cvt", "aud_ch_cvt", "aud_bit_cvt"};
70+
const char *name[] = {"aud_dec", "aud_ch_cvt", "aud_bit_cvt", "aud_rate_cvt"};
5871
ret = esp_gmf_pool_new_pipeline(pool, "io_file", name, sizeof(name) / sizeof(char *), "io_codec_dev", &pipe);
5972
ESP_GMF_RET_ON_NOT_OK(TAG, ret, { return; }, "Failed to new pipeline");
6073

6174
esp_gmf_io_codec_dev_set_dev(ESP_GMF_PIPELINE_GET_OUT_INSTANCE(pipe), esp_gmf_app_get_playback_handle());
6275

6376
esp_gmf_element_handle_t dec_el = NULL;
6477
esp_gmf_pipeline_get_el_by_name(pipe, "aud_dec", &dec_el);
65-
esp_gmf_info_sound_t info = {0};
78+
79+
esp_gmf_info_sound_t info = {};
80+
esp_gmf_audio_helper_get_audio_type_by_uri(DEFAULT_PLAY_URL, &info.format_id);
6681
esp_gmf_audio_dec_reconfig_by_sound_info(dec_el, &info);
6782

6883
ESP_LOGI(TAG, "[ 3.1 ] Set audio url to play");
69-
esp_gmf_pipeline_set_in_uri(pipe, "/sdcard/test.mp3");
84+
esp_gmf_pipeline_set_in_uri(pipe, DEFAULT_PLAY_URL);
7085

7186
ESP_LOGI(TAG, "[ 3.2 ] Create gmf task, bind task to pipeline and load linked element jobs to the bind task");
7287
esp_gmf_task_cfg_t cfg = DEFAULT_ESP_GMF_TASK_CONFIG();

gmf_examples/basic_examples/pipeline_record_sdcard/main/play_record_sdcard.c

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,37 @@
1919

2020
static const char *TAG = "REC_SDCARD";
2121

22-
esp_err_t _pipeline_event(esp_gmf_event_pkt_t *event, void *ctx)
22+
#define DEFAULT_RECORD_SAMPLE_RATE 16000
23+
#define DEFAULT_RECORD_CHANNEL 1
24+
#define DEFAULT_RECORD_BITS 16
25+
26+
esp_gmf_err_t _pipeline_event(esp_gmf_event_pkt_t *event, void *ctx)
2327
{
2428
ESP_LOGI(TAG, "CB: RECV Pipeline EVT: el:%s-%p, type:%d, sub:%s, payload:%p, size:%d,%p",
2529
"OBJ_GET_TAG(event->from)", event->from, event->type, esp_gmf_event_get_state_str(event->sub),
2630
event->payload, event->payload_size, ctx);
27-
return 0;
31+
return ESP_GMF_ERR_OK;
2832
}
2933

3034
void app_main(void)
3135
{
3236
esp_log_level_set("*", ESP_LOG_INFO);
3337
int ret = 0;
3438
ESP_LOGI(TAG, "[ 1 ] Mount sdcard");
35-
esp_gmf_app_setup_codec_dev(NULL);
3639
void *sdcard_handle = NULL;
3740
esp_gmf_app_setup_sdcard(&sdcard_handle);
3841

42+
// Configuration of codec to be aligned with audio pipeline input
43+
esp_gmf_app_codec_info_t codec_info = ESP_GMF_APP_CODEC_INFO_DEFAULT();
44+
codec_info.record_info.sample_rate = DEFAULT_RECORD_SAMPLE_RATE;
45+
codec_info.record_info.bits_per_sample = DEFAULT_RECORD_BITS;
46+
codec_info.record_info.channel = DEFAULT_RECORD_CHANNEL;
47+
codec_info.play_info = codec_info.record_info;
48+
esp_gmf_app_setup_codec_dev(&codec_info);
49+
50+
// Set default microphone gain
51+
esp_codec_dev_set_in_gain((esp_codec_dev_handle_t)esp_gmf_app_get_record_handle(), 32);
52+
3953
ESP_LOGI(TAG, "[ 2 ] Register all the elements and set audio information to record codec device");
4054
esp_gmf_pool_handle_t pool = NULL;
4155
esp_gmf_pool_init(&pool);
@@ -59,9 +73,9 @@ void app_main(void)
5973
esp_gmf_element_handle_t enc_el = NULL;
6074
esp_gmf_pipeline_get_el_by_name(pipe, "aud_enc", &enc_el);
6175
esp_gmf_info_sound_t info = {
62-
.sample_rates = 16000,
63-
.channels = 1,
64-
.bits = 16,
76+
.sample_rates = DEFAULT_RECORD_SAMPLE_RATE,
77+
.channels = DEFAULT_RECORD_CHANNEL,
78+
.bits = DEFAULT_RECORD_BITS,
6579
.format_id = ESP_AUDIO_TYPE_AAC,
6680
};
6781
esp_gmf_audio_enc_reconfig_by_sound_info(enc_el, &info);

gmf_examples/idf_component.yml

Lines changed: 1 addition & 1 deletion
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 GMF Related Examples
33
url: https://github.com/espressif/esp-gmf/tree/main/gmf_examples
44
documentation: "https://github.com/espressif/esp-gmf/blob/main/gmf_examples/README.md"

0 commit comments

Comments
 (0)