Daiki Kato / Mbed OS GR-Boards_Audio_WAV

Dependencies:   mbed-os-lychee EasyPlayback

Committer:
dkato
Date:
Mon Oct 30 07:05:01 2017 +0000
Revision:
0:34a2fd49a1ee
first commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
dkato 0:34a2fd49a1ee 1 #include "mbed.h"
dkato 0:34a2fd49a1ee 2 #include "SdUsbConnect.h"
dkato 0:34a2fd49a1ee 3 #include "EasyPlayback.h"
dkato 0:34a2fd49a1ee 4 #include "EasyDec_WavCnv2ch.h"
dkato 0:34a2fd49a1ee 5
dkato 0:34a2fd49a1ee 6 #define FNAME_LEN (64)
dkato 0:34a2fd49a1ee 7 #define MOUNT_NAME "storage"
dkato 0:34a2fd49a1ee 8
dkato 0:34a2fd49a1ee 9 static InterruptIn skip_btn(USER_BUTTON0);
dkato 0:34a2fd49a1ee 10 static EasyPlayback AudioPlayer;
dkato 0:34a2fd49a1ee 11
dkato 0:34a2fd49a1ee 12 static void skip_btn_fall(void) {
dkato 0:34a2fd49a1ee 13 AudioPlayer.skip();
dkato 0:34a2fd49a1ee 14 }
dkato 0:34a2fd49a1ee 15
dkato 0:34a2fd49a1ee 16 int main() {
dkato 0:34a2fd49a1ee 17 DIR * d;
dkato 0:34a2fd49a1ee 18 struct dirent * p;
dkato 0:34a2fd49a1ee 19 char file_path[sizeof("/"MOUNT_NAME"/") + FNAME_LEN];
dkato 0:34a2fd49a1ee 20 SdUsbConnect storage(MOUNT_NAME);
dkato 0:34a2fd49a1ee 21
dkato 0:34a2fd49a1ee 22 AudioPlayer.add_decoder<EasyDec_WavCnv2ch>(".wav"); // decoder setting
dkato 0:34a2fd49a1ee 23 AudioPlayer.add_decoder<EasyDec_WavCnv2ch>(".WAV"); // decoder setting
dkato 0:34a2fd49a1ee 24 AudioPlayer.outputVolume(0.5); // Volume control (min:0.0 max:1.0)
dkato 0:34a2fd49a1ee 25 skip_btn.fall(&skip_btn_fall); // button setting
dkato 0:34a2fd49a1ee 26
dkato 0:34a2fd49a1ee 27 while (1) {
dkato 0:34a2fd49a1ee 28 storage.wait_connect();
dkato 0:34a2fd49a1ee 29 d = opendir("/"MOUNT_NAME"/"); // file search
dkato 0:34a2fd49a1ee 30 while ((p = readdir(d)) != NULL) {
dkato 0:34a2fd49a1ee 31 size_t len = strlen(p->d_name);
dkato 0:34a2fd49a1ee 32 if (len < FNAME_LEN) {
dkato 0:34a2fd49a1ee 33 sprintf(file_path, "/%s/%s", MOUNT_NAME, p->d_name); // make file path
dkato 0:34a2fd49a1ee 34 printf("%s\r\n", file_path);
dkato 0:34a2fd49a1ee 35 AudioPlayer.play(file_path); // playback
dkato 0:34a2fd49a1ee 36 }
dkato 0:34a2fd49a1ee 37 }
dkato 0:34a2fd49a1ee 38 closedir(d);
dkato 0:34a2fd49a1ee 39 }
dkato 0:34a2fd49a1ee 40 }