2121
2222static 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
3940void 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 ();
0 commit comments