Wavplayer -- By ripper121

WAVPlayer

Author :  ripper121

This is a little WAV player.

It will list all WAV files you placed into the "WAVFiles" Folder.

At the moment 100 Files are supported (you can change this at #define MAX_TRACKS 100)

Please don't rename the Folders, because the Player needs a constant path.


Buttons:

A - Start playing of the selected File

UP - Go up

Down - Go down


The wave files included are only for testing and I got them from the "picomon" Game 

WAVPlayer.zip




#include 
#define MAX_TRACKS 100
const char* path = "/WAVPlayer/WAVFiles/";
String wavFileNames[MAX_TRACKS];
const char* wavFileList[MAX_TRACKS];
String playingTrack = "";
int8_t wavfileCount = 0;
int8_t track = -1;

void setup() {
gb.begin();
SerialUSB.begin(9600);
list();
}

void loop() {
// put your main code here, to run repeatedly:
while (!gb.update());
// clear the previous screen
gb.display.clear();
gb.display.println("Playing: ");
gb.display.println(playingTrack);
gb.display.println("");
gb.display.println("Press A to Stop");

if (gb.buttons.pressed(BUTTON_A)) {
gb.sound.stop(track);
track = -1;
list();
}
}

void scan() {
wavfileCount = 0;
SdBaseFile s;
SdFile file;
s.open(path, O_READ);
while (1) {
char name[255];
if (!file.openNext(&s, O_READ)) break;
bool isDir = file.isDir();
file.getName(name, 255);
file.close();
if (!isDir) {
String fileName = String(name);
if (fileName.indexOf(".wav") >= 0 || fileName.indexOf(".WAV") >= 0 ) {
wavFileNames[wavfileCount] = fileName;
wavfileCount++;
}
}
}
s.close();
}

void list() {
scan();
if (wavfileCount > 0) {
for (int i = 0; i < wavfileCount; i++) {
wavFileList[i] = (const char *)wavFileNames[i].c_str();
}
uint8_t entry = gb.gui.menu("File List", wavFileList, wavfileCount);
if (wavFileList[entry] != "") {
gb.gui.popup(wavFileList[entry], 200);
playingTrack = wavFileList[entry];
String trackPath = String(path) + String(wavFileList[entry]);
track = gb.sound.play(trackPath.c_str());
}
}
}


See more
Author :  deeph

Nice ! You can convert almost any audio file to the right .wav format with ffmpeg (thanks Sorunome !) :

ffmpeg -i  in.mp3 -acodec pcm_u8 -ar 44.1k -ac 1 out.wav
Author :  jicehel

Thanks for this prog and it's make a good tuto to how to use wav  ;)

Author :  ripper121

Hardest part was to get the list of files in the folder ^^

Author :  geed

Very usefull small tool, ideal to test sfx and music, thanks :)

Author :  NightWolf

Thanks @ripper1211

Author :  ripper121

Thanks.

If I have some time, i will add scrolling trough the files and support more then 10 files.

Author :  NightWolf

Hey Ripper- so this app would support 10 songs? If I wanted to put a CD on there in .wav format i could, but I'd need to swap it out if I wanted to do another CD? i understand this device is not a music player. But it's cool it can play music!

Author :  ripper121

The WAVPlayer is scanning the directory /WAVPlayer/WAVFiles/ for wav files.

You can put more then 10 in it, but the Player would only list the first 10.

Author :  NightWolf

Still, pretty cool we can play music on this thing. Can't wait to try it out. So soon we'd be able to get a full album on it possibly, swap it out when needed?

Author :  ripper121

Update 1.1:

Now with new Gamebuino Menu for up to 100 files (you can change this limitation, but I have set it to be safe with the RAM)


If someone can finde a solution with the:

String wavFileNames[MAX_TRACKS];
const char* wavFileList[MAX_TRACKS];

that I dont need to convert the String list to Constant Char list, this would help to improve speed and ram usage.

Author :  Sorunome

Is it String[] or char*[] (as in c-strings). If it is the later, you can just cast it with (const char**)wavFileNames

Author :  ripper121

When the text from a Menu entry is to long, text is shown between the lines.

So this will do it?

void list() {
  scan();
  if (wavfileCount > 0) {
    uint8_t entry = gb.gui.menu("File List", (const char **)wavFileNames, wavfileCount);
    if ((const char **)wavFileNames[entry] != "") {
      gb.gui.popup((const char **)wavFileNames[entry], 200);
      playingTrack = (const char **)wavFileNames[entry];
      String trackPath = String(path) + String((const char **)wavFileNames[entry]);
      track = gb.sound.play(trackPath.c_str());
    }
  }
}
Author :  Sorunome

I think so? Try it out!

Author :  Flobann

We can add music or it's only for game files ??

Author :  jicehel

??? I don't understand the question. This player is to play .wav music but i don't know if it's answer to your question because i don't have well understood what you would ask. Sorry

Author :  Flobann

Sorry, actually I just want to know if I can put music like an MP3 ??

Author :  ripper121

No only WAV.

Take a look to Odroid Go, this device can Play MP3 because it uses a ESP32