mp3
This commit is contained in:
parent
e944023ab3
commit
6b5623c560
BIN
Mozart - Lacrimosa.mp3
Normal file
BIN
Mozart - Lacrimosa.mp3
Normal file
Binary file not shown.
|
@ -13,3 +13,4 @@ platform = espressif32
|
||||||
board = esp32-devkitlipo
|
board = esp32-devkitlipo
|
||||||
framework = arduino
|
framework = arduino
|
||||||
monitor_speed = 9600
|
monitor_speed = 9600
|
||||||
|
lib_deps = esphome/ESP32-audioI2S@^2.0.7
|
||||||
|
|
180
src/main.cpp
180
src/main.cpp
|
@ -8,109 +8,111 @@
|
||||||
https://dronebotworkshop.com
|
https://dronebotworkshop.com
|
||||||
*/
|
*/
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
// Include I2S driver
|
/*
|
||||||
#include <driver/i2s.h>
|
Simple Internet Radio Demo
|
||||||
|
esp32-i2s-simple-radio.ino
|
||||||
|
Simple ESP32 I2S radio
|
||||||
|
Uses MAX98357 I2S Amplifier Module
|
||||||
|
Uses ESP32-audioI2S Library - https://github.com/schreibfaul1/ESP32-audioI2S
|
||||||
|
|
||||||
// Connections to INMP441 I2S microphone
|
DroneBot Workshop 2022
|
||||||
#define I2S_WS 25
|
https://dronebotworkshop.com
|
||||||
#define I2S_SD 33
|
*/
|
||||||
#define I2S_SCK 32
|
|
||||||
|
|
||||||
// Use I2S Processor 0
|
// Include required libraries
|
||||||
#define I2S_PORT I2S_NUM_0
|
#include "WiFi.h"
|
||||||
|
#include "Audio.h"
|
||||||
|
|
||||||
// Define input buffer length
|
// Define I2S connections
|
||||||
#define bufferLen 1024
|
#define I2S_DOUT 22
|
||||||
int16_t sBuffer[bufferLen];
|
#define I2S_BCLK 26
|
||||||
|
#define I2S_LRC 25
|
||||||
|
|
||||||
void i2s_install()
|
// Create audio object
|
||||||
{
|
Audio audio;
|
||||||
// Set up I2S Processor configuration
|
|
||||||
const i2s_config_t i2s_config = {
|
|
||||||
.mode = i2s_mode_t(I2S_MODE_MASTER | I2S_MODE_RX),
|
|
||||||
.sample_rate = 40000,
|
|
||||||
.bits_per_sample = i2s_bits_per_sample_t(16),
|
|
||||||
.channel_format = I2S_CHANNEL_FMT_ONLY_LEFT,
|
|
||||||
.communication_format = i2s_comm_format_t(I2S_COMM_FORMAT_STAND_I2S),
|
|
||||||
.intr_alloc_flags = ESP_INTR_FLAG_LEVEL1,
|
|
||||||
.dma_buf_count = 4,
|
|
||||||
.dma_buf_len = bufferLen,
|
|
||||||
.use_apll = false,
|
|
||||||
.tx_desc_auto_clear = false,
|
|
||||||
.fixed_mclk = 0};
|
|
||||||
|
|
||||||
i2s_driver_install(I2S_PORT, &i2s_config, 0, NULL);
|
// Wifi Credentials
|
||||||
}
|
String ssid = "cohabit";
|
||||||
|
String password = "Fablab";
|
||||||
|
|
||||||
void i2s_setpin()
|
void setup() {
|
||||||
{
|
|
||||||
// Set I2S pin configuration
|
|
||||||
const i2s_pin_config_t pin_config = {
|
|
||||||
.bck_io_num = I2S_SCK,
|
|
||||||
.ws_io_num = I2S_WS,
|
|
||||||
.data_out_num = -1,
|
|
||||||
.data_in_num = I2S_SD};
|
|
||||||
|
|
||||||
i2s_set_pin(I2S_PORT, &pin_config);
|
// Start Serial Monitor
|
||||||
}
|
|
||||||
|
|
||||||
void setup()
|
|
||||||
{
|
|
||||||
|
|
||||||
// Set up Serial Monitor
|
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
Serial.println(" ");
|
|
||||||
|
|
||||||
delay(1000);
|
// Setup WiFi in Station mode
|
||||||
|
WiFi.disconnect();
|
||||||
// Set up I2S
|
WiFi.mode(WIFI_STA);
|
||||||
i2s_install();
|
WiFi.begin(ssid.c_str(), password.c_str());
|
||||||
i2s_setpin();
|
|
||||||
i2s_start(I2S_PORT);
|
|
||||||
|
|
||||||
|
while (WiFi.status() != WL_CONNECTED) {
|
||||||
delay(500);
|
delay(500);
|
||||||
|
Serial.print(".");
|
||||||
|
}
|
||||||
|
|
||||||
|
// WiFi Connected, print IP to serial monitor
|
||||||
|
Serial.println("");
|
||||||
|
Serial.println("WiFi connected");
|
||||||
|
Serial.println("IP address: ");
|
||||||
|
Serial.println(WiFi.localIP());
|
||||||
|
Serial.println("");
|
||||||
|
|
||||||
|
// Connect MAX98357 I2S Amplifier Module
|
||||||
|
audio.setPinout(I2S_BCLK, I2S_LRC, I2S_DOUT);
|
||||||
|
|
||||||
|
// Set thevolume (0-100)
|
||||||
|
audio.setVolume(10);
|
||||||
|
|
||||||
|
// Connect to an Internet radio station (select one as desired)
|
||||||
|
//audio.connecttohost("http://vis.media-ice.musicradio.com/CapitalMP3");
|
||||||
|
//audio.connecttohost("mediaserv30.live-nect MAX98357 I2S Amplifier Module
|
||||||
|
//audio.connecttohost("www.surfmusic.de/m3u/100-5-das-hitradio,4529.m3u");
|
||||||
|
//audio.connecttohost("stream.1a-webradio.de/deutsch/mp3-128/vtuner-1a");
|
||||||
|
//audio.connecttohost("www.antenne.de/webradio/antenne.m3u");
|
||||||
|
audio.connecttohost("0n-80s.radionetz.de:8000/0n-70s.mp3");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop()
|
void loop()
|
||||||
|
|
||||||
{
|
{
|
||||||
|
// Run audio player
|
||||||
|
audio.loop();
|
||||||
|
|
||||||
// False print statements to "lock range" on serial plotter display
|
}
|
||||||
// Change rangelimit value to adjust "sensitivity"
|
|
||||||
int rangelimit = 3000;
|
// Audio status functions
|
||||||
Serial.print(rangelimit * -1);
|
|
||||||
Serial.print(" ");
|
void audio_info(const char *info) {
|
||||||
Serial.print(rangelimit);
|
Serial.print("info "); Serial.println(info);
|
||||||
Serial.print(" ");
|
}
|
||||||
|
void audio_id3data(const char *info) { //id3 metadata
|
||||||
// Get I2S data and place in data buffer
|
Serial.print("id3data "); Serial.println(info);
|
||||||
size_t bytesIn = 0;
|
}
|
||||||
esp_err_t result = i2s_read(I2S_PORT, &sBuffer, bufferLen, &bytesIn, portMAX_DELAY);
|
void audio_eof_mp3(const char *info) { //end of file
|
||||||
|
Serial.print("eof_mp3 "); Serial.println(info);
|
||||||
if (result == ESP_OK)
|
}
|
||||||
{
|
void audio_showstation(const char *info) {
|
||||||
// Read I2S data buffer
|
Serial.print("station "); Serial.println(info);
|
||||||
int16_t samples_read = bytesIn / 8;
|
}
|
||||||
if (samples_read > 0)
|
void audio_showstreaminfo(const char *info) {
|
||||||
{
|
Serial.print("streaminfo "); Serial.println(info);
|
||||||
float mean = 0;
|
}
|
||||||
for (int16_t i = 0; i < samples_read; ++i)
|
void audio_showstreamtitle(const char *info) {
|
||||||
{
|
Serial.print("streamtitle "); Serial.println(info);
|
||||||
mean += (sBuffer[i]);
|
}
|
||||||
}
|
void audio_bitrate(const char *info) {
|
||||||
|
Serial.print("bitrate "); Serial.println(info);
|
||||||
// Average the data reading
|
}
|
||||||
mean /= samples_read;
|
void audio_commercial(const char *info) { //duration in sec
|
||||||
|
Serial.print("commercial "); Serial.println(info);
|
||||||
// Print to serial plotter
|
}
|
||||||
Serial.println(mean);
|
void audio_icyurl(const char *info) { //homepage
|
||||||
|
Serial.print("icyurl "); Serial.println(info);
|
||||||
int recu = bytesIn / sizeof(int32_t);
|
}
|
||||||
for (int i = 0; i < recu; i++)
|
void audio_lasthost(const char *info) { //stream URL played
|
||||||
{
|
Serial.print("lasthost "); Serial.println(info);
|
||||||
Serial.printf("%ld\n", sBuffer[i]);
|
}
|
||||||
}
|
void audio_eof_speech(const char *info) {
|
||||||
// Serial.print(" - ");
|
Serial.print("eof_speech "); Serial.println(info);
|
||||||
Serial.println(bytesIn);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
Loading…
Reference in a new issue