espressif / esp-adf

Espressif Audio Development Framework
Other
1.54k stars 676 forks source link

How to get the output data of an audio element with interrupt. (AUD-2758) #569

Closed utkutpcgl closed 3 years ago

utkutpcgl commented 3 years ago

Dear esp-adf team,

I want to send the output data of an audio element (amr encoder output data) with espnow whenever the output data of the encoder is ready. I use audio_element_output() inside the callback function I defined with audio_element_set_write_cb().

For example:

audio_element_set_write_cb(amrEncoder, writeToEspnowSendBuffer , NULL);

audio_element_err_t writeToEspnowSendBuffer(audio_element_handle_t self, char *buffer, int len, TickType_t ticks_to_wait, void *context){
    audio_element_err_t returnVal;
    returnVal = audio_element_output(self, buffer, len);

Right after I call output on encoder I expect the output data to be transferred to my buffer or at least a ringbuffer. How can I do this? I will use this encoder output later for real-time sound communication. I will transmit the sound data coming out of amr encoder whenever it is ready. Hence, I must use an interrupt here. What is the proper way. I use espnow to send the sound data and the receiver needs real time sound data (output of amr encoder).

Thanks in advance. Kind regards.

HengYongChao commented 3 years ago

Hi, How about this?

 static int writeToEspnowSendBuffer(audio_element_handle_t el, char *buf, int len, TickType_t wait_time, void *ctx)
{

    char *buf = (char *)ctx;
    int bytes_read = rb_write(consume_ring, (char *)buf, len, portMAX_DELAY);
    return bytes_read;
}

You run a task to receive consume_ring ringbuf data, is this kind of response useful to you?