forked from earlephilhower/ESP8266Audio
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test/run on host, output to null device (earlephilhower#299)
* test/run on host to null device * compilation fix
- Loading branch information
Showing
3 changed files
with
159 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
#include <Arduino.h> | ||
|
||
#ifdef ESP32 | ||
#include <WiFi.h> | ||
#else | ||
#include <ESP8266WiFi.h> | ||
#endif | ||
#include "AudioFileSourceICYStream.h" | ||
#include "AudioFileSourceBuffer.h" | ||
#include "AudioGeneratorMP3.h" | ||
#include "AudioOutputNull.h" | ||
|
||
// To run, set your ESP8266 build to 160MHz, update the SSID info, and upload. | ||
|
||
// Enter your WiFi setup here: | ||
#ifndef STASSID | ||
#define STASSID "" | ||
#define STAPSK "" | ||
#endif | ||
|
||
const char* ssid = STASSID; | ||
const char* password = STAPSK; | ||
|
||
// Randomly picked URL | ||
const char *URL="http://icecast.radiofrance.fr/franceinter-lofi.mp3"; | ||
//const char *URL="http://kvbstreams.dyndns.org:8000/wkvi-am"; | ||
|
||
AudioGeneratorMP3 *mp3; | ||
AudioFileSourceICYStream *file; | ||
AudioFileSourceBuffer *buff; | ||
AudioOutputNull *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 | ||
char s1[32], s2[64]; | ||
strncpy_P(s1, type, sizeof(s1)); | ||
s1[sizeof(s1)-1]=0; | ||
strncpy_P(s2, string, sizeof(s2)); | ||
s2[sizeof(s2)-1]=0; | ||
Serial.printf("METADATA(%s) '%s' = '%s'\n", ptr, s1, s2); | ||
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); | ||
// Note that the string may be in PROGMEM, so copy it to RAM for printf | ||
char s1[64]; | ||
strncpy_P(s1, string, sizeof(s1)); | ||
s1[sizeof(s1)-1]=0; | ||
Serial.printf("STATUS(%s) '%d' = '%s'\n", ptr, code, s1); | ||
Serial.flush(); | ||
} | ||
|
||
|
||
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"); | ||
buff = new AudioFileSourceBuffer(file, 4096); | ||
buff->RegisterStatusCB(StatusCallback, (void*)"buffer"); | ||
out = new AudioOutputNull(); | ||
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); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#!/bin/bash | ||
|
||
ino=${PWD##*/} | ||
|
||
if [ ! -d "${ESP8266ARDUINO}/tests/host" ]; then | ||
echo "\${ESP8266ARDUINO} should point to ESP8266 Arduino core directory" | ||
exit 1 | ||
fi | ||
|
||
THISLIB=$(pwd)/../.. | ||
MAD=$(ls ${THISLIB}/src/libmad/*.c) | ||
|
||
cd ${ESP8266ARDUINO}/tests/host | ||
|
||
if [ "$1" = "clean" ]; then | ||
make clean | ||
cd ${THISLIB} | ||
rm -f src/*.o src/libmad/*.o | ||
exit 0 | ||
fi | ||
|
||
if [ "$1" = "-h" ]; then | ||
echo "usage:" | ||
echo " $0" | ||
echo " $0 clean" | ||
echo " FORCE32=0 $0 (run with valgrind)" | ||
echo " FORCE32=1 $0 (run in 32 bits)" | ||
echo "variable ESP8266ARDUINO must point to esp8266 Arduino core directory" | ||
exit 0 | ||
fi | ||
|
||
[ -z "${FORCE32}" ] && FORCE32=0 | ||
|
||
if [ "${FORCE32}" = 0 ]; then | ||
run=valgrind | ||
else | ||
run= | ||
fi | ||
|
||
eval make FORCE32=${FORCE32} V=1 -j \ | ||
USERCSOURCES=\"${MAD}\" \ | ||
USERCXXSOURCES=\"${THISLIB}/src/AudioFileSourceBuffer.cpp ${THISLIB}/src/AudioLogger.cpp ${THISLIB}/src/AudioGeneratorMP3.cpp ${THISLIB}/src/AudioFileSourceICYStream.cpp ${THISLIB}/src/AudioFileSourceHTTPStream.cpp\" \ | ||
USERCFLAGS=\"-I${THISLIB}/src/\" \ | ||
${THISLIB}/examples/${ino}/${ino} | ||
|
||
set -x | ||
|
||
$run ./bin/${ino}/${ino} "$@" | ||
stty sane | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters