ESP32 Webradio

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

ESP32 Webradio

Postby BuddyCasino » Sun Jan 22, 2017 11:45 am

I was a big fan of Sprite_TMs https://github.com/espressif/ESP8266_MP3_DECODER project, and so I ported it to the ESP32.

Go and get it here:
https://github.com/MrBuddyCasino/ESP32_MP3_Decoder

I made a picture, but Github currently refuses to serve blobs it seems: https://github.com/MrBuddyCasino/ESP32_ ... wiring.jpg

Running it without the I2S codec doesn't currently work, patches welcome: https://github.com/MrBuddyCasino/ESP32_ ... r/issues/1

WiFive
Posts: 3529
Joined: Tue Dec 01, 2015 7:35 am

Re: ESP32 Webradio

Postby WiFive » Sun Jan 22, 2017 11:58 am

Image

WiFive
Posts: 3529
Joined: Tue Dec 01, 2015 7:35 am

Re: ESP32 Webradio

Postby WiFive » Sun Jan 22, 2017 12:00 pm

Interested in the i2s dac output resolution

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

Re: ESP32 Webradio

Postby BuddyCasino » Sun Jan 22, 2017 12:36 pm

The built-in one? It has only 8 Bit resolution, but still better than the ~5 Bit of hacked PWM of the ESP8266 predecessor project.
The hardware codec I used has... I don't know, 16 Bit?

User avatar
Jakobsen
Posts: 89
Joined: Mon Jan 16, 2017 8:12 am

Re: ESP32 Webradio

Postby Jakobsen » Sun Jan 22, 2017 11:08 pm

Cool work done BuddyCasino

I cloned you code and had to disable last line in app_main.c

Code: Select all

  // init player
    player = calloc(1, sizeof(Player));
    player->state = PLAYER_STARTING;
    ESP_LOGI(TAG, "RAM left %d", esp_get_free_heap_size());
//    ESP_LOGI(TAG, "app_main stack: %d\n", uxTaskGetStackHighWaterMark(NULL));
uxTaskGetStackHigh.... issued a core dump ...

I did a capture of the I2S output and the format looks like sweep music to me. Have a look:

Image

I will try to get the i2s driver to do 32 bits - so it can play on my merus-audio amplifier.
Analog Digital IC designer / DevOps @ Merus Audio, Copenhagen, Denmark.
We do novel and best in class Audio amplifiers for consumer products.
Programmed assembler for C-64 back in 1980's, learned some electronics - hacking since then

User avatar
Jakobsen
Posts: 89
Joined: Mon Jan 16, 2017 8:12 am

Re: ESP32 Webradio

Postby Jakobsen » Sun Jan 22, 2017 11:57 pm

Still no good new for the i2s driver in 32 bit mode

Code: Select all

    int ret; ret = 0; 
    int i;
    for (i=0; i < no_samples; i++) {

#if defined(USE_DAC)
        short samp = mono_to_8bit_stereo(short_sample_buff[i]);
#else
        int samp = mono_to_16bit_stereo(short_sample_buff[i]);
        char samp2x32[8];   
        samp2x32[0] = 0; 
		samp2x32[1] = 0; 
		samp2x32[2] = 0; 
		samp2x32[3] = 0; 
		samp2x32[4] = 0xff; 
		samp2x32[5] = 0; 
		samp2x32[6] = 0; 
		samp2x32[7] = 0; 
		     
#endif


        //Dependent on the amount of buffer we have too much or too little, we're going to add or remove
        //samples. This basically does error diffusion on the sample added or removed.
        if (sampErr>(1<<24)) {
            sampErr-=(1<<24);
            //...and don't output an i2s sample
        } else if (sampErr<-(1<<24)) {
            sampErr+=(1<<24);
            //..and output 2 samples instead of one.
            i2s_push_sample(I2S_NUM_0,  (char *)&samp2x32, portMAX_DELAY);
            i2s_push_sample(I2S_NUM_0,  (char *)&samp2x32, portMAX_DELAY);
        } else {
            //Just output the sample.
           ret = i2s_push_sample(I2S_NUM_0,  (char *)&samp2x32, portMAX_DELAY);
        }
    }
    printf("Number of char pushed:%d #samples:%d\n",ret,no_samples);
}
I set the bit pr sample to 32 in the driver construct increased the buffer length by a factor 2.
The result is what I saw when playing with example 22_i2s
Image

Every second left/right sample set is missing,

I tried to hard code the sample code that get pushed to

Code: Select all

 
        char samp2x32[8];   
        samp2x32[0] = 1; 
        samp2x32[1] = 3; 
       	samp2x32[2] = 7; 
        samp2x32[3] = 0x0f; 
        samp2x32[4] = 0x1f; 
        samp2x32[5] = 0x3f; 
        samp2x32[6] = 0x7f; 
       	samp2x32[7] = 0xff; 
and this is what I get
Image

some thing is miss aligned in the driver and after 30 sec I get a

Code: Select all

 
 I (38679) http_client: ... done reading from socket. Last read return=0 errno=128
/Jorgen
Analog Digital IC designer / DevOps @ Merus Audio, Copenhagen, Denmark.
We do novel and best in class Audio amplifiers for consumer products.
Programmed assembler for C-64 back in 1980's, learned some electronics - hacking since then

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

Re: ESP32 Webradio

Postby BuddyCasino » Mon Jan 23, 2017 7:43 am

Jakobsen wrote: uxTaskGetStackHigh.... issued a core dump ...
Oops you're right, that only works if some freertos config option is changed in menuconfig. Fixed it.

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

Re: ESP32 Webradio

Postby BuddyCasino » Mon Jan 23, 2017 7:55 am

Jakobsen wrote:Still no good new for the i2s driver in 32 bit mode
Interesting - since I couldn't get it to work in 8-Bit mode either, maybe theres a bug in the driver somewhere?
If your HTTP connection gets dropped after some time, it can be a sign that you're reading too slowly and the server has to kick you out so you don't consume excessive amounts of buffer.

User avatar
Jakobsen
Posts: 89
Joined: Mon Jan 16, 2017 8:12 am

Re: ESP32 Webradio

Postby Jakobsen » Mon Jan 23, 2017 11:41 pm

YES - had to do a hack in the i2s driver
When I set the number of bits pr sample to 32, this call for 8 bytes pr sample when calling i2s_push_sample. This works for 16 bits pr sample where i2s_push_sample calls for 4 byte. So just for a try I hack the i2s in the 32 bit setting to only put 4 bits to the DMA buffer - And this look like nice music to me ......

Image

It is 'only' 16 bits mono in both channels but that is the smalls web enable stack I have seen.

Here is the very dirty code:

Code: Select all

   data_ptr = (char*)p_i2s_obj[i2s_num]->tx->curr_ptr;
    data_ptr += p_i2s_obj[i2s_num]->tx->rw_pos;
    for (i = 0; i < p_i2s_obj[i2s_num]->bytes_per_sample; i++) {
        *data_ptr++ = *sample++;
        bytes_to_push ++;
    }
    if (p_i2s_obj[i2s_num]->channel_num == 3) {                <--------------------------odd number of channels :-)
        for (i = 0; i < p_i2s_obj[i2s_num]->bytes_per_sample; i++) {
            *data_ptr++ = *sample++;
            bytes_to_push ++;
        }
    }

    p_i2s_obj[i2s_num]->tx->rw_pos += p_i2s_obj[i2s_num]->bytes_per_sample; // * p_i2s_obj[i2s_num]->channel_num;
    return bytes_to_push;
}


I will connect to the amplifier we have build and post the results tomorrow :-)
/jorgen
Analog Digital IC designer / DevOps @ Merus Audio, Copenhagen, Denmark.
We do novel and best in class Audio amplifiers for consumer products.
Programmed assembler for C-64 back in 1980's, learned some electronics - hacking since then

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

Re: ESP32 Webradio

Postby BuddyCasino » Tue Jan 24, 2017 7:37 am

Not sure I understood what you did there, but I'll have a closer look this evening.

Who is online

Users browsing this forum: No registered users and 6 guests