Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
E
ESP32-audioI2S
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
xpstem
ESP32-audioI2S
Commits
9ead3cb6
Unverified
Commit
9ead3cb6
authored
Jan 03, 2024
by
Wolle
Committed by
GitHub
Jan 03, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Delete examples/plays all files in a directory/plays_all_files_in_a_directory
parent
8af9f59a
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
0 additions
and
112 deletions
+0
-112
examples/plays all files in a directory/plays_all_files_in_a_directory
...s all files in a directory/plays_all_files_in_a_directory
+0
-112
No files found.
examples/plays all files in a directory/plays_all_files_in_a_directory
deleted
100644 → 0
View file @
8af9f59a
#include "Arduino.h"
#include "Audio.h"
#include "SD_MMC.h"
#include "FS.h"
#include <vector>
#define I2S_LRC 26
#define I2S_DOUT 25
#define I2S_BCLK 27
#define SD_MMC_D0 2
#define SD_MMC_CLK 14
#define SD_MMC_CMD 15
void listDir(fs::FS &fs, const char * dirname, uint8_t levels); //proto
std::vector<char*> v_audioContent;
int pirPin = 4;
Audio audio;
File dir;
const char audioDir[] = "/mp3";
void setup() {
Serial.begin(115200);
pinMode(SD_MMC_D0, INPUT_PULLUP);
SD_MMC.setPins(SD_MMC_CLK,SD_MMC_CMD, SD_MMC_D0);
if(!SD_MMC.begin( "/sdmmc", true, false, 20000)){
Serial.println("Card Mount Failed");
return;
}
audio.setPinout(I2S_BCLK, I2S_LRC, I2S_DOUT, -1, 0);
audio.setVolume(17); // 0...21 Will need to add a volume setting in the app
dir = SD_MMC.open(audioDir);
listDir(SD_MMC, audioDir, 1);
if(v_audioContent.size() > 0){
const char* s = (const char*)v_audioContent[v_audioContent.size() -1];
Serial.printf("playing %s\n", s);
audio.connecttoFS(SD_MMC, s);
v_audioContent.pop_back();
}
}
void loop(){
audio.loop();
}
void listDir(fs::FS &fs, const char * dirname, uint8_t levels){
Serial.printf("Listing directory: %s\n", dirname);
File root = fs.open(dirname);
if(!root){
Serial.println("Failed to open directory");
return;
}
if(!root.isDirectory()){
Serial.println("Not a directory");
return;
}
File file = root.openNextFile();
while(file){
if(file.isDirectory()){
Serial.print(" DIR : ");
Serial.println(file.name());
if(levels){
listDir(fs, file.path(), levels -1);
}
} else {
Serial.print(" FILE: ");
Serial.print(file.name());
Serial.print(" SIZE: ");
Serial.println(file.size());
v_audioContent.insert(v_audioContent.begin(), strdup(file.path()));
}
file = root.openNextFile();
}
Serial.printf("num files %i", v_audioContent.size());
root.close();
file.close();
}
void vector_clear_and_shrink(vector<char*>&vec){
uint size = vec.size();
for (int i = 0; i < size; i++) {
if(vec[i]){
free(vec[i]);
vec[i] = NULL;
}
}
vec.clear();
vec.shrink_to_fit();
}
// optional
void audio_info(const char *info){
Serial.print("info "); Serial.println(info);
}
void audio_id3data(const char *info){ //id3 metadata
Serial.print("id3data ");Serial.println(info);
}
void audio_eof_mp3(const char *info){ //end of file
Serial.print("eof_mp3 ");Serial.println(info);
if(v_audioContent.size() == 0){
vector_clear_and_shrink(v_audioContent); // free memory
return;
}
const char* s = (const char*)v_audioContent[v_audioContent.size() - 1];
Serial.printf("playing %s\n", s);
audio.connecttoFS(SD_MMC, s);
v_audioContent.pop_back();
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment