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:
dkato
Date:
Thu Nov 05 02:46:24 2015 +0000
Revision:
2:d9fca8cd7f03
Parent:
0:ee40da884cfc
Child:
4:521ca1d224d2
The output frequency was changed to 96kHz. The help command was added.

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 "misratypes.h"
dkato 0:ee40da884cfc 27 #include "r_errno.h"
dkato 0:ee40da884cfc 28 #include "decode.h"
dkato 0:ee40da884cfc 29 #include "audio_out.h"
dkato 0:ee40da884cfc 30 #include "display.h"
dkato 0:ee40da884cfc 31 #include "TLV320_RBSP.h"
dkato 0:ee40da884cfc 32
dkato 0:ee40da884cfc 33 /*--- Macro definition of mbed-rtos mail ---*/
dkato 0:ee40da884cfc 34 #define MAIL_QUEUE_SIZE (12) /* Queue size */
dkato 0:ee40da884cfc 35 #define MAIL_PARAM_NUM (3) /* Elements number of mail parameter array */
dkato 0:ee40da884cfc 36
dkato 0:ee40da884cfc 37 /* aud_mail_t */
dkato 0:ee40da884cfc 38 #define MAIL_PARAM0 (0) /* Index number of mail parameter array */
dkato 0:ee40da884cfc 39 #define MAIL_PARAM1 (1) /* Index number of mail parameter array */
dkato 0:ee40da884cfc 40 #define MAIL_PARAM2 (2) /* Index number of mail parameter array */
dkato 0:ee40da884cfc 41
dkato 0:ee40da884cfc 42 #define MAIL_PARAM_NON (0u) /* Value of unused element of mail parameter array */
dkato 0:ee40da884cfc 43
dkato 0:ee40da884cfc 44 /* mail_id = AUD_MAILID_DATA_OUT */
dkato 0:ee40da884cfc 45 #define MAIL_DATA_OUT_CB (MAIL_PARAM0) /* Callback function */
dkato 0:ee40da884cfc 46
dkato 0:ee40da884cfc 47 /* mail_id = AUD_MAILID_ZERO_OUT : No parameter */
dkato 0:ee40da884cfc 48
dkato 0:ee40da884cfc 49 /* mail_id = AUD_MAILID_SCUX_READ_FIN */
dkato 0:ee40da884cfc 50 #define MAIL_SCUX_READ_RESULT (MAIL_PARAM0) /* Result of the process */
dkato 0:ee40da884cfc 51 #define MAIL_SCUX_READ_BUF_INDEX (MAIL_PARAM1) /* Index number of PCM buffer */
dkato 0:ee40da884cfc 52 #define MAIL_SCUX_READ_BYTE_NUM (MAIL_PARAM2) /* Byte number of PCM data */
dkato 0:ee40da884cfc 53
dkato 0:ee40da884cfc 54 /* mail_id = AUD_MAILID_PCM_OUT_FIN */
dkato 0:ee40da884cfc 55 #define MAIL_PCM_OUT_RESULT (MAIL_PARAM0) /* Result of the process */
dkato 0:ee40da884cfc 56 #define MAIL_PCM_OUT_BUF_INDEX (MAIL_PARAM1) /* Index number of PCM buffer */
dkato 0:ee40da884cfc 57
dkato 0:ee40da884cfc 58 /*--- Macro definition of PCM buffer ---*/
dkato 0:ee40da884cfc 59 #define UNIT_TIME_MS (10u) /* Unit time of PCM data processing (ms) */
dkato 0:ee40da884cfc 60 #define SEC_TO_MSEC (1000u)
dkato 0:ee40da884cfc 61
dkato 0:ee40da884cfc 62 /* Sample number per unit time (ms) */
dkato 0:ee40da884cfc 63 #define SAMPLE_PER_UNIT_MS ((UNIT_TIME_MS * DEC_OUTPUT_SAMPLE_RATE) / SEC_TO_MSEC)
dkato 0:ee40da884cfc 64
dkato 0:ee40da884cfc 65 #define OUTPUT_START_TRIGGER (3) /* Numerical value of the trigger */
dkato 0:ee40da884cfc 66 /* to start the output of PCM data */
dkato 0:ee40da884cfc 67 #define OUTPUT_UPDATE_TRIGGER (1) /* Numerical value of the trigger */
dkato 0:ee40da884cfc 68 /* to update the output of PCM data */
dkato 0:ee40da884cfc 69
dkato 2:d9fca8cd7f03 70 #define PCM_BUF_NUM (DEC_SCUX_READ_NUM)
dkato 0:ee40da884cfc 71 #define TOTAL_SAMPLE_NUM (SAMPLE_PER_UNIT_MS * DEC_OUTPUT_CHANNEL_NUM)
dkato 0:ee40da884cfc 72
dkato 0:ee40da884cfc 73 /*--- Macro definition of TLV320_RBSP ---*/
dkato 0:ee40da884cfc 74 #define AUDIO_POWER_MIC_OFF (0x02) /* Microphone input :OFF */
dkato 0:ee40da884cfc 75 #define AUDIO_INT_LEVEL (0x80)
dkato 0:ee40da884cfc 76 #define AUDIO_READ_NUM (0)
dkato 0:ee40da884cfc 77 #define AUDIO_WRITE_NUM (PCM_BUF_NUM)
dkato 0:ee40da884cfc 78 #define ERR_MSG_TLV320_RBSP_WRITE "\nError: TLV320_RBSP::write()\n"
dkato 0:ee40da884cfc 79
dkato 0:ee40da884cfc 80 /* 4 bytes aligned. No cache memory. */
dkato 0:ee40da884cfc 81 #define NC_BSS_SECT __attribute__((section("NC_BSS"),aligned(4)))
dkato 0:ee40da884cfc 82 #define ERR_MSG_RECV_ILLEGAL_MAIL "\nError: aud_thread function received illegal mail.\n"
dkato 0:ee40da884cfc 83
dkato 0:ee40da884cfc 84 /*--- User defined types of mbed-rtos mail ---*/
dkato 0:ee40da884cfc 85 typedef enum {
dkato 0:ee40da884cfc 86 AUD_MAILID_DUMMY = 0,
dkato 0:ee40da884cfc 87 AUD_MAILID_DATA_OUT, /* Requests the output of PCM data. */
dkato 0:ee40da884cfc 88 AUD_MAILID_ZERO_OUT, /* Requests the output of zero data. */
dkato 0:ee40da884cfc 89 AUD_MAILID_SCUX_READ_FIN, /* Finished the reading process of SCUX. */
dkato 0:ee40da884cfc 90 AUD_MAILID_PCM_OUT_FIN, /* Finished the output of data. */
dkato 0:ee40da884cfc 91 AUD_MAILID_NUM
dkato 0:ee40da884cfc 92 } AUD_MAIL_ID;
dkato 0:ee40da884cfc 93
dkato 0:ee40da884cfc 94 typedef struct {
dkato 0:ee40da884cfc 95 AUD_MAIL_ID mail_id;
dkato 0:ee40da884cfc 96 uint32_t param[MAIL_PARAM_NUM];
dkato 0:ee40da884cfc 97 } aud_mail_t;
dkato 0:ee40da884cfc 98
dkato 0:ee40da884cfc 99 /*--- User defined types of audio output thread ---*/
dkato 0:ee40da884cfc 100 /* The control data of PCM buffer. */
dkato 0:ee40da884cfc 101 typedef struct {
dkato 0:ee40da884cfc 102 uint32_t pcm_buf_index; /* Index of PCM buffer array */
dkato 0:ee40da884cfc 103 uint32_t pcm_buf_remain_cnt; /* Counter of the remain elements in PCM buffer array */
dkato 0:ee40da884cfc 104 uint32_t pcm_stock_cnt; /* Counter of the stock elements in PCM buffer array */
dkato 0:ee40da884cfc 105 uint32_t output_trg_cnt; /* Number of the trigger to start the output of PCM data */
dkato 0:ee40da884cfc 106 } pcm_buf_ctrl_t;
dkato 0:ee40da884cfc 107
dkato 0:ee40da884cfc 108 static Mail<aud_mail_t, MAIL_QUEUE_SIZE> mail_box;
dkato 0:ee40da884cfc 109 static TLV320_RBSP audio(P10_13, I2C_SDA, I2C_SCL, P4_4, P4_5, P4_7,
dkato 0:ee40da884cfc 110 P4_6, AUDIO_INT_LEVEL, AUDIO_WRITE_NUM, AUDIO_READ_NUM);
dkato 0:ee40da884cfc 111
dkato 0:ee40da884cfc 112 static void init_pcm_buf(pcm_buf_ctrl_t * const p_ctrl);
dkato 0:ee40da884cfc 113 static bool read_scux(int32_t (* const p_buf)[TOTAL_SAMPLE_NUM], const uint32_t buf_id);
dkato 0:ee40da884cfc 114 static bool write_audio(int32_t (* const p_buf)[TOTAL_SAMPLE_NUM], const uint32_t buf_id);
dkato 0:ee40da884cfc 115 static void read_callback(void * p_data, int32_t result, void * p_app_data);
dkato 0:ee40da884cfc 116 static void pcm_out_callback(void * p_data, int32_t result, void * p_app_data);
dkato 0:ee40da884cfc 117 static bool send_mail(const AUD_MAIL_ID mail_id, const uint32_t param0,
dkato 0:ee40da884cfc 118 const uint32_t param1, const uint32_t param2);
dkato 0:ee40da884cfc 119 static bool recv_mail(AUD_MAIL_ID * const p_mail_id, uint32_t * const p_param0,
dkato 0:ee40da884cfc 120 uint32_t * const p_param1, uint32_t * const p_param2);
dkato 0:ee40da884cfc 121
dkato 0:ee40da884cfc 122 void aud_thread(void const *argument)
dkato 0:ee40da884cfc 123 {
dkato 0:ee40da884cfc 124 pcm_buf_ctrl_t buf_ctrl;
dkato 0:ee40da884cfc 125 pcm_buf_ctrl_t * const p_ctrl = &buf_ctrl;
dkato 0:ee40da884cfc 126 bool scux_read_enable = false;
dkato 0:ee40da884cfc 127 AUD_MAIL_ID mail_type;
dkato 0:ee40da884cfc 128 uint32_t mail_param[MAIL_PARAM_NUM];
dkato 0:ee40da884cfc 129 bool result;
dkato 0:ee40da884cfc 130 AUD_CbDataOut cb_data_out;
dkato 0:ee40da884cfc 131 uint32_t i;
dkato 0:ee40da884cfc 132 uint32_t buf_id;
dkato 0:ee40da884cfc 133 int32_t *p_buf;
dkato 0:ee40da884cfc 134 uint32_t byte_cnt;
dkato 0:ee40da884cfc 135 static int32_t NC_BSS_SECT pcm_buf[PCM_BUF_NUM][TOTAL_SAMPLE_NUM];
dkato 0:ee40da884cfc 136
dkato 0:ee40da884cfc 137 UNUSED_ARG(argument);
dkato 0:ee40da884cfc 138
dkato 0:ee40da884cfc 139 /* Initializes the control data of PCM buffer. */
dkato 0:ee40da884cfc 140 init_pcm_buf(p_ctrl);
dkato 0:ee40da884cfc 141
dkato 0:ee40da884cfc 142 /* Sets the output of PCM data using TLV320_RBSP. */
dkato 0:ee40da884cfc 143 (void) audio.format(DEC_OUTPUT_BITS_PER_SAMPLE);
dkato 0:ee40da884cfc 144 (void) audio.frequency(DEC_OUTPUT_SAMPLE_RATE);
dkato 0:ee40da884cfc 145 audio.power(AUDIO_POWER_MIC_OFF);
dkato 0:ee40da884cfc 146 while (1) {
dkato 0:ee40da884cfc 147 result = recv_mail(&mail_type, &mail_param[MAIL_PARAM0],
dkato 0:ee40da884cfc 148 &mail_param[MAIL_PARAM1], &mail_param[MAIL_PARAM2]);
dkato 0:ee40da884cfc 149 if (result == true) {
dkato 0:ee40da884cfc 150 switch (mail_type) {
dkato 0:ee40da884cfc 151 case AUD_MAILID_DATA_OUT: /* Requests the output of PCM data. */
dkato 0:ee40da884cfc 152 cb_data_out = (AUD_CbDataOut)mail_param[MAIL_DATA_OUT_CB];
dkato 0:ee40da884cfc 153 if (scux_read_enable != true) {
dkato 0:ee40da884cfc 154 scux_read_enable = true;
dkato 0:ee40da884cfc 155 result = true;
dkato 0:ee40da884cfc 156 for (i = 0; (i < p_ctrl->pcm_buf_remain_cnt) && (result == true); i++) {
dkato 0:ee40da884cfc 157 buf_id = (p_ctrl->pcm_buf_index + i) % PCM_BUF_NUM;
dkato 0:ee40da884cfc 158 result = read_scux(&pcm_buf[buf_id], buf_id);
dkato 0:ee40da884cfc 159 }
dkato 0:ee40da884cfc 160 if (result == true) {
dkato 0:ee40da884cfc 161 p_ctrl->output_trg_cnt = OUTPUT_START_TRIGGER;
dkato 0:ee40da884cfc 162 }
dkato 0:ee40da884cfc 163 } else {
dkato 0:ee40da884cfc 164 result = false;
dkato 0:ee40da884cfc 165 }
dkato 0:ee40da884cfc 166 cb_data_out(result);
dkato 0:ee40da884cfc 167 break;
dkato 0:ee40da884cfc 168 case AUD_MAILID_ZERO_OUT: /* Requests the output of zero data. */
dkato 0:ee40da884cfc 169 scux_read_enable = false;
dkato 0:ee40da884cfc 170 break;
dkato 0:ee40da884cfc 171 case AUD_MAILID_SCUX_READ_FIN: /* Finished the reading process of SCUX. */
dkato 0:ee40da884cfc 172 buf_id = mail_param[MAIL_SCUX_READ_BUF_INDEX];
dkato 0:ee40da884cfc 173 byte_cnt = mail_param[MAIL_SCUX_READ_BYTE_NUM];
dkato 0:ee40da884cfc 174 if ((buf_id < PCM_BUF_NUM) && (byte_cnt <= sizeof(pcm_buf[0]))) {
dkato 0:ee40da884cfc 175 if (byte_cnt < sizeof(pcm_buf[0])) {
dkato 0:ee40da884cfc 176 /* End of stream */
dkato 0:ee40da884cfc 177 /* Fills the remain area of PCM buffer with 0. */
dkato 0:ee40da884cfc 178 p_buf = &pcm_buf[buf_id][byte_cnt/sizeof(pcm_buf[0][0])];
dkato 0:ee40da884cfc 179 (void) memset(p_buf, 0, sizeof(pcm_buf[0]) - byte_cnt);
dkato 0:ee40da884cfc 180 p_ctrl->output_trg_cnt = OUTPUT_UPDATE_TRIGGER;
dkato 0:ee40da884cfc 181 }
dkato 0:ee40da884cfc 182 p_ctrl->pcm_stock_cnt++;
dkato 0:ee40da884cfc 183 if (p_ctrl->pcm_stock_cnt >= p_ctrl->output_trg_cnt) {
dkato 0:ee40da884cfc 184 /* Starts the output of PCM data. */
dkato 0:ee40da884cfc 185 result = true;
dkato 0:ee40da884cfc 186 for (i = 0; (i < p_ctrl->pcm_stock_cnt) && (result == true); i++) {
dkato 0:ee40da884cfc 187 buf_id = (p_ctrl->pcm_buf_index + i) % PCM_BUF_NUM;
dkato 0:ee40da884cfc 188 result = write_audio(&pcm_buf[buf_id], buf_id);
dkato 0:ee40da884cfc 189 if (result == true) {
dkato 0:ee40da884cfc 190 p_ctrl->pcm_buf_remain_cnt--;
dkato 0:ee40da884cfc 191 }
dkato 0:ee40da884cfc 192 }
dkato 0:ee40da884cfc 193 if (result != true) {
dkato 0:ee40da884cfc 194 /* Unexpected cases : Output error message to PC */
dkato 0:ee40da884cfc 195 (void) dsp_notify_print_string(ERR_MSG_TLV320_RBSP_WRITE);
dkato 0:ee40da884cfc 196 }
dkato 0:ee40da884cfc 197 p_ctrl->pcm_buf_index =
dkato 0:ee40da884cfc 198 (p_ctrl->pcm_buf_index + p_ctrl->pcm_stock_cnt) % PCM_BUF_NUM;
dkato 0:ee40da884cfc 199 p_ctrl->pcm_stock_cnt = 0u;
dkato 0:ee40da884cfc 200 p_ctrl->output_trg_cnt = OUTPUT_UPDATE_TRIGGER;
dkato 0:ee40da884cfc 201 }
dkato 0:ee40da884cfc 202 } else {
dkato 0:ee40da884cfc 203 /* Unexpected cases : This is fail-safe processing. */
dkato 0:ee40da884cfc 204 scux_read_enable = false;
dkato 0:ee40da884cfc 205 }
dkato 0:ee40da884cfc 206 break;
dkato 0:ee40da884cfc 207 case AUD_MAILID_PCM_OUT_FIN: /* Finished the output of data. */
dkato 0:ee40da884cfc 208 p_ctrl->pcm_buf_remain_cnt++;
dkato 0:ee40da884cfc 209 if ((int32_t)mail_param[MAIL_PCM_OUT_RESULT] == true) {
dkato 0:ee40da884cfc 210 if (scux_read_enable == true) {
dkato 0:ee40da884cfc 211 buf_id = mail_param[MAIL_PCM_OUT_BUF_INDEX];
dkato 0:ee40da884cfc 212 (void) read_scux(&pcm_buf[buf_id], buf_id);
dkato 0:ee40da884cfc 213 }
dkato 0:ee40da884cfc 214 } else {
dkato 0:ee40da884cfc 215 /* Unexpected cases : Output error message to PC */
dkato 0:ee40da884cfc 216 (void) dsp_notify_print_string(ERR_MSG_TLV320_RBSP_WRITE);
dkato 0:ee40da884cfc 217 }
dkato 0:ee40da884cfc 218 break;
dkato 0:ee40da884cfc 219 default:
dkato 0:ee40da884cfc 220 /* Unexpected cases : Output error message to PC */
dkato 0:ee40da884cfc 221 (void) dsp_notify_print_string(ERR_MSG_RECV_ILLEGAL_MAIL);
dkato 0:ee40da884cfc 222 break;
dkato 0:ee40da884cfc 223 }
dkato 0:ee40da884cfc 224 }
dkato 0:ee40da884cfc 225 }
dkato 0:ee40da884cfc 226 }
dkato 0:ee40da884cfc 227
dkato 0:ee40da884cfc 228 bool aud_req_data_out(const AUD_CbDataOut p_cb)
dkato 0:ee40da884cfc 229 {
dkato 0:ee40da884cfc 230 bool ret = false;
dkato 0:ee40da884cfc 231
dkato 0:ee40da884cfc 232 if (p_cb != NULL) {
dkato 0:ee40da884cfc 233 ret = send_mail(AUD_MAILID_DATA_OUT, (uint32_t)p_cb, MAIL_PARAM_NON, MAIL_PARAM_NON);
dkato 0:ee40da884cfc 234 }
dkato 0:ee40da884cfc 235 return ret;
dkato 0:ee40da884cfc 236 }
dkato 0:ee40da884cfc 237
dkato 0:ee40da884cfc 238 bool aud_req_zero_out(void)
dkato 0:ee40da884cfc 239 {
dkato 0:ee40da884cfc 240 bool ret = false;
dkato 0:ee40da884cfc 241
dkato 0:ee40da884cfc 242 ret = send_mail(AUD_MAILID_ZERO_OUT, MAIL_PARAM_NON, MAIL_PARAM_NON, MAIL_PARAM_NON);
dkato 0:ee40da884cfc 243 return ret;
dkato 0:ee40da884cfc 244 }
dkato 0:ee40da884cfc 245
dkato 0:ee40da884cfc 246 bool aud_get_audio_data(const AUD_CbAudioData p_cb, uint16_t * const p_buf)
dkato 0:ee40da884cfc 247 {
dkato 0:ee40da884cfc 248 UNUSED_ARG(p_cb);
dkato 0:ee40da884cfc 249 UNUSED_ARG(p_buf);
dkato 0:ee40da884cfc 250 return true;
dkato 0:ee40da884cfc 251 }
dkato 0:ee40da884cfc 252
dkato 0:ee40da884cfc 253 /** Initialises the control data of PCM buffer
dkato 0:ee40da884cfc 254 *
dkato 0:ee40da884cfc 255 * @param p_ctrl Pointer to the control data of PCM buffer.
dkato 0:ee40da884cfc 256 */
dkato 0:ee40da884cfc 257 static void init_pcm_buf(pcm_buf_ctrl_t * const p_ctrl)
dkato 0:ee40da884cfc 258 {
dkato 0:ee40da884cfc 259 if (p_ctrl != NULL) {
dkato 0:ee40da884cfc 260 p_ctrl->pcm_buf_index = 0u;
dkato 0:ee40da884cfc 261 p_ctrl->pcm_buf_remain_cnt = PCM_BUF_NUM;
dkato 0:ee40da884cfc 262 p_ctrl->pcm_stock_cnt = 0u;
dkato 0:ee40da884cfc 263 p_ctrl->output_trg_cnt = OUTPUT_START_TRIGGER;
dkato 0:ee40da884cfc 264 }
dkato 0:ee40da884cfc 265 }
dkato 0:ee40da884cfc 266
dkato 0:ee40da884cfc 267 /** Gets PCM data from SCUX driver
dkato 0:ee40da884cfc 268 *
dkato 0:ee40da884cfc 269 * @param p_buf Pointer to PCM buffer array to store the data.
dkato 0:ee40da884cfc 270 * @param buf_id The control ID of PCM buffer.
dkato 0:ee40da884cfc 271 *
dkato 0:ee40da884cfc 272 * @returns
dkato 0:ee40da884cfc 273 * Results of process. true is success. false is failure.
dkato 0:ee40da884cfc 274 */
dkato 0:ee40da884cfc 275 static bool read_scux(int32_t (* const p_buf)[TOTAL_SAMPLE_NUM], const uint32_t buf_id)
dkato 0:ee40da884cfc 276 {
dkato 0:ee40da884cfc 277 bool ret = false;
dkato 0:ee40da884cfc 278 rbsp_data_conf_t cb_conf = {
dkato 0:ee40da884cfc 279 &read_callback,
dkato 0:ee40da884cfc 280 NULL
dkato 0:ee40da884cfc 281 };
dkato 0:ee40da884cfc 282
dkato 0:ee40da884cfc 283 if ((p_buf != NULL) && (buf_id < PCM_BUF_NUM)) {
dkato 0:ee40da884cfc 284 cb_conf.p_app_data = (void *)buf_id;
dkato 0:ee40da884cfc 285 ret = dec_scux_read(p_buf, sizeof(p_buf[0]), &cb_conf);
dkato 0:ee40da884cfc 286 }
dkato 0:ee40da884cfc 287 return ret;
dkato 0:ee40da884cfc 288 }
dkato 0:ee40da884cfc 289
dkato 0:ee40da884cfc 290 /** Writes PCM data to TLV320_RBSP driver
dkato 0:ee40da884cfc 291 *
dkato 0:ee40da884cfc 292 * @param p_buf Pointer to PCM buffer array.
dkato 0:ee40da884cfc 293 * @param buf_id The control ID of PCM buffer.
dkato 0:ee40da884cfc 294 *
dkato 0:ee40da884cfc 295 * @returns
dkato 0:ee40da884cfc 296 * Results of process. true is success. false is failure.
dkato 0:ee40da884cfc 297 */
dkato 0:ee40da884cfc 298 static bool write_audio(int32_t (* const p_buf)[TOTAL_SAMPLE_NUM], const uint32_t buf_id)
dkato 0:ee40da884cfc 299 {
dkato 0:ee40da884cfc 300 bool ret = false;
dkato 0:ee40da884cfc 301 int32_t result;
dkato 0:ee40da884cfc 302 rbsp_data_conf_t cb_conf = {
dkato 0:ee40da884cfc 303 &pcm_out_callback,
dkato 0:ee40da884cfc 304 NULL
dkato 0:ee40da884cfc 305 };
dkato 0:ee40da884cfc 306
dkato 0:ee40da884cfc 307 if ((p_buf != NULL) && (buf_id < PCM_BUF_NUM)) {
dkato 0:ee40da884cfc 308 cb_conf.p_app_data = (void *)buf_id;
dkato 0:ee40da884cfc 309 result = audio.write(p_buf, sizeof(p_buf[0]), &cb_conf);
dkato 0:ee40da884cfc 310 if (result == ESUCCESS) {
dkato 0:ee40da884cfc 311 ret = true;
dkato 0:ee40da884cfc 312 }
dkato 0:ee40da884cfc 313 }
dkato 0:ee40da884cfc 314 return ret;
dkato 0:ee40da884cfc 315 }
dkato 0:ee40da884cfc 316
dkato 0:ee40da884cfc 317 /** Callback function of SCUX driver
dkato 0:ee40da884cfc 318 *
dkato 0:ee40da884cfc 319 * @param p_data Pointer to PCM byffer array.
dkato 0:ee40da884cfc 320 * @param result Result of the process.
dkato 0:ee40da884cfc 321 * @param p_app_data The control ID of PCM buffer.
dkato 0:ee40da884cfc 322 */
dkato 0:ee40da884cfc 323 static void read_callback(void * p_data, int32_t result, void * p_app_data)
dkato 0:ee40da884cfc 324 {
dkato 0:ee40da884cfc 325 const uint32_t buf_id = (uint32_t)p_app_data;
dkato 0:ee40da884cfc 326 uint32_t read_byte;
dkato 0:ee40da884cfc 327 bool flag_result;
dkato 0:ee40da884cfc 328
dkato 0:ee40da884cfc 329 UNUSED_ARG(p_data);
dkato 0:ee40da884cfc 330 if (result > 0) {
dkato 0:ee40da884cfc 331 flag_result = true;
dkato 0:ee40da884cfc 332 read_byte = (uint32_t)result;
dkato 0:ee40da884cfc 333 } else {
dkato 0:ee40da884cfc 334 flag_result = false;
dkato 0:ee40da884cfc 335 read_byte = 0u;
dkato 0:ee40da884cfc 336 }
dkato 0:ee40da884cfc 337 (void) send_mail(AUD_MAILID_SCUX_READ_FIN, (uint32_t)flag_result, buf_id, read_byte);
dkato 0:ee40da884cfc 338 }
dkato 0:ee40da884cfc 339
dkato 0:ee40da884cfc 340 /** Callback function of TLV320_RBSP driver
dkato 0:ee40da884cfc 341 *
dkato 0:ee40da884cfc 342 * @param p_data Pointer to PCM byffer array.
dkato 0:ee40da884cfc 343 * @param result Result of the process.
dkato 0:ee40da884cfc 344 * @param p_app_data The control ID of PCM buffer.
dkato 0:ee40da884cfc 345 */
dkato 0:ee40da884cfc 346 static void pcm_out_callback(void * p_data, int32_t result, void * p_app_data)
dkato 0:ee40da884cfc 347 {
dkato 0:ee40da884cfc 348 const uint32_t buf_id = (uint32_t)p_app_data;
dkato 0:ee40da884cfc 349 bool flag_result;
dkato 0:ee40da884cfc 350
dkato 0:ee40da884cfc 351 UNUSED_ARG(p_data);
dkato 0:ee40da884cfc 352 if (result > 0) {
dkato 0:ee40da884cfc 353 flag_result = true;
dkato 0:ee40da884cfc 354 } else {
dkato 0:ee40da884cfc 355 flag_result = false;
dkato 0:ee40da884cfc 356 }
dkato 0:ee40da884cfc 357 (void) send_mail(AUD_MAILID_PCM_OUT_FIN, (uint32_t)flag_result, buf_id, MAIL_PARAM_NON);
dkato 0:ee40da884cfc 358 }
dkato 0:ee40da884cfc 359
dkato 0:ee40da884cfc 360 /** Sends the mail to Decode thread
dkato 0:ee40da884cfc 361 *
dkato 0:ee40da884cfc 362 * @param mail_id Mail ID
dkato 0:ee40da884cfc 363 * @param param0 Parameter 0 of this mail
dkato 0:ee40da884cfc 364 * @param param1 Parameter 1 of this mail
dkato 0:ee40da884cfc 365 * @param param2 Parameter 2 of this mail
dkato 0:ee40da884cfc 366 *
dkato 0:ee40da884cfc 367 * @returns
dkato 0:ee40da884cfc 368 * Results of process. true is success. false is failure.
dkato 0:ee40da884cfc 369 */
dkato 0:ee40da884cfc 370 static bool send_mail(const AUD_MAIL_ID mail_id, const uint32_t param0,
dkato 0:ee40da884cfc 371 const uint32_t param1, const uint32_t param2)
dkato 0:ee40da884cfc 372 {
dkato 0:ee40da884cfc 373 bool ret = false;
dkato 0:ee40da884cfc 374 osStatus stat;
dkato 0:ee40da884cfc 375 aud_mail_t * const p_mail = mail_box.alloc();
dkato 0:ee40da884cfc 376
dkato 0:ee40da884cfc 377 if (p_mail != NULL) {
dkato 0:ee40da884cfc 378 p_mail->mail_id = mail_id;
dkato 0:ee40da884cfc 379 p_mail->param[MAIL_PARAM0] = param0;
dkato 0:ee40da884cfc 380 p_mail->param[MAIL_PARAM1] = param1;
dkato 0:ee40da884cfc 381 p_mail->param[MAIL_PARAM2] = param2;
dkato 0:ee40da884cfc 382 stat = mail_box.put(p_mail);
dkato 0:ee40da884cfc 383 if (stat == osOK) {
dkato 0:ee40da884cfc 384 ret = true;
dkato 0:ee40da884cfc 385 } else {
dkato 0:ee40da884cfc 386 (void) mail_box.free(p_mail);
dkato 0:ee40da884cfc 387 }
dkato 0:ee40da884cfc 388 }
dkato 0:ee40da884cfc 389 return ret;
dkato 0:ee40da884cfc 390 }
dkato 0:ee40da884cfc 391
dkato 0:ee40da884cfc 392 /** Receives the mail to Decode thread
dkato 0:ee40da884cfc 393 *
dkato 0:ee40da884cfc 394 * @param p_mail_id Pointer to the variable to store the mail ID
dkato 0:ee40da884cfc 395 * @param p_param0 Pointer to the variable to store the parameter 0 of this mail
dkato 0:ee40da884cfc 396 * @param p_param1 Pointer to the variable to store the parameter 1 of this mail
dkato 0:ee40da884cfc 397 * @param p_param2 Pointer to the variable to store the parameter 2 of this mail
dkato 0:ee40da884cfc 398 *
dkato 0:ee40da884cfc 399 * @returns
dkato 0:ee40da884cfc 400 * Results of process. true is success. false is failure.
dkato 0:ee40da884cfc 401 */
dkato 0:ee40da884cfc 402 static bool recv_mail(AUD_MAIL_ID * const p_mail_id, uint32_t * const p_param0,
dkato 0:ee40da884cfc 403 uint32_t * const p_param1, uint32_t * const p_param2)
dkato 0:ee40da884cfc 404 {
dkato 0:ee40da884cfc 405 bool ret = false;
dkato 0:ee40da884cfc 406 osEvent evt;
dkato 0:ee40da884cfc 407 aud_mail_t *p_mail;
dkato 0:ee40da884cfc 408
dkato 0:ee40da884cfc 409 if ((p_mail_id != NULL) && (p_param0 != NULL) &&
dkato 0:ee40da884cfc 410 (p_param1 != NULL) && (p_param2 != NULL)) {
dkato 0:ee40da884cfc 411 evt = mail_box.get();
dkato 0:ee40da884cfc 412 if (evt.status == osEventMail) {
dkato 0:ee40da884cfc 413 p_mail = (aud_mail_t *)evt.value.p;
dkato 0:ee40da884cfc 414 if (p_mail != NULL) {
dkato 0:ee40da884cfc 415 *p_mail_id = p_mail->mail_id;
dkato 0:ee40da884cfc 416 *p_param0 = p_mail->param[MAIL_PARAM0];
dkato 0:ee40da884cfc 417 *p_param1 = p_mail->param[MAIL_PARAM1];
dkato 0:ee40da884cfc 418 *p_param2 = p_mail->param[MAIL_PARAM2];
dkato 0:ee40da884cfc 419 ret = true;
dkato 0:ee40da884cfc 420 }
dkato 0:ee40da884cfc 421 (void) mail_box.free(p_mail);
dkato 0:ee40da884cfc 422 }
dkato 0:ee40da884cfc 423 }
dkato 0:ee40da884cfc 424 return ret;
dkato 0:ee40da884cfc 425 }