Last active
January 16, 2022 10:54
-
-
Save mongonta0716/18c28bff2dc533d8b51903c939a66a61 to your computer and use it in GitHub Desktop.
Example of MP3 Play for M5Stack Core2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma mark - Depend ESP8266Audio and ESP8266_Spiram libraries | |
/* | |
cd ~/Arduino/libraries | |
git clone https://github.com/earlephilhower/ESP8266Audio | |
git clone https://github.com/Gianbacchio/ESP8266_Spiram | |
*/ | |
#include <M5Core2.h> | |
#include <driver/i2s.h> | |
#include <WiFi.h> | |
#include "AudioFileSourceSD.h" | |
#include "AudioFileSourceID3.h" | |
#include "AudioGeneratorMP3.h" | |
#include "AudioOutputI2S.h" | |
AudioGeneratorMP3 *mp3; | |
AudioFileSourceSD *file; | |
AudioOutputI2S *out; | |
AudioFileSourceID3 *id3; | |
#define OUTPUT_GAIN 10 | |
void setup() | |
{ | |
M5.begin(); | |
M5.Axp.SetSpkEnable(true); | |
WiFi.mode(WIFI_OFF); | |
delay(500); | |
M5.Lcd.setTextFont(2); | |
M5.Lcd.printf("Sample MP3 playback begins...\n"); | |
Serial.printf("Sample MP3 playback begins...\n"); | |
// pno_cs from https://ccrma.stanford.edu/~jos/pasp/Sound_Examples.html | |
file = new AudioFileSourceSD("/mp3/chikichiki.mp3"); | |
id3 = new AudioFileSourceID3(file); | |
out = new AudioOutputI2S(0, 0); // Output to builtInDAC | |
out->SetPinout(12, 0, 2); | |
out->SetOutputModeMono(true); | |
out->SetGain((float)OUTPUT_GAIN/100.0); | |
mp3 = new AudioGeneratorMP3(); | |
mp3->begin(id3, out); | |
} | |
void loop() | |
{ | |
if (mp3->isRunning()) { | |
if (!mp3->loop()) mp3->stop(); | |
} else { | |
Serial.printf("MP3 done\n"); | |
delay(1000); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Perhaps you also need to add the following line.