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