Files
ESP8266Audio/examples/StreamMP3FromHTTP_SPIRAM/StreamMP3FromHTTP_SPIRAM.ino
T
Earle F. Philhower, III 0fd2d0413b Replace external SPIRAM lib w/internal optimized (#250)
* Replace external SPIRAM lib w/internal optimized

Instead of requiring everyone to download and install another Arduino
library to use this lib, include an optimized, self-contained one from
the 8266 VM PR: https://github.com/esp8266/Arduino/pull/6994

Does change the API as it now requires a HW chip select, so that
parameter is removed from the SpiRAM buffer object.

* Redo the FIFO to try and be faster

* Fix the SPI interface, buffering.

SPI FIFO needs special care so do all work in a RAM copy and the copy it
over manually w/32b writes.

Ensure the SPI command is done before touching the FIFO.

Fix buffering organization.

Make the buffer report status as a #### bar.

* Fix infinite wait on EOF

* Add SW chip select support

* Update URL to one that's live today

* Clean up metadata printout

* Clean up readme refs to obsolete lib

* Slow down the DIO->SIO reset sequence

* Update readme to remove old SPIRam library ref

Also add the resistor to the 1T circuit to avoid transistor overheating.
2020-04-14 15:41:47 -07:00

100 lines
2.7 KiB
Arduino

#include <Arduino.h>
#ifdef ESP32
#include <WiFi.h>
#else
#include <ESP8266WiFi.h>
#endif
#include "AudioFileSourceICYStream.h"
#include "AudioFileSourceSPIRAMBuffer.h"
#include "AudioGeneratorMP3.h"
#include "AudioOutputI2SNoDAC.h"
// To run, set your ESP8266 build to 160MHz, update the SSID info, and upload.
// Enter your WiFi setup here:
const char *SSID = ".....";
const char *PASSWORD = ".....";
// Randomly picked URL
const char *URL="http://kvbstreams.dyndns.org:8000/wkvi-am";
AudioGeneratorMP3 *mp3;
AudioFileSourceICYStream *file;
AudioFileSourceSPIRAMBuffer *buff;
AudioOutputI2SNoDAC *out;
// Called when a metadata event occurs (i.e. an ID3 tag, an ICY block, etc.
void MDCallback(void *cbData, const char *type, bool isUnicode, const char *string)
{
const char *ptr = reinterpret_cast<const char *>(cbData);
(void) isUnicode; // Punt this ball for now
// Note that the type and string may be in PROGMEM, so copy them to RAM for printf
Serial.printf_P(PSTR("METADATA(%s) '%s' = '%s'\n"), ptr, type, string);
Serial.flush();
}
// Called when there's a warning or error (like a buffer underflow or decode hiccup)
void StatusCallback(void *cbData, int code, const char *string)
{
const char *ptr = reinterpret_cast<const char *>(cbData);
static uint32_t lastTime = 0;
static int lastCode = -99999;
uint32_t now = millis();
if ((lastCode != code) || (now - lastTime > 1000)) {
Serial.printf_P(PSTR("STATUS(%s) '%d' = '%s'\n"), ptr, code, string);
Serial.flush();
lastTime = now;
lastCode = code;
}
}
void setup()
{
Serial.begin(115200);
delay(1000);
Serial.println("Connecting to WiFi");
WiFi.disconnect();
WiFi.softAPdisconnect(true);
WiFi.mode(WIFI_STA);
WiFi.begin(SSID, PASSWORD);
// Try forever
while (WiFi.status() != WL_CONNECTED) {
Serial.println("...Connecting to WiFi");
delay(1000);
}
Serial.println("Connected");
audioLogger = &Serial;
file = new AudioFileSourceICYStream(URL);
file->RegisterMetadataCB(MDCallback, (void*)"ICY");
// Initialize 23LC1024 SPI RAM buffer with chip select ion GPIO4 and ram size of 128KByte
buff = new AudioFileSourceSPIRAMBuffer(file, 4, 128*1024);
buff->RegisterStatusCB(StatusCallback, (void*)"buffer");
out = new AudioOutputI2SNoDAC();
mp3 = new AudioGeneratorMP3();
mp3->RegisterStatusCB(StatusCallback, (void*)"mp3");
mp3->begin(buff, out);
}
void loop()
{
static int lastms = 0;
if (mp3->isRunning()) {
if (millis()-lastms > 1000) {
lastms = millis();
Serial.printf("Running for %d ms...\n", lastms);
Serial.flush();
}
if (!mp3->loop()) mp3->stop();
} else {
Serial.printf("MP3 done\n");
delay(1000);
}
}