esp-adf
esp-adf copied to clipboard
如何缩减管道的ram运用 (AUD-6274)
`void audio_board_pipeline_init() { esp_log_level_set("*", ESP_LOG_WARN); esp_log_level_set(TAG, ESP_LOG_INFO);
ESP_LOGI(TAG, "[ 1 ] Start codec chip");
audio_board_handle_t board_handle = audio_board_init();
audio_hal_ctrl_codec(board_handle->audio_hal, AUDIO_HAL_CODEC_MODE_BOTH, AUDIO_HAL_CTRL_START);
es8311_set_mic_gain(ES8311_MIC_GAIN_36DB);
ESP_LOGI(TAG, "[ 2 ] Create audio pipeline for recording");
audio_pipeline_cfg_t pipeline_cfg = DEFAULT_AUDIO_PIPELINE_CONFIG();
pipeline = audio_pipeline_init(&pipeline_cfg);
mem_assert(pipeline);
ESP_LOGI(TAG, "[2.1] Create i2s stream to read audio data from codec chip");
i2s_stream_cfg_t i2s_cfg = I2S_STREAM_CFG_DEFAULT_WITH_PARA(0, 8000, 16, AUDIO_STREAM_READER);
i2s_cfg.std_cfg.slot_cfg.slot_mode = I2S_SLOT_MODE_MONO;
i2s_cfg.std_cfg.slot_cfg.slot_mask = I2S_STD_SLOT_LEFT;
i2s_stream_reader = i2s_stream_init(&i2s_cfg);
ESP_LOGI(TAG, "[2.3] Create raw to receive data");
raw_stream_cfg_t raw_cfg = {
.out_rb_size = 512,
.type = AUDIO_STREAM_READER,
};
raw_read = raw_stream_init(&raw_cfg);
ESP_LOGI(TAG, "[ 3 ] Register all elements to audio pipeline");
audio_pipeline_register(pipeline, i2s_stream_reader, "i2s");
audio_pipeline_register(pipeline, raw_read, "raw");
ESP_LOGI(TAG, "[ 4 ] Link elements together [codec_chip]-->i2s_stream-->filter-->raw-->[VAD]");
const char *link_tag[3] = {"i2s", "raw"};
audio_pipeline_link(pipeline, &link_tag[0], 2);
ESP_LOGI(TAG, "[ 5 ] Start audio_pipeline");
audio_pipeline_run(pipeline);
// init_fft();
// 1. 配置 I2S
}` 这是我的管道初始化,目前我遇到了很多ram不足的问题,我发现问题出现在这个初始化,请问有什么方法可以缩小ram运用? 或者是直接用idf?目前我只用到mic采集,用的是es8311,请求帮助!
你如果简单的用不用创建pipeline,
audio_board_handle_t board_handle = audio_board_init();
audio_hal_ctrl_codec(board_handle->audio_hal, AUDIO_HAL_CODEC_MODE_BOTH, AUDIO_HAL_CTRL_START);
es8311_set_mic_gain(ES8311_MIC_GAIN_36DB);
ESP_LOGI(TAG, "[ 2 ] Create audio pipeline for recording");
audio_pipeline_cfg_t pipeline_cfg = DEFAULT_AUDIO_PIPELINE_CONFIG();
pipeline = audio_pipeline_init(&pipeline_cfg);
mem_assert(pipeline);
ESP_LOGI(TAG, "[2.1] Create i2s stream to read audio data from codec chip");
i2s_stream_cfg_t i2s_cfg = I2S_STREAM_CFG_DEFAULT_WITH_PARA(0, 8000, 16, AUDIO_STREAM_READER);
i2s_cfg.std_cfg.slot_cfg.slot_mode = I2S_SLOT_MODE_MONO;
i2s_cfg.std_cfg.slot_cfg.slot_mask = I2S_STD_SLOT_LEFT;
i2s_stream_reader = i2s_stream_init(&i2s_cfg);
上面的初始化完成,直接调用就可以拿到数据
uint8_t data[256];
while (1) {
audio_element_input(i2s_stream_reader , buf, sizeof(buf));
}