Browse Source

audio from progmem test

main
Hendrik Langer 7 years ago
parent
commit
8ad0cda223
  1. 1644
      src/alarmsound.h
  2. 2
      src/main.cpp
  3. 14
      src/mp3.cpp
  4. 2
      src/mp3.h

1644
src/alarmsound.h

File diff suppressed because it is too large

2
src/main.cpp

@ -383,6 +383,8 @@ void loop()
led.wakeUpLight(0); led.wakeUpLight(0);
Serial.println("WAKEUP TIME!!!!!"); Serial.println("WAKEUP TIME!!!!!");
mp3.setVolume(2); mp3.setVolume(2);
// mp3.start_Progmem();
// delay(1500);
mp3.start("http://radioessen.cast.addradio.de/radioessen/simulcast/high/stream.mp3"); mp3.start("http://radioessen.cast.addradio.de/radioessen/simulcast/high/stream.mp3");
led.changeAnimation(2, 0); led.changeAnimation(2, 0);
} }

14
src/mp3.cpp

@ -3,6 +3,7 @@
#include <HTTPClient.h> #include <HTTPClient.h>
#include <SD.h> #include <SD.h>
#include "AudioFileSourceICYStream.h" #include "AudioFileSourceICYStream.h"
#include "AudioFileSourcePROGMEM.h"
#include "AudioFileSourceBuffer.h" #include "AudioFileSourceBuffer.h"
#include "AudioGeneratorMP3.h" #include "AudioGeneratorMP3.h"
#include "AudioOutputI2S.h" #include "AudioOutputI2S.h"
@ -17,6 +18,8 @@
#include "esp_system.h" #include "esp_system.h"
#include <math.h> #include <math.h>
#include "alarmsound.h"
char titleStr[64]; char titleStr[64];
// convert mp3 files with `xxd -i alarm.wav > alarmsound.h` // convert mp3 files with `xxd -i alarm.wav > alarmsound.h`
@ -54,6 +57,7 @@ void MP3::stop() {
void MP3::start(const char* url) { void MP3::start(const char* url) {
strncpy(URL, url, sizeof(URL)); strncpy(URL, url, sizeof(URL));
URL[sizeof(URL)-1] = '\0'; URL[sizeof(URL)-1] = '\0';
fromProgmem = false;
start(); start();
} }
@ -74,6 +78,11 @@ void MP3::start() {
} }
} }
void MP3::start_Progmem() {
fromProgmem = true;
start();
}
void MP3::setVolume(int volume) { void MP3::setVolume(int volume) {
if (volume > 0 && volume <= 100) { if (volume > 0 && volume <= 100) {
this->volume = volume; this->volume = volume;
@ -92,13 +101,14 @@ uint32_t MP3::getBuffFill() {
void MP3::mp3_decoder_task(void *pvParameters) { void MP3::mp3_decoder_task(void *pvParameters) {
AudioGenerator *decoder = nullptr; AudioGenerator *decoder = nullptr;
AudioFileSourceICYStream *file = nullptr; AudioFileSource *file = nullptr;
AudioFileSourceBuffer *buff = nullptr; AudioFileSourceBuffer *buff = nullptr;
AudioOutputI2S *out = nullptr; AudioOutputI2S *out = nullptr;
// strcpy(titleStr, "loading..."); // strcpy(titleStr, "loading...");
file = new AudioFileSourceICYStream(URL); if (fromProgmem) file = new AudioFileSourcePROGMEM(alarmsound, sizeof(alarmsound));
else file = new AudioFileSourceICYStream(URL);
file->RegisterMetadataCB(MDCallback, (void*)"ICY"); file->RegisterMetadataCB(MDCallback, (void*)"ICY");
buff = new AudioFileSourceBuffer(file, preallocateBuffer, preallocateBufferSize); buff = new AudioFileSourceBuffer(file, preallocateBuffer, preallocateBufferSize);
audiobuffer = buff; audiobuffer = buff;

2
src/mp3.h

@ -20,12 +20,14 @@ class MP3 {
void stop(void); void stop(void);
void start(void); void start(void);
void start(const char*); void start(const char*);
void start_Progmem();
void setVolume(int); void setVolume(int);
int getVolume(); int getVolume();
bool playing = false; bool playing = false;
int volume = 20; int volume = 20;
bool volumeChanged = true; bool volumeChanged = true;
uint32_t getBuffFill(void); uint32_t getBuffFill(void);
bool fromProgmem;
private: private:
TaskHandle_t audioTaskHandle; TaskHandle_t audioTaskHandle;
void mp3_decoder_task(void*); void mp3_decoder_task(void*);

Loading…
Cancel
Save