WAVPlayer

Créations

ripper121

il y a 6 ans

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

Voir la création

deeph

NEW il y a 6 ans

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 il y a 6 ans

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

ripper121

il y a 6 ans

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

ripper121

NEW il y a 6 ans

jicehel jicehel

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

geed

NEW il y a 6 ans

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

NightWolf

NEW il y a 6 ans

Thanks @ripper1211

ripper121

NEW il y a 6 ans

Thanks.

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

NightWolf

il y a 6 ans

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 il y a 6 ans

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 il y a 6 ans

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 il y a 6 ans

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 il y a 6 ans

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 il y a 6 ans

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 il y a 6 ans

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 il y a 6 ans

I think so? Try it out!

Flobann

NEW il y a 5 ans

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

jicehel

NEW il y a 5 ans

??? 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

Flobann

il y a 5 ans

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