WAVPlayer v1.1 Update

Creations

ripper121

3 months ago

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());
    }
  }
}

View full creation

deeph

NEW 3 months ago

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

jicehel

NEW 3 months ago

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

ripper121

3 months ago

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

ripper121

NEW 3 months ago

jicehel jicehel

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

geed

NEW 2 months ago

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

NightWolf

NEW 2 months ago

Thanks @ripper1211

ripper121

NEW 2 months ago

Thanks.

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

NightWolf

2 months ago

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!

NightWolf

NEW 2 months ago

ripper121 ripper121

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!

ripper121

NEW 2 months ago

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.

NightWolf

NEW 2 months ago

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?

ripper121

NEW 1 month ago

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.

Sorunome

NEW 1 month ago

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

ripper121

NEW 1 month ago

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());
    }
  }
}

Sorunome

NEW 1 month ago

I think so? Try it out!

You must be logged in in order to post a message on the forum

Log in