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:
5:c140dcdc2d45
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 "misratypes.h"
dkato 0:ee40da884cfc 27 #include "r_errno.h"
dkato 0:ee40da884cfc 28 #include "system.h"
dkato 0:ee40da884cfc 29 #include "decode.h"
dkato 0:ee40da884cfc 30 #include "audio_out.h"
dkato 0:ee40da884cfc 31 #include "dec_flac.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 (2) /* Elements number of mail parameter array */
dkato 0:ee40da884cfc 36
dkato 0:ee40da884cfc 37 /* dec_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
dkato 0:ee40da884cfc 41 #define MAIL_PARAM_NON (0u) /* Value of unused element of mail parameter array */
dkato 0:ee40da884cfc 42
dkato 0:ee40da884cfc 43 /* mail_id = DEC_MAILID_OPEN */
dkato 0:ee40da884cfc 44 #define MAIL_OPEN_CB (MAIL_PARAM0) /* Callback function */
dkato 0:ee40da884cfc 45 #define MAIL_OPEN_FILE (MAIL_PARAM1) /* File handle */
dkato 0:ee40da884cfc 46
dkato 0:ee40da884cfc 47 /* mail_id = DEC_MAILID_PLAY : No parameter */
dkato 0:ee40da884cfc 48
dkato 0:ee40da884cfc 49 /* mail_id = DEC_MAILID_PAUSE_ON : No parameter */
dkato 0:ee40da884cfc 50
dkato 0:ee40da884cfc 51 /* mail_id = DEC_MAILID_PAUSE_OFF : No parameter */
dkato 0:ee40da884cfc 52
dkato 0:ee40da884cfc 53 /* mail_id = DEC_MAILID_STOP : No parameter */
dkato 0:ee40da884cfc 54
dkato 0:ee40da884cfc 55 /* mail_id = DEC_MAILID_CLOSE */
dkato 0:ee40da884cfc 56 #define MAIL_CLOSE_CB (MAIL_PARAM0) /* Callback function */
dkato 0:ee40da884cfc 57
dkato 0:ee40da884cfc 58 /* mail_id = DEC_MAILID_CB_AUD_DATA_OUT */
dkato 0:ee40da884cfc 59 #define MAIL_DATA_OUT_RESULT (MAIL_PARAM0) /* Result of the process */
dkato 0:ee40da884cfc 60
dkato 0:ee40da884cfc 61 /* mail_id = DEC_MAILID_SCUX_WRITE_FIN */
dkato 0:ee40da884cfc 62 #define MAIL_SCUX_WRITE_RESULT (MAIL_PARAM0) /* Result of the process */
dkato 0:ee40da884cfc 63 #define MAIL_SCUX_WRITE_BUF_INDEX (MAIL_PARAM1) /* Index number of PCM buffer */
dkato 0:ee40da884cfc 64
dkato 0:ee40da884cfc 65 /* mail_id = DEC_MAILID_SCUX_FLUSH_FIN */
dkato 0:ee40da884cfc 66 #define MAIL_SCUX_FLUSH_RESULT (MAIL_PARAM0) /* Result of the process */
dkato 0:ee40da884cfc 67
dkato 0:ee40da884cfc 68
dkato 0:ee40da884cfc 69 /*--- Macro definition of PCM buffer ---*/
dkato 0:ee40da884cfc 70 #define UNIT_TIME_MS (50u) /* Unit time of PCM data processing (ms) */
dkato 0:ee40da884cfc 71 #define SEC_TO_MSEC (1000u)
dkato 0:ee40da884cfc 72
dkato 0:ee40da884cfc 73 /* Sample number per uint time (ms) */
dkato 0:ee40da884cfc 74 #define SAMPLE_NUM_PER_UNIT_MS (((UNIT_TIME_MS * DEC_INPUT_MAX_SAMPLE_RATE) / SEC_TO_MSEC) * DEC_OUTPUT_CHANNEL_NUM)
dkato 0:ee40da884cfc 75 /* Max number of samples per 1 block */
dkato 0:ee40da884cfc 76 #define MAX_SAMPLE_PER_1BLOCK (DEC_MAX_BLOCK_SIZE * DEC_OUTPUT_CHANNEL_NUM)
dkato 0:ee40da884cfc 77
dkato 0:ee40da884cfc 78 #define PCM_BUF_NUM (3u)
dkato 0:ee40da884cfc 79 #define TOTAL_SAMPLE_NUM (MAX_SAMPLE_PER_1BLOCK + SAMPLE_NUM_PER_UNIT_MS)
dkato 0:ee40da884cfc 80
dkato 0:ee40da884cfc 81 #define PCM_BUF_SINGLE (1)
dkato 0:ee40da884cfc 82 #define PCM_BUF_TOP_ID (0)
dkato 0:ee40da884cfc 83
dkato 0:ee40da884cfc 84 /*--- Macro definition of R_BSP_Scux ---*/
dkato 0:ee40da884cfc 85 #define SCUX_INT_LEVEL (0x80)
dkato 2:d9fca8cd7f03 86 #define SCUX_READ_NUM (DEC_SCUX_READ_NUM)
dkato 0:ee40da884cfc 87 #define SCUX_WRITE_NUM (PCM_BUF_NUM)
dkato 0:ee40da884cfc 88
dkato 0:ee40da884cfc 89 /* 4 bytes aligned. No cache memory. */
dkato 5:c140dcdc2d45 90 #if defined(__ICCARM__)
dkato 5:c140dcdc2d45 91 #define NC_BSS_SECT @ ".mirrorram"
dkato 5:c140dcdc2d45 92 #else
dkato 0:ee40da884cfc 93 #define NC_BSS_SECT __attribute__((section("NC_BSS"),aligned(4)))
dkato 4:521ca1d224d2 94 #endif
dkato 0:ee40da884cfc 95
dkato 0:ee40da884cfc 96 /*--- User defined types of mbed-rtos mail ---*/
dkato 0:ee40da884cfc 97 typedef enum {
dkato 0:ee40da884cfc 98 DEC_MAILID_DUMMY = 0,
dkato 0:ee40da884cfc 99 DEC_MAILID_OPEN, /* Requests the opening of the decoder. */
dkato 0:ee40da884cfc 100 DEC_MAILID_PLAY, /* Requests the starting of the playback. */
dkato 0:ee40da884cfc 101 DEC_MAILID_PAUSE_ON, /* Requests the starting of the pause. */
dkato 0:ee40da884cfc 102 DEC_MAILID_PAUSE_OFF, /* Requests the stopping of the pause. */
dkato 0:ee40da884cfc 103 DEC_MAILID_STOP, /* Requests the stopping of the playback. */
dkato 0:ee40da884cfc 104 DEC_MAILID_CLOSE, /* Requests the closing of the decoder. */
dkato 0:ee40da884cfc 105 DEC_MAILID_CB_AUD_DATA_OUT, /* Finished the preparation for the audio output. */
dkato 0:ee40da884cfc 106 DEC_MAILID_SCUX_WRITE_FIN, /* Finished the writing process of SCUX. */
dkato 0:ee40da884cfc 107 DEC_MAILID_SCUX_FLUSH_FIN, /* Finished the flush process of SCUX. */
dkato 0:ee40da884cfc 108 DEC_MAILID_NUM
dkato 0:ee40da884cfc 109 } DEC_MAIL_ID;
dkato 0:ee40da884cfc 110
dkato 0:ee40da884cfc 111 typedef struct {
dkato 0:ee40da884cfc 112 DEC_MAIL_ID mail_id;
dkato 0:ee40da884cfc 113 uint32_t param[MAIL_PARAM_NUM];
dkato 0:ee40da884cfc 114 } dec_mail_t;
dkato 0:ee40da884cfc 115
dkato 0:ee40da884cfc 116 /*--- User defined types of decode thread ---*/
dkato 0:ee40da884cfc 117 /* The playback information of the playback file */
dkato 0:ee40da884cfc 118 typedef struct {
dkato 0:ee40da884cfc 119 SYS_PlayStat play_stat; /* Playback status */
dkato 0:ee40da884cfc 120 uint32_t play_time; /* Playback start time */
dkato 0:ee40da884cfc 121 uint32_t total_time; /* Total playback time */
dkato 0:ee40da884cfc 122 } play_info_t;
dkato 0:ee40da884cfc 123
dkato 0:ee40da884cfc 124 /* Control data of Decode thread */
dkato 0:ee40da884cfc 125 typedef struct {
dkato 0:ee40da884cfc 126 play_info_t play_info;
dkato 0:ee40da884cfc 127 flac_ctrl_t flac_ctrl;
dkato 0:ee40da884cfc 128 } dec_ctrl_t;
dkato 0:ee40da884cfc 129
dkato 0:ee40da884cfc 130 /* Status of Decode thread */
dkato 0:ee40da884cfc 131 typedef enum {
dkato 0:ee40da884cfc 132 DEC_ST_IDLE = 0, /* Idle */
dkato 0:ee40da884cfc 133 DEC_ST_META_FIN, /* Finished the decoding until a metadata */
dkato 0:ee40da884cfc 134 DEC_ST_PLAY, /* Decoder start */
dkato 0:ee40da884cfc 135 DEC_ST_PAUSE, /* Decoder pause */
dkato 0:ee40da884cfc 136 DEC_ST_STOP_PREPARE, /* Preparing of decoder stop */
dkato 0:ee40da884cfc 137 DEC_ST_STOP, /* Decoder stop */
dkato 0:ee40da884cfc 138 DEC_ST_NUM
dkato 0:ee40da884cfc 139 } DEC_STATE;
dkato 0:ee40da884cfc 140
dkato 0:ee40da884cfc 141 static Mail<dec_mail_t, MAIL_QUEUE_SIZE> mail_box;
dkato 0:ee40da884cfc 142 static R_BSP_Scux scux(SCUX_CH_0, SCUX_INT_LEVEL, SCUX_WRITE_NUM, SCUX_READ_NUM);
dkato 0:ee40da884cfc 143
dkato 0:ee40da884cfc 144 static bool open_proc(flac_ctrl_t * const p_ctrl,
dkato 0:ee40da884cfc 145 FILE * const p_handle, const DEC_CbOpen p_cb);
dkato 0:ee40da884cfc 146 static void close_proc(flac_ctrl_t * const p_ctrl, const DEC_CbClose p_cb);
dkato 0:ee40da884cfc 147 static bool play_proc(flac_ctrl_t * const p_ctrl, const uint32_t buf_id,
dkato 0:ee40da884cfc 148 int32_t (* const p_buf)[TOTAL_SAMPLE_NUM], const uint32_t element_num);
dkato 0:ee40da884cfc 149 static bool pause_proc(const uint32_t buf_id,
dkato 0:ee40da884cfc 150 int32_t (* const p_buf)[TOTAL_SAMPLE_NUM], const uint32_t element_num);
dkato 0:ee40da884cfc 151 static uint32_t get_audio_data(flac_ctrl_t * const p_ctrl,
dkato 0:ee40da884cfc 152 int32_t * const p_buf, const uint32_t buf_num);
dkato 0:ee40da884cfc 153 static void data_out_callback(const bool result);
dkato 0:ee40da884cfc 154 static void write_callback(void * p_data, int32_t result, void * p_app_data);
dkato 0:ee40da884cfc 155 static void flush_callback(int32_t result);
dkato 0:ee40da884cfc 156 static bool send_mail(const DEC_MAIL_ID mail_id,
dkato 0:ee40da884cfc 157 const uint32_t param0, const uint32_t param1);
dkato 0:ee40da884cfc 158 static bool recv_mail(DEC_MAIL_ID * const p_mail_id,
dkato 0:ee40da884cfc 159 uint32_t * const p_param0, uint32_t * const p_param1);
dkato 0:ee40da884cfc 160 static void update_decode_stat(const SYS_PlayStat stat, play_info_t * const p_play_info);
dkato 0:ee40da884cfc 161 static void update_decode_playtime(const uint32_t play_time, play_info_t * const p_play_info);
dkato 0:ee40da884cfc 162 static void init_decode_playinfo(const uint32_t total_time, play_info_t * const p_play_info);
dkato 0:ee40da884cfc 163 static void notify_decode_stat(const play_info_t * const p_play_info);
dkato 0:ee40da884cfc 164
dkato 0:ee40da884cfc 165 void dec_thread(void const *argument)
dkato 0:ee40da884cfc 166 {
dkato 0:ee40da884cfc 167 dec_ctrl_t dec_ctrl; /* Control data of Decode thread */
dkato 0:ee40da884cfc 168 DEC_STATE dec_stat; /* Status of Decode thread */
dkato 0:ee40da884cfc 169 DEC_MAIL_ID mail_type;
dkato 0:ee40da884cfc 170 uint32_t mail_param[MAIL_PARAM_NUM];
dkato 0:ee40da884cfc 171 uint32_t buf_id;
dkato 0:ee40da884cfc 172 uint32_t buf_num;
dkato 0:ee40da884cfc 173 uint32_t time_code;
dkato 0:ee40da884cfc 174 bool result;
dkato 4:521ca1d224d2 175 #if defined(__ICCARM__)
dkato 5:c140dcdc2d45 176 static int32_t pcm_buf[PCM_BUF_NUM][TOTAL_SAMPLE_NUM] NC_BSS_SECT;
dkato 4:521ca1d224d2 177 #else
dkato 0:ee40da884cfc 178 static int32_t NC_BSS_SECT pcm_buf[PCM_BUF_NUM][TOTAL_SAMPLE_NUM];
dkato 4:521ca1d224d2 179 #endif
dkato 0:ee40da884cfc 180
dkato 0:ee40da884cfc 181 UNUSED_ARG(argument);
dkato 0:ee40da884cfc 182 dec_stat = DEC_ST_IDLE;
dkato 0:ee40da884cfc 183 while (1) {
dkato 0:ee40da884cfc 184 result = recv_mail(&mail_type, &mail_param[MAIL_PARAM0], &mail_param[MAIL_PARAM1]);
dkato 0:ee40da884cfc 185 if (result == true) {
dkato 0:ee40da884cfc 186 /* State transition processing */
dkato 0:ee40da884cfc 187 switch (dec_stat) {
dkato 0:ee40da884cfc 188 case DEC_ST_META_FIN: /* Finished the decoding until a metadata */
dkato 0:ee40da884cfc 189 if (mail_type == DEC_MAILID_PLAY) {
dkato 0:ee40da884cfc 190 time_code = flac_get_total_time(&dec_ctrl.flac_ctrl);
dkato 0:ee40da884cfc 191 init_decode_playinfo(time_code, &dec_ctrl.play_info);
dkato 0:ee40da884cfc 192 update_decode_stat(SYS_PLAYSTAT_PLAY, &dec_ctrl.play_info);
dkato 0:ee40da884cfc 193 (void) aud_req_data_out(&data_out_callback);
dkato 0:ee40da884cfc 194 dec_stat = DEC_ST_PLAY;
dkato 0:ee40da884cfc 195 } else if (mail_type == DEC_MAILID_CLOSE) {
dkato 0:ee40da884cfc 196 scux.ClearStop();
dkato 0:ee40da884cfc 197 close_proc(&dec_ctrl.flac_ctrl, (DEC_CbClose)mail_param[MAIL_CLOSE_CB]);
dkato 0:ee40da884cfc 198 dec_stat = DEC_ST_IDLE;
dkato 0:ee40da884cfc 199 } else {
dkato 0:ee40da884cfc 200 /* DO NOTHING */
dkato 0:ee40da884cfc 201 }
dkato 0:ee40da884cfc 202 break;
dkato 0:ee40da884cfc 203 case DEC_ST_PLAY: /* Decoder start */
dkato 0:ee40da884cfc 204 if (mail_type == DEC_MAILID_PAUSE_ON) {
dkato 0:ee40da884cfc 205 update_decode_stat(SYS_PLAYSTAT_PAUSE, &dec_ctrl.play_info);
dkato 0:ee40da884cfc 206 dec_stat = DEC_ST_PAUSE;
dkato 0:ee40da884cfc 207 } else if (mail_type == DEC_MAILID_STOP) {
dkato 0:ee40da884cfc 208 scux.ClearStop();
dkato 0:ee40da884cfc 209 (void) aud_req_zero_out();
dkato 0:ee40da884cfc 210 update_decode_stat(SYS_PLAYSTAT_STOP, &dec_ctrl.play_info);
dkato 0:ee40da884cfc 211 dec_stat = DEC_ST_STOP;
dkato 0:ee40da884cfc 212 } else if ((mail_type == DEC_MAILID_CB_AUD_DATA_OUT) ||
dkato 0:ee40da884cfc 213 (mail_type == DEC_MAILID_SCUX_WRITE_FIN)) {
dkato 0:ee40da884cfc 214 if (mail_type == DEC_MAILID_SCUX_WRITE_FIN) {
dkato 0:ee40da884cfc 215 buf_id = mail_param[MAIL_SCUX_WRITE_BUF_INDEX];
dkato 0:ee40da884cfc 216 buf_num = PCM_BUF_SINGLE;
dkato 0:ee40da884cfc 217 } else {
dkato 0:ee40da884cfc 218 buf_id = PCM_BUF_TOP_ID;
dkato 0:ee40da884cfc 219 buf_num = PCM_BUF_NUM;
dkato 0:ee40da884cfc 220 }
dkato 0:ee40da884cfc 221 result = play_proc(&dec_ctrl.flac_ctrl, buf_id, &pcm_buf[buf_id], buf_num);
dkato 0:ee40da884cfc 222 if (result == true) {
dkato 0:ee40da884cfc 223 time_code = flac_get_play_time(&dec_ctrl.flac_ctrl);
dkato 0:ee40da884cfc 224 update_decode_playtime(time_code, &dec_ctrl.play_info);
dkato 0:ee40da884cfc 225 /* "dec_stat" variable does not change. */
dkato 0:ee40da884cfc 226 } else {
dkato 0:ee40da884cfc 227 result = scux.FlushStop(&flush_callback);
dkato 0:ee40da884cfc 228 if (result == true) {
dkato 0:ee40da884cfc 229 dec_stat = DEC_ST_STOP_PREPARE;
dkato 0:ee40da884cfc 230 } else {
dkato 0:ee40da884cfc 231 /* Error occurred by SCUX driver. */
dkato 0:ee40da884cfc 232 (void) aud_req_zero_out();
dkato 0:ee40da884cfc 233 update_decode_stat(SYS_PLAYSTAT_STOP, &dec_ctrl.play_info);
dkato 0:ee40da884cfc 234 dec_stat = DEC_ST_STOP;
dkato 0:ee40da884cfc 235 }
dkato 0:ee40da884cfc 236 }
dkato 0:ee40da884cfc 237 } else {
dkato 0:ee40da884cfc 238 /* DO NOTHING */
dkato 0:ee40da884cfc 239 }
dkato 0:ee40da884cfc 240 break;
dkato 0:ee40da884cfc 241 case DEC_ST_PAUSE: /* Decoder pause */
dkato 0:ee40da884cfc 242 if (mail_type == DEC_MAILID_PAUSE_OFF) {
dkato 0:ee40da884cfc 243 update_decode_stat(SYS_PLAYSTAT_PLAY, &dec_ctrl.play_info);
dkato 0:ee40da884cfc 244 dec_stat = DEC_ST_PLAY;
dkato 0:ee40da884cfc 245 } else if (mail_type == DEC_MAILID_STOP) {
dkato 0:ee40da884cfc 246 scux.ClearStop();
dkato 0:ee40da884cfc 247 (void) aud_req_zero_out();
dkato 0:ee40da884cfc 248 update_decode_stat(SYS_PLAYSTAT_STOP, &dec_ctrl.play_info);
dkato 0:ee40da884cfc 249 dec_stat = DEC_ST_STOP;
dkato 0:ee40da884cfc 250 } else if ((mail_type == DEC_MAILID_CB_AUD_DATA_OUT) ||
dkato 0:ee40da884cfc 251 (mail_type == DEC_MAILID_SCUX_WRITE_FIN)) {
dkato 0:ee40da884cfc 252 if (mail_type == DEC_MAILID_SCUX_WRITE_FIN) {
dkato 0:ee40da884cfc 253 buf_id = mail_param[MAIL_SCUX_WRITE_BUF_INDEX];
dkato 0:ee40da884cfc 254 buf_num = PCM_BUF_SINGLE;
dkato 0:ee40da884cfc 255 } else {
dkato 0:ee40da884cfc 256 buf_id = PCM_BUF_TOP_ID;
dkato 0:ee40da884cfc 257 buf_num = PCM_BUF_NUM;
dkato 0:ee40da884cfc 258 }
dkato 0:ee40da884cfc 259 result = pause_proc(buf_id, &pcm_buf[buf_id], buf_num);
dkato 0:ee40da884cfc 260 if (result == true) {
dkato 0:ee40da884cfc 261 /* "dec_stat" variable does not change. */
dkato 0:ee40da884cfc 262 } else {
dkato 0:ee40da884cfc 263 result = scux.FlushStop(&flush_callback);
dkato 0:ee40da884cfc 264 if (result == true) {
dkato 0:ee40da884cfc 265 dec_stat = DEC_ST_STOP_PREPARE;
dkato 0:ee40da884cfc 266 } else {
dkato 0:ee40da884cfc 267 /* Error occurred by SCUX driver. */
dkato 0:ee40da884cfc 268 (void) aud_req_zero_out();
dkato 0:ee40da884cfc 269 update_decode_stat(SYS_PLAYSTAT_STOP, &dec_ctrl.play_info);
dkato 0:ee40da884cfc 270 dec_stat = DEC_ST_STOP;
dkato 0:ee40da884cfc 271 }
dkato 0:ee40da884cfc 272 }
dkato 0:ee40da884cfc 273 } else {
dkato 0:ee40da884cfc 274 /* DO NOTHING */
dkato 0:ee40da884cfc 275 }
dkato 0:ee40da884cfc 276 break;
dkato 0:ee40da884cfc 277 case DEC_ST_STOP_PREPARE: /* Preparing of decoder stop */
dkato 0:ee40da884cfc 278 if (mail_type == DEC_MAILID_SCUX_FLUSH_FIN) {
dkato 0:ee40da884cfc 279 (void) aud_req_zero_out();
dkato 0:ee40da884cfc 280 update_decode_stat(SYS_PLAYSTAT_STOP, &dec_ctrl.play_info);
dkato 0:ee40da884cfc 281 dec_stat = DEC_ST_STOP;
dkato 0:ee40da884cfc 282 } else {
dkato 0:ee40da884cfc 283 /* DO NOTHING */
dkato 0:ee40da884cfc 284 }
dkato 0:ee40da884cfc 285 break;
dkato 0:ee40da884cfc 286 case DEC_ST_STOP: /* Decoder stop */
dkato 0:ee40da884cfc 287 if (mail_type == DEC_MAILID_CLOSE) {
dkato 0:ee40da884cfc 288 close_proc(&dec_ctrl.flac_ctrl, (DEC_CbClose)mail_param[MAIL_CLOSE_CB]);
dkato 0:ee40da884cfc 289 dec_stat = DEC_ST_IDLE;
dkato 0:ee40da884cfc 290 } else {
dkato 0:ee40da884cfc 291 /* DO NOTHING */
dkato 0:ee40da884cfc 292 }
dkato 0:ee40da884cfc 293 break;
dkato 0:ee40da884cfc 294 case DEC_ST_IDLE: /* Idle */
dkato 0:ee40da884cfc 295 default:
dkato 0:ee40da884cfc 296 if (mail_type == DEC_MAILID_OPEN) {
dkato 0:ee40da884cfc 297 result = open_proc(&dec_ctrl.flac_ctrl,
dkato 0:ee40da884cfc 298 (FILE*)mail_param[MAIL_OPEN_FILE],
dkato 0:ee40da884cfc 299 (DEC_CbOpen)mail_param[MAIL_OPEN_CB]);
dkato 0:ee40da884cfc 300 if (result == true) {
dkato 0:ee40da884cfc 301 dec_stat = DEC_ST_META_FIN;
dkato 0:ee40da884cfc 302 } else {
dkato 0:ee40da884cfc 303 /* "dec_stat" variable does not change. */
dkato 0:ee40da884cfc 304 }
dkato 0:ee40da884cfc 305 } else {
dkato 0:ee40da884cfc 306 dec_stat = DEC_ST_IDLE; /* This is fail-safe processing. */
dkato 0:ee40da884cfc 307 }
dkato 0:ee40da884cfc 308 break;
dkato 0:ee40da884cfc 309 }
dkato 0:ee40da884cfc 310 }
dkato 0:ee40da884cfc 311 }
dkato 0:ee40da884cfc 312 }
dkato 0:ee40da884cfc 313
dkato 0:ee40da884cfc 314 bool dec_open(FILE * const p_handle, const DEC_CbOpen p_cb)
dkato 0:ee40da884cfc 315 {
dkato 0:ee40da884cfc 316 bool ret = false;
dkato 0:ee40da884cfc 317
dkato 0:ee40da884cfc 318 if ((p_handle != NULL) && (p_cb != NULL)) {
dkato 0:ee40da884cfc 319 ret = send_mail(DEC_MAILID_OPEN, (uint32_t)p_cb, (uint32_t)p_handle);
dkato 0:ee40da884cfc 320 }
dkato 0:ee40da884cfc 321 return ret;
dkato 0:ee40da884cfc 322 }
dkato 0:ee40da884cfc 323
dkato 0:ee40da884cfc 324 bool dec_play(void)
dkato 0:ee40da884cfc 325 {
dkato 0:ee40da884cfc 326 bool ret = false;
dkato 0:ee40da884cfc 327
dkato 0:ee40da884cfc 328 ret = send_mail(DEC_MAILID_PLAY, MAIL_PARAM_NON, MAIL_PARAM_NON);
dkato 0:ee40da884cfc 329
dkato 0:ee40da884cfc 330 return ret;
dkato 0:ee40da884cfc 331 }
dkato 0:ee40da884cfc 332
dkato 0:ee40da884cfc 333 bool dec_pause_on(void)
dkato 0:ee40da884cfc 334 {
dkato 0:ee40da884cfc 335 bool ret = false;
dkato 0:ee40da884cfc 336
dkato 0:ee40da884cfc 337 ret = send_mail(DEC_MAILID_PAUSE_ON, MAIL_PARAM_NON, MAIL_PARAM_NON);
dkato 0:ee40da884cfc 338
dkato 0:ee40da884cfc 339 return ret;
dkato 0:ee40da884cfc 340 }
dkato 0:ee40da884cfc 341
dkato 0:ee40da884cfc 342 bool dec_pause_off(void)
dkato 0:ee40da884cfc 343 {
dkato 0:ee40da884cfc 344 bool ret = false;
dkato 0:ee40da884cfc 345
dkato 0:ee40da884cfc 346 ret = send_mail(DEC_MAILID_PAUSE_OFF, MAIL_PARAM_NON, MAIL_PARAM_NON);
dkato 0:ee40da884cfc 347
dkato 0:ee40da884cfc 348 return ret;
dkato 0:ee40da884cfc 349 }
dkato 0:ee40da884cfc 350
dkato 0:ee40da884cfc 351 bool dec_stop(void)
dkato 0:ee40da884cfc 352 {
dkato 0:ee40da884cfc 353 bool ret;
dkato 0:ee40da884cfc 354
dkato 0:ee40da884cfc 355 ret = send_mail(DEC_MAILID_STOP, MAIL_PARAM_NON, MAIL_PARAM_NON);
dkato 0:ee40da884cfc 356
dkato 0:ee40da884cfc 357 return ret;
dkato 0:ee40da884cfc 358 }
dkato 0:ee40da884cfc 359
dkato 0:ee40da884cfc 360 bool dec_close(const DEC_CbClose p_cb)
dkato 0:ee40da884cfc 361 {
dkato 0:ee40da884cfc 362 bool ret = false;
dkato 0:ee40da884cfc 363
dkato 0:ee40da884cfc 364 if (p_cb != NULL) {
dkato 0:ee40da884cfc 365 ret = send_mail(DEC_MAILID_CLOSE, (uint32_t)p_cb, MAIL_PARAM_NON);
dkato 0:ee40da884cfc 366 }
dkato 0:ee40da884cfc 367 return ret;
dkato 0:ee40da884cfc 368 }
dkato 0:ee40da884cfc 369
dkato 0:ee40da884cfc 370 bool dec_scux_read(void * const p_data, const uint32_t data_size,
dkato 0:ee40da884cfc 371 const rbsp_data_conf_t * const p_data_conf)
dkato 0:ee40da884cfc 372 {
dkato 0:ee40da884cfc 373 bool ret = false;
dkato 0:ee40da884cfc 374 int32_t result;
dkato 0:ee40da884cfc 375
dkato 0:ee40da884cfc 376 result = scux.read(p_data, data_size, p_data_conf);
dkato 0:ee40da884cfc 377 if (result == ESUCCESS) {
dkato 0:ee40da884cfc 378 ret = true;
dkato 0:ee40da884cfc 379 }
dkato 0:ee40da884cfc 380 return ret;
dkato 0:ee40da884cfc 381 }
dkato 0:ee40da884cfc 382
dkato 0:ee40da884cfc 383 /** Executes the opening process of the decoder
dkato 0:ee40da884cfc 384 *
dkato 0:ee40da884cfc 385 * @param p_ctrl Pointer to the control data of FLAC module.
dkato 0:ee40da884cfc 386 * @param p_handle Pointer to the handle of FLAC file.
dkato 0:ee40da884cfc 387 * @param p_cb Pointer to the callback for notification of the process result.
dkato 0:ee40da884cfc 388 *
dkato 0:ee40da884cfc 389 * @returns
dkato 0:ee40da884cfc 390 * Results of process. true is success. false is failure.
dkato 0:ee40da884cfc 391 */
dkato 0:ee40da884cfc 392 static bool open_proc(flac_ctrl_t * const p_ctrl, FILE * const p_handle, const DEC_CbOpen p_cb)
dkato 0:ee40da884cfc 393 {
dkato 0:ee40da884cfc 394 bool ret = false;
dkato 0:ee40da884cfc 395 bool result;
dkato 0:ee40da884cfc 396 scux_src_usr_cfg_t conf;
dkato 0:ee40da884cfc 397
dkato 0:ee40da884cfc 398 if ((p_ctrl != NULL) && (p_handle != NULL) && (p_cb != NULL)) {
dkato 0:ee40da884cfc 399 result = flac_open(p_handle, p_ctrl);
dkato 0:ee40da884cfc 400 if (result == true) {
dkato 0:ee40da884cfc 401 /* Sets SCUX config */
dkato 0:ee40da884cfc 402 conf.src_enable = true;
dkato 0:ee40da884cfc 403 conf.word_len = SCUX_DATA_LEN_24;
dkato 2:d9fca8cd7f03 404 conf.mode_sync = true;
dkato 0:ee40da884cfc 405 conf.input_rate = p_ctrl->sample_rate;
dkato 0:ee40da884cfc 406 conf.output_rate = DEC_OUTPUT_SAMPLE_RATE;
dkato 0:ee40da884cfc 407 conf.select_in_data_ch[0] = SELECT_IN_DATA_CH_0;
dkato 0:ee40da884cfc 408 conf.select_in_data_ch[1] = SELECT_IN_DATA_CH_1;
dkato 0:ee40da884cfc 409 result = scux.SetSrcCfg(&conf);
dkato 0:ee40da884cfc 410 if (result == true) {
dkato 0:ee40da884cfc 411 ret = scux.TransStart();
dkato 0:ee40da884cfc 412 }
dkato 0:ee40da884cfc 413 }
dkato 0:ee40da884cfc 414 p_cb(ret, p_ctrl->sample_rate, p_ctrl->channel_num);
dkato 0:ee40da884cfc 415 }
dkato 0:ee40da884cfc 416 return ret;
dkato 0:ee40da884cfc 417 }
dkato 0:ee40da884cfc 418
dkato 0:ee40da884cfc 419 /** Executes the closing process of the decoder
dkato 0:ee40da884cfc 420 *
dkato 0:ee40da884cfc 421 * @param p_ctrl Pointer to the control data of FLAC module.
dkato 0:ee40da884cfc 422 * @param p_cb Pointer to the callback for notification of the process result.
dkato 0:ee40da884cfc 423 *
dkato 0:ee40da884cfc 424 * @returns
dkato 0:ee40da884cfc 425 * Results of process. true is success. false is failure.
dkato 0:ee40da884cfc 426 */
dkato 0:ee40da884cfc 427 static void close_proc(flac_ctrl_t * const p_ctrl, const DEC_CbClose p_cb)
dkato 0:ee40da884cfc 428 {
dkato 0:ee40da884cfc 429 if ((p_ctrl != NULL) && (p_cb != NULL)) {
dkato 0:ee40da884cfc 430 flac_close(p_ctrl);
dkato 0:ee40da884cfc 431 p_cb();
dkato 0:ee40da884cfc 432 }
dkato 0:ee40da884cfc 433 }
dkato 0:ee40da884cfc 434
dkato 0:ee40da884cfc 435 /** Executes the starting process of the pause
dkato 0:ee40da884cfc 436 *
dkato 0:ee40da884cfc 437 * @param p_ctrl Pointer to the control data of FLAC module.
dkato 0:ee40da884cfc 438 * @param buf_id Index of PCM buffer array.
dkato 0:ee40da884cfc 439 * @param p_buf Pointer to PCM buffer array to use in this process.
dkato 0:ee40da884cfc 440 * @param element_num Elements number of PCM buffer array.
dkato 0:ee40da884cfc 441 *
dkato 0:ee40da884cfc 442 * @returns
dkato 0:ee40da884cfc 443 * Results of process. true is success. false is failure.
dkato 0:ee40da884cfc 444 */
dkato 0:ee40da884cfc 445 static bool pause_proc(const uint32_t buf_id,
dkato 0:ee40da884cfc 446 int32_t (* const p_buf)[TOTAL_SAMPLE_NUM], const uint32_t element_num)
dkato 0:ee40da884cfc 447 {
dkato 0:ee40da884cfc 448 bool ret = false;
dkato 0:ee40da884cfc 449 uint32_t i;
dkato 0:ee40da884cfc 450 int32_t result;
dkato 0:ee40da884cfc 451 const uint32_t pause_data_size = SAMPLE_NUM_PER_UNIT_MS * sizeof(*p_buf[0]);
dkato 0:ee40da884cfc 452 rbsp_data_conf_t cb_conf = {
dkato 0:ee40da884cfc 453 &write_callback,
dkato 0:ee40da884cfc 454 NULL
dkato 0:ee40da884cfc 455 };
dkato 0:ee40da884cfc 456
dkato 0:ee40da884cfc 457 if ((p_buf != NULL) && (element_num > 0u) &&
dkato 0:ee40da884cfc 458 (element_num <= PCM_BUF_NUM) && ((buf_id + element_num) <= PCM_BUF_NUM)) {
dkato 0:ee40da884cfc 459 /* Audio output process */
dkato 0:ee40da884cfc 460 result = ESUCCESS;
dkato 0:ee40da884cfc 461 for (i = 0; (i < element_num) && (result == ESUCCESS); i++) {
dkato 0:ee40da884cfc 462 (void) memset(&p_buf[i], 0, pause_data_size);
dkato 0:ee40da884cfc 463 cb_conf.p_app_data = (void *)(buf_id + i);
dkato 0:ee40da884cfc 464 result = scux.write(&p_buf[i], pause_data_size, &cb_conf);
dkato 0:ee40da884cfc 465 }
dkato 0:ee40da884cfc 466 if (result == ESUCCESS) {
dkato 0:ee40da884cfc 467 ret = true;
dkato 0:ee40da884cfc 468 }
dkato 0:ee40da884cfc 469 }
dkato 0:ee40da884cfc 470 return ret;
dkato 0:ee40da884cfc 471 }
dkato 0:ee40da884cfc 472
dkato 0:ee40da884cfc 473 /** Executes the starting process of the playback
dkato 0:ee40da884cfc 474 *
dkato 0:ee40da884cfc 475 * @param p_ctrl Pointer to the control data of FLAC module.
dkato 0:ee40da884cfc 476 * @param buf_id Index of PCM buffer array.
dkato 0:ee40da884cfc 477 * @param p_buf Pointer to PCM buffer array to use in this process.
dkato 0:ee40da884cfc 478 * @param element_num Elements number of PCM buffer array.
dkato 0:ee40da884cfc 479 *
dkato 0:ee40da884cfc 480 * @returns
dkato 0:ee40da884cfc 481 * Results of process. true is success. false is failure.
dkato 0:ee40da884cfc 482 */
dkato 0:ee40da884cfc 483 static bool play_proc(flac_ctrl_t * const p_ctrl, const uint32_t buf_id,
dkato 0:ee40da884cfc 484 int32_t (* const p_buf)[TOTAL_SAMPLE_NUM], const uint32_t element_num)
dkato 0:ee40da884cfc 485 {
dkato 0:ee40da884cfc 486 bool ret = false;
dkato 0:ee40da884cfc 487 int32_t result;
dkato 0:ee40da884cfc 488 uint32_t i;
dkato 0:ee40da884cfc 489 uint32_t decoded_cnt;
dkato 0:ee40da884cfc 490 uint32_t num;
dkato 0:ee40da884cfc 491 uint32_t read_byte[PCM_BUF_NUM];
dkato 0:ee40da884cfc 492 rbsp_data_conf_t cb_conf = {
dkato 0:ee40da884cfc 493 &write_callback,
dkato 0:ee40da884cfc 494 NULL
dkato 0:ee40da884cfc 495 };
dkato 0:ee40da884cfc 496
dkato 0:ee40da884cfc 497 if ((p_ctrl != NULL) && (p_buf != NULL) && (element_num > 0u) &&
dkato 0:ee40da884cfc 498 (element_num <= PCM_BUF_NUM) && ((buf_id + element_num) <= PCM_BUF_NUM)) {
dkato 0:ee40da884cfc 499 /* FLAC decoder process */
dkato 0:ee40da884cfc 500 decoded_cnt = 0u;
dkato 0:ee40da884cfc 501 do {
dkato 0:ee40da884cfc 502 num = get_audio_data(p_ctrl, p_buf[decoded_cnt], sizeof(p_buf[0])/sizeof(*p_buf[0]));
dkato 0:ee40da884cfc 503 read_byte[decoded_cnt] = num * sizeof(num);
dkato 0:ee40da884cfc 504 if (num > 0u) {
dkato 0:ee40da884cfc 505 decoded_cnt++;
dkato 0:ee40da884cfc 506 }
dkato 0:ee40da884cfc 507 } while ((decoded_cnt < element_num) && (num > 0u));
dkato 0:ee40da884cfc 508 /* Audio output process */
dkato 0:ee40da884cfc 509 if (decoded_cnt > 0u) {
dkato 0:ee40da884cfc 510 result = ESUCCESS;
dkato 0:ee40da884cfc 511 for (i = 0; (i < decoded_cnt) && (result == ESUCCESS); i++) {
dkato 0:ee40da884cfc 512 cb_conf.p_app_data = (void *)(buf_id + i);
dkato 0:ee40da884cfc 513 result = scux.write(&p_buf[i], read_byte[i], &cb_conf);
dkato 0:ee40da884cfc 514 }
dkato 0:ee40da884cfc 515 if (result == ESUCCESS) {
dkato 0:ee40da884cfc 516 ret = true;
dkato 0:ee40da884cfc 517 }
dkato 0:ee40da884cfc 518 }
dkato 0:ee40da884cfc 519 }
dkato 0:ee40da884cfc 520 return ret;
dkato 0:ee40da884cfc 521 }
dkato 0:ee40da884cfc 522
dkato 0:ee40da884cfc 523 /** Gets the decoded data from FLAC decoder library
dkato 0:ee40da884cfc 524 *
dkato 0:ee40da884cfc 525 * @param p_ctrl Pointer to the control data of FLAC module.
dkato 0:ee40da884cfc 526 * @param p_buf Pointer to PCM buffer array to store the decoded data.
dkato 0:ee40da884cfc 527 * @param buf_num Elements number of PCM buffer array.
dkato 0:ee40da884cfc 528 *
dkato 0:ee40da884cfc 529 * @returns
dkato 0:ee40da884cfc 530 * Elements number of decoded data.
dkato 0:ee40da884cfc 531 */
dkato 0:ee40da884cfc 532 static uint32_t get_audio_data(flac_ctrl_t * const p_ctrl,
dkato 0:ee40da884cfc 533 int32_t * const p_buf, const uint32_t buf_num)
dkato 0:ee40da884cfc 534 {
dkato 0:ee40da884cfc 535 uint32_t read_cnt = 0u;
dkato 0:ee40da884cfc 536 bool result;
dkato 0:ee40da884cfc 537
dkato 0:ee40da884cfc 538 if ((p_ctrl != NULL) && (p_buf != NULL) && (buf_num > 0u)) {
dkato 0:ee40da884cfc 539 result = flac_set_pcm_buf(p_ctrl, p_buf, buf_num);
dkato 0:ee40da884cfc 540 while ((result == true) && ((read_cnt + MAX_SAMPLE_PER_1BLOCK) <= buf_num)) {
dkato 0:ee40da884cfc 541 result = flac_decode(p_ctrl);
dkato 0:ee40da884cfc 542 read_cnt = flac_get_pcm_cnt(p_ctrl);
dkato 0:ee40da884cfc 543 }
dkato 0:ee40da884cfc 544 }
dkato 0:ee40da884cfc 545 return read_cnt;
dkato 0:ee40da884cfc 546 }
dkato 0:ee40da884cfc 547
dkato 0:ee40da884cfc 548 /** Callback function of Audio Out Thread
dkato 0:ee40da884cfc 549 *
dkato 0:ee40da884cfc 550 * @param result Result of the process of Audio Out Thread
dkato 0:ee40da884cfc 551 */
dkato 0:ee40da884cfc 552 static void data_out_callback(const bool result)
dkato 0:ee40da884cfc 553 {
dkato 0:ee40da884cfc 554 (void) send_mail(DEC_MAILID_CB_AUD_DATA_OUT, (uint32_t)result, MAIL_PARAM_NON);
dkato 0:ee40da884cfc 555 }
dkato 0:ee40da884cfc 556
dkato 0:ee40da884cfc 557 /** Callback function of SCUX driver
dkato 0:ee40da884cfc 558 *
dkato 0:ee40da884cfc 559 * @param p_data Pointer to PCM byffer array.
dkato 0:ee40da884cfc 560 * @param result Result of the process.
dkato 0:ee40da884cfc 561 * @param p_app_data The control ID of PCM buffer.
dkato 0:ee40da884cfc 562 */
dkato 0:ee40da884cfc 563 static void write_callback(void * p_data, int32_t result, void * p_app_data)
dkato 0:ee40da884cfc 564 {
dkato 0:ee40da884cfc 565 const uint32_t buf_id = (uint32_t)p_app_data;
dkato 0:ee40da884cfc 566 bool flag_result;
dkato 0:ee40da884cfc 567
dkato 0:ee40da884cfc 568 UNUSED_ARG(p_data);
dkato 0:ee40da884cfc 569 if (result > 0) {
dkato 0:ee40da884cfc 570 flag_result = true;
dkato 0:ee40da884cfc 571 } else {
dkato 0:ee40da884cfc 572 flag_result = false;
dkato 0:ee40da884cfc 573 }
dkato 0:ee40da884cfc 574 (void) send_mail(DEC_MAILID_SCUX_WRITE_FIN, (uint32_t)flag_result, buf_id);
dkato 0:ee40da884cfc 575 }
dkato 0:ee40da884cfc 576
dkato 0:ee40da884cfc 577 /** Callback function of SCUX driver
dkato 0:ee40da884cfc 578 *
dkato 0:ee40da884cfc 579 * @param result Result of the process.
dkato 0:ee40da884cfc 580 */
dkato 0:ee40da884cfc 581 static void flush_callback(int32_t result)
dkato 0:ee40da884cfc 582 {
dkato 0:ee40da884cfc 583 bool flag_result;
dkato 0:ee40da884cfc 584
dkato 0:ee40da884cfc 585 if (result > 0) {
dkato 0:ee40da884cfc 586 flag_result = true;
dkato 0:ee40da884cfc 587 } else {
dkato 0:ee40da884cfc 588 flag_result = false;
dkato 0:ee40da884cfc 589 }
dkato 0:ee40da884cfc 590 (void) send_mail(DEC_MAILID_SCUX_FLUSH_FIN, (uint32_t)flag_result, MAIL_PARAM_NON);
dkato 0:ee40da884cfc 591 }
dkato 0:ee40da884cfc 592
dkato 0:ee40da884cfc 593 /** Sends the mail to Decode thread
dkato 0:ee40da884cfc 594 *
dkato 0:ee40da884cfc 595 * @param mail_id Mail ID
dkato 0:ee40da884cfc 596 * @param param0 Parameter 0 of this mail
dkato 0:ee40da884cfc 597 * @param param1 Parameter 1 of this mail
dkato 0:ee40da884cfc 598 *
dkato 0:ee40da884cfc 599 * @returns
dkato 0:ee40da884cfc 600 * Results of process. true is success. false is failure.
dkato 0:ee40da884cfc 601 */
dkato 0:ee40da884cfc 602 static bool send_mail(const DEC_MAIL_ID mail_id,
dkato 0:ee40da884cfc 603 const uint32_t param0, const uint32_t param1)
dkato 0:ee40da884cfc 604 {
dkato 0:ee40da884cfc 605 bool ret = false;
dkato 0:ee40da884cfc 606 osStatus stat;
dkato 0:ee40da884cfc 607 dec_mail_t * const p_mail = mail_box.alloc();
dkato 0:ee40da884cfc 608
dkato 0:ee40da884cfc 609 if (p_mail != NULL) {
dkato 0:ee40da884cfc 610 p_mail->mail_id = mail_id;
dkato 0:ee40da884cfc 611 p_mail->param[MAIL_PARAM0] = param0;
dkato 0:ee40da884cfc 612 p_mail->param[MAIL_PARAM1] = param1;
dkato 0:ee40da884cfc 613 stat = mail_box.put(p_mail);
dkato 0:ee40da884cfc 614 if (stat == osOK) {
dkato 0:ee40da884cfc 615 ret = true;
dkato 0:ee40da884cfc 616 } else {
dkato 0:ee40da884cfc 617 (void) mail_box.free(p_mail);
dkato 0:ee40da884cfc 618 }
dkato 0:ee40da884cfc 619 }
dkato 0:ee40da884cfc 620 return ret;
dkato 0:ee40da884cfc 621 }
dkato 0:ee40da884cfc 622
dkato 0:ee40da884cfc 623 /** Receives the mail to Decode thread
dkato 0:ee40da884cfc 624 *
dkato 0:ee40da884cfc 625 * @param p_mail_id Pointer to the variable to store the mail ID
dkato 0:ee40da884cfc 626 * @param p_param0 Pointer to the variable to store the parameter 0 of this mail
dkato 0:ee40da884cfc 627 * @param p_param1 Pointer to the variable to store the parameter 1 of this mail
dkato 0:ee40da884cfc 628 *
dkato 0:ee40da884cfc 629 * @returns
dkato 0:ee40da884cfc 630 * Results of process. true is success. false is failure.
dkato 0:ee40da884cfc 631 */
dkato 0:ee40da884cfc 632 static bool recv_mail(DEC_MAIL_ID * const p_mail_id,
dkato 0:ee40da884cfc 633 uint32_t * const p_param0, uint32_t * const p_param1)
dkato 0:ee40da884cfc 634 {
dkato 0:ee40da884cfc 635 bool ret = false;
dkato 0:ee40da884cfc 636 osEvent evt;
dkato 0:ee40da884cfc 637 dec_mail_t *p_mail;
dkato 0:ee40da884cfc 638
dkato 0:ee40da884cfc 639 if ((p_mail_id != NULL) && (p_param0 != NULL) && (p_param1 != NULL)) {
dkato 0:ee40da884cfc 640 evt = mail_box.get();
dkato 0:ee40da884cfc 641 if (evt.status == osEventMail) {
dkato 0:ee40da884cfc 642 p_mail = (dec_mail_t *)evt.value.p;
dkato 0:ee40da884cfc 643 if (p_mail != NULL) {
dkato 0:ee40da884cfc 644 *p_mail_id = p_mail->mail_id;
dkato 0:ee40da884cfc 645 *p_param0 = p_mail->param[MAIL_PARAM0];
dkato 0:ee40da884cfc 646 *p_param1 = p_mail->param[MAIL_PARAM1];
dkato 0:ee40da884cfc 647 ret = true;
dkato 0:ee40da884cfc 648 }
dkato 0:ee40da884cfc 649 (void) mail_box.free(p_mail);
dkato 0:ee40da884cfc 650 }
dkato 0:ee40da884cfc 651 }
dkato 0:ee40da884cfc 652 return ret;
dkato 0:ee40da884cfc 653 }
dkato 0:ee40da884cfc 654
dkato 0:ee40da884cfc 655 /** Updates the status of Decode thread
dkato 0:ee40da884cfc 656 *
dkato 0:ee40da884cfc 657 * @param stat New status of Decode thread
dkato 0:ee40da884cfc 658 * @param p_play_info Pointer to the playback information of the playback file
dkato 0:ee40da884cfc 659 */
dkato 0:ee40da884cfc 660 static void update_decode_stat(const SYS_PlayStat stat, play_info_t * const p_play_info)
dkato 0:ee40da884cfc 661 {
dkato 0:ee40da884cfc 662 if (p_play_info != NULL) {
dkato 0:ee40da884cfc 663 if (p_play_info->play_stat != stat) {
dkato 0:ee40da884cfc 664 p_play_info->play_stat = stat;
dkato 0:ee40da884cfc 665 notify_decode_stat(p_play_info);
dkato 0:ee40da884cfc 666 }
dkato 0:ee40da884cfc 667 }
dkato 0:ee40da884cfc 668 }
dkato 0:ee40da884cfc 669
dkato 0:ee40da884cfc 670 /** Updates the playback time
dkato 0:ee40da884cfc 671 *
dkato 0:ee40da884cfc 672 * @param play_time Current playback time
dkato 0:ee40da884cfc 673 * @param p_play_info Pointer to the playback information of the playback file
dkato 0:ee40da884cfc 674 */
dkato 0:ee40da884cfc 675 static void update_decode_playtime(const uint32_t play_time, play_info_t * const p_play_info)
dkato 0:ee40da884cfc 676 {
dkato 0:ee40da884cfc 677 if (p_play_info != NULL) {
dkato 0:ee40da884cfc 678 if (p_play_info->play_time != play_time) {
dkato 0:ee40da884cfc 679 p_play_info->play_time = play_time;
dkato 0:ee40da884cfc 680 notify_decode_stat(p_play_info);
dkato 0:ee40da884cfc 681 }
dkato 0:ee40da884cfc 682 }
dkato 0:ee40da884cfc 683 }
dkato 0:ee40da884cfc 684
dkato 0:ee40da884cfc 685 /** Initialises the playback information
dkato 0:ee40da884cfc 686 *
dkato 0:ee40da884cfc 687 * @param total_time Total playback time
dkato 0:ee40da884cfc 688 * @param p_play_info Pointer to the playback information of the playback file
dkato 0:ee40da884cfc 689 */
dkato 0:ee40da884cfc 690 static void init_decode_playinfo(const uint32_t total_time, play_info_t * const p_play_info)
dkato 0:ee40da884cfc 691 {
dkato 0:ee40da884cfc 692 if (p_play_info != NULL) {
dkato 0:ee40da884cfc 693 p_play_info->play_stat = SYS_PLAYSTAT_STOP;
dkato 0:ee40da884cfc 694 p_play_info->play_time = 0u;
dkato 0:ee40da884cfc 695 p_play_info->total_time = total_time;
dkato 0:ee40da884cfc 696 }
dkato 0:ee40da884cfc 697 }
dkato 0:ee40da884cfc 698
dkato 0:ee40da884cfc 699 /** Notifies Main thread of the status of Decode thread
dkato 0:ee40da884cfc 700 *
dkato 0:ee40da884cfc 701 * @param p_play_info Pointer to the playback information of the playback file
dkato 0:ee40da884cfc 702 */
dkato 0:ee40da884cfc 703 static void notify_decode_stat(const play_info_t * const p_play_info)
dkato 0:ee40da884cfc 704 {
dkato 0:ee40da884cfc 705 if (p_play_info != NULL) {
dkato 0:ee40da884cfc 706 (void) sys_notify_play_time(p_play_info->play_stat,
dkato 0:ee40da884cfc 707 p_play_info->play_time, p_play_info->total_time);
dkato 0:ee40da884cfc 708 }
dkato 0:ee40da884cfc 709 }