Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

解码后获取数据做fft还不影响pipline发送数据到i2s writer? (AUD-5753) #1291

Closed
bailiqun opened this issue Oct 10, 2024 · 2 comments

Comments

@bailiqun
Copy link

bailiqun commented Oct 10, 2024

sdcard -> fatfs_stream_reader-->decoder-->i2s_stream-->speaker
总体pipline是这样的,然后我需要获的decoder输出的pcm数据, i2s_stream发送前的数据做fft变换,有什么办法吗?

十分感谢

@github-actions github-actions bot changed the title 解码后获取数据做fft还不影响pipline发送数据到i2s writer? 解码后获取数据做fft还不影响pipline发送数据到i2s writer? (AUD-5753) Oct 10, 2024
@TempoTian
Copy link
Contributor

你可以用下面的方法做个tricking,用新的write callback覆盖I2S的write函数
不过为了避免播放断音,最好很快的处理完,如果比较耗时可以先写到一个ringbuf然后在另起一个Task处理

static int i2s_write_cb(audio_element_handle_t el, char *buf, int len, TickType_t wait_time, void *ctx)
{
    stream_func original_write_func = (stream_func)ctx;
    // Process your data, you must process data in time to avoid I2S write data blocked,
    int ret = original_write_func(el, buf, len, wait_time, ctx);
    if (ret < 0) {
        ESP_LOGE(TAG, "i2s write failed");
    }
    return bytes_write;
}

// Set I2S new write callback function
 audio_element_set_write_cb(i2s_writer, i2s_write_cb, audio_element_get_write_cb(i2s_writer)); // context is original write function

@bailiqun
Copy link
Author

帅的一塌糊涂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants