# Internet radio with a web-based user interface
Yet another version of an ESP32 Internet radio, implemented using Phil Schatzmann's 
versatile Arduino audio tools library. The program runs as an independent task in 
Core 1. The main loop is idle or performs other tasks.

## Working principle
The mp3-encoded ICY or HTTP stream from the Internet passes through the 
pipeline consisting of a copier, decoder, and volume control and is finally 
forwarded as an I2S stream to the DAC/Class-C amplifier MAX98357. 
```
                                                       ch1    .----------.     _ /|
                                                       .----> | MAX98357 |--> |_| | spkr
                                                       |      `----------´       \|
         .--------.     .---------.     .--------.     |
 icy --> | copier | --> | decoder | --> | volume | ----+ i2s
         `--------´     `---------´     `--------´     |
                                                       |      .----------.     _ /|
                                                       `----> | MAX98357 |--> |_| | spkr
                                                       ch2    `----------´       \|
``` 

## Web Interface
![GUI](images/webradioGUI.jpg)

After establishing a WiFi connection to the local router using AutoConnect, 
go to http://webradio. You can now listen to the preset radio station and 
operate the radio via the web interface. 

## Features
- Selection of a Radio URL from a predefined list
- Adjustable volume via a slider
- Speaker on/off
- Display of meta data (composer, opus) and time and date
- The last station played and the volume setting are
  saved and recalled the next time the device is started

## Wiring
The ESP32 supplies the LRC, BCLK, and DIN signals to its pins 18, 19 
and 21. To separate the stereo channels, the two MAX98357 modules are 
connected from 5V to the SD inputs with different resistors. At an 
operating voltage of 5V, they have values of 560k and 180k, respectively.
```
                      .-----------------.
           18 -->     o LRC             |
           19 -->     o BCLK       MAX  |
           21 -->     o DIN       98357 |
                      o Gain            |   Spkr right
  5V Vin ---[560K]----o SD              |    _/|
          GND -->     o GND             o---|  |
          5V  -->     o Vin (5V)        o---|_ |
                      `-----------------´     \|
                      .-----------------.
           18 -->     o LRC             |
           19 -->     o BCLK       MAX  |
           21 -->     o DIN       98357 |
                      o Gain            |   Spkr left
  5V Vin ---[180K]----o SD              |    _/|
          GND -->     o GND             o---|  |
          5V  -->     o Vin (5V)        o---|_ |
                      `-----------------´     \|
```
## Libraries used (see platformio.ini)

- ESPAsyncWebServer @ 3.11.2
- audio-tools @ 1.2.5+sha.8270686
- libhelix @ 0.9.4+sha.7d0444c
- LittleFS @ 3.3.8
- WiFi @ 3.3.8
- Preferences @ 3.3.8
- Toolkit @ 0.0.1


## Credits
Thanks to Phil Schatzmann for his audio tools and to Stéphane Calderoni 
for his inspiring CSS designs for the web interface.