|
@ -6,6 +6,7 @@ |
|
|
#include "AudioFileSourcePROGMEM.h" |
|
|
#include "AudioFileSourcePROGMEM.h" |
|
|
#include "AudioFileSourceBuffer.h" |
|
|
#include "AudioFileSourceBuffer.h" |
|
|
#include "AudioGeneratorMP3.h" |
|
|
#include "AudioGeneratorMP3.h" |
|
|
|
|
|
#include "AudioGeneratorRTTTL.h" |
|
|
#include "AudioOutputI2S.h" |
|
|
#include "AudioOutputI2S.h" |
|
|
//#include "driver/gpio.h"
|
|
|
//#include "driver/gpio.h"
|
|
|
//#include "driver/periph_ctrl.h"
|
|
|
//#include "driver/periph_ctrl.h"
|
|
@ -84,6 +85,13 @@ void MP3::start_Progmem() { |
|
|
start(); |
|
|
start(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void MP3::playRTTTL(const char* str, size_t len) { |
|
|
|
|
|
rtttl = str; |
|
|
|
|
|
rtttl_len = len; |
|
|
|
|
|
volume = 2; |
|
|
|
|
|
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; |
|
@ -109,6 +117,7 @@ void MP3::mp3_decoder_task(void *pvParameters) { |
|
|
|
|
|
|
|
|
// strcpy(titleStr, "loading...");
|
|
|
// strcpy(titleStr, "loading...");
|
|
|
if (fromProgmem) file = new AudioFileSourcePROGMEM(alarmsound, alarmsound_len); |
|
|
if (fromProgmem) file = new AudioFileSourcePROGMEM(alarmsound, alarmsound_len); |
|
|
|
|
|
else if (rtttl_len > 0) file = new AudioFileSourcePROGMEM( rtttl, rtttl_len ); |
|
|
else file = new AudioFileSourceICYStream(URL); |
|
|
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); |
|
@ -118,7 +127,13 @@ void MP3::mp3_decoder_task(void *pvParameters) { |
|
|
out = new AudioOutputI2S(I2S_NUM_0, false); |
|
|
out = new AudioOutputI2S(I2S_NUM_0, false); |
|
|
out->SetPinout(12, 13, 25); |
|
|
out->SetPinout(12, 13, 25); |
|
|
} |
|
|
} |
|
|
|
|
|
if (rtttl_len > 0) { |
|
|
|
|
|
decoder = new AudioGeneratorRTTTL(); |
|
|
|
|
|
Serial.println(rtttl_len); Serial.println(FPSTR(rtttl)); |
|
|
|
|
|
rtttl_len = 0; |
|
|
|
|
|
} else { |
|
|
decoder = new AudioGeneratorMP3(preallocateCodec, preallocateCodecSize); |
|
|
decoder = new AudioGeneratorMP3(preallocateCodec, preallocateCodecSize); |
|
|
|
|
|
} |
|
|
decoder->RegisterStatusCB(StatusCallback, (void*)"mp3"); |
|
|
decoder->RegisterStatusCB(StatusCallback, (void*)"mp3"); |
|
|
decoder->begin(buff, out); |
|
|
decoder->begin(buff, out); |
|
|
if (volume > 0 && volume <= 100) { |
|
|
if (volume > 0 && volume <= 100) { |
|
@ -143,6 +158,7 @@ void MP3::mp3_decoder_task(void *pvParameters) { |
|
|
strcpy(titleStr, "stopped"); |
|
|
strcpy(titleStr, "stopped"); |
|
|
|
|
|
|
|
|
playing = false; |
|
|
playing = false; |
|
|
|
|
|
i2s_zero_dma_buffer(I2S_NUM_0); |
|
|
|
|
|
|
|
|
if (decoder) { |
|
|
if (decoder) { |
|
|
decoder->stop(); |
|
|
decoder->stop(); |
|
|