Page 15 of 18

Re: ESP32 Webradio

Posted: Fri Aug 11, 2017 11:05 am
by Palak Joshi

I am also using the nghttp2 library to format the multipart frames to communicate with Alexa. I am currently able to get the response of audio with a multipart message. But, currently it is only possible to send data up to 16KB, I want to do streaming of my recorded data which can be greater than 16KB as a whole.

Can you please help me in sending the audio data in the chunk to the AVS using nghttp2?

Looking forward to your response, please help.


Re: ESP32 Webradio

Posted: Sat Aug 12, 2017 6:23 am
by pataga
BuddyCasino, apologies if this is a digression from the current discussions, but you had mentioned potential optimizations for the case where there is a high latency connection. I am using a 4G hotspot at home for my internet connection and normally have no buffering issues with standard def youtube videos.

But I have consistent buffer underflow problems running the webradio. If I switch to the next radio channel, it starts up again, but within a few seconds, the buffer underflow issue starts again. See attached monitor screenshot which captures this scenario.

Am a noob when it comes to this area, but any chance you can let me know where to look and what tweaks might help with this ?

Hardware set up is an Easykit ESP32-B1 (Chip Rev 0 ) connected to a "DIY More" PCM5102A module. The only modification i made to your code was to configure the I2S signals on different pins for a shortest-path connection to the PCM5102 board. Stereo audio quality is quite good on headphones.

buffer_underflow.jpg (315.75 KiB) Viewed 1858 times

Re: ESP32 Webradio

Posted: Sun Aug 13, 2017 8:23 pm
by BuddyCasino
Yeah I've got a feeling this used to work better. Try:
- check freertos task priorities
- check wifi connection quality (RSSI)

You can increase the network buffer if you don't care about AAC.

Re: ESP32 Webradio

Posted: Mon Aug 14, 2017 7:30 am
by pataga
OK thanks BuddyCasino, will try this out.

Re: ESP32 Webradio

Posted: Tue Aug 15, 2017 9:08 am
by pataga
Hi BuddyCasino, I tried tweaking task priorities, increasing dummy spiram fifo size, increasing the number of Wifi RX buffers etc. None of them worked, but the following trial and error hack seems to have mitigated the buffer under flow problem for me :


uint8_t fill_level = (bytes_in_buf * 100) / spiRamFifoLen();

// seems 4k is enough to prevent initial buffer underflow
// me : 20% of 32k = 6k, comment needs fixing ?
uint8_t min_fill_lvl = player->buffer_pref == BUF_PREF_FAST ? 20 : 90;
bool enough_buffer = fill_level > min_fill_lvl;

//bool early_start = (bytes_in_buf > 1028 && player->media_stream->eof);
bool early_start = ((bytes_in_buf > (3*1028)) && player->media_stream->eof);
if (player->decoder_status != RUNNING && (enough_buffer || early_start)) {

Doubling the value of early_start seemed to have worked, but after a few minutes, could detect some stuttering. Tripling it was even better. Can now run several minutes without any choppiness, and any stuttering goes away within a few seconds. Before, it would never recover once the buffer underflow started.

I did find something that I thought may be inconsistent in \fifo\spiram_fifo.c. The fifo lowmark (112*1024) is defined as a value larger than the fifo size (32000). I modified it to be half of the fifo size (not sure what is appropriate). Though just this change alone without the change to audio_player.c did not fix the buffer underflow issue.

//#define FIFO_LOWMARK (112*1024)
#define FIFO_LOWMARK (16*1024)

//Re-define a bunch of things so we use the internal buffer
//allocate enough for about one mp3 frame
//#define SPIRAMSIZE 1850
#define SPIRAMSIZE 32000
static char fakespiram[SPIRAMSIZE];

Re: ESP32 Webradio

Posted: Tue Aug 15, 2017 11:44 am
by BuddyCasino
Thanks for the feedback, those look like useful modifications.

Re: ESP32 Webradio

Posted: Fri Sep 22, 2017 8:31 am
by Saskia
Youj implemented a Bluetooth Speaker Mode. Is this for sending audio data to the esp32, so the esp32 is used as a bluetooth speaker or is it also possible to send the audio data from the esp32 to a bluetooth speaker? Last one would be great.

Re: ESP32 Webradio

Posted: Fri Sep 22, 2017 8:40 am
by BuddyCasino
Its for sending audio to the ESP32. Whats your use case for doing it the other way round?

Re: ESP32 Webradio

Posted: Fri Sep 22, 2017 10:40 am
by Saskia
I could use a bluetooth speaker for sound output instead of a amplifier breakout board.

Re: ESP32 Webradio

Posted: Fri Sep 29, 2017 6:42 pm
by BuddyCasino
I went on a Bluedroid SDK search, but it seems A2DP source mode is not implemented. You'll have to ask Espressif if/when they'll plan to support it. I agree it would be quite useful.