The "GR-PEACH_Audio_Playback_Sample" is a sample code that can provides high-resolution audio playback of FLAC format files. It also allows the user to audio-playback control functions such as play, pause, and stop by manipulating key switches.

Dependencies:   R_BSP TLV320_RBSP USBHost_custom

Note

For a sample program of with LCD Board,
please refer to GR-PEACH_Audio_Playback_7InchLCD_Sample.

Introduction

The "GR-PEACH_Audio_Playback_Sample" is a sample code that can provides high-resolution audio playback of FLAC format files. It also allows the user to audio-playback control functions such as play, pause, and stop by manipulating key switches.

1. Overview of the Sample Code

1.1 Software Block Diagram

Figure 1.1 shows the software block diagram.

/media/uploads/dkato/audioplayback_figure1_1x.png

1.2 Pin Definitions

Table 1.1 shows the pins that this sample code are to use.

/media/uploads/dkato/audioplayback_table1_1.png

2. Sample Code Operating Environment

This sample code runs in GR-PEACH + the Audio/Camera shield for the GR-PEACH environment. This section explains the functions of the ports that are used by this sample code.

2.1 Operating Environment

Figure 2.1 shows the configuration of the operating environment for running this sample code.

/media/uploads/dkato/audioplayback_figure2_1.png /media/uploads/1050186/figure2_2.png /media/uploads/dkato/audioplayback_figure2_3.png

2.2 List of User Operations

A list of user operations on the command line, TFT touch keys, and switch key that the user can perform for this sample code is shown in. Table 2.1.

/media/uploads/dkato/audioplayback_table2_1x.png

3. Function Outline

The functions of this sample code are summarized in Table 3.1 to Table 3.3.

/media/uploads/dkato/audioplayback_table3_1.png /media/uploads/dkato/audioplayback_table3_2.png /media/uploads/dkato/audioplayback_table3_3.png /media/uploads/dkato/audioplayback_figure3_1.png

3.1 Playback Control

The playback control that the sample code supports include play, pause, stop, skip to next, and skip to previous.

3.2 Trick Play Control

Manipulating "Repeat" alternates between "Repeat mode On" and "Repeat mode Off". The default mode is "Repeat mode On". When the repeat mode is on, the playback of the first song starts after the playback of the last song is finished. When the repeat mode is off, the sample code enters the stopped state after the playback of the last song is finished.

3.3 Acquisition of the Song Information

The information of the song being played is obtained by operating the "Play info" during the playback of the song. Table 3.4 lists the items of information that can be obtained by the "Play info" operation.

/media/uploads/dkato/audioplayback_table3_4.png

3.4 How the Folder Structure is Analyzed

The sample coded analyzes the folder structure in the breadth-first search order. The order in which files are numbered is illustrated in Table 3.5. The sample code does not sort the files by file or folder name.

/media/uploads/dkato/audioplayback_table3_5.png

4.Others

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

Committer:
Osamu Nakamura
Date:
Fri Mar 31 14:00:23 2017 +0900
Revision:
6:df19c3e787ca
Parent:
3:44c8558c3a83
Introduced mbedOS 5 instead of mbedOS 2 (classic)

Who changed what in which revision?

UserRevisionLine numberNew contents of line
dkato 0:ee40da884cfc 1 /*******************************************************************************
dkato 0:ee40da884cfc 2 * DISCLAIMER
dkato 0:ee40da884cfc 3 * This software is supplied by Renesas Electronics Corporation and is only
dkato 0:ee40da884cfc 4 * intended for use with Renesas products. No other uses are authorized. This
dkato 0:ee40da884cfc 5 * software is owned by Renesas Electronics Corporation and is protected under
dkato 0:ee40da884cfc 6 * all applicable laws, including copyright laws.
dkato 0:ee40da884cfc 7 * THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIES REGARDING
dkato 0:ee40da884cfc 8 * THIS SOFTWARE, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING BUT NOT
dkato 0:ee40da884cfc 9 * LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
dkato 0:ee40da884cfc 10 * AND NON-INFRINGEMENT. ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED.
dkato 0:ee40da884cfc 11 * TO THE MAXIMUM EXTENT PERMITTED NOT PROHIBITED BY LAW, NEITHER RENESAS
dkato 0:ee40da884cfc 12 * ELECTRONICS CORPORATION NOR ANY OF ITS AFFILIATED COMPANIES SHALL BE LIABLE
dkato 0:ee40da884cfc 13 * FOR ANY DIRECT, INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR
dkato 0:ee40da884cfc 14 * ANY REASON RELATED TO THIS SOFTWARE, EVEN IF RENESAS OR ITS AFFILIATES HAVE
dkato 0:ee40da884cfc 15 * BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
dkato 0:ee40da884cfc 16 * Renesas reserves the right, without notice, to make changes to this software
dkato 0:ee40da884cfc 17 * and to discontinue the availability of this software. By using this software,
dkato 0:ee40da884cfc 18 * you agree to the additional terms and conditions found by accessing the
dkato 0:ee40da884cfc 19 * following link:
dkato 0:ee40da884cfc 20 * http://www.renesas.com/disclaimer*
dkato 0:ee40da884cfc 21 * Copyright (C) 2015 Renesas Electronics Corporation. All rights reserved.
dkato 0:ee40da884cfc 22 *******************************************************************************/
dkato 0:ee40da884cfc 23
dkato 0:ee40da884cfc 24 #include "mbed.h"
dkato 0:ee40da884cfc 25 #include "rtos.h"
dkato 0:ee40da884cfc 26 #include "display.h"
dkato 0:ee40da884cfc 27 #include "disp_term.h"
dkato 0:ee40da884cfc 28
dkato 0:ee40da884cfc 29 /*--- Macro definition ---*/
dkato 0:ee40da884cfc 30 #define MOVE_CURSOR_TO_LEFT "\x1b[128D" /* Moves a cursor to the left. */
dkato 0:ee40da884cfc 31 #define CLEAR_CURSOR_RIGHT "\x1b[0K" /* Clears the right side of the cursor position. */
dkato 0:ee40da884cfc 32 #define CLEAR_CURSOR_LINE "\x1b[2K" /* Clears a cursor line. */
dkato 0:ee40da884cfc 33 #define CLEAR_ALL "\x1b[2J" /* Clears all screen. */
dkato 0:ee40da884cfc 34 #define STR_CR "\r\n"
dkato 0:ee40da884cfc 35
dkato 0:ee40da884cfc 36 #define MSG_PROMPT MOVE_CURSOR_TO_LEFT \
1050186 3:44c8558c3a83 37 "T%ld %ld:%02ld:%02ld > "\
dkato 0:ee40da884cfc 38 CLEAR_CURSOR_RIGHT
dkato 0:ee40da884cfc 39 #define MSG_FILENAME_PREFIX "File Name = "
dkato 0:ee40da884cfc 40 #define MSG_FILE_TYPE "File type : FLAC"
1050186 3:44c8558c3a83 41 #define MSG_SAMPLING_FREQ "Sampling freq. : %ld Hz"
dkato 0:ee40da884cfc 42 #define MSG_CHANNEL_PREFIX "Channel : "
dkato 0:ee40da884cfc 43 #define MSG_CHANNEL_MONO "Mono"
dkato 0:ee40da884cfc 44 #define MSG_CHANNEL_STEREO "Stereo"
dkato 0:ee40da884cfc 45 #define MSG_REPEAT_PREFIX "Repeat Mode = "
dkato 0:ee40da884cfc 46 #define MSG_MODE_ON "on"
dkato 0:ee40da884cfc 47 #define MSG_MODE_OFF "off"
dkato 0:ee40da884cfc 48
dkato 2:d9fca8cd7f03 49 #define HELP_CMD_NUM (7u)
dkato 2:d9fca8cd7f03 50
dkato 2:d9fca8cd7f03 51 /* help information */
dkato 2:d9fca8cd7f03 52 #define HELP_INFO_HELP "help : Show help information for commands."
dkato 2:d9fca8cd7f03 53 #define HELP_INFO_NEXT "next : Select the next song."
dkato 2:d9fca8cd7f03 54 #define HELP_INFO_PLAYINFO "playinfo : Show the song information."
dkato 2:d9fca8cd7f03 55 #define HELP_INFO_PLAYPAUSE "playpause : Control playback/pause."
dkato 2:d9fca8cd7f03 56 #define HELP_INFO_PREV "prev : Select the previous song."
dkato 2:d9fca8cd7f03 57 #define HELP_INFO_REPEAT "repeat : Turn on and off the repeat mode."
dkato 2:d9fca8cd7f03 58 #define HELP_INFO_STOP "stop : Stop playback."
dkato 2:d9fca8cd7f03 59
dkato 0:ee40da884cfc 60 #define MIN_TO_SEC (60u)
dkato 0:ee40da884cfc 61 #define HOUR_TO_SEC (3600u)
dkato 0:ee40da884cfc 62
dkato 0:ee40da884cfc 63 static Serial pc_out(USBTX, USBRX);
dkato 0:ee40da884cfc 64
dkato 0:ee40da884cfc 65 static void output_prompt(const dsp_com_ctrl_t * const p_com);
dkato 0:ee40da884cfc 66 static void output_playinfo(const dsp_com_ctrl_t * const p_com);
dkato 2:d9fca8cd7f03 67 static void output_help_info(void);
dkato 0:ee40da884cfc 68 static void clear_current_line(void);
dkato 0:ee40da884cfc 69 static void output_cr(void);
dkato 0:ee40da884cfc 70 static void output_string(const char_t * const p_str);
dkato 0:ee40da884cfc 71
dkato 0:ee40da884cfc 72 void dsp_init_term(void)
dkato 0:ee40da884cfc 73 {
dkato 0:ee40da884cfc 74 pc_out.baud(DSP_PC_COM_BAUDRATE);
dkato 0:ee40da884cfc 75 output_string(CLEAR_ALL); /* Clears all screen. */
dkato 0:ee40da884cfc 76 }
dkato 0:ee40da884cfc 77
dkato 0:ee40da884cfc 78 void dsp_output_term(const DSP_MAIL_ID mail_id, const dsp_com_ctrl_t * const p_com,
dkato 0:ee40da884cfc 79 const dsp_trm_ctrl_t * const p_trm)
dkato 0:ee40da884cfc 80 {
dkato 0:ee40da884cfc 81 bool is_update;
dkato 0:ee40da884cfc 82 const char_t *p_str;
dkato 0:ee40da884cfc 83
dkato 0:ee40da884cfc 84 if ((p_com != NULL) && (p_trm != NULL)) {
dkato 0:ee40da884cfc 85 switch(mail_id) {
dkato 0:ee40da884cfc 86 case DSP_MAILID_CMD_STR: /* Input character string by the command-line */
dkato 0:ee40da884cfc 87 /* Input character string is displayed after Command Prompt. */
dkato 0:ee40da884cfc 88 is_update = true;
dkato 0:ee40da884cfc 89 break;
dkato 0:ee40da884cfc 90 case DSP_MAILID_PRINT_STR: /* Character string for the status indication */
dkato 0:ee40da884cfc 91 is_update = true;
dkato 0:ee40da884cfc 92 clear_current_line();
dkato 0:ee40da884cfc 93 output_string(&p_com->dspl_str[0]);
dkato 0:ee40da884cfc 94 output_cr();
dkato 0:ee40da884cfc 95 break;
dkato 0:ee40da884cfc 96 case DSP_MAILID_PLAY_TIME: /* Playback time */
dkato 0:ee40da884cfc 97 /* Playback time is displayed in Command Prompt. */
dkato 0:ee40da884cfc 98 is_update = true;
dkato 0:ee40da884cfc 99 break;
dkato 0:ee40da884cfc 100 case DSP_MAILID_PLAY_INFO: /* Music information */
dkato 0:ee40da884cfc 101 is_update = true;
dkato 0:ee40da884cfc 102 clear_current_line();
dkato 0:ee40da884cfc 103 output_playinfo(p_com);
dkato 0:ee40da884cfc 104 break;
dkato 0:ee40da884cfc 105 case DSP_MAILID_PLAY_MODE: /* Repeat mode */
dkato 0:ee40da884cfc 106 is_update = true;
dkato 0:ee40da884cfc 107 clear_current_line();
dkato 0:ee40da884cfc 108 output_string(MSG_REPEAT_PREFIX);
dkato 0:ee40da884cfc 109 if (p_com->repeat_mode == true) {
dkato 0:ee40da884cfc 110 p_str = MSG_MODE_ON;
dkato 0:ee40da884cfc 111 } else {
dkato 0:ee40da884cfc 112 p_str = MSG_MODE_OFF;
dkato 0:ee40da884cfc 113 }
dkato 0:ee40da884cfc 114 output_string(p_str);
dkato 0:ee40da884cfc 115 output_cr();
dkato 0:ee40da884cfc 116 break;
dkato 0:ee40da884cfc 117 case DSP_MAILID_FILE_NAME: /* File name */
dkato 0:ee40da884cfc 118 is_update = true;
dkato 0:ee40da884cfc 119 clear_current_line();
dkato 0:ee40da884cfc 120 output_string(MSG_FILENAME_PREFIX);
dkato 0:ee40da884cfc 121 output_string(&p_com->file_name[0]);
dkato 0:ee40da884cfc 122 output_cr();
dkato 0:ee40da884cfc 123 break;
dkato 2:d9fca8cd7f03 124 case DSP_MAILID_HELP: /* Help information */
dkato 2:d9fca8cd7f03 125 is_update = true;
dkato 2:d9fca8cd7f03 126 clear_current_line();
dkato 2:d9fca8cd7f03 127 output_help_info();
dkato 2:d9fca8cd7f03 128 break;
dkato 0:ee40da884cfc 129 case DSP_MAILID_CYCLE_IND: /* Cyclic notice */
dkato 0:ee40da884cfc 130 default: /* Unexpected cases : mail id was illegal. */
dkato 0:ee40da884cfc 131 is_update = false;
dkato 0:ee40da884cfc 132 break;
dkato 0:ee40da884cfc 133 }
dkato 0:ee40da884cfc 134
dkato 0:ee40da884cfc 135 if (is_update == true) {
dkato 0:ee40da884cfc 136 /* Outputs the command prompt. */
dkato 0:ee40da884cfc 137 output_prompt(p_com);
dkato 0:ee40da884cfc 138
dkato 0:ee40da884cfc 139 /* Outputs a input character string. */
dkato 0:ee40da884cfc 140 output_string(&p_trm->inpt_str[0]);
dkato 0:ee40da884cfc 141
dkato 0:ee40da884cfc 142 if (p_trm->edge_fin_inpt == true) {
dkato 0:ee40da884cfc 143 /* Because command input was finished, I move a cursor. */
dkato 0:ee40da884cfc 144 /* And outputs the command prompt for next input. */
dkato 0:ee40da884cfc 145 output_cr();
dkato 0:ee40da884cfc 146 output_prompt(p_com);
dkato 0:ee40da884cfc 147 }
dkato 0:ee40da884cfc 148 }
dkato 0:ee40da884cfc 149 }
dkato 0:ee40da884cfc 150 }
dkato 0:ee40da884cfc 151
dkato 0:ee40da884cfc 152 /** Prints the command prompt
dkato 0:ee40da884cfc 153 *
dkato 0:ee40da884cfc 154 * @param p_com Pointer to common data in all module.
dkato 0:ee40da884cfc 155 */
dkato 0:ee40da884cfc 156 static void output_prompt(const dsp_com_ctrl_t * const p_com)
dkato 0:ee40da884cfc 157 {
dkato 0:ee40da884cfc 158 char_t str_buf[DSP_DISP_STR_MAX_LEN];
dkato 0:ee40da884cfc 159 uint32_t tim;
dkato 0:ee40da884cfc 160 uint32_t hour;
dkato 0:ee40da884cfc 161 uint32_t min;
dkato 0:ee40da884cfc 162 uint32_t sec;
dkato 0:ee40da884cfc 163
dkato 0:ee40da884cfc 164 if (p_com != NULL) {
dkato 0:ee40da884cfc 165 tim = p_com->play_time;
dkato 0:ee40da884cfc 166 hour = tim / HOUR_TO_SEC;
dkato 0:ee40da884cfc 167 tim = tim % HOUR_TO_SEC;
dkato 0:ee40da884cfc 168 min = tim / MIN_TO_SEC;
dkato 0:ee40da884cfc 169 sec = tim % MIN_TO_SEC;
dkato 0:ee40da884cfc 170 (void) sprintf(str_buf, MSG_PROMPT, p_com->track_id, hour, min, sec);
dkato 0:ee40da884cfc 171 output_string(str_buf);
dkato 0:ee40da884cfc 172 }
dkato 0:ee40da884cfc 173 }
dkato 0:ee40da884cfc 174
dkato 0:ee40da884cfc 175 /** Prints the file information of the current playback music.
dkato 0:ee40da884cfc 176 *
dkato 0:ee40da884cfc 177 * @param p_com Pointer to common data in all module.
dkato 0:ee40da884cfc 178 */
dkato 0:ee40da884cfc 179 static void output_playinfo(const dsp_com_ctrl_t * const p_com)
dkato 0:ee40da884cfc 180 {
dkato 0:ee40da884cfc 181 char_t str_buf[DSP_DISP_STR_MAX_LEN];
dkato 0:ee40da884cfc 182 const char_t * p_str;
dkato 0:ee40da884cfc 183
dkato 0:ee40da884cfc 184 if (p_com != NULL) {
dkato 0:ee40da884cfc 185 /* Prints the file type */
dkato 0:ee40da884cfc 186 output_string(MSG_FILE_TYPE);
dkato 0:ee40da884cfc 187 output_cr();
dkato 0:ee40da884cfc 188
dkato 0:ee40da884cfc 189 /* Prints the sampling frequency */
dkato 0:ee40da884cfc 190 (void) sprintf(str_buf, MSG_SAMPLING_FREQ, p_com->samp_freq);
dkato 0:ee40da884cfc 191 output_string(str_buf);
dkato 0:ee40da884cfc 192 output_cr();
dkato 0:ee40da884cfc 193
dkato 0:ee40da884cfc 194 /* Prints the channel structure */
dkato 0:ee40da884cfc 195 output_string(MSG_CHANNEL_PREFIX);
dkato 0:ee40da884cfc 196 if (p_com->channel == 1u) {
dkato 0:ee40da884cfc 197 p_str = MSG_CHANNEL_MONO;
dkato 0:ee40da884cfc 198 } else {
dkato 0:ee40da884cfc 199 p_str = MSG_CHANNEL_STEREO;
dkato 0:ee40da884cfc 200 }
dkato 0:ee40da884cfc 201 output_string(p_str);
dkato 0:ee40da884cfc 202 output_cr();
dkato 0:ee40da884cfc 203 }
dkato 0:ee40da884cfc 204 }
dkato 0:ee40da884cfc 205
dkato 2:d9fca8cd7f03 206 /** Prints the command help informations.
dkato 2:d9fca8cd7f03 207 *
dkato 2:d9fca8cd7f03 208 */
dkato 2:d9fca8cd7f03 209 static void output_help_info(void)
dkato 2:d9fca8cd7f03 210 {
dkato 2:d9fca8cd7f03 211 uint32_t i;
dkato 2:d9fca8cd7f03 212 struct {
dkato 2:d9fca8cd7f03 213 const char_t *p_help_info;
dkato 2:d9fca8cd7f03 214 } static const info_list[HELP_CMD_NUM] = {
dkato 2:d9fca8cd7f03 215 { HELP_INFO_HELP },
dkato 2:d9fca8cd7f03 216 { HELP_INFO_NEXT },
dkato 2:d9fca8cd7f03 217 { HELP_INFO_PLAYINFO },
dkato 2:d9fca8cd7f03 218 { HELP_INFO_PLAYPAUSE },
dkato 2:d9fca8cd7f03 219 { HELP_INFO_PREV },
dkato 2:d9fca8cd7f03 220 { HELP_INFO_REPEAT },
dkato 2:d9fca8cd7f03 221 { HELP_INFO_STOP }
dkato 2:d9fca8cd7f03 222 };
dkato 2:d9fca8cd7f03 223
dkato 2:d9fca8cd7f03 224 /* Prints the help information in alphabetical order. */
dkato 2:d9fca8cd7f03 225 for (i = 0u; i < HELP_CMD_NUM; i++) {
dkato 2:d9fca8cd7f03 226 output_string(info_list[i].p_help_info);
dkato 2:d9fca8cd7f03 227 output_cr();
dkato 2:d9fca8cd7f03 228 }
dkato 2:d9fca8cd7f03 229 }
dkato 2:d9fca8cd7f03 230
dkato 0:ee40da884cfc 231 /** Clears a cursor line
dkato 0:ee40da884cfc 232 *
dkato 0:ee40da884cfc 233 */
dkato 0:ee40da884cfc 234 static void clear_current_line(void)
dkato 0:ee40da884cfc 235 {
dkato 0:ee40da884cfc 236 output_string(MOVE_CURSOR_TO_LEFT); /* Moves a cursor to the left. */
dkato 0:ee40da884cfc 237 output_string(CLEAR_CURSOR_LINE); /* Clears a cursor line. */
dkato 0:ee40da884cfc 238 }
dkato 0:ee40da884cfc 239
dkato 0:ee40da884cfc 240 /** Prints the CARRIAGE RETURN
dkato 0:ee40da884cfc 241 *
dkato 0:ee40da884cfc 242 */
dkato 0:ee40da884cfc 243 static void output_cr(void)
dkato 0:ee40da884cfc 244 {
dkato 0:ee40da884cfc 245 output_string(STR_CR);
dkato 0:ee40da884cfc 246 }
dkato 0:ee40da884cfc 247
dkato 0:ee40da884cfc 248 /** Prints the specified character string
dkato 0:ee40da884cfc 249 *
dkato 0:ee40da884cfc 250 * @param p_str Pointer to the character string.
dkato 0:ee40da884cfc 251 */
dkato 0:ee40da884cfc 252 static void output_string(const char_t * const p_str)
dkato 0:ee40da884cfc 253 {
dkato 0:ee40da884cfc 254 if (p_str != NULL) {
dkato 0:ee40da884cfc 255 (void) pc_out.puts(p_str);
dkato 0:ee40da884cfc 256 }
dkato 0:ee40da884cfc 257 }