ESP32 Webradio

User avatar
supersat
Posts: 10
Joined: Tue Apr 11, 2017 10:17 pm

Re: ESP32 Webradio

Postby supersat » Thu Apr 13, 2017 4:09 am

It turns out there are two issues:

1. The built-in DAC expects unsigned samples, while the conversion to 8 bit samples (convert_16bit_stereo_to_8bit_stereo in audio_renderer.c) converts to signed samples.

2. The renderer config is always set to I2S_BITS_PER_SAMPLE_16BIT, even when using the DAC_BUILT_IN mode. This causes signed 16 bit samples to always be sent to the I2S interface.

With these changes, the built-in DAC mode works. The output is fairly noisy (although I'm not sure if that's a function of the DAC or my circuit), but passable as a demo.

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

Re: ESP32 Webradio

Postby BuddyCasino » Thu Apr 13, 2017 6:45 am

I'm setting bits_per_sample to I2S_BITS_PER_SAMPLE_8BIT in init_i2s_dac(), are you sure? Anyway, thanks for pointing this out, wanna make a pull request?

User avatar
supersat
Posts: 10
Joined: Tue Apr 11, 2017 10:17 pm

Re: ESP32 Webradio

Postby supersat » Thu Apr 13, 2017 7:14 am

Pull request submitted. init_i2s_dac() sets the I2S peripheral configuration to use I2S_BITS_PER_SAMPLE_8BIT, but the renderer config isn't updated to reflect this, so it prepares 16-bit samples.

User avatar
rudi ;-)
Posts: 1698
Joined: Fri Nov 13, 2015 3:25 pm

Re: ESP32 Webradio

Postby rudi ;-) » Sat Apr 15, 2017 11:44 pm

hi mike,
i have a try with the webradio from your repo, and try to use the DAC version.
i have no luck with the streaming honest say.
a short test with I2S same.
used board was: DevKitC V2

no luck looks like this:

I (2735) http_client: ... socket send success
I (11385) wifi: pm start, type:0

created MAD task
MAD: Decoder start.
dec err 0x0101 (lost synchronization)
dec err 0x0235 (bad main_data_begin pointer)
dec err 0x0235 (bad main_data_begin pointer)
I (11445) renderer: setting sample rate to 44100

I (11445) I2S: Req RATE: 44100, real rate: 44642.000, BITS: 16, CLKM: 14, BCK: 8, MCLK: 11289967.000, SCLK: 1428544.000000, diva: 64, divb: 11
dec err 0x0101 (lost synchronization)
dec err 0x0235 (bad main_data_begin pointer)
dec err 0x0235 (bad main_data_begin pointer)
Buffer fill 4%, 2605 bytes
dec err 0x0101 (lost synchronization)
dec err 0x0235 (bad main_data_begin pointer)
dec err 0x0235 (bad main_data_begin pointer)
dec err 0x0101 (lost synchronization)
dec err 0x0235 (bad main_data_begin pointer)
dec err 0x0235 (bad main_data_begin pointer)
Buffer fill 4%, 3132 bytes
Buffer fill 5%, 3421 bytes
Buffer fill 6%, 3930 bytes
Buffer fill 7%, 4492 bytes
Buffer fill 7%, 5001 bytes
Buffer fill 8%, 5511 bytes
Buffer fill 13%, 8580 bytes
Buffer fill 10%, 6582 bytes
Buffer fill 14%, 9599 bytes
Buffer fill 15%, 10160 bytes
Buffer fill 16%, 10670 bytes
Buffer fill 21%, 13687 bytes
Buffer fill 22%, 14249 bytes
Buffer fill 26%, 17266 bytes
Buffer fill 27%, 17775 bytes
Buffer fill 32%, 20845 bytes
Buffer underflow, need 2508 bytes.
Buffer underflow, need 2508 bytes.
Buffer underflow, need 2508 bytes.
Buffer underflow, need 2508 bytes.
Buffer underflow, need 2508 bytes.
Buffer underflow, need 2508 bytes.
Buffer underflow, need 2508 bytes.
Buffer underflow, need 2508 bytes.
Buffer underflow, need 2508 bytes.
Buffer underflow, need 2508 bytes.
Buffer underflow, need 2508 bytes.
Buffer underflow, need 2508 bytes.
Buffer underflow, need 2508 bytes.
Buffer underflow, need 2508 bytes.
Buffer underflow, need 2508 bytes.
Buffer underflow, need 2508 bytes.
Buffer underflow, need 2508 bytes.
Buffer fill 1%, 819 bytes
dec err 0x0101 (lost synchronization)
dec err 0x0235 (bad main_data_begin pointer)
dec err 0x0235 (bad main_data_begin pointer)
dec err 0x0101 (lost synchronization)
dec err 0x0102 (reserved header layer value)
dec err 0x0235 (bad main_data_begin pointer)
dec err 0x0235 (bad main_data_begin pointer)
dec err 0x0101 (lost synchronization)
dec err 0x0103 (forbidden bitrate value)
dec err 0x0103 (forbidden bitrate value)
dec err 0x0235 (bad main_data_begin pointer)
dec err 0x0235 (bad main_data_begin pointer)
dec err 0x0101 (lost synchronization)
Guru Meditation Error of type InstrFetchProhibited occurred on core 1. Exception was unhandled.
Register dump:
PC : 0x00000000 PS : 0x00060730 A0 : 0x80111733 A1 : 0x3ffdabc0
A2 : 0x3ffdac7c A3 : 0x3ffca254 A4 : 0x0000001f A5 : 0x000002c0
A6 : 0x000003ba A7 : 0x00000000 A8 : 0x80113418 A9 : 0x3f40ab58
A10 : 0x3ffca254 A11 : 0x3ffdac7c A12 : 0x00000060 A13 : 0x0000bb80
A14 : 0x00006cfb A15 : 0x3ffc5a98 SAR : 0x0000001e EXCCAUSE: 0x00000014
EXCVADDR: 0x00000000 LBEG : 0x4000c349 LEND : 0x4000c36b LCOUNT : 0x00000000

Backtrace: 0x00000000:0x3ffdabc0 0x40111733:0x3ffdabf0

Rebooting...
ets Jun 8 2016 00:22:57

best wishes
rudi ;-)


other try:
...
Buffer underflow, need 2734 bytes.
Buffer underflow, need 2734 bytes.
Buffer underflow, need 2734 bytes.
dec err 0x0235 (bad main_data_begin pointer)
dec err 0x0101 (lost synchronization)
dec err 0x0235 (bad main_data_begin pointer)
dec err 0x0235 (bad main_data_begin pointer)
dec err 0x0101 (lost synchronization)
dec err 0x0235 (bad main_data_begin pointer)
Buffer underflow, need 2734 bytes.
Buffer underflow, need 2734 bytes.
Buffer underflow, need 2734 bytes.
Buffer underflow, need 2734 bytes.
Buffer underflow, need 2734 bytes.
Buffer underflow, need 2734 bytes.
dec err 0x0235 (bad main_data_begin pointer)
dec err 0x0101 (lost synchronization)
dec err 0x0101 (lost synchronization)
dec err 0x0104 (reserved sample frequency value)
dec err 0x0235 (bad main_data_begin pointer)
dec err 0x0235 (bad main_data_begin pointer)
dec err 0x0101 (lost synchronization)
dec err 0x0102 (reserved header layer value)
dec err 0x0235 (bad main_data_begin pointer)
dec err 0x0101 (lost synchronization)
dec err 0x0101 (lost synchronization)
dec err 0x0104 (reserved sample frequency value)
dec err 0x0235 (bad main_data_begin pointer)
dec err 0x0235 (bad main_data_begin pointer)
dec err 0x0101 (lost synchronization)
dec err 0x0102 (reserved header layer value)
Buffer underflow, need 2734 bytes.
Buffer underflow, need 2734 bytes.
Buffer underflow, need 2734 bytes.
Buffer underflow, need 2734 bytes.
Buffer underflow, need 2734 bytes.
I (38360) http_client: ... done reading from socket. Last read return=0 errno=128
I (38370) http_client: socket closed
I (38370) web_radio: http_client_get completed
dec err 0x0235 (bad main_data_begin pointer)
dec err 0x0101 (lost synchronization)
dec err 0x0235 (bad main_data_begin pointer)
dec err 0x0235 (bad main_data_begin pointer)
dec err 0x0101 (lost synchronization)
dec err 0x0235 (bad main_data_begin pointer)
Buffer underflow, need 2734 bytes.
Buffer underflow, need 2734 bytes.
Buffer underflow, need 2734 bytes.
Buffer underflow, need 2734 bytes.
Buffer underflow, need 2734 bytes.
Buffer underflow, need 2734 bytes.
Buffer underflow, need 2734 bytes.
...
-------------------------------------
love it, change it or leave it.
-------------------------------------
問候飛出去的朋友遍全球魯迪

User avatar
supersat
Posts: 10
Joined: Tue Apr 11, 2017 10:17 pm

Re: ESP32 Webradio

Postby supersat » Sun Apr 16, 2017 3:02 am

Did you remember to define DAC_BUG_WORKAROUND in playerconfig.h? I believe you get those underrun errors if you don't.

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

Re: ESP32 Webradio

Postby BuddyCasino » Sun Apr 16, 2017 6:09 am

Yes, I think the DAC uses the bitclk instead of sample rate as I2S clock source, so its reading data way too fast. The DAC_BUG_WORKAROUND corrects for that.

User avatar
rudi ;-)
Posts: 1698
Joined: Fri Nov 13, 2015 3:25 pm

Re: ESP32 Webradio

Postby rudi ;-) » Sun Apr 16, 2017 3:14 pm

hi

in the test where i get the reboot and Buffer underflow
i have used the DAC_BUG_WORKAROUND in DAC mode
#define CONFIG_OUTPUT_MODE DAC_BUILT_IN

and uncomment the line
#define DAC_BUG_WORKAROUND

also
i test the I2S mode
#define CONFIG_OUTPUT_MODE I2S

and comment the line back
// #define DAC_BUG_WORKAROUND

my "hotspot" is a test phone with tethering
the wifi ssid and pass is right,
the connect is right
and the internet dataspeed would be 50MBit/s
so i think the connection is right too.

tested with the last IDF, the preview and some other.
no luck. i tested also other boards.

best wishes
rudi ;-)



edit:
ok figured it out for DAC:
the Hotspot Speed is ok theoretical
but does not have the specification,
i used an extern antenna now on hotspot.

i think the esp32 does not get the next data fast enough from hotspot.
i will change from wifi to ETH PHY now in next step.

Hardware initialized. Waiting for network.
I (460) wifi: n:1 0, o:1 0, ap:255 255, sta:1 0, prof:1
I (2420) wifi: state: init -> auth (b0)
I (2430) wifi: state: auth -> assoc (0)
I (2430) wifi: state: assoc -> run (10)
I (2660) wifi: connected with eMbeddedSecurityHome2, channel 1
I (3230) event: ip: 192.168.43.12, mask: 255.255.255.0, gw: 192.168.43.1
I (3230) gpio: GPIO[0]| InputEn: 1| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldo wn: 0| Intr:1
I (3230) I2S: Req RATE: 44100, real rate: 44642.000, BITS: 8, CLKM: 14, BCK: 16, MCLK: 11289967.000, SCLK: 1428544.000000, diva: 64, divb: 11
I (3250) I2S: DMA Malloc info, datalen=blocksize=128, dma_buf_count=14
I (3260) main: RAM left 160280
I (3270) http_client: DNS lookup succeeded. IP=173.239.76.148
I (3270) http_client: ... allocated socket
I (9160) http_client: ... connected
I (9160) http_client: requesting GET /illstreet-128-mp3 HTTP/1.0
Host: ice1.somafm.com


I (9160) http_client: ... socket send success
created MAD task
MAD: Decoder start.
dec err 0x0101 (lost synchronization)
dec err 0x0235 (bad main_data_begin pointer)
dec err 0x0235 (bad main_data_begin pointer)
I (10220) renderer: setting sample rate to 2756

I (10220) I2S: Req RATE: 2756, real rate: 2765.000, BITS: 8, CLKM: 226, BCK: 16, MCLK: 705574.312, SCLK: 88480.000000, diva: 64, divb: 49
Buffer fill 3%, 2350 bytes
Buffer fill 4%, 2912 bytes
I (12440) wifi: pm start, type:0

Buffer fill 9%, 5929 bytes
Buffer fill 10%, 6438 bytes
Buffer fill 14%, 9507 bytes
Buffer fill 15%, 10017 bytes
Buffer fill 16%, 10526 bytes
Buffer fill 21%, 13596 bytes
Buffer fill 22%, 14105 bytes
Buffer fill 22%, 14615 bytes
Buffer fill 23%, 15176 bytes
Buffer fill 28%, 18193 bytes
Buffer fill 29%, 18703 bytes
Buffer fill 30%, 19264 bytes
Buffer fill 34%, 22344 bytes
Buffer fill 31%, 20346 bytes
Buffer fill 36%, 23415 bytes
Buffer fill 37%, 23925 bytes
Buffer fill 34%, 21927 bytes
Buffer fill 39%, 24996 bytes
Buffer fill 39%, 25505 bytes
Buffer fill 44%, 28522 bytes
Buffer fill 45%, 29084 bytes
Buffer fill 46%, 29593 bytes
Buffer fill 47%, 30103 bytes
Buffer fill 47%, 30664 bytes
Buffer fill 48%, 31174 bytes
Buffer fill 49%, 31683 bytes
Buffer fill 54%, 34753 bytes
Buffer fill 55%, 35262 bytes
Buffer fill 55%, 35771 bytes
Buffer fill 60%, 38841 bytes
Buffer fill 61%, 39350 bytes
Buffer fill 62%, 39860 bytes
Buffer fill 67%, 42929 bytes
Buffer fill 67%, 43438 bytes
Buffer fill 68%, 43948 bytes
Buffer fill 73%, 47017 bytes
Buffer fill 74%, 47526 bytes
Buffer fill 75%, 48036 bytes
Buffer fill 75%, 48597 bytes
Buffer fill 80%, 51667 bytes
Buffer fill 77%, 49679 bytes
Buffer fill 82%, 52812 bytes
Buffer fill 83%, 53321 bytes
Buffer fill 84%, 53831 bytes
Buffer fill 88%, 56900 bytes
Buffer fill 89%, 57472 bytes
Buffer fill 90%, 57982 bytes
Buffer fill 95%, 60999 bytes
Buffer fill 96%, 61560 bytes
Buffer fill 97%, 62133 bytes
Buffer fill 97%, 62642 bytes
FIFO full.
FIFO full.
FIFO full.
FIFO full.
FIFO full.
FIFO full.
FIFO full.
FIFO full.
FIFO full.
FIFO full.
Buffer fill 98%, 63204 bytes
FIFO full.
FIFO full.
FIFO full.
FIFO full.
FIFO full.
FIFO full.
FIFO full.
FIFO full.
FIFO full.
FIFO full.
Buffer fill 99%, 63776 bytes
FIFO full.
FIFO full.
FIFO full.
FIFO full.
FIFO full.
FIFO full.
FIFO full.
FIFO full.
FIFO full.
FIFO full.
FIFO full.
FIFO full.
FIFO full.
FIFO full.
Buffer fill 96%, 61778 bytes
FIFO full.
FIFO full.
FIFO full.
FIFO full.
FIFO full.
FIFO full.
FIFO full.
FIFO full.
Buffer fill 97%, 62339 bytes
FIFO full.
FIFO full.
FIFO full.
FIFO full.
FIFO full.
FIFO full.
FIFO full.
FIFO full.
FIFO full.
FIFO full.
FIFO full.
FIFO full.
Buffer fill 98%, 62912 bytes
FIFO full.
FIFO full.
FIFO full.
FIFO full.
FIFO full.
FIFO full.
FIFO full.
FIFO full.
FIFO full.
FIFO full.
Buffer fill 99%, 63484 bytes
FIFO full.
FIFO full.
FIFO full.
FIFO full.
FIFO full.
FIFO full.
FIFO full.
FIFO full.
FIFO full.
FIFO full.
Buffer fill 99%, 63918 bytes
FIFO full.
FIFO full.
FIFO full.
FIFO full.
FIFO full.
FIFO full.
FIFO full.
FIFO full.
FIFO full.
FIFO full.
FIFO full.
FIFO full.
Buffer fill 97%, 62111 bytes
FIFO full.
FIFO full.
FIFO full.
FIFO full.
FIFO full.
FIFO full.
FIFO full.
FIFO full.
FIFO full.
FIFO full.
Buffer fill 97%, 62620 bytes
FIFO full.
FIFO full.
FIFO full.
FIFO full.
FIFO full.
FIFO full.
FIFO full.
FIFO full.
FIFO full.
FIFO full.
FIFO full.
FIFO full.
Buffer fill 98%, 63181 bytes
GPIO[0] intr, val: 1
stopping player
I (67440) web_radio: RAM left 142188
MAD: Decoder stopped.
I (67440) http_client: ... done reading from socket. Last read return=63 errno=0
I (67440) http_client: socket closed
I (67450) web_radio: http_client_get completed
-------------------------------------
love it, change it or leave it.
-------------------------------------
問候飛出去的朋友遍全球魯迪

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

Re: ESP32 Webradio

Postby BuddyCasino » Sun Apr 16, 2017 4:22 pm

Glad you got it working. I've got an optimization pending that might help in high-latency scenarios such as mobile phone connections, will test this.

User avatar
rudi ;-)
Posts: 1698
Joined: Fri Nov 13, 2015 3:25 pm

Re: ESP32 Webradio

Postby rudi ;-) » Sun Apr 16, 2017 5:12 pm

BuddyCasino wrote:Glad you got it working. I've got an optimization pending that might help in high-latency scenarios such as mobile phone connections, will test this.
thanks for your work on it.
yep this was the point mike. would be fine if there is a procedure for high latency scenarios.
perhabs first test the network latency on a blind date connection
and then setup the stream.

now i have change to the inhouse hotspot and it works like a charme mike!
thank you!

i try to use the player and sbc decoder for BT A2DB example just in time.

PR:
support for
- SBC stream
- example GSM610 stream

Suggestion improvement:
if pushed stop button and play again the unsynchron data buffer makes a noise on output bevor it goes to synchron. if we can make silence this time it would be fine.

best wishes
rudi ;-)
-------------------------------------
love it, change it or leave it.
-------------------------------------
問候飛出去的朋友遍全球魯迪

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

Re: ESP32 Webradio

Postby BuddyCasino » Sun Apr 16, 2017 5:49 pm

rudi ;-) wrote: i try to use the player and sbc decoder for BT A2DB example just in time.

PR:
support for
- SBC stream
- example GSM610 stream
Not sure if I understood you - are you working on adding A2DP support? Pull requests are always welcome, wanted to add that anyway, but most of my free time goes to finishing the Alexa client currently.
rudi ;-) wrote: Suggestion improvement:
if pushed stop button and play again the unsynchron data buffer makes a noise on output bevor it goes to synchron. if we can make silence this time it would be fine.
Yeah I noticed that too, I'm filling the DMA queue with silence which helps a bit but not completely, I'm missing something. Also I wasn't sure how much of that is due to the I2S codec I'm using, which e.g. makes a pop when the sample rate changes. But now with the DAC working properly I can test that better.

Who is online

Users browsing this forum: No registered users and 32 guests