Edzelf / ESP32-Radio

Internet radio based on ESP32, VS1053 and a TFT screen.
GNU General Public License v3.0
964 stars 227 forks source link

Audio lag, large delay on playback #504

Closed tsctrl closed 2 years ago

tsctrl commented 2 years ago

hi Ed!

i had issue where audio is lagging. it is 2s playback and then 10s silence and playback again for 2s then silence back.

i have use the provided pcb and check the connection. i am using usb to power the esp and did not attach the 220uf and 470uf caps for now to test.

i am on master branch. compiled and flash successfully to the original esp32 devkit. the internet radio link just play nicely on web browser.

the rotary encoder dail is not working as expected, i am using a 3x 10k ohm rotary encoder. only able to mute and unmute. 2 or 3 press will display channel selection but turning the knob does not change the channel on display.

thanks!

tsctrl commented 2 years ago

update, i have use V2 with hardware playback with the same result.

  1. checkout v2
  2. reset and upload config and data
  3. connect to ESP32-Radio wifi
  4. reset config to default
  5. enter my wifi uname and password
  6. restart and listen to NPO Radio1

result: large delay on playback as above. D: Song stopped correctly after 0 msec D: Connect to host icecast.omroep.nl:80/radio1-bb-mp3 D: Connect to icecast.omroep.nl on port 80, extension /radio1-bb-mp3 D: Connected to MP3 host at 145.58.53.145 on port 80 D: send GET command D: Switch to HEADER D: Headerline: Content-Type: audio/mpeg D: audio/mpeg seen. D: Headerline: icy-br:192 D: Headerline: ice-audio-info: samplerate=48000;channels=2;bitrate=192 D: Headerline: icy-br:192 D: Headerline: icy-genre:Talk D: Headerline: icy-metadata:1 D: Headerline: icy-name:NPO Radio1 D: Headerline: icy-pub:0 D: Headerline: icy-url:http://www.radio1.nl D: Headerline: Server: Icecast 2.4.0-kh15 D: Headerline: Cache-Control: no-cache, no-store D: Headerline: Expires: Mon, 26 Jul 1997 05:00:00 GMT D: Headerline: Connection: Close D: Headerline: Access-Control-Allow-Origin: * D: Headerline: Access-Control-Allow-Headers: Origin, Accept, X-Requested-With, Content-Type, Icy-MetaData D: Headerline: Access-Control-Allow-Methods: GET, OPTIONS, SOURCE, PUT, HEAD, STATS D: Headerline: icy-metaint:16000 D: Switch to DATA, bitrate is 192, metaint is 16000 D: Streamtitle found, 47 bytes

Edzelf commented 2 years ago

Can you disconnect the rotary switch. Maybe this is causing the trouble.

tsctrl commented 2 years ago

i have disconnected the rotary encoder. ir sensor, lcd and only retain the vs1053.restarted the device i still having the same issue.

Edzelf commented 2 years ago

With the "test" command in the serial interface you can see some stream info. If there is a low number of bytes in the stream, you have a network problem. Try a different network.

tsctrl commented 2 years ago

hi @Edzelf, how low is low? i am streaming the url directly in web browser using the same network as the esp32 is connected and it play smoothly in browser.

wondering if there is any variable or settings i could change to tweak or play around to get the optimal stream. other than that what else i could do to check?

thanks!

tsctrl commented 2 years ago

could you point the code part where the stream was transfered to the spi? any way i could increase the buffer?

tsctrl commented 2 years ago

Screenshot_20220406-211634_Chrome

this is the details when i press the test button.

tsctrl commented 2 years ago

Here some console logs:

D: Connect to new host 109.206.96.34:8100 D: Connect to 109.206.96.34 on port 8100, extension / D: Connected to server D: Switch to HEADER D: Headerline: icy-name:NAXI LOVE RADIO (NAXI,Belgrade,Serbia, NAXI,Beograd,Srbija) - 128k D: Headerline: icy-genre:Love and Romance D: Headerline: icy-url:http://www.naxi.rs D: Headerline: content-type:audio/mpeg D: audio/mpeg seen. D: Headerline: icy-pub:0 D: Headerline: icy-metaint:8192 D: Headerline: icy-br:128 D: Switch to DATA, bitrate is 128, metaint is 8192 D: Duration mp3loop 35 D: Metadata block 48 bytes D: Streamtitle found, 47 bytes D: StreamTitle='Ja biram sta slusam';StreamUrl=''; D: Command client available D: handlehttp started D: Get command is: status D: Send reply for status D: Command: status with parameter 0 D: Command client available D: handlehttp started D: Get command is: status D: Send reply for status

D: Command: test with parameter 0 D: Stack maintask is 6008 D: Stack playtask is 92 D: Stack spftask is 600 D: ADC reading is 0 D: scaniocount is 10 D: Max. mp3_loop duration is 35 D: 0 IR interrupts seen D: Free memory is 218192, chunks in queue 97, stream 0, bitrate 3435518 kbps D: Duration mp3loop 1 D: Duration mp3loop 4 D: Duration mp3loop 6 D: Command client available D: handlehttp started D: Get command is: status D: Send reply for status D: Command: status with parameter 0 D: Duration mp3loop 7

tsctrl commented 2 years ago

tested most of the preset and radio in the search list with the same results

Edzelf commented 2 years ago

As you can see, there is no input in the stream. So try a different network. D: Free memory is 218192, chunks in queue 97, stream 0, bitrate 3435518 kbps

tsctrl commented 2 years ago

i have tried to place the module just beside the internet router to get the strongest signal and tried with other wifi network too. mobile hotspot and different fibre internet with the same lag.

Rainer-G commented 2 years ago
Hi when you disconnected the Encoder, did you also set the Encoder Pins data and cklock in the config web page to -1, this will disable Interrupts caused by open Input Pins. Rainer Gesendet von Mail für Windows Von: tsctrlGesendet: Donnerstag, 7. April 2022 12:31An: Edzelf/ESP32-RadioCc: SubscribedBetreff: Re: [Edzelf/ESP32-Radio] Audio lag, large delay on playback (Issue #504) i have tried to place the module just beside the internet router to get the strongest signal and tried with other wifi network too. mobile hotspot and different fibre internet with the same lag.—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you are subscribed to this thread.Message ID: ***@***.***> 
tsctrl commented 2 years ago

Hi @Rainer-G ,

thank you and appreciate your reply. i updated pin definition in config to -1 as below: D: Command: pin_enc_clk with parameter -1 D: Command: pin_enc_dt with parameter -1 D: Command: pin_enc_sw with parameter -1

and pull the rotary decoder off but still have the same issue. I also tried with open hotspot from my pc connected to gbit lan, the esp is very close to the pc hotspot but still having the same lag issue.

probably my vs chip is fake? or i guess this is something related to the how the wifi connection is fetching the stream and how the stream is feed to the vs1053. probably require some logic where how many byte was in buff and how it is transferred to the vs1053. i also have tweaks esp hardware related wifi configuration to enable more rx buffer, speed optimization, enable features like ampdu tx and also set the esp signal strength to the max but still with the same issue.

tsctrl commented 2 years ago

Hi @Edzelf

below is my startup logs:

D: Starting ESP32-radio running on CPU 0 at 240 MHz. Version Mon, 28 Jun 2021 12:40:00 GMT. Free memory 282876 D: Display type is BLUETFT D: Partition nvs found, 24576 bytes D: Read 42 keys from NVS D: pin_ir set to 35 D: pin_enc_clk set to 25 D: pin_enc_dt set to 26 D: pin_enc_sw set to 27 D: pin_tft_cs set to 15 D: pin_tft_dc set to 2 D: pin_tft_scl set to -1 D: pin_tft_sda set to -1 D: pin_tft_bl set to -1 D: pin_tft_blx set to -1 D: pin_sd_cs set to 21 D: pin_ch376_cs set to -1 D: pin_ch376_int set to -1 D: pin_vs_cs set to 5 D: pin_vs_dcs set to 16 D: pin_vs_dreq set to 4 D: pin_shutdown set to -1 D: pin_shutdownx set to -1 D: pin_spi_sck set to 18 D: pin_spi_miso set to 19 D: pin_spi_mosi set to 23 D: GPIO0 is HIGH D: GPIO2 is HIGH D: GPIO4 is HIGH D: GPIO5 is HIGH D: GPIO12 is HIGH D: GPIO13 is HIGH D: GPIO14 is HIGH D: GPIO15 is HIGH D: GPIO16 is LOW, probably no PULL-UP D: GPIO17 is HIGH D: GPIO18 is LOW, probably no PULL-UP D: GPIO19 is HIGH D: GPIO21 is HIGH D: GPIO22 is HIGH D: GPIO23 is HIGH D: GPIO25 is HIGH D: GPIO26 is HIGH D: GPIO27 is HIGH D: GPIO32 is HIGH D: GPIO33 is HIGH D: GPIO34 is LOW, probably no PULL-UP D: GPIO35 is LOW, probably no PULL-UP D: GPIO39 is LOW, probably no PULL-UP D: gpio_00 will execute uppreset = 1 D: gpio_12 will execute upvolume = 2 D: gpio_13 will execute downvolume = 2 D: Enable pin 35 for IR D: Start display D: Create list with acceptable WiFi networks D: Added xxxx to list of networks D: End adding networks D: Scan Networks D: Scan completed D: Number of available networks: 12 D: 1 xxxxx - Signal: -16 dBm, Encryption WPA2_PSK, ..... D: End of list D: Command: clk_dst with parameter 0 D: Command: clk_offset with parameter 8 D: Command: clk_server with parameter my.pool.ntp.org D: Command: gpio_00 with parameter uppreset = 1 D: Command: gpio_12 with parameter upvolume = 2 D: Command: gpio_13 with parameter downvolume = 2 D: Command: ir_40bf with parameter upvolume = 2 D: Command: ir_c03f with parameter downvolume = 2 D: Command: mqttbroker with parameter none D: Command: mqttpasswd with parameter *** D: Command: mqttport with parameter 1883 D: Command: mqttprefix with parameter none D: Command: mqttuser with parameter none D: Command: pin_enc_clk with parameter 25 D: Command: pin_enc_dt with parameter 26 D: Command: pin_enc_sw with parameter 27 D: Command: pin_ir with parameter 35 D: Command: pin_sd_cs with parameter 21 D: Command: pin_tft_cs with parameter 15 D: Command: pin_tft_dc with parameter 2 D: Command: pin_vs_cs with parameter 5 D: Command: pin_vs_dcs with parameter 16 D: Command: pin_vs_dreq with parameter 4 D: Command: preset with parameter 8 D: Command: preset_00 with parameter 109.206.96.34:8100 D: Command: preset_01 with parameter airspectrum.cdnstream1.com:8114/1648_128 D: Command: preset_02 with parameter us2.internet-radio.com:8050 D: Command: preset_03 with parameter airspectrum.cdnstream1.com:8000/1261_192 D: Command: preset_04 with parameter airspectrum.cdnstream1.com:8008/1604_128 D: Command: preset_05 with parameter us1.internet-radio.com:8105 D: Command: preset_06 with parameter icecast.omroep.nl:80/radio1-bb-mp3 D: Command: preset_07 with parameter 205.164.62.15:10032 D: Command: preset_08 with parameter astro2.rastream.com/era D: Command: preset_09 with parameter 94.23.66.155:8106 D: Command: preset_10 with parameter ihr/IHR_IEDM D: Command: preset_11 with parameter ihr/IHR_TRAN D: Command: toneha with parameter 0 D: Command: tonehf with parameter 0 D: Command: tonela with parameter 0 D: Command: tonelf with parameter 0 D: Command: volume with parameter 72 D: Slow SPI, Testing VS1053 read/write registers... D: Fast SPI, Testing VS1053 read/write registers again... D: Connect to WiFi D: Try WiFi xxxx D: Connected to xxxxx D: IP = 192.168.0.132 D: Start server for commands D: Network found. Starting mqtt and OTA D: Rotary encoder is enabled D: Sync TOD D: Sync TOD, new value is 01:09:43 D: STOP requested D: New preset/file requested (8/0) from astro2.rastream.com/era D: New station request D: Connect to new host astro2.rastream.com/era D: Connect to astro2.rastream.com on port 80, extension /era D: Song stopped correctly after 0 msec D: Connected to server D: Switch to HEADER D: Headerline: icy-br: 47 D: Headerline: icy-pub: 0 D: Headerline: icy-description: Unspecified description D: Headerline: icy-url: D: Headerline: Instance-id: 2f65edb2bb2da9af8cbeed2ca3f4f298 D: Headerline: Cache-Control: no-cache D: Headerline: Server: AIS Streaming Relay 8.6.5 D: Headerline: icy-genre: various D: Headerline: Expires: Mon, 26 Jul 1997 05:00:00 GMT D: Headerline: icy-metaint: 1024 D: Headerline: Pragma: no-cache D: Headerline: icy-name: D: Headerline: Connection: close D: Headerline: Content-Type: audio/aacp D: audio/aacp seen. D: Headerline: Set-Cookie: AISSessionId=6220f200b840d683_3197913_vKHviNQD_MTAzLjIxLjgxLjM6ODA!_0000004hLFL; Path=/; Domain=astro2.rastream.com; Max-Age= D: Switch to DATA, bitrate is 47, metaint is 1024 D: Metadata block 96 bytes D: Streamtitle found, 91 bytes D: StreamTitle='Adele - Easy On Me';StreamUrl='Easy On MeAdeleEasy On MeAdeleEasy On MeAdele'; D: Duration mp3loop 82 D: Metadata block 256 bytes D: Streamtitle found, 240 bytes

thanks!

tsctrl commented 2 years ago

updated pin definition for rotary encoder in config to -1 after the config above with the same issue. use/play any channel with the same issue

Edzelf commented 2 years ago

The station astro2.rastream.com/era plays well on my radio. But I am using version 2. The "test" command reveals:

test
D: Free memory is 66832, chunks in queue 400, bitrate 48 kbps

So the input stream queue is fully filled (400 chunks is the max). This line: D: GPIO16 is LOW, probably no PULL-UP is strange, GPIO16 is your vs_dcs, that should be pulled high if idle. configuring pins to -1 is not necessary, all pins except the SPI pins are set to -1 by default.

Rainer-G commented 2 years ago
Hi, no Problem, I like to help as I had similar Problems some time ago…I’m running the same V1 software version with a bluetft display connected with sda/scl so I compared you log with mine. Only small differencies: D: GPIO16 is LOW, probably no PULL-UPD: GPIO17 is HIGHD: GPIO18 is LOW, probably no PULL-UP Is this always this way with pin 16 and 18 LOW? It may happen from time to time but should normally be HIGHEsp. Pin 16 should not be low when starting the ESP32, pleas check the wiring D: Slow SPI, Testing VS1053 read/write registers...D: Fast SPI, Testing VS1053 read/write registers again...D: endFillByte is 0 I’m missing the 3rd line in your log, did you cut it out? When I had the problems with sound dropping and the VS1053 running out of data, I found a bad connection for one of the SPI Pins.I also added a decoupling capacitor across VCC/GND close to the VS supply pins. My WiFi is -48dm and everything is OK with the data comming from the same station as yours ( as it is with your PC when you try it there ). Do you use IR receiver on pin 35? CheersRainer   Gesendet von Mail für Windows Von: tsctrlGesendet: Samstag, 9. April 2022 18:48An: Edzelf/ESP32-RadioCc: Rainer-G; MentionBetreff: Re: [Edzelf/ESP32-Radio] Audio lag, large delay on playback (Issue #504) Hi @Rainer-G ,thank you and appreciate your reply. i updated pin definition in config to -1 as below:D: Command: pin_enc_clk with parameter -1D: Command: pin_enc_dt with parameter -1D: Command: pin_enc_sw with parameter -1and pull the rotary decoder off but still have the same issue.I also tried with open hotspot from my pc connected to gbit lan, the esp is very close to the pc hotspot but still having the same lag issue.probably my vs chip is fake? or i guess this is something related to the how the wifi connection is fetching the stream and how the stream is feed to the vs1053. probably require some logic where how many byte was in buff and how it is transferred to the vs1053. i also have tweaks esp hardware related wifi configuration to enable more rx buffer, speed optimization, enable features like ampdu tx and also set the esp signal strength to the max but still with the same issue.—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you were mentioned.Message ID: ***@***.***> 
tsctrl commented 2 years ago

Hi @Edzelf , @Rainer-G

I have fix the issue. image

using the pcb in the doc but did not realize the pin 16 is used for nextion and i have plug it in for dcs. i move the dupon to pin 32 and it works! no more lags! // GPIO16 RXD2 - - - TX of NEXTION (if in use)

Before i end this, i would like to ask here a bit more. i have question regarding the vs1053. is the output is only from the audio out 3.5mm audio jack? means the isolator transformer need to be connected to the audio jack before going to the PAM amplifier? i saw other version of pcb in the doc which the PAM amplifier and the isolator transformer is hooked up directly in the pcb. how its done? thats what make me wondering if there is other output pin available from the vs1053 to be connected to the pcb traces where i did not find any. I unable to find the pcb from Harm Verbeek to check as the site to download the pcb was unavailable now.

image

Thank you so much for your time, help and reply. thanks again for this great project!

Rainer-G commented 2 years ago
hI; It is rather easy to connect the VS1053 with the PAM amplifier. Here is a part of my PCB, you can see the 3,5mm jack of the VS1053 on top right:Connect the Ground pin from the 3,5 mm jack ( which is actually VREF, not GND and must not be connected to GND ) to one side of the left and right tranformer, and Out_R / Out_l to  LIN / RIN of the second pin of the transformer. On the other side, connect one pin to GND of the amplifier and the other to the input of the amplifier. In the example above, I have a voltage divider to reduce the output level (my PAM8610 has a higher input sensivity as the on on the board shown). There are a few VS Boards with different components mounted: I found on without pin headers and 3,5mm jack soldered ( ideal for me as I needed pins on the back of the PCB ), one with both soldered and also one with an SMD jack rather than a through hole version. On one of my PCB I used an isolated DC/DC12 to 5 Volt converter to supply the ESP32, VS1053 and display and used a cable with 3,5 mm plugs on both sides to connect the VS1053 directly to the PAM8610. This made connection easy and also reduced noice coming over the power rails! CheersRainer Gesendet von Mail für Windows Von: tsctrlGesendet: Sonntag, 10. April 2022 01:19An: Edzelf/ESP32-RadioCc: Rainer-G; MentionBetreff: Re: [Edzelf/ESP32-Radio] Audio lag, large delay on playback (Issue #504) Hi @Edzelf , @Rainer-GI have fix the issue.using the pcb in the doc but did not realize the pin 16 is used for nextion and i have plug it in for dcs. i move the dupon to pin 32 and it works! no more lags!// GPIO16 RXD2 - - - TX of NEXTION (if in use)Before i end this, i would like to ask here a it more. i have question regarding the vs1053. is the output is only from the audio out 3.5mm audio jack? means the isolator transformer need to be connected to the audio jack before going to the PAM amplifier? i saw other version of pcb in the doc which the PAM amplifier and the isolator transformer is hooked in the pcb. how its was done? thats what make me wondering if there is outer output pin available from the vs1053 to be connected to the pcb traces where i did not find any. I unable to find the pcb from Harm Verbeek to check as the site to download the pcb was unavailable now.Thank you so much for your time, help and reply. thanks again for this great project!—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you were mentioned.Message ID: ***@***.***> 
tsctrl commented 2 years ago

hi @Rainer-G , thank you for the tips, look like couldnt avoid to use the 3.5mm jack interface to the pam. it looks improper to connect both component (vs-pam) using the 3.5mm jack and crimping 3.5jack with wire are so frustrating. that is one of the reason i hopefully does not have to use any 3.5mm audio jack on my setup. any way of using isolated power or a transformer couldnt help me to solve the 3.5mm jack setup. where i am wondering the picture i shared previously where it install pam transformer and vs in a single board without require 3.5mm jack or it is actually required but not installed by @Edzelf in the doc image.

i have bought a isolated psu 5-15v recomended by Ed in the doc as this one to try but it havent arrive yet Screenshot_20220410-221609

also a audio transformer too: Screenshot_20220410-221355_Shopee

would like to see how it goes. hope i did not have to use any of this component and could accept the audio quality without it. so far i am satisfied with audio output from vs to external speakers with build in amp amp. i havent use internal speakers with pam. i guess using pam could be the cause of the audio quality issue mentioned. i still have lots to try to decide.

would like to know what kind of isolated 12v power u are using. thanks again!

Rainer-G commented 2 years ago
Hi, if you use an external amplifier there is no need for transformers if you can make sure that the GND from VS and ampliefier are not connected.You can also try to connect capacitors to the output of the VS1053 and use GND as common wire. This may make problems with noise from the power supply but a good layout of the power rails can solve this.Adafruit with the VS1053 Feather board uses capacitors on-board and has the 3,5 jack connected to GND, works perfect but the board is rather expensive. On my board I removed the jack from the VS1053 and connected the output to the board using prinheads:  CheersRainer Gesendet von Mail für Windows Von: tsctrlGesendet: Sonntag, 10. April 2022 16:37An: Edzelf/ESP32-RadioCc: Rainer-G; MentionBetreff: Re: [Edzelf/ESP32-Radio] Audio lag, large delay on playback (Issue #504) hi @Rainer-G , thank you for the tips, look like couldnt avoid to use the 3.5mm jack interface to the pam. it looks improper to connect both component (vs-pam) using the 3.5mm jack and crimping 3.5jack with wire are so frustrating. thats one of the reason i hopefully does not have to use any 3.5mm audio jack on my setup. any way of using isolated power or a transformer couldnt help me to solve the 3.5mm jack setup. where i am wondering the picture i shared previously install pam transformer and vs in a single board without require 3.5mm jack or ot is actually required but not installed by @Edzelf in the dic image.i have bought a isolated psu 5-15v recomended by Ed in the doc as this one to try but it havent arrive yetalso a audio transformer too:would like to see how it goes. hope i did not have to use any of this component and could accept the audio quality without it. so far i am satisfied with direct external amp output from vs. i havent use speakers with pam. i guess using pam could be the cause of the audio quality issue mentioned. i still have lots to try to decide.would like to know what kind of isolated 12v power u are using. thanks again!—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you were mentioned.Message ID: ***@***.***> 
Rainer-G commented 2 years ago
One more: are you sure that the power supply below is isolated? I cannot see any transformer to isolate the input from the output???If there is no isolation you will definitely need the audio transformers. Rainer Gesendet von Mail für Windows Von: tsctrlGesendet: Sonntag, 10. April 2022 16:37An: Edzelf/ESP32-RadioCc: Rainer-G; MentionBetreff: Re: [Edzelf/ESP32-Radio] Audio lag, large delay on playback (Issue #504) hi @Rainer-G , thank you for the tips, look like couldnt avoid to use the 3.5mm jack interface to the pam. it looks improper to connect both component (vs-pam) using the 3.5mm jack and crimping 3.5jack with wire are so frustrating. thats one of the reason i hopefully does not have to use any 3.5mm audio jack on my setup. any way of using isolated power or a transformer couldnt help me to solve the 3.5mm jack setup. where i am wondering the picture i shared previously install pam transformer and vs in a single board without require 3.5mm jack or ot is actually required but not installed by @Edzelf in the dic image.i have bought a isolated psu 5-15v recomended by Ed in the doc as this one to try but it havent arrive yetalso a audio transformer too:would like to see how it goes. hope i did not have to use any of this component and could accept the audio quality without it. so far i am satisfied with direct external amp output from vs. i havent use speakers with pam. i guess using pam could be the cause of the audio quality issue mentioned. i still have lots to try to decide.would like to know what kind of isolated 12v power u are using. thanks again!—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you were mentioned.Message ID: ***@***.***> 
tsctrl commented 2 years ago

thanks @Rainer-G, will add the isolation as seems it is required. i will check the option how it is done in VS1053 Feather board too.

closing this issue as resolved.