diff --git a/examples/StreamMP3FromHTTP/StreamMP3FromHTTP.ino b/examples/StreamMP3FromHTTP/StreamMP3FromHTTP.ino index 8ea4515..84d7d5b 100644 --- a/examples/StreamMP3FromHTTP/StreamMP3FromHTTP.ino +++ b/examples/StreamMP3FromHTTP/StreamMP3FromHTTP.ino @@ -22,7 +22,7 @@ const char* ssid = STASSID; const char* password = STAPSK; // Randomly picked URL -const char *URL="http://streaming.shoutcast.com/80sPlanet?lang=en-US"; +const char *URL="http://kvbstreams.dyndns.org:8000/wkvi-am"; AudioGeneratorMP3 *mp3; AudioFileSourceICYStream *file; diff --git a/examples/StreamOnHost/AudioOutputNullSlow.h b/examples/StreamOnHost/AudioOutputNullSlow.h new file mode 100644 index 0000000..95548f6 --- /dev/null +++ b/examples/StreamOnHost/AudioOutputNullSlow.h @@ -0,0 +1,54 @@ +/* + AudioOutput + Base class of an audio output player + + Copyright (C) 2017 Earle F. Philhower, III + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef _AUDIOOUTPUTNULLSLOW_H +#define _AUDIOOUTPUTNULLSLOW_H + +#include "AudioOutput.h" + +class AudioOutputNullSlow : public AudioOutput +{ + public: + AudioOutputNullSlow(int hertz) { SetRate(hertz); }; + ~AudioOutputNullSlow() {}; + virtual bool begin() { samples = 0; startms = millis(); return true; } + virtual bool ConsumeSample(int16_t sample[2]) { + // return false (= output buffer full) + // sometimes to let the main loop running + constexpr int everylog2 = 10; + if ((++samples & ((1<> everylog2)); + return false; + } + return true; + } + virtual bool stop() { endms = millis(); return true; }; + unsigned long GetMilliseconds() { return endms - startms; } + int GetSamples() { return samples; } + int GetFrequency() { return hertz; } + + protected: + unsigned long startms; + unsigned long endms; + int samples; +}; + +#endif + diff --git a/examples/StreamOnHost/StreamOnHost.ino b/examples/StreamOnHost/StreamOnHost.ino index 4f79777..e2a66f7 100644 --- a/examples/StreamOnHost/StreamOnHost.ino +++ b/examples/StreamOnHost/StreamOnHost.ino @@ -8,27 +8,27 @@ #include "AudioFileSourceICYStream.h" #include "AudioFileSourceBuffer.h" #include "AudioGeneratorMP3.h" -#include "AudioOutputNull.h" +#include "AudioOutputNullSlow.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 "" +#define STASSID "your-ssid" +#define STAPSK "your-password" #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"; +const char *URL="http://kvbstreams.dyndns.org:8000/wkvi-am"; +//const char *URL="http://icecast.radiofrance.fr/franceinter-lofi.mp3"; AudioGeneratorMP3 *mp3; AudioFileSourceICYStream *file; AudioFileSourceBuffer *buff; -AudioOutputNull *out; +AudioOutputNullSlow *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) @@ -80,9 +80,9 @@ void setup() audioLogger = &Serial; file = new AudioFileSourceICYStream(URL); file->RegisterMetadataCB(MDCallback, (void*)"ICY"); - buff = new AudioFileSourceBuffer(file, 4096); + buff = new AudioFileSourceBuffer(file, 2048); buff->RegisterStatusCB(StatusCallback, (void*)"buffer"); - out = new AudioOutputNull(); + out = new AudioOutputNullSlow(44100); mp3 = new AudioGeneratorMP3(); mp3->RegisterStatusCB(StatusCallback, (void*)"mp3"); mp3->begin(buff, out); diff --git a/examples/StreamOnHost/onHost b/examples/StreamOnHost/onHost index 5220cb6..a02939f 100755 --- a/examples/StreamOnHost/onHost +++ b/examples/StreamOnHost/onHost @@ -17,16 +17,22 @@ if [ "$1" = "clean" ]; then cd ${THISLIB} rm -f src/*.o src/libmad/*.o exit 0 -fi - -if [ "$1" = "-h" ]; then +elif [ "$1" = diff ]; then + cd ${THISLIB}/examples + diff -u StreamMP3FromHTTP/StreamMP3FromHTTP.ino ${ino}/${ino}.ino + exit 0 +else + echo "" echo "usage:" echo " $0" echo " $0 clean" + echo " $0 diff" 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 + echo "" + [ "$1" = "-h" ] && exit 0 + sleep 1 fi [ -z "${FORCE32}" ] && FORCE32=0 @@ -37,7 +43,7 @@ else run= fi -eval make FORCE32=${FORCE32} V=1 -j \ +eval make FORCE32=${FORCE32} -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/\" \ diff --git a/src/AudioFileSourceHTTPStream.cpp b/src/AudioFileSourceHTTPStream.cpp index 09d1e0c..2917fbc 100644 --- a/src/AudioFileSourceHTTPStream.cpp +++ b/src/AudioFileSourceHTTPStream.cpp @@ -84,7 +84,7 @@ retry: cb.st(STATUS_DISCONNECTED, PSTR("Stream disconnected")); http.end(); for (int i = 0; i < reconnectTries; i++) { - char buff[32]; + char buff[64]; sprintf_P(buff, PSTR("Attempting to reconnect, try %d"), i); cb.st(STATUS_RECONNECTING, buff); delay(reconnectDelayMs); diff --git a/src/AudioFileSourceICYStream.cpp b/src/AudioFileSourceICYStream.cpp index ac03f61..522db40 100644 --- a/src/AudioFileSourceICYStream.cpp +++ b/src/AudioFileSourceICYStream.cpp @@ -84,13 +84,15 @@ AudioFileSourceICYStream::~AudioFileSourceICYStream() uint32_t AudioFileSourceICYStream::readInternal(void *data, uint32_t len, bool nonBlock) { // Ensure we can't possibly read 2 ICY headers in a single go #355 - len = std::min((int)(icyMetaInt >> 1), (int)len); + if (icyMetaInt > 1) { + len = std::min((int)(icyMetaInt >> 1), (int)len); + } retry: if (!http.connected()) { cb.st(STATUS_DISCONNECTED, PSTR("Stream disconnected")); http.end(); for (int i = 0; i < reconnectTries; i++) { - char buff[32]; + char buff[64]; sprintf_P(buff, PSTR("Attempting to reconnect, try %d"), i); cb.st(STATUS_RECONNECTING, buff); delay(reconnectDelayMs);