This sample will play a ".wav" file of the USB root folder. Only RIFF format.

Fork of GR-PEACH_Audio_WAV by Daiki Kato

Audio sample for GR-PEACH or GR-LYCHEE. This sample will play a ".wav" file in the root of USB memory or SD card. If the USER_BUTTON0 is pressed, the next song is played.

The default setting of serial communication (baud rate etc.) in mbed is shown the following link.
Please refer to the link and change the settings of your PC terminal software.
The default value of baud rate in mbed is 9600, and this application uses baud rate 9600.
https://developer.mbed.org/teams/Renesas/wiki/GR-PEACH-Getting-Started#install-the-usb-serial-communication

Please refer to following link about Audio/Camera Shield.
https://developer.mbed.org/teams/Renesas/wiki/Audio_Camera-shield

For GR-PEACH:

FormatWav file (RIFF format) ".wav"
Channel2ch
Frequencies32kHz, 44.1kHz, 48kHz, 88.2kHz and 96kHz
Quantization bit rate16bits, 24bits and 32bits


For GR-LYCHEE:

FormatWav file (RIFF format) ".wav"
Channel2ch
Frequencies32kHz, 44.1kHz and 48kHz
Quantization bit rate16bits



  • Use USB0 of PEACH:
    /media/uploads/dkato/audio_wav_usb0.png

    If you use the USB0 as USB Host, please close GR-PEACH's JP3.
    /media/uploads/RyoheiHagimoto/usb.jpg

    Please select USB0 connector by the following configuration.

mbed_app.json

{
    "config": {
        "usb-host-ch":{
            "help": "(for GR-PEACH) 0:ch0 1:ch1",
            "value": "0"
        },
        "audio-camera-shield":{
            "help": "(for GR-PEACH) 0:not use 1:use",
            "value": "0"
        }
    }
}



  • Use USB1 of GR-PEACH:
    /media/uploads/dkato/audio_wav_usb1.png

    If you use the USB1 as USB Host, please close Audio/Camera Shield's JP1. /media/uploads/dkato/audiocamerashield_jp1.jpg

    Please select Audio/Camera Shield and USB1 connector by the following configuration.

mbed_app.json

{
    "config": {
        "usb-host-ch":{
            "help": "(for GR-PEACH) 0:ch0 1:ch1",
            "value": "1"
        },
        "audio-camera-shield":{
            "help": "(for GR-PEACH) 0:not use 1:use",
            "value": "1"
        }
    }
}
Committer:
1050186
Date:
Fri Dec 28 02:46:43 2018 +0000
Revision:
10:1e59ae6a81df
Parent:
9:a1045daef81d
Support Mbed OS 5.10, replace Renesas libraries to mbed-gr-libs and optimize main.cpp and related files for supporting GR-LYCHEE too.

Who changed what in which revision?

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