ESP32 Webradio

Palak Joshi
Posts: 1
Joined: Fri Aug 11, 2017 9:15 am

Re: ESP32 Webradio

Postby Palak Joshi » Fri Aug 11, 2017 11:05 am

Hi,

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.

Thanks.

pataga
Posts: 28
Joined: Sat Aug 12, 2017 5:53 am

Re: ESP32 Webradio

Postby pataga » Sat Aug 12, 2017 6:23 am

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
buffer_underflow.jpg (315.75 KiB) Viewed 1101 times

BuddyCasino
Posts: 231
Joined: Sun Jun 19, 2016 12:00 am

Re: ESP32 Webradio

Postby BuddyCasino » Sun Aug 13, 2017 8:23 pm

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.

pataga
Posts: 28
Joined: Sat Aug 12, 2017 5:53 am

Re: ESP32 Webradio

Postby pataga » Mon Aug 14, 2017 7:30 am

OK thanks BuddyCasino, will try this out.

pataga
Posts: 28
Joined: Sat Aug 12, 2017 5:53 am

Re: ESP32 Webradio

Postby pataga » Tue Aug 15, 2017 9:08 am

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 :

\audio_player\audio_player.c

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)

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

BuddyCasino
Posts: 231
Joined: Sun Jun 19, 2016 12:00 am

Re: ESP32 Webradio

Postby BuddyCasino » Tue Aug 15, 2017 11:44 am

Thanks for the feedback, those look like useful modifications.

Saskia
Posts: 30
Joined: Mon Jun 26, 2017 11:45 am

Re: ESP32 Webradio

Postby Saskia » Fri Sep 22, 2017 8:31 am

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.

BuddyCasino
Posts: 231
Joined: Sun Jun 19, 2016 12:00 am

Re: ESP32 Webradio

Postby BuddyCasino » Fri Sep 22, 2017 8:40 am

Its for sending audio to the ESP32. Whats your use case for doing it the other way round?

Saskia
Posts: 30
Joined: Mon Jun 26, 2017 11:45 am

Re: ESP32 Webradio

Postby Saskia » Fri Sep 22, 2017 10:40 am

I could use a bluetooth speaker for sound output instead of a amplifier breakout board.

BuddyCasino
Posts: 231
Joined: Sun Jun 19, 2016 12:00 am

Re: ESP32 Webradio

Postby BuddyCasino » Fri Sep 29, 2017 6:42 pm

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.

Who is online

Users browsing this forum: No registered users and 2 guests