How to make two parallel pipelines

spacebiker
Posts: 11
Joined: Mon May 24, 2021 10:23 am

How to make two parallel pipelines

Postby spacebiker » Thu Jun 10, 2021 3:24 pm

There is an example of parallel pipelines: https://github.com/espressif/esp-adf/bl ... _to_file.c
I need to do the same thing, but bluetooth instead of http.
So I have two pipelines: bt -> i2s and raw -> wav_encoder -> fatfs

So i init all pipelines:

Code: Select all

    i2s_stream_cfg_t i2s_cfg1 = I2S_STREAM_CFG_DEFAULT();
    i2s_cfg1.type = AUDIO_STREAM_WRITER;
    i2s_stream_writer = i2s_stream_init(&i2s_cfg1);

    i2s_stream_cfg_t i2s_cfg2 = I2S_STREAM_CFG_DEFAULT();
    i2s_cfg2.type = AUDIO_STREAM_READER;
    i2s_stream_reader = i2s_stream_init(&i2s_cfg2);

    raw_stream_cfg_t raw_cfg = RAW_STREAM_CFG_DEFAULT();
    raw_cfg.type = AUDIO_STREAM_READER;
    raw_read = raw_stream_init(&raw_cfg);

    bt_stream_reader = bluetooth_service_create_stream();
    
    audio_pipeline_register(pipeline_bluetooth_i2sw, bt_stream_reader, "bt");
    audio_pipeline_register(pipeline_bluetooth_i2sw, i2s_stream_writer, "i2s_w");

    audio_pipeline_register(pipeline_i2sr_raw, i2s_stream_reader, "i2s_r");
    audio_pipeline_register(pipeline_i2sr_raw, raw_read, "raw");

    const char *link_d[2] = {"bt", "i2s_w"};
    audio_pipeline_link(pipeline_bluetooth_i2sw, &link_d[0], 2);

    const char *link_e[2] = {"i2s_r", "raw"};
    audio_pipeline_link(pipeline_i2sr_raw, &link_e[0], 2);   
   

Code: Select all

    fatfs_stream_cfg_t fatfs_write_cfg = FATFS_STREAM_CFG_DEFAULT();
    fatfs_write_cfg.type = AUDIO_STREAM_WRITER;
    fatfs_stream_writer = fatfs_stream_init(&fatfs_write_cfg);

    raw_stream_cfg_t raw_cfg = RAW_STREAM_CFG_DEFAULT();
    raw_cfg.type = AUDIO_STREAM_WRITER;
    el_raw_read = raw_stream_init(&raw_cfg);

    wav_encoder_cfg_t wav_cfg = DEFAULT_WAV_ENCODER_CONFIG();
    wav_encoder = wav_encoder_init(&wav_cfg);

    audio_pipeline_cfg_t  pipeline_for_record_cfg = DEFAULT_AUDIO_PIPELINE_CONFIG();
    pipeline_for_record = audio_pipeline_init(&pipeline_for_record_cfg);

    audio_element_set_uri(fatfs_stream_writer, "/sdcard/rec2.wav");
        
    audio_pipeline_register(pipeline_for_record, el_raw_read, "raw");
    audio_pipeline_register(pipeline_for_record, wav_encoder, "wav");
    audio_pipeline_register(pipeline_for_record, fatfs_stream_writer, "file");

    const char *link_tag[3] = {"raw", "wav", "file"};
    audio_pipeline_link(pipeline_for_record, &link_tag[0], 3);
And I made ring buffer connected to bt_stream_reader:

Code: Select all

ringbuf_handle_t rb = audio_element_get_output_ringbuf(el_raw_read);
audio_element_set_multi_output_ringbuf(bt_stream_reader, rb, 0);    
and trying to save audio data on sd card. But every time I play music I get 44 bytes .wav file full of 0x00.
What am I doing wrong? Thank you

Full code is here: https://pastebin.com/bg0HVhUe

Who is online

Users browsing this forum: No registered users and 35 guests