页次: 1
音频管道初始化代码
void player_pipeline_init()
{
audio_pipeline_cfg_t pipeline_cfg = DEFAULT_AUDIO_PIPELINE_CONFIG();
pipeline = audio_pipeline_init(&pipeline_cfg);
mem_assert(pipeline);
raw_stream_cfg_t raw_cfg = RAW_STREAM_CFG_DEFAULT();
raw_cfg.type = AUDIO_STREAM_WRITER;
raw_writer = raw_stream_init(&raw_cfg);
i2s_stream_cfg_t i2s_cfg = I2S_STREAM_CFG_DEFAULT();
i2s_cfg.type = AUDIO_STREAM_WRITER;
i2s_stream_writer = i2s_stream_init(&i2s_cfg);
audio_pipeline_register(pipeline, raw_writer, "raw_writer");
audio_pipeline_register(pipeline, i2s_stream_writer, "i2s");
audio_pipeline_link(pipeline, (const char *[]) {"raw_writer","i2s"}, 2);
i2s_stream_set_clk(i2s_stream_writer, 16000, 16, 1);
audio_pipeline_run(pipeline);
}
获取HTTP流,播放的代码
esp_http_client_config_t config =
{
.url = request_data,
.event_handler = http_client_event_msg_t,
};
client = esp_http_client_init(&config);
esp_http_client_set_method(client,HTTP_METHOD_GET);
esp_err_t err = esp_http_client_perform(client);
if(err == ESP_OK)
{
int audio_length = esp_http_client_get_content_length(client);
char *audio_data = (char *)calloc(audio_length,sizeof(char));
esp_http_client_read(client,audio_data,audio_length);
if(audio_data != NULL)
{
int write_len1,write_len2,offset = 0;
while(offset<audio_length)
{
write_len1 = (audio_length-offset)>1024?1024:(audio_length-offset);
write_len2 = raw_stream_write(raw_writer,audio_data+offset,write_len1);
offset += write_len2;
ESP_LOGI(TAG,"offset = %d",offset);
}
free(audio_data);
audio_data = NULL;
}
}
esp_http_client_cleanup(client);
问题出在哪里
页次: 1