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

key/key_cmd.cpp

Committer:
Osamu Nakamura
Date:
2017-03-31
Revision:
6:df19c3e787ca
Parent:
2:d9fca8cd7f03

File content as of revision 6:df19c3e787ca:

/*******************************************************************************
* DISCLAIMER
* This software is supplied by Renesas Electronics Corporation and is only
* intended for use with Renesas products. No other uses are authorized. This
* software is owned by Renesas Electronics Corporation and is protected under
* all applicable laws, including copyright laws.
* THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIES REGARDING
* THIS SOFTWARE, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING BUT NOT
* LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
* AND NON-INFRINGEMENT. ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED.
* TO THE MAXIMUM EXTENT PERMITTED NOT PROHIBITED BY LAW, NEITHER RENESAS
* ELECTRONICS CORPORATION NOR ANY OF ITS AFFILIATED COMPANIES SHALL BE LIABLE
* FOR ANY DIRECT, INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR
* ANY REASON RELATED TO THIS SOFTWARE, EVEN IF RENESAS OR ITS AFFILIATES HAVE
* BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* Renesas reserves the right, without notice, to make changes to this software
* and to discontinue the availability of this software. By using this software,
* you agree to the additional terms and conditions found by accessing the
* following link:
* http://www.renesas.com/disclaimer*
* Copyright (C) 2015 Renesas Electronics Corporation. All rights reserved.
*******************************************************************************/

#include "mbed.h"
#include "rtos.h"
#include "misratypes.h"

#include "key_cmd.h"
#include "system.h"
#include "display.h"

/*--- Macro definition ---*/
#define CHR_BS              '\b'        /* 0x08: BACKSPACE */
#define CHR_LF              '\n'        /* 0x0A: LINE FEED */
#define CHR_CR              '\r'        /* 0x0D: CARRIAGE RETURN */
#define CHR_SPACE           ' '         /* 0x20: SPACE */
#define PRINT_CHR_MIN       CHR_SPACE   /* Minimum numeric value of printable character. */
#define PRINT_CHR_MAX       '~'         /* Maximum numeric value of printable character. */

/* Command Name */
#define CMD_STOP            "STOP"      /* Stop */
#define CMD_PLAYPAUSE       "PLAYPAUSE" /* Play / Pause */
#define CMD_NEXT            "NEXT"      /* Next track */
#define CMD_PREV            "PREV"      /* Previous track */
#define CMD_PLAYINFO        "PLAYINFO"  /* Play info */
#define CMD_REPEAT          "REPEAT"    /* Repeat */
#define CMD_HELP            "HELP"      /* Help */

#define VALID_CMD_NUM       (7u)

#define MAX_CNT_OF_ARG      (1u)

#define MSG_UNKNOWN_CMD     "command not found"

/*--- User defined types ---*/
typedef struct {
    char_t          argv[MAX_CNT_OF_ARG][CMD_INPUT_MAX_LEN];
    uint32_t        argc;
} split_str_t;

static Serial pc_in(USBTX, USBRX);

static void clear_input_string(cmd_ctrl_t * const p);
static bool read_data(cmd_ctrl_t * const p);
static bool split_input_string(split_str_t * const p,
                        const char_t * const p_inp_str, const uint32_t inp_len);
static SYS_KeyCode parse_input_string(const split_str_t * const p);

void cmd_init_proc(cmd_ctrl_t * const p_ctrl)
{
    if (p_ctrl != NULL) {
        pc_in.baud(DSP_PC_COM_BAUDRATE);
        clear_input_string(p_ctrl);
    }
}

SYS_KeyCode cmd_main_proc(cmd_ctrl_t * const p_ctrl)
{
    SYS_KeyCode     key_ev = SYS_KEYCODE_NON;
    split_str_t     split;
    bool            result;
    
    if (p_ctrl != NULL) {
        result = read_data(p_ctrl);
        if (result == true) {
            /* Decided the input character string from command-line. */
            /* Splits the input character string in argument. */
            result = split_input_string(&split, p_ctrl->inp_str, p_ctrl->inp_len);
            if (result == true) {
                key_ev = parse_input_string(&split);
                if (key_ev == SYS_KEYCODE_NON) {
                    /* The input character string is unknown command. */
                    (void) dsp_notify_print_string(MSG_UNKNOWN_CMD);
                }
            }
            clear_input_string(p_ctrl);
        }
    }
    return key_ev;
}

/** Clears the data of the input character string
 *
 *  @param p Pointer to the control data of command-line module.
 */
static void clear_input_string(cmd_ctrl_t * const p)
{
    if (p != NULL) {
        p->inp_str[0] = '\0';
        p->inp_len = 0u;
    }
}

/** Reads the input character string from command-line
 *
 *  @param p Pointer to the control data of command-line module.
 *
 *  @returns 
 *    Results of process. true is success. false is failure.
 */
static bool read_data(cmd_ctrl_t * const p)
{
    bool            ret = false;
    int32_t         c;

    if (p != NULL) {
        if (pc_in.readable() == true) {
            c = pc_in.getc();
            if ((PRINT_CHR_MIN <= c) && (c <= PRINT_CHR_MAX)) {
                /* The character of "c" variable can print.  */
                /* Checks the length except the null terminal character. */
                if (p->inp_len < ((sizeof(p->inp_str)/sizeof(p->inp_str[0])) - 1u)) {
                    p->inp_str[p->inp_len] = (char_t)c;
                    p->inp_len++;
                    p->inp_str[p->inp_len] = '\0';
                } else {
                    /* Because buffer is full, "c" variable is canceled. */
                }
            } else {
                /* The character of "c" variable can not print.  */
                if ((c == CHR_CR) || (c == CHR_LF) || (c == '\0')) {
                    /* Detected the end of the input from command-line. */
                    ret = true;
                } else if (c == CHR_BS) {
                    /* Deletes one character. */
                    if (p->inp_len > 0u) {
                        p->inp_len--;
                        p->inp_str[p->inp_len] = '\0';
                    }
                } else {
                    /* DO NOTHING */
                }
            }
            /* Sends the input character string to display thread. */
            (void) dsp_notify_input_string(p->inp_str, ret);
        }
    }
    return ret;
}

/** Splits the input character string in argument
 *
 *  @param p Pointer to the structure to store the argument data.
 *  @param p_inp_str Pointer to the input character string.
 *  @param inp_len Length of the input character string. 
 *                 (Excepting the null terminal character.)
 *
 *  @returns 
 *    Results of process. true is success. false is failure.
 */
static bool split_input_string(split_str_t * const p,
                        const char_t * const p_inp_str, const uint32_t inp_len)
{
    bool            ret = false;
    uint32_t        arg_cnt;
    uint32_t        chr_cnt;
    uint32_t        i;
    
    if ((p != NULL) && (p_inp_str != NULL) && (inp_len > 0u)) {
        arg_cnt = 0u;
        chr_cnt = 0u;
        /* Checks the input character string. */
        /* (Including the null terminal character.) */
        for (i = 0u; i < (inp_len + 1u); i++) {
            /* Deletes the white space. */
            if (((int32_t)p_inp_str[i] == CHR_SPACE) || 
                ((int32_t)p_inp_str[i] == '\0')) {
                if (chr_cnt > 0u) {
                    /* Detects the white space after the string. */
                    arg_cnt++;
                    chr_cnt = 0u;
                }
            } else {
                /* Checks the length except the null terminal character. */
                if (chr_cnt < (sizeof(p->argv[0]) - 1u)) {
                    if (arg_cnt < (sizeof(p->argv)/sizeof(p->argv[0]))) {
                        p->argv[arg_cnt][chr_cnt] = p_inp_str[i];
                        p->argv[arg_cnt][chr_cnt + 1u] = '\0';
                    }
                    chr_cnt++;
                }
            }
        }
        if ((arg_cnt > 0u) && 
            (arg_cnt <= (sizeof(p->argv)/sizeof(p->argv[0])))) {
            p->argc = arg_cnt;
            ret = true;
        } else {
            p->argc = 0u;
        }
    }
    return ret;
}

/** Parses the input character string using the argument data
 *
 *  @param p Pointer to the structure of the argument data.
 *
 *  @returns 
 *    Key code.
 */
static SYS_KeyCode parse_input_string(const split_str_t * const p)
{
    SYS_KeyCode         key_ret = SYS_KEYCODE_NON;
    const char_t        *p_str;
    uint32_t            max_len;
    uint32_t            i;
    struct {
        const char_t    *p_cmd;
        SYS_KeyCode     key_ev;
    } static const cmd_list[VALID_CMD_NUM] = {
        {   CMD_STOP,       SYS_KEYCODE_STOP        },
        {   CMD_PLAYPAUSE,  SYS_KEYCODE_PLAYPAUSE   },
        {   CMD_NEXT,       SYS_KEYCODE_NEXT        },
        {   CMD_PREV,       SYS_KEYCODE_PREV        },
        {   CMD_PLAYINFO,   SYS_KEYCODE_PLAYINFO    },
        {   CMD_REPEAT,     SYS_KEYCODE_REPEAT      },
        {   CMD_HELP,       SYS_KEYCODE_HELP        }
    };

    if (p != NULL) {
        if (p->argc == MAX_CNT_OF_ARG) {
            p_str = p->argv[0];
            max_len = sizeof(p->argv[0])/sizeof(p->argv[0][0]);
            for (i = 0u; (i < VALID_CMD_NUM) && (key_ret == SYS_KEYCODE_NON); i++) {
                if (strncasecmp(cmd_list[i].p_cmd, p_str, max_len) == 0) {
                    key_ret = cmd_list[i].key_ev;
                }
            }
        }
    }
    return key_ret;
}