fix: moved audio code to seperate module
This commit is contained in:
@@ -13,9 +13,8 @@ platform = espressif32
|
||||
board = m5stack-atom
|
||||
framework = arduino
|
||||
lib_deps =
|
||||
earlephilhower/ESP8266Audio@^1.9.2
|
||||
;m5stack/M5Core2@^0.0.6
|
||||
https://github.com/lorol/LITTLEFS.git
|
||||
;http://192.168.2.3/Bonobo.Git.Server/ESP8266Audio.git
|
||||
;http://192.168.2.3/Bonobo.Git.Server/LittleFS_esp32.git
|
||||
monitor_speed = 115200
|
||||
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,62 +1,9 @@
|
||||
#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 "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()
|
||||
{
|
||||
@@ -64,33 +11,10 @@ void setup()
|
||||
delay(1000);
|
||||
|
||||
initStorage();
|
||||
|
||||
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);
|
||||
initAudio();
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
if (mp3->isRunning())
|
||||
{
|
||||
if (!mp3->loop())
|
||||
{
|
||||
mp3->stop();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.printf("sound done\n");
|
||||
delay(1000);
|
||||
}
|
||||
handleAudio();
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user