espressif / esp-adf

Espressif Audio Development Framework
Other
1.53k stars 671 forks source link

Problems with using examples\recorder\pipeline_recording_to_sdcard (AUD-5609) #1246

Open Szeroy opened 1 month ago

Szeroy commented 1 month ago

I want to use a routine to read data from digital microphone and save it to sd card, but the routine uses chip reading microphone inside, my current microphone is directly i2s directly read 24bit raw data, how should I modify it? I see that the initialization inside the direct call is the component's function to read, do not know how I should write my own read function put in. This is a function inside the routine,I see that there are many parameters in the structure i2s_stream_cfg_t , I am not clear how to modify it.Pass on the data I've read myself.

audio_element_handle_t i2s_stream_init(i2s_stream_cfg_t *config)
{
    audio_element_cfg_t cfg = DEFAULT_AUDIO_ELEMENT_CONFIG();
    audio_element_handle_t el;
    cfg.open = _i2s_open;
    cfg.close = _i2s_close;
    cfg.process = _i2s_process;
    cfg.destroy = _i2s_destroy;
    cfg.task_stack = config->task_stack;
    cfg.task_prio = config->task_prio;
    cfg.task_core = config->task_core;
    cfg.stack_in_ext = config->stack_in_ext;
    cfg.out_rb_size = config->out_rb_size;
    cfg.multi_out_rb_num = config->multi_out_num;
    cfg.tag = "iis";
    cfg.buffer_len = config->buffer_len;
hbler99 commented 4 weeks ago

It's recommended to utilize the read/write callback function which perform as out/in way for each element. For example:

    audio_element_set_write_cb(i2s_writer_el, i2s_write_cb, (void *)Input_file);
    audio_element_set_read_cb(i2s_reader_el, i2s_read_cb, (void *)Output_file);
static int i2s_write_cb(audio_element_handle_t self, char *buffer, int len, TickType_t ticks_to_wait, void *context)
{
    memcpy(buffer, YOUR CONTENT, LEN);
}

static int i2s_read_cb(audio_element_handle_t self, char *buffer, int len, TickType_t ticks_to_wait, void *context)
{
    memcpy(YOUR NEED CONTENT, buffer, LEN);
}

The other method is to use a ring buffer to read/write data. Please refer to examples/recorder/element_cb_sdcard_amr for more details.