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:
Mon Apr 18 12:05:33 2016 +0000
Revision:
4:521ca1d224d2
Parent:
2:d9fca8cd7f03
Child:
5:c140dcdc2d45
Supports IAR.

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