Update xdrv_42_i2s_audio.ino

This commit is contained in:
gemu2015 2020-09-01 07:23:08 +02:00
parent 28b21171a8
commit 89f90721be

View File

@ -53,10 +53,11 @@ AudioOutputI2S *out;
AudioFileSourceID3 *id3; AudioFileSourceID3 *id3;
AudioGeneratorMP3 *decoder = NULL; AudioGeneratorMP3 *decoder = NULL;
#ifdef USE_WEBRADIO #ifdef USE_WEBRADIO
AudioFileSourceICYStream *ifile = NULL; AudioFileSourceICYStream *ifile = NULL;
AudioFileSourceBuffer *buff = NULL; AudioFileSourceBuffer *buff = NULL;
//char title[64]; char wr_title[64];
//char status[64]; //char status[64];
#ifdef ESP8266 #ifdef ESP8266
@ -211,8 +212,13 @@ void I2S_Init(void) {
out->stop(); out->stop();
#ifdef USE_WEBRADIO #ifdef USE_WEBRADIO
preallocateBuffer = malloc(preallocateBufferSize); if (psramFound()) {
preallocateCodec = malloc(preallocateCodecSize); preallocateBuffer = heap_caps_malloc(preallocateBufferSize, MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT);
preallocateCodec = heap_caps_malloc(preallocateCodecSize, MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT);
} else {
preallocateBuffer = malloc(preallocateBufferSize);
preallocateCodec = malloc(preallocateCodecSize);
}
if (!preallocateBuffer || !preallocateCodec) { if (!preallocateBuffer || !preallocateCodec) {
//Serial.printf_P(PSTR("FATAL ERROR: Unable to preallocate %d bytes for app\n"), preallocateBufferSize+preallocateCodecSize); //Serial.printf_P(PSTR("FATAL ERROR: Unable to preallocate %d bytes for app\n"), preallocateBufferSize+preallocateCodecSize);
} }
@ -246,8 +252,9 @@ void MDCallback(void *cbData, const char *type, bool isUnicode, const char *str)
(void) isUnicode; // Punt this ball for now (void) isUnicode; // Punt this ball for now
(void) ptr; (void) ptr;
if (strstr_P(type, PSTR("Title"))) { if (strstr_P(type, PSTR("Title"))) {
//strncpy(title, str, sizeof(title)); strncpy(wr_title, str, sizeof(wr_title));
//title[sizeof(title)-1] = 0; wr_title[sizeof(wr_title)-1] = 0;
//AddLog_P2(LOG_LEVEL_INFO,PSTR("WR-Title: %s"),wr_title);
} else { } else {
// Who knows what to do? Not me! // Who knows what to do? Not me!
} }
@ -331,6 +338,15 @@ void Cmd_WebRadio(void) {
} }
const char HTTP_WEBRADIO[] PROGMEM =
"{s}" "I2S_WR-Title" "{m}%s{e}";
void I2S_WR_Show(void) {
if (decoder) {
WSContentSend_PD(HTTP_WEBRADIO,wr_title);
}
}
#endif #endif
#ifdef ESP32 #ifdef ESP32
@ -338,14 +354,33 @@ void Play_mp3(const char *path) {
#if defined(USE_SCRIPT) && defined(USE_SCRIPT_FATFS) #if defined(USE_SCRIPT) && defined(USE_SCRIPT_FATFS)
if (decoder || mp3) return; if (decoder || mp3) return;
bool I2S_Task;
TTGO_PWR_ON TTGO_PWR_ON
if (*path=='+') {
I2S_Task = true;
path++;
} else {
I2S_Task = false;
}
file = new AudioFileSourceFS(*fsp,path); file = new AudioFileSourceFS(*fsp,path);
id3 = new AudioFileSourceID3(file); id3 = new AudioFileSourceID3(file);
mp3 = new AudioGeneratorMP3(); mp3 = new AudioGeneratorMP3();
mp3->begin(id3, out); mp3->begin(id3, out);
xTaskCreatePinnedToCore(mp3_task, "MP3", 8192, NULL, 3, &mp3_task_h, 1); if (I2S_Task) {
xTaskCreatePinnedToCore(mp3_task, "MP3", 8192, NULL, 3, &mp3_task_h, 1);
} else {
while (mp3->isRunning()) {
if (!mp3->loop()) {
mp3->stop();
mp3_delete();
break;
}
OsWatchLoop();
}
}
#endif // USE_SCRIPT #endif // USE_SCRIPT
} }
@ -440,7 +475,13 @@ bool Xdrv42(uint8_t function) {
case FUNC_INIT: case FUNC_INIT:
I2S_Init(); I2S_Init();
break; break;
#ifdef USE_WEBSERVER
#ifdef USE_WEBRADIO
case FUNC_WEB_SENSOR:
I2S_WR_Show();
break;
#endif
#endif
} }
return result; return result;
} }