/*
 *	cliptsp.h
 *
 *	DSP Group TrueSpeech Decoder
 *
 *	CLiP - Common Library for P/ECE
 *	Copyright (C) 2001-2014 Naoyuki Sawa
 *
 *	* Mon Jul 07 01:54:09 JST 2014 Naoyuki Sawa
 *	- 1st 儕儕乕僗丅
 */
#ifndef __CLIP_TSP_H__
#define __CLIP_TSP_H__

//劕劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劖
//劔仭摉儌僕儏乕儖巊梡忋偺拲堄帠崁丂丂丂丂丂丂丂丂丂丂丂丂丂丂丂丂丂丂丂丂丂丂丂丂丂丂丂丂丂丂丂丂丂丂丂丂劔
//劔仩摉儌僕儏乕儖偺嵞惗儖乕僠儞偼丄僗僞僢僋偺巊梡検偑傗傗懡傔偱偡丅(栺800僶僀僩) 丂丂丂丂丂丂丂丂丂丂丂丂劔
//劔丂摉儌僕儏乕儖偺婡擻傪巊梡偡傞傾僾儕働乕僔儑儞偼丄僗僞僢僋傪懡傔偵妋曐偟偰偔偩偝偄丅丂丂丂丂丂丂丂丂丂劔
//劔丂栚埨偲偟偰偼丄摉儌僕儏乕儖傪巊梡偟側偄応崌傛傝傕丄1僉儘僶僀僩偖傜偄懡偔妋曐偟偰偔偩偝偄丅 丂丂丂丂丂劔
//劔仩嬶懱揑偵偼丄壓婰偺嶰庬椶偺僗僞僢僋傪丄懡傔偵妋曐偟偰偔偩偝偄: 丂丂丂丂丂丂丂丂丂丂丂丂丂丂丂丂丂丂丂劔
//劔丂嘆僔僗僥儉僗僞僢僋丂丂丂丂丂丂丂丂丂丂丂丂丂丂丂丂丂丂丂丂丂丂丂丂丂丂丂丂丂丂丂丂丂丂丂丂丂丂丂丂丂劔
//劔丂丂傾僾儕働乕僔儑儞Makefile偺SYSSTACK偱掕媊偡傞僗僞僢僋僒僀僘偱偡丅丂丂丂丂丂丂丂丂丂丂丂丂丂丂丂丂丂劔
//劔丂嘇儐乕僓乕僗僞僢僋丂丂丂丂丂丂丂丂丂丂丂丂丂丂丂丂丂丂丂丂丂丂丂丂丂丂丂丂丂丂丂丂丂丂丂丂丂丂丂丂丂劔
//劔丂丂傾僾儕働乕僔儑儞Makefile偺USRSTACK偱掕媊偡傞僗僞僢僋僒僀僘偱偡丅丂丂丂丂丂丂丂丂丂丂丂丂丂丂丂丂丂劔
//劔丂丂USRSTACK傪掕媊偟側偄応崌偼丄崅懍RAM偺巆傝梕検偑廩暘偱偁傞偙偲傪妋擣偟偰偔偩偝偄丅 丂丂丂丂丂丂丂丂劔
//劔丂嘊僞僗僋僗僞僢僋丂仼丂!!梫拲堄!!丂丂丂丂丂丂丂丂丂丂丂丂丂丂丂丂丂丂丂丂丂丂丂丂丂丂丂丂丂丂丂丂丂丂劔
//劔丂丂task_create()偺堷悢偱巜掕偡傞僗僞僢僋僒僀僘偱偡丅(僞僗僋婡擻傪巊梡偡傞傾僾儕働乕僔儑儞偺傒) 丂丂丂劔
//劔丂丂摿偵偙偺僗僞僢僋偑堨傟偨応崌偵丄尨場傪摿掕偟偯傜偄僶僌偲側傞偺偱丄拲堄偟偰偔偩偝偄丅丂丂丂丂丂丂丂劔
//劔丂丂僗僞僢僋偑堨傟偨応崌偺徢忬偺椺偲偟偰偼丄task_select()偺拞偱傾僪儗僗僄儔乕偑敪惗偟偨傝丄 丂丂丂丂丂劔
//劔丂丂僞僗僋儕僗僩傪憖嶌偡傞嵺偺InsertTailList()摍偺娭悢偺拞偱傾僪儗僗僄儔乕偑敪惗偟傑偡丅丂丂丂丂丂丂丂劔
//劔仩摉儌僕儏乕儖偺婡擻傪巊梡偡傞傾僾儕働乕僔儑儞偼丄stack_switch_FRAM4傪巊梡偟側偄偱偔偩偝偄丅丂丂丂丂丂劔
//劔丂FRAM4偺僒僀僘偼512偱偁傝丄摉儌僕儏乕儖偺嵞惗儖乕僠儞偺僗僞僢僋巊梡検傛傝傕彫偝偄偐傜偱偡丅丂丂丂丂丂劔
//劔丂僗僞僢僋傪FRAM4傊愗傝懼偊偰偄傞娫偵丄妱傝崬傒偑敪惗偟嵞惗儖乕僠儞傪幚峴偡傞偲丄僗僞僢僋偑堨傟傑偡丅 劔
//劔丂偨偩偟丄妱傝崬傒傪嬛巭偵偟偰僗僞僢僋傪FRAM4傊愗傝懼偊傞偙偲偼丄栤戣偁傝傑偣傫丅 丂丂丂丂丂丂丂丂丂丂劔
//劘劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劒劗

/****************************************************************************
 *	掕悢丄峔憿懱
 ****************************************************************************/
//PCEWAVEINFO.type偺撈帺奼挘
#define PW_TYPE_TRUESPEECH 4
/*--------------------------------------------------------------------------*/
//婗敪惈儚乕僋僄儕傾丅僼儗乕儉僨僐乕僪奐巒帪偺弶婜抣偼晄掕偱峔傢側偄丅僼儗乕儉娫偱堐帩偡傞昁梫偑柍偄丅
typedef struct _ST_TrueSpeechWorkV {													//嘆嘇嘊嘋嘍嘐嘑嘒
	int16_t quart;			//+  0,  2: 僒僽僼儗乕儉斣崋: 0乣3								//倂丂丂丂俼俼丂俼
	int16_t flag;			//+  2,  2: 1-bit flag, shows how to choose filters						//丂倂丂俼丂丂丂丂
	int16_t vector[8];		//+  4, 16: input vector: 5/5/4/4/4/3/3/3							//丂倂俼丂丂丂丂丂
	int16_t offset1[2];		//+ 20,  4: 8-bit value, used in one copying offset						//丂倂丂丂俼丂丂丂
	int16_t offset2[4];		//+ 24,  8: 7-bit value, encodes offsets for copying and for two-point filter			//丂倂丂丂俼丂丂丂
	int16_t pulseval[4];		//+ 32,  8: 7x2-bit pulse values								//丂倂丂丂丂俼丂丂
	int16_t pulseoff[4];		//+ 40,  8: 4-bit offset of pulse values block							//丂倂丂丂丂俼丂丂
	int32_t pulsepos[4];		//+ 48, 16: 27-bit variable, encodes 7 pulse positions						//丂倂丂丂丂俼丂丂
	int16_t prevfilt[8];		//+ 64, 16: filter from previous frame								//倂丂丂俼丂丂丂丂
	int16_t filters[4][8];		//+ 80, 64: filters for every subframe								//丂丂丂倂丂丂丂俼
	int16_t newvec[60];		//+144,120: tmp vector										//丂丂丂丂倂丂俼丂
} ST_TrueSpeechWorkV;			//=264
/*--------------------------------------------------------------------------*/
//晄婗敪惈儚乕僋僄儕傾丅嵞惗奐巒帪偵僋儕傾偣傛丅僼儗乕儉娫偱堐帩偡傞昁梫偑桳傞丅
typedef struct _ST_TrueSpeechWorkN {													//嘆嘇嘊嘋嘍嘐嘑嘒
	int16_t cvector[8];		//+  0, 16: correlated input vector								//俼丂俵俼丂丂丂丂
	int16_t filtbuf[60 + 86];	//+ 16,292: some big vector used for storing filters						//丂丂丂丂俼丂俵丂
} ST_TrueSpeechWorkN;			//=308
/*--------------------------------------------------------------------------*/
//僠儍僱儖儚乕僋僄儕傾
typedef struct _ST_TrueSpeechCh {
	       int32_t  iLoop;		//+  0,  4: 0=掆巭,1乣=巆傝儖乕僾夞悢,-1=柍尷儖乕僾
	       int16_t  iVol;		//+  4,  2: 0=徚壒,1乣256=壒検
	      uint16_t  nOutLeft;	//+  6,  2: 0乣240=OutBuf[]偺巆傝僒儞僾儖悢
	const uint32_t* pData;		//+  8,  4: 僨乕僞憱嵏埵抲
	      uint32_t  nFrame;		//+ 12,  4: 巆傝僼儗乕儉悢
	const uint32_t* pInitData;	//+ 16,  4: 僨乕僞憱嵏埵抲偺儕僙僢僩抣
	      uint32_t  nInitFrame;	//+ 20,  4: 巆傝僼儗乕儉悢偺儕僙僢僩抣
	       int16_t  OutBuf[240];	//+ 24,480: 僼儗乕儉僨僐乕僪弌椡僶僢僼傽
	ST_TrueSpeechWorkN WorkN;	//+504,308: 晄婗敪惈儚乕僋僄儕傾
} ST_TrueSpeechCh;			//=812
/****************************************************************************
 *	傾僾儕働乕僔儑儞梡娭悢
 ****************************************************************************/
void TrueSpeech_Init(int nCh);
void TrueSpeech_Exit();
void TrueSpeech_PlayCh(int iCh, const void* pData, int iLoop);
void TrueSpeech_StopCh(int iCh);
void TrueSpeech_StopAll();
int TrueSpeech_GetChStat(int iCh);
void TrueSpeech_SetChAtt(int iCh, int iAtt);
/****************************************************************************
 *	撪晹娭悢
 ****************************************************************************/
void TrueSpeech_DecodeFrame(ST_TrueSpeechWorkV* pWorkV, ST_TrueSpeechWorkN* pCh, const uint32_t in[/*8*/], int16_t out[/*240*/]);	//嘆
void TrueSpeech_ReadFrame(ST_TrueSpeechWorkV* pWorkV, const uint32_t in[/*8*/]);							//嘇
void TrueSpeech_CorrelateFilter(ST_TrueSpeechWorkV* pWorkV, ST_TrueSpeechWorkN* pCh);							//嘊
void TrueSpeech_FiltersMerge(ST_TrueSpeechWorkV* pWorkV, ST_TrueSpeechWorkN* pCh);							//嘋
void TrueSpeech_ApplyTwopointFilter(ST_TrueSpeechWorkV* pWorkV, ST_TrueSpeechWorkN* pCh);						//嘍
void TrueSpeech_PlacePulses(ST_TrueSpeechWorkV* pWorkV, int16_t out[/*60*/]);								//嘐
void TrueSpeech_UpdateFilters(ST_TrueSpeechWorkV* pWorkV, ST_TrueSpeechWorkN* pCh, int16_t out[/*60*/]);				//嘑
void TrueSpeech_Synth(ST_TrueSpeechWorkV* pWorkV, int16_t out[/*60*/]);									//嘒
void TrueSpeech_Mix1(ST_TrueSpeechCh* pCh, int mixbuf[/*160*/]);
void TrueSpeech_Mix2(short wbuff[/*320*/], int mixbuf[/*160*/]);
/*--------------------------------------------------------------------------*/
extern const int16_t TBL_TrueSpeech_Codebook0[32];
extern const int16_t TBL_TrueSpeech_Codebook1[32];
extern const int16_t TBL_TrueSpeech_Codebook2[16];
extern const int16_t TBL_TrueSpeech_Codebook3[16];
extern const int16_t TBL_TrueSpeech_Codebook4[16];
extern const int16_t TBL_TrueSpeech_Codebook5[8];
extern const int16_t TBL_TrueSpeech_Codebook6[8];
extern const int16_t TBL_TrueSpeech_Codebook7[8];
extern const int16_t TBL_TrueSpeech_Order2Coeffs[25][2];
extern const int16_t TBL_TrueSpeech_PulseScales[16][4];
extern const int16_t TBL_TrueSpeech_PulseValues[4][30];

#endif /*__CLIP_TSP_H__*/
