ESP32 Webradio

joeybab3
Posts: 2
Joined: Wed Jun 28, 2017 7:06 am

Re: ESP32 Webradio

Postby joeybab3 » Wed Jun 28, 2017 7:08 am

I can't seem to get mine to do anything other than crackle on either DAC or PDM. It crackles on either bluetooth or wifi mode, any ideas?

Bletru
Posts: 1
Joined: Wed Jun 28, 2017 12:34 pm

Re: ESP32 Webradio

Postby Bletru » Wed Jun 28, 2017 12:48 pm

Hi there,

I am impressed and very happy with the implementation of this Web Radio application.
Even using the built-in DAC with a speaker sounds quite good.

What is missing is the possibility to change the volume. Every station is always "full power".

I had a look at the code, especially at audio_renderer.c in /esp-idf-2.0/components/audio_renderer/ directory
where the samples are prepared

Code: Select all

        if(renderer_instance->output_mode == DAC_BUILT_IN)
        {
            // assume 16 bit src bit_depth
            short left = *(short *) ptr_l;
            short right = *(short *) ptr_r;


            left = left / 64;
            right =right / 64;
           
           
           
            // The built-in DAC wants unsigned samples, so we shift the range
            // from -32768-32767 to 0-65535.

            left  = left  + 0x8000;
            right = right + 0x8000;

            uint32_t sample = (uint16_t) left;
            sample = (sample << 16 & 0xffff0000) | ((uint16_t) right);

            bytes_pushed = i2s_push_sample(renderer_instance->i2s_num, (const char*) &sample, max_wait);
        }


and hoped that I can only divide the values "left" and "right" by some value before doing the signed unsigned shift.
But it does not work.

Any idea to add some possibility to change the volume of the samples?

Thanks in advance for your answer.
Last edited by Bletru on Wed Jun 28, 2017 5:14 pm, edited 1 time in total.

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

Re: ESP32 Webradio

Postby BuddyCasino » Wed Jun 28, 2017 3:14 pm

Any idea to add some possibility to change the volume of the samples?

Some DSP stuff (bi-quad filter) is planned by Jorgen. I looked into volume control, multiplying the final sample by some float should do the trick. In general volume control can be complex (the ESP32 has no hardware support for saturating arithmetic), and some amplifiers have I2C volume control, but a basic version should be simple.

I'm accepting pull requests, a separate volume_control component would be welcome.

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

Re: ESP32 Webradio

Postby BuddyCasino » Wed Jun 28, 2017 3:16 pm

joeybab3 wrote:I can't seem to get mine to do anything other than crackle on either DAC or PDM. It crackles on either bluetooth or wifi mode, any ideas?

Thats not enough information to help. You can open an issue on Github to keep the signal/noise ratio on the forum down.
Be sure to include your hardware schematics and log output, basically everything that could be relevant.

joeybab3
Posts: 2
Joined: Wed Jun 28, 2017 7:06 am

Re: ESP32 Webradio

Postby joeybab3 » Wed Jun 28, 2017 5:03 pm

I thought about opening an issue but I've found people to be kind of harsh sometimes if you open an issue when there's a forum available so I figured I'd post here. I'll go ahead and open an issue on github though.

naguirre
Posts: 1
Joined: Sun Apr 02, 2017 7:09 am

Re: ESP32 Webradio

Postby naguirre » Wed Jul 05, 2017 10:54 pm

BuddyCasino wrote:Ah, you mean bluetooth. Didn't test that a lot, ESP-IDF does most of the work anyway so I'm not sure I can fix that. The "xBtuQueue Failed" is triggered in btu_task.c, which is Broadcom code. Its possible that we don't consume the PCM buffer fast enough, but I have no idea really.


Hi,
i tried to fix this problem, where audio stop working after a while, or is continuously interrupted while playing, with BT Audio.
I finally found a workarround by adding a delay in the bt task in esp-idf. It's not the most beautiful patch i have ever written, but it does the job, at least in my tests.

Code: Select all

diff --git a/components/bt/bluedroid/btc/profile/std/a2dp/btc_media_task.c b/components/bt/bluedroid/btc/profile/std/a2dp/btc_media_task.c
index 8610ef8..d8dd600 100644
--- a/components/bt/bluedroid/btc/profile/std/a2dp/btc_media_task.c
+++ b/components/bt/bluedroid/btc/profile/std/a2dp/btc_media_task.c
@@ -264,6 +264,7 @@ static void btc_media_task_handler(void *arg)
             btc_media_ctrl_handler(e);
             osi_free(e);
         }
+        vTaskDelay(1);
     }
 }


It's like if bluetooth task handling a2dp profile was always reading the receiving queue and no other tasks were scheduled. Note that it works well with the a2dp example of esp-idf sdk, and it's the implementation of ad2p in esp32 webradio which is not working :( Maybe the task feeding audio in esp webradio has the same proprity and is never schedule. IIRC correctly the BT audio task has a priority 3.
It may help others people.

Regards,
Nicolas

randy_house
Posts: 1
Joined: Mon Jul 17, 2017 10:32 pm

Re: ESP32 Webradio

Postby randy_house » Mon Jul 17, 2017 10:38 pm

@BuddyCasino

I actually have a question regarding how you use `nghttp2` to do multipart HTTP/2 POST request. Do you simply use `nghttp2_submit_request` to send your request? How do you combine the Json and Audio into one request?

Thanks
Randy


BuddyCasino wrote:
dotthree wrote:What kind of instability problems are you having?

Since last evening I can actually post a pre-recorded audio file to Alexa, get an HTTP2 multipart MP3 answer back, decode it via MAD and play it via I2S amplifier.
There are some issues left that I really need to resolve before publishing the code:
  • getting audio input via I2S input to work
  • resolve SSL connection issues that sometimes cause very long connect times (minutes)
  • handle authentication better

There is still much work to be done after that, but I'll publish it as soon as it does the bare minimum task. Pinky promise!

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

Re: ESP32 Webradio

Postby BuddyCasino » Tue Jul 18, 2017 8:13 am

randy_house wrote:I actually have a question regarding how you use `nghttp2` to do multipart HTTP/2 POST request. Do you simply use `nghttp2_submit_request` to send your request? How do you combine the Json and Audio into one request?


Yeah thats tricky. I'll try to upload it to Github this week. My decision to implement some required Alexa webservices in Rust delayed things a little...

randy_house
Posts: 1
Joined: Mon Jul 17, 2017 10:32 pm

Re: ESP32 Webradio

Postby randy_house » Tue Jul 18, 2017 4:44 pm

Dear Buddy Casino

It is great to hear back from you. I am looking forward to your post on Github. Currently, I have figured out the connections and the down channel, I am stuck on making the actual request (to be more specific, I am stuck on the part where you put Json + Audio onto a multi-part Http2 message, using `nghttp2`). Thanks for replying to my message!


BuddyCasino wrote:
randy_house wrote:I actually have a question regarding how you use `nghttp2` to do multipart HTTP/2 POST request. Do you simply use `nghttp2_submit_request` to send your request? How do you combine the Json and Audio into one request?


Yeah thats tricky. I'll try to upload it to Github this week. My decision to implement some required Alexa webservices in Rust delayed things a little...

VijayThakkar
Posts: 1
Joined: Fri Aug 11, 2017 9:19 am

Re: ESP32 Webradio

Postby VijayThakkar » Fri Aug 11, 2017 9:25 am

Hi Buddy Casino,

I am also facing connection issue with Alexa using nghttp2 + mbedTLS.
It would be grateful if you share working code on GitHub.

Thanks in Advance.
Regards,
Vijay

Who is online

Users browsing this forum: BlackEdder, Google [Bot] and 3 guests