The "GR-PEACH_Audio_Playback_7InchLCD_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:   GR-PEACH_video R_BSP TLV320_RBSP USBHost_custom

Fork of GR-PEACH_Audio_Playback_Sample by Renesas

Note

For a sample program of without LCD Board, please refer to GR-PEACH_Audio_Playback_Sample.

Introduction

The "GR-PEACH_Audio_Playback_7InchLCD_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/1050186/lcd_figure1_1.png

1.2 Pin Definitions

Table 1.1 shows the pins used in this sample code.

/media/uploads/1050186/lcd_table1_1.png

2. Sample Code Operating Environment

In order to operate this sample code, GR-PEACH, Audio Camera Shield and 7.1 inch LCD Shield must be needed. For details on Audio Camera Shield and 7.1 inch LCD Shield, please refer to the following links, respectively:

In this section, it is described that how board is configured and to control audio playback via command line and touch screen.

2.1 Operating Environment

Figure 2.1 shows the overview of the operating environment for this sample code.

/media/uploads/1050186/lcd_figure2_1.png

Figure 2.2 and 2.3 show how to configure GR-PEACH, Audio Camera Shield and 7.1 inch LCD shield when using USB0 and USB1, respectively.

/media/uploads/1050186/lcd_figure2_2.png /media/uploads/1050186/lcd_figure2_3.png

Table 2.1 lists the overview of Graphical User Interface (GUI) of this sample code.

/media/uploads/1050186/lcd_table2_1.png

2.2 List of User Operations

Table 2.2 shows the relationship among Audio Playback, Command Line and Onboard Switch.

/media/uploads/1050186/lcd_table2_2.png

3. Function Outline

Table 3.1, 3.2 and 3.3 shows the overview of functions implemented in this sample code.

/media/uploads/1050186/lcd_table3_1.png /media/uploads/1050186/lcd_table3_2.png /media/uploads/1050186/lcd_table3_3.png /media/uploads/1050186/lcd_figure3_1.png

3.1 Playback Control

This sample program supports the operation "play", "pause", "stop", "play next song" and "play previous song".

3.2 Trick Play Control

In order to enable/disable Repeat Mode, user need to type "repeat" on command line or click the corresponding icon shown in Table 2.2. By derault, Repeat Mode is enabled. When Repeat Mode is enabled, the first song is played back after the playback of the last song is finished. Otherwise, the playback is shopped when finishing to play back the last song.

3.3 How to see Song Information

The information of the song being played back can be seen by typing playinfo on command line. Table 3.4 lists the items user can see on the terminal.

/media/uploads/dkato/audioplayback_table3_4.png

3.4 How to analyze the folder structure in USB stick

In this sample code, the folder structure in USB stick is analyzed in the breadth-first order. Table 3.5 shows how the files in USB stick are numbered.

/media/uploads/dkato/audioplayback_table3_5.png

4.Others

4.1 Serial Communication Setting

With respect to the default serial communication related setting on mbed, please refer to the follwing link:
https://developer.mbed.org/teams/Renesas/wiki/GR-PEACH-Getting-Started#install-the-usb-serial-communication
Please set up the terminal software you would like to use on your PC in consideration of the above. For example, 9600 should be specified for the baud rate on the terminal in order to control this sample via command line.

4.2 Necessary modification when using GCC ARM Embedded

If you would like to use GCC ARM Embedded, you must revise the following linker script incorporated in mbed OS 5 package as follows:

  • Linker Script to be modified
    $(PROJECT_ROOT)/mbed-os/targets/TARGET_RENESAS/TARGET_RZ_A1H/device/TOOLCHAIN_GCC_ARM/RZA1H.ld

    Please note that $(PROJECT_ROOT) in the above denotes the root directory of this sample code

  • Before Modification

RZA1H.ld

/* Linker script for mbed RZ_A1H */

/* Linker script to configure memory regions. */
MEMORY
{
  ROM   (rx)  : ORIGIN = 0x00000000, LENGTH = 0x02000000
  BOOT_LOADER (rx) : ORIGIN = 0x18000000, LENGTH = 0x00004000 
  SFLASH (rx) : ORIGIN = 0x18004000, LENGTH = 0x07FFC000 
  L_TTB (rw)  : ORIGIN = 0x20000000, LENGTH = 0x00004000 
  RAM (rwx) : ORIGIN = 0x20020000, LENGTH = 0x00700000
  RAM_NC (rwx) : ORIGIN = 0x20900000, LENGTH = 0x00100000
}
(snip)
  • After Modification

RZA1H.ld

/* Linker script for mbed RZ_A1H */

/* Linker script to configure memory regions. */
MEMORY
{
  ROM   (rx)  : ORIGIN = 0x00000000, LENGTH = 0x02000000
  BOOT_LOADER (rx) : ORIGIN = 0x18000000, LENGTH = 0x00004000 
  SFLASH (rx) : ORIGIN = 0x18004000, LENGTH = 0x07FFC000 
  L_TTB (rw)  : ORIGIN = 0x20000000, LENGTH = 0x00004000 
  RAM (rwx) : ORIGIN = 0x20020000, LENGTH = 0x00180000
  RAM_NC (rwx) : ORIGIN = 0x20200000, LENGTH = 0x00680000
}
(snip)
Committer:
Osamu Nakamura
Date:
Tue Apr 11 12:42:10 2017 +0900
Revision:
6:a957aaa284f0
Parent:
4:2672de88a46b
Update R-BSP from rev. cbb9d60c8748 to fb9eda52224e so that this program can be compiled with IAR toolchain.

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