ESP32 Webradio

frankiPL
Posts: 8
Joined: Thu Nov 16, 2017 8:59 am

Re: ESP32 Webradio

Postby frankiPL » Thu Nov 16, 2017 9:18 am

Hi MrBuddyCasino,

I was asking You earlier about reading from broadcast (created issue on github).
Now I would like to run Your project in two modes (to test it for 80 devices)
1. reading stream from local server
2. reading stream from SD card
We have added SD card support and server to write mp3 files from external server to SD card, for each ESP32 player
Regarding second option I can see two possibilities
a) feed mp3 stream from mp3 File to audio_stream_consumer in audio_player.c
b) use http_client_get from http.c and first write "fake" headers into http_parser_execute and then mp3 stream

Could you tell us which one we should use? "B" option should read/set all header values before audio_player_start on the other hand we intend to play only mp3 with constant bitrate, so maybe we should skip the http header parsing and just write mp3 stream to spiramfifo ?

Best Regards
Marek

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

Re: ESP32 Webradio

Postby BuddyCasino » Fri Nov 17, 2017 12:54 pm

The right abstraction would be a separate URL handler for sd cards I guess. So depending on the URL scheme, the handler would choose http/https/scdard/filesystem or whatever. Not sure how well sdcard access can be abstracted, never done it.

frankiPL
Posts: 8
Joined: Thu Nov 16, 2017 8:59 am

Re: ESP32 Webradio

Postby frankiPL » Sat Nov 18, 2017 10:23 am

Hi

We have created new task for reading from SD card and it works well, below there is example code.
This is still work in progress, but if You accept pull requests we would like to add this functionality when it is complete.

Best Regards
Marek

Code: Select all

static void sd_get_task(void *pvParameters)
{
    web_radio_t *radio_conf = pvParameters;

    /* configure callbacks */
    http_parser_settings callbacks = { 0 };
    callbacks.on_body = on_body_cb;
    callbacks.on_header_field = on_header_field_cb;
    callbacks.on_header_value = on_header_value_cb;
    callbacks.on_headers_complete = on_headers_complete_cb;
    callbacks.on_message_complete = on_message_complete_cb;

    // blocks until end of stream
    int result = st_file_get("/sdcard/test_file.mp3",&callbacks,radio_conf->player_config);

    if (result != 0) {
        ESP_LOGE(TAG, "sd_client_get error");
    } else {
        ESP_LOGI(TAG, "sd_client_get completed");
    }

    vTaskDelete(NULL);
}

void web_radio_start(web_radio_t *config)
{
    // start reader task
    //xTaskCreatePinnedToCore(&http_get_task, "http_get_task", 2560, config, 20,NULL, 0);
    xTaskCreatePinnedToCore(&sd_get_task, "sd_get_task", 2560, config, 20,NULL, 0);
}

char header[]="HTTP/1.0 200 OK\nContent-Type: audio/mpeg\n\n";
FILE* st_read_file;

int st_file_get(const char *file_name, http_parser_settings *callbacks, void *user_data) {

    /* Read HTTP response */
    char recv_buf[64];
    bzero(recv_buf, sizeof(recv_buf));
    ssize_t recved;

    /* parse response */
    http_parser parser;
    http_parser_init(&parser, HTTP_RESPONSE);
    parser.data = user_data;

    esp_err_t nparsed = 0;
    ESP_LOGI(TAG,"%s size:%d",header,strlen(header));
    nparsed = http_parser_execute(&parser, callbacks, header, strlen(header));


    st_open_file("","test_file.mp3");
    fseek(st_file,400000,SEEK_SET);

    nparsed=0;
    do {
        recved = fread(recv_buf,sizeof(char),sizeof(recv_buf)-1,st_read_file);
       // ESP_LOGI(TAG,"write mp3 bytes:%d",recved);

        // using http parser causes stack overflow somtimes - disable for now
        nparsed = http_parser_execute(&parser, callbacks, recv_buf, recved);

    } while(recved > 0 && nparsed >= 0);

    st_read_close_file();

    return 0;
}
void st_read_open_file(const char *dir_name,const char *file_name) {
    char path[100];
    create_file_path(path,dir_name,file_name);
    ESP_LOGI(TAG,"st_open_file path:%s",path);
    st_read_file = fopen(path, "r");
    if (st_read_file == NULL) {
        ESP_LOGE(TAG, "Failed to open file %s",path);
        return;
    }
    ESP_LOGI(TAG,"File open OK\n");
}
void st_read_close_file() {
    fclose(st_read_file);
    ESP_LOGI(TAG,"File closed\n");
}

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

Re: ESP32 Webradio

Postby BuddyCasino » Sun Nov 19, 2017 3:55 pm

Nice, looks like you know what you're doing. Can you tell me what hardware are you using? So I can order the parts to test it on my side.

frankiPL
Posts: 8
Joined: Thu Nov 16, 2017 8:59 am

Re: ESP32 Webradio

Postby frankiPL » Sat Nov 25, 2017 12:55 pm

Hi,

Very sorry for the late reply, I had to switch to other tasks.
I have some problem with writing to SD card in SPI mode, so I described my configuration in this thread
https://www.esp32.com/viewtopic.php?f=2&t=3657 unfortunately no response.
We will try access card in SDIO mode.
In about two weeks we will order some prototype boards with ESP32 and other modules like DAC so if you are interested I can write more.

Best Regards
Marek

joknjokn
Posts: 1
Joined: Tue Nov 28, 2017 8:57 am

Re: ESP32 Webradio

Postby joknjokn » Tue Nov 28, 2017 9:31 am

Hello everyone,

I was looking into whether the ESP32 could be used as the "brain" in DIY guitar pedals/synthesizers. It seems relatively powerful.

With your knowledge (I'm no expert), do you think it would be powerful enough for this, with potential good audio quality?

If so, do you have a suggestion for a tiny budget-friendly I2S DAC board with input and output of good/fine quality?

Thank you for any help!

- Jonas
Student, Aalborg University Copenhagen

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

Re: ESP32 Webradio

Postby BuddyCasino » Tue Nov 28, 2017 2:11 pm

It should work very well for this task. You can find code on Github or via Hackaday projects, the ESP32 has two full-duplex I2S ports which you can use. If I were you I'd just go search Aliexpress for I2S boards that suit you, there are plenty on sale for little money.

Quanghoster
Posts: 3
Joined: Wed Feb 14, 2018 9:34 am

Re: ESP32 Webradio

Postby Quanghoster » Wed Feb 14, 2018 9:42 am

Hi,
I've just came across your project and am looking at using it in in a project to update an old 80s boombox. This will be the first project using the SDK as I've been using the Arduino IDE so far so a spot of learning to do, though I'm familiar with C and similar tool chains from my Linux programming days.

Cool project, thanks for sharing. One question I have (though I'm sure there will be more) is, is the Bluetooth mode and webradio mode build specific? i.e. when you load the application can you switch between modes at runtime or is the application build just as one or the other?

Thanks,
Andy

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

Re: ESP32 Webradio

Postby BuddyCasino » Wed Feb 14, 2018 10:39 am

The problem is that Bluetooth consumes a lot of RAM, and the web radio needs a lot of it, especially for AAC. It is currently not possible to dynamically allocate and de-allocate the Bluetooth memory, which makes switching between the two modes during runtime impossible. You might get around this if you use a module with external PSRAM.

frankiPL
Posts: 8
Joined: Thu Nov 16, 2017 8:59 am

Re: ESP32 Webradio

Postby frankiPL » Wed Feb 14, 2018 10:46 am

Hi

I have tried this recently. I mean to use bluetooth with this project and indeed I could not flash the chip because project was to big (I mean flashing was ok, but esp does not boot).
However, I have seen somewhere that new esp-idf (I'm not sure which version) will have or already has bluetooth memory allocated dynamically. Correct me if I'm wrong.

Best Regards
Marek

Who is online

Users browsing this forum: No registered users and 3 guests