fix: moved audio code to seperate module
This commit is contained in:
@@ -13,9 +13,8 @@ platform = espressif32
|
|||||||
board = m5stack-atom
|
board = m5stack-atom
|
||||||
framework = arduino
|
framework = arduino
|
||||||
lib_deps =
|
lib_deps =
|
||||||
earlephilhower/ESP8266Audio@^1.9.2
|
;http://192.168.2.3/Bonobo.Git.Server/ESP8266Audio.git
|
||||||
;m5stack/M5Core2@^0.0.6
|
;http://192.168.2.3/Bonobo.Git.Server/LittleFS_esp32.git
|
||||||
https://github.com/lorol/LITTLEFS.git
|
|
||||||
monitor_speed = 115200
|
monitor_speed = 115200
|
||||||
lib_ldf_mode = deep+
|
lib_ldf_mode = deep+
|
||||||
|
|
||||||
|
|||||||
80
FW/m5stack_audio/src/audio.cpp
Normal file
80
FW/m5stack_audio/src/audio.cpp
Normal file
@@ -0,0 +1,80 @@
|
|||||||
|
#include "audio.h"
|
||||||
|
|
||||||
|
AudioGeneratorMP3 *mp3;
|
||||||
|
AudioFileSourceID3 *id3;
|
||||||
|
|
||||||
|
AudioFileSourceLittleFS *file;
|
||||||
|
|
||||||
|
AudioOutputI2S *out;
|
||||||
|
|
||||||
|
const char *waveFile = "/Let_it_be.mp3";
|
||||||
|
|
||||||
|
// 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)
|
||||||
|
{
|
||||||
|
(void)cbData;
|
||||||
|
Serial.printf("ID3 callback for: %s = '", type);
|
||||||
|
|
||||||
|
if (isUnicode)
|
||||||
|
{
|
||||||
|
string += 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (*string)
|
||||||
|
{
|
||||||
|
char a = *(string++);
|
||||||
|
if (isUnicode)
|
||||||
|
{
|
||||||
|
string++;
|
||||||
|
}
|
||||||
|
Serial.printf("%c", a);
|
||||||
|
}
|
||||||
|
Serial.printf("'\n");
|
||||||
|
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 initAudio()
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
audioLogger = &Serial;
|
||||||
|
file = new AudioFileSourceLittleFS(waveFile);
|
||||||
|
id3 = new AudioFileSourceID3(file);
|
||||||
|
id3->RegisterMetadataCB(MDCallback, (void *)"ID3TAG");
|
||||||
|
|
||||||
|
mp3 = new AudioGeneratorMP3();
|
||||||
|
mp3->RegisterStatusCB(StatusCallback, (void*)"mp3");
|
||||||
|
|
||||||
|
out = new AudioOutputI2S();
|
||||||
|
out->SetPinout(19, 33, 22); //bclk, wclk, data
|
||||||
|
mp3->begin(id3, out);
|
||||||
|
out->SetGain(0.25);
|
||||||
|
}
|
||||||
|
|
||||||
|
void handleAudio()
|
||||||
|
{
|
||||||
|
if (mp3->isRunning())
|
||||||
|
{
|
||||||
|
if (!mp3->loop())
|
||||||
|
{
|
||||||
|
mp3->stop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Serial.printf("sound done\n");
|
||||||
|
delay(1000);
|
||||||
|
}
|
||||||
|
}
|
||||||
11
FW/m5stack_audio/src/audio.h
Normal file
11
FW/m5stack_audio/src/audio.h
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "AudioFileSourcePROGMEM.h"
|
||||||
|
#include <AudioFileSourceLittleFS.h>
|
||||||
|
#include "AudioGeneratorMP3.h"
|
||||||
|
#include "AudioFileSourceID3.h"
|
||||||
|
#include "AudioOutputI2S.h"
|
||||||
|
|
||||||
|
|
||||||
|
void initAudio(void);
|
||||||
|
void handleAudio(void);
|
||||||
@@ -1,96 +1,20 @@
|
|||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
|
|
||||||
#include "AudioFileSourcePROGMEM.h"
|
|
||||||
#include <AudioFileSourceLittleFS.h>
|
|
||||||
//#include "AudioGeneratorWAV.h"
|
|
||||||
#include "AudioGeneratorMP3.h"
|
|
||||||
#include "AudioFileSourceID3.h"
|
|
||||||
#include "AudioOutputI2S.h"
|
|
||||||
|
|
||||||
#include "storage.h"
|
#include "storage.h"
|
||||||
|
#include "audio.h"
|
||||||
|
|
||||||
// VIOLA sample taken from https://ccrma.stanford.edu/~jos/pasp/Sound_Examples.html
|
|
||||||
#include "viola.h"
|
|
||||||
|
|
||||||
//AudioGeneratorWAV *wav;
|
|
||||||
AudioGeneratorMP3 *mp3;
|
|
||||||
AudioFileSourceID3 *id3;
|
|
||||||
|
|
||||||
AudioFileSourceLittleFS *file;
|
|
||||||
|
|
||||||
AudioOutputI2S *out;
|
|
||||||
|
|
||||||
const char *waveFile = "/Let_it_be.mp3";
|
|
||||||
|
|
||||||
// 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)
|
|
||||||
{
|
|
||||||
(void)cbData;
|
|
||||||
Serial.printf("ID3 callback for: %s = '", type);
|
|
||||||
|
|
||||||
if (isUnicode)
|
|
||||||
{
|
|
||||||
string += 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
while (*string)
|
|
||||||
{
|
|
||||||
char a = *(string++);
|
|
||||||
if (isUnicode)
|
|
||||||
{
|
|
||||||
string++;
|
|
||||||
}
|
|
||||||
Serial.printf("%c", a);
|
|
||||||
}
|
|
||||||
Serial.printf("'\n");
|
|
||||||
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()
|
void setup()
|
||||||
{
|
{
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
delay(1000);
|
delay(1000);
|
||||||
|
|
||||||
initStorage();
|
initStorage();
|
||||||
|
initAudio();
|
||||||
audioLogger = &Serial;
|
|
||||||
file = new AudioFileSourceLittleFS(waveFile);
|
|
||||||
id3 = new AudioFileSourceID3(file);
|
|
||||||
id3->RegisterMetadataCB(MDCallback, (void *)"ID3TAG");
|
|
||||||
|
|
||||||
mp3 = new AudioGeneratorMP3();
|
|
||||||
mp3->RegisterStatusCB(StatusCallback, (void*)"mp3");
|
|
||||||
|
|
||||||
out = new AudioOutputI2S();
|
|
||||||
out->SetPinout(19, 33, 22); //bclk, wclk, data
|
|
||||||
mp3->begin(id3, out);
|
|
||||||
out->SetGain(0.25);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop()
|
void loop()
|
||||||
{
|
{
|
||||||
if (mp3->isRunning())
|
handleAudio();
|
||||||
{
|
|
||||||
if (!mp3->loop())
|
|
||||||
{
|
|
||||||
mp3->stop();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Serial.printf("sound done\n");
|
|
||||||
delay(1000);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user