您尚未登录。

楼主 #1 2019-11-11 16:21:30

苦逼的大白
会员
注册时间: 2019-11-11
已发帖子: 5
积分: 5

自己写了一个获取HTTP流,播放的程序,但播放出来全是噪音

音频管道初始化代码
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);

问题出在哪里

离线

楼主 #2 2019-11-11 16:23:53

苦逼的大白
会员
注册时间: 2019-11-11
已发帖子: 5
积分: 5

Re: 自己写了一个获取HTTP流,播放的程序,但播放出来全是噪音

音频数据采样率为16000 16bit 单通道。写入哪里,分批写或者一次写完都全是噪音。音频数据是没问题的

离线

#3 2019-11-11 20:03:26

晕哥
管理员
所在地: 微信 whycan_cn
注册时间: 2017-09-06
已发帖子: 9,223
积分: 9197

Re: 自己写了一个获取HTTP流,播放的程序,但播放出来全是噪音

这是从http服务器下载数据吗?是什么格式?mp3?





离线

楼主 #4 2019-11-12 09:23:56

苦逼的大白
会员
注册时间: 2019-11-11
已发帖子: 5
积分: 5

Re: 自己写了一个获取HTTP流,播放的程序,但播放出来全是噪音

晕哥 说:

这是从http服务器下载数据吗?是什么格式?mp3?

pcm,采样率16000,16位单通道

离线

#5 2019-11-12 09:42:20

晕哥
管理员
所在地: 微信 whycan_cn
注册时间: 2017-09-06
已发帖子: 9,223
积分: 9197

Re: 自己写了一个获取HTTP流,播放的程序,但播放出来全是噪音

建议问题先简化一下:
1. 把收到的数据存TF卡, 在电脑播放, 用于判断收到的数据是否正常.
2. 直接播放 TF 卡的 PCM 文件.





离线

页脚

工信部备案:粤ICP备20025096号 Powered by FluxBB

感谢为中文互联网持续输出优质内容的各位老铁们。 QQ: 516333132, 微信(wechat): whycan_cn (哇酷网/挖坑网/填坑网) service@whycan.cn