This is a sample that drives a speaker with PWM.
Fork of GR-PEACH_Audio_WAV by
This is a sample that drives a speaker with PWM. This sample will play a ".wav" file of the microSD or USB memory root folder. If the USER_BUTTON0 is pressed, the next song is played.
| Format | Wav file (RIFF format) ".wav" |
| Channel | 1ch and 2ch |
| Frequencies | 32kHz, 44.1kHz and 48kHz |
| Quantization bit rate | 8bits and 16bits |
You can adjust the volume by changing the following.
main.cpp
AudioPlayer.outputVolume(0.5); // Volume control (min:0.0 max:1.0)
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
Revision 1:967144cffd53, committed 2015-06-02
- Comitter:
- dkato
- Date:
- Tue Jun 02 10:19:02 2015 +0000
- Parent:
- 0:a24aaf3a41b1
- Child:
- 2:d59ebfef28c7
- Commit message:
- improving readability
Changed in this revision
--- a/R_BSP.lib Mon Jun 01 08:56:23 2015 +0000 +++ b/R_BSP.lib Tue Jun 02 10:19:02 2015 +0000 @@ -1,1 +1,1 @@ -http://developer.mbed.org/users/dkato/code/R_BSP/#702bf7b2b7d8 +http://developer.mbed.org/users/dkato/code/R_BSP/#9a5f9b476dbe
--- a/USBHost.lib Mon Jun 01 08:56:23 2015 +0000 +++ b/USBHost.lib Tue Jun 02 10:19:02 2015 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/mbed_official/code/USBHost/#8738e5882d4e +http://mbed.org/users/mbed_official/code/USBHost/#220cd93c9a5f
--- a/main.cpp Mon Jun 01 08:56:23 2015 +0000
+++ b/main.cpp Tue Jun 02 10:19:02 2015 +0000
@@ -12,12 +12,14 @@
#endif
DigitalIn button(USER_BUTTON0);
-#define READ_BUFF_SIZE (4096)
-#define READ_BUFF_NUM (16)
-#define MAIL_QUEUE_SIZE (READ_BUFF_NUM)
+#define FILE_READ_BUFF_SIZE (4096)
+#define AUDIO_WRITE_BUFF_SIZE (FILE_READ_BUFF_SIZE)
+#define AUDIO_WRITE_BUFF_NUM (16)
+#define AUDIO_READ_BUFF_NUM (0)
+#define MAIL_QUEUE_SIZE (AUDIO_WRITE_BUFF_NUM)
#define FILE_NAME_LEN (64)
-#define INFO_TYPE_WRITE_END (0)
#define TEXT_SIZE (64)
+#define FLD_PATH "/usb/"
typedef struct {
void * p_data;
@@ -25,17 +27,14 @@
} mail_t;
Mail<mail_t, MAIL_QUEUE_SIZE> mail_box;
-static uint8_t read_buff[READ_BUFF_NUM][READ_BUFF_SIZE] __attribute((section("NC_BSS"),aligned(4))); //4 bytes aligned! No cache memory
+static uint8_t audio_write_buff[AUDIO_WRITE_BUFF_NUM][AUDIO_WRITE_BUFF_SIZE] __attribute((section("NC_BSS"),aligned(4))); //4 bytes aligned! No cache memory
static uint8_t title_buf[TEXT_SIZE + 1];
static uint8_t artist_buf[TEXT_SIZE + 1];
static uint8_t album_buf[TEXT_SIZE + 1];
static uint32_t music_data_size;
static uint32_t music_data_index;
-#define WRITE_BUFF_NUM (READ_BUFF_NUM)
-#define FLD_PATH "/usb/"
-
-TLV320_RBSP audio(P3_13, P10_13, I2C_SDA, I2C_SCL, P4_4, P4_5, P4_7, P4_6, 0x80, WRITE_BUFF_NUM, READ_BUFF_NUM); // I2S Codec
+TLV320_RBSP audio(P3_13, P10_13, I2C_SDA, I2C_SCL, P4_4, P4_5, P4_7, P4_6, 0x80, AUDIO_WRITE_BUFF_NUM, AUDIO_READ_BUFF_NUM); // I2S Codec
static void callback_audio_tans_end(void * p_data, int32_t result, void * p_app_data) {
mail_t *mail = mail_box.alloc();
@@ -182,9 +181,9 @@
FILE * fp = NULL;
DIR * d = NULL;
char file_path[sizeof(FLD_PATH) + FILE_NAME_LEN];
- rbsp_data_conf_t audio_write_data = {&callback_audio_tans_end, NULL};
+ rbsp_data_conf_t audio_write_async_ctl = {&callback_audio_tans_end, NULL};
int cnt;
- size_t read_size;
+ size_t audio_data_size;
#if (USB_HOST_CH == 1) //Audio Shield USB1
//Audio Shield USB1 enable
@@ -196,13 +195,13 @@
audio.power(0x02); // mic off
audio.inputVolume(0.7, 0.7);
- for (cnt = 0; cnt < READ_BUFF_NUM; cnt++) {
+ for (cnt = 0; cnt < AUDIO_WRITE_BUFF_NUM; cnt++) {
mail_t *mail = mail_box.alloc();
if (mail == NULL) {
printf("error mail alloc\n");
} else {
- mail->p_data = read_buff[cnt];
+ mail->p_data = audio_write_buff[cnt];
mail->result = 0;
mail_box.put(mail);
}
@@ -258,19 +257,19 @@
if (evt.status == osEventMail) {
mail_t *mail = (mail_t *)evt.value.p;
- read_size = get_audio_data(mail->p_data, READ_BUFF_SIZE, fp);
- if (read_size > 0) {
- audio.write(mail->p_data, read_size, &audio_write_data);
+ audio_data_size = get_audio_data(mail->p_data, FILE_READ_BUFF_SIZE, fp);
+ if (audio_data_size > 0) {
+ audio.write(mail->p_data, audio_data_size, &audio_write_async_ctl);
mail_box.free(mail);
} else {
mail_box.put(mail);
}
} else {
- read_size = 0;
+ audio_data_size = 0;
}
// file close
- if ((read_size < READ_BUFF_SIZE) || (button == 0)) {
+ if ((audio_data_size < FILE_READ_BUFF_SIZE) || (button == 0)) {
fclose(fp);
fp = NULL;
Thread::wait(500);
--- a/mbed.bld Mon Jun 01 08:56:23 2015 +0000 +++ b/mbed.bld Tue Jun 02 10:19:02 2015 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/mbed_official/code/mbed/builds/dbbf35b96557 \ No newline at end of file +http://mbed.org/users/mbed_official/code/mbed/builds/cbbeb26dbd92 \ No newline at end of file
