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"
        }
    }
}

Files at this revision

API Documentation at this revision

Comitter:
dkato
Date:
Tue Aug 18 04:19:19 2015 +0000
Parent:
6:ad0b3ce4284b
Child:
8:7121197d098e
Commit message:
High-Resolution Audio

Changed in this revision

R_BSP.lib Show annotated file Show diff for this revision Revisions of this file
TLV320_RBSP.lib Show annotated file Show diff for this revision Revisions of this file
dec_wav.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- a/R_BSP.lib	Fri Jun 26 07:35:16 2015 +0000
+++ b/R_BSP.lib	Tue Aug 18 04:19:19 2015 +0000
@@ -1,1 +1,1 @@
-http://developer.mbed.org/teams/Renesas/code/R_BSP/#b72e037c50c3
+http://developer.mbed.org/teams/Renesas/code/R_BSP/#1390bfcb667c
--- a/TLV320_RBSP.lib	Fri Jun 26 07:35:16 2015 +0000
+++ b/TLV320_RBSP.lib	Tue Aug 18 04:19:19 2015 +0000
@@ -1,1 +1,1 @@
-http://developer.mbed.org/teams/Renesas/code/TLV320_RBSP/#4b34a496efac
+http://developer.mbed.org/teams/Renesas/code/TLV320_RBSP/#b1fab4a2b59d
--- a/dec_wav.h	Fri Jun 26 07:35:16 2015 +0000
+++ b/dec_wav.h	Tue Aug 18 04:19:19 2015 +0000
@@ -147,12 +147,54 @@
      * @return get data size
      */
     size_t GetNextData(void *buf, size_t len) {
-        if ((music_data_index + len) > music_data_size) {
-            len = music_data_size - music_data_index;
+        if (block_size == 24) {
+            // Add padding
+            int write_index = 0;
+            int wavfile_index;
+            int read_len;
+            int pading_index = 0;
+            uint8_t * p_buf = (uint8_t *)buf;
+            size_t ret;
+
+            if ((music_data_index + len) > music_data_size) {
+                len = music_data_size - music_data_index;
+            }
+            while (write_index < len) {
+                read_len = (len - write_index) * 3 / 4;
+                if (read_len > sizeof(wk_wavfile_buff)) {
+                    read_len = sizeof(wk_wavfile_buff);
+                }
+                music_data_index += read_len;
+                ret = fread(wk_wavfile_buff, sizeof(char), read_len, wav_fp);
+                if (ret < read_len) {
+                    break;
+                }
+                wavfile_index = 0;
+                while ((write_index < len) && (wavfile_index < read_len)) {
+                    if (pading_index == 0) {
+                        p_buf[write_index] = 0;
+                    } else {
+                        p_buf[write_index] = wk_wavfile_buff[wavfile_index];
+                        wavfile_index++;
+                    }
+                    if (pading_index < 3) {
+                        pading_index++;
+                    } else {
+                        pading_index = 0;
+                    }
+                    write_index++;
+                }
+            }
+
+            return write_index;
+        } else {
+            if ((music_data_index + len) > music_data_size) {
+                len = music_data_size - music_data_index;
+            }
+            music_data_index += len;
+
+            return fread(buf, sizeof(char), len, wav_fp);
         }
-        music_data_index += len;
-
-        return fread(buf, sizeof(char), len, wav_fp);
     };
 
     /** get channel
@@ -175,15 +217,18 @@
      *
      * @return sampling rate
      */
-    uint16_t GetSamplingRate() {
+    uint32_t GetSamplingRate() {
         return sampling_rate;
     };
 
 private:
+    #define FILE_READ_BUFF_SIZE    (3072)
+
     FILE * wav_fp;
     uint32_t music_data_size;
     uint32_t music_data_index;
     uint16_t channel;
     uint16_t block_size;
     uint32_t sampling_rate;
+    uint8_t wk_wavfile_buff[FILE_READ_BUFF_SIZE];
 };
--- a/main.cpp	Fri Jun 26 07:35:16 2015 +0000
+++ b/main.cpp	Tue Aug 18 04:19:19 2015 +0000
@@ -28,7 +28,7 @@
 static uint8_t artist_buf[TEXT_SIZE];
 static uint8_t album_buf[TEXT_SIZE];
 
-TLV320_RBSP audio(P3_13, P10_13, I2C_SDA, I2C_SCL, P4_4, P4_5, P4_7, P4_6,
+TLV320_RBSP audio(P10_13, I2C_SDA, I2C_SCL, P4_4, P4_5, P4_7, P4_6,
                   0x80, (AUDIO_WRITE_BUFF_NUM - 1), 0);
 
 static void callback_audio_write_end(void * p_data, int32_t result, void * p_app_data) {
@@ -89,15 +89,21 @@
                             fclose(fp);
                             fp = NULL;
                         } else if ((wav_file.GetChannel() != 2)
-                                || (wav_file.GetBlockSize() != 16)
-                                || (wav_file.GetSamplingRate() != 44100)) {
+                                || (audio.format(wav_file.GetBlockSize()) == false)
+                                || (audio.frequency(wav_file.GetSamplingRate()) == false)) {
+                            printf("Error File  :%s\n", p->d_name);
+                            printf("Audio Info  :%dch, %dbit, %dHz\n", wav_file.GetChannel(),
+                                    wav_file.GetBlockSize(), wav_file.GetSamplingRate());
+                            printf("\n");
                             fclose(fp);
                             fp = NULL;
                         } else {
-                            printf("File  :%s\n", p->d_name);
-                            printf("Title :%s\n", title_buf);
-                            printf("Artist:%s\n", artist_buf);
-                            printf("Album :%s\n", album_buf);
+                            printf("File        :%s\n", p->d_name);
+                            printf("Audio Info  :%dch, %dbit, %dHz\n", wav_file.GetChannel(),
+                                    wav_file.GetBlockSize(), wav_file.GetSamplingRate());
+                            printf("Title       :%s\n", title_buf);
+                            printf("Artist      :%s\n", artist_buf);
+                            printf("Album       :%s\n", album_buf);
                             printf("\n");
                             break;
                         }
--- a/mbed.bld	Fri Jun 26 07:35:16 2015 +0000
+++ b/mbed.bld	Tue Aug 18 04:19:19 2015 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/mbed/builds/cbbeb26dbd92
\ No newline at end of file
+http://mbed.org/users/mbed_official/code/mbed/builds/b9ad9a133dc7
\ No newline at end of file