- initial import
This commit is contained in:
12
src/libs/gsmhr/CMakeLists.txt
Normal file
12
src/libs/gsmhr/CMakeLists.txt
Normal file
@@ -0,0 +1,12 @@
|
||||
project (gsmhr_codec)
|
||||
|
||||
# Rely on C++ 11
|
||||
set (CMAKE_CXX_STANDARD 11)
|
||||
set (CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
set (GSMHR_SOURCES
|
||||
gsmhr.cpp
|
||||
gsmhr_sp_rom.c
|
||||
)
|
||||
|
||||
add_library(gsmhr_codec ${GSMHR_SOURCES})
|
||||
15726
src/libs/gsmhr/gsmhr.cpp
Normal file
15726
src/libs/gsmhr/gsmhr.cpp
Normal file
File diff suppressed because it is too large
Load Diff
804
src/libs/gsmhr/gsmhr.h
Normal file
804
src/libs/gsmhr/gsmhr.h
Normal file
@@ -0,0 +1,804 @@
|
||||
#ifndef __GSM_HR_CODEC_H
|
||||
#define __GSM_HR_CODEC_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include "gsmhr_sp_rom.h"
|
||||
|
||||
namespace GsmHr
|
||||
{
|
||||
#define DATE "August 8, 1996 "
|
||||
#define VERSION "Version 4.2 "
|
||||
|
||||
#define LW_SIGN (long)0x80000000 /* sign bit */
|
||||
#define LW_MIN (long)0x80000000
|
||||
#define LW_MAX (long)0x7fffffff
|
||||
|
||||
#define SW_SIGN (short)0x8000 /* sign bit for int16_t type */
|
||||
#define SW_MIN (short)0x8000 /* smallest Ram */
|
||||
#define SW_MAX (short)0x7fff /* largest Ram */
|
||||
#define SPEECH 1
|
||||
#define CNIFIRSTSID 2
|
||||
#define PN_INIT_SEED (int32_t)0x1091988L /* initial seed for Comfort
|
||||
* noise pn-generator */
|
||||
|
||||
#define CNICONT 3
|
||||
#define CNIBFI 4
|
||||
#define VALIDSID 11
|
||||
#define INVALIDSID 22
|
||||
#define GOODSPEECH 33
|
||||
#define UNUSABLE 44
|
||||
|
||||
typedef short int int16_tRom; /* 16 bit ROM data (sr*) */
|
||||
typedef long int int32_tRom; /* 32 bit ROM data (L_r*) */
|
||||
|
||||
struct NormSw
|
||||
{ /* normalized int16_t fractional
|
||||
* number snr.man precedes snr.sh (the
|
||||
* shift count)i */
|
||||
int16_t man; /* "mantissa" stored in 16 bit
|
||||
* location */
|
||||
int16_t sh; /* the shift count, stored in 16 bit
|
||||
* location */
|
||||
};
|
||||
|
||||
|
||||
struct QuantList
|
||||
{
|
||||
/* structure which points to the beginning of a block of candidate vq
|
||||
* vectors. It also stores the residual error for each vector. */
|
||||
int iNum; /* total number in list */
|
||||
int iRCIndex; /* an index to the first vector of the
|
||||
* block */
|
||||
int16_t pswPredErr[PREQ1_NUM_OF_ROWS]; /* PREQ1 is the biggest block */
|
||||
};
|
||||
|
||||
/* Global constants *
|
||||
********************/
|
||||
|
||||
#define NP 10 /* order of the lpc filter */
|
||||
#define N_SUB 4 /* number of subframes */
|
||||
#define F_LEN 160 /* number of samples in a frame */
|
||||
#define S_LEN 40 /* number of samples in a subframe */
|
||||
#define A_LEN 170 /* LPC analysis length */
|
||||
#define OS_FCTR 6 /* maximum LTP lag oversampling
|
||||
* factor */
|
||||
|
||||
#define OVERHANG 8 /* vad parameter */
|
||||
#define strStr strStr16
|
||||
|
||||
#define LTP_LEN 147 /* 147==0x93 length of LTP history */
|
||||
#define CNINTPER 12
|
||||
|
||||
class Codec
|
||||
{
|
||||
protected:
|
||||
|
||||
// From typedefs.h
|
||||
int giFrmCnt; /* 0,1,2,3,4..... */
|
||||
int giSfrmCnt = 0; /* 0,1,2,3 */
|
||||
|
||||
int giDTXon = 1; /* DTX Mode on/off */
|
||||
|
||||
|
||||
// From err_conc.c
|
||||
int32_t plSubfrEnergyMem[4];
|
||||
int16_t swLevelMem[4],
|
||||
lastR0,
|
||||
pswLastGood[18],
|
||||
swState,
|
||||
swLastFlag;
|
||||
|
||||
|
||||
// From sp_dec.c
|
||||
|
||||
int16_t gswPostFiltAgcGain,
|
||||
gpswPostFiltStateNum[NP],
|
||||
gpswPostFiltStateDenom[NP],
|
||||
swPostEmphasisState,
|
||||
pswSynthFiltState[NP],
|
||||
pswOldFrmKsDec[NP],
|
||||
pswOldFrmAsDec[NP],
|
||||
pswOldFrmPFNum[NP],
|
||||
pswOldFrmPFDenom[NP],
|
||||
swOldR0Dec,
|
||||
pswLtpStateBaseDec[LTP_LEN + S_LEN],
|
||||
pswPPreState[LTP_LEN + S_LEN];
|
||||
|
||||
|
||||
int16_t swMuteFlagOld; /* error concealment */
|
||||
|
||||
|
||||
|
||||
int16_t swRxDTXState = CNINTPER - 1; /* DTX State at the rx.
|
||||
* Modulo */
|
||||
|
||||
int16_t swDecoMode = SPEECH;
|
||||
int16_t swDtxMuting = 0;
|
||||
int16_t swDtxBfiCnt = 0;
|
||||
|
||||
int16_t swOldR0IndexDec = 0;
|
||||
|
||||
int16_t swRxGsHistPtr = 0;
|
||||
int32_t pL_RxGsHist[(OVERHANG - 1) * N_SUB];
|
||||
|
||||
int16_t swR0Dec;
|
||||
|
||||
int16_t swVoicingMode, /* MODE */
|
||||
pswVq[3], /* LPC1, LPC2, LPC3 */
|
||||
swSi, /* INT_LPC */
|
||||
swEngyRShift; /* for use by spectral postfilter */
|
||||
|
||||
|
||||
int16_t swR0NewCN; /* DTX mode */
|
||||
|
||||
int32_tRom ppLr_gsTable[4][32]; /* DTX mode */
|
||||
|
||||
int16_t
|
||||
*pswLtpStateOut = &pswLtpStateBaseDec[LTP_LEN],
|
||||
pswSythAsSpace[NP * N_SUB],
|
||||
pswPFNumAsSpace[NP * N_SUB],
|
||||
pswPFDenomAsSpace[NP * N_SUB],
|
||||
*ppswSynthAs[N_SUB] = {
|
||||
&pswSythAsSpace[0],
|
||||
&pswSythAsSpace[10],
|
||||
&pswSythAsSpace[20],
|
||||
&pswSythAsSpace[30],
|
||||
},
|
||||
|
||||
*ppswPFNumAs[N_SUB] = {
|
||||
&pswPFNumAsSpace[0],
|
||||
&pswPFNumAsSpace[10],
|
||||
&pswPFNumAsSpace[20],
|
||||
&pswPFNumAsSpace[30],
|
||||
},
|
||||
*ppswPFDenomAs[N_SUB] = {
|
||||
&pswPFDenomAsSpace[0],
|
||||
&pswPFDenomAsSpace[10],
|
||||
&pswPFDenomAsSpace[20],
|
||||
&pswPFDenomAsSpace[30],
|
||||
};
|
||||
|
||||
int16_tRom
|
||||
psrSPFDenomWidenCf[NP] = {
|
||||
0x6000, 0x4800, 0x3600, 0x2880, 0x1E60,
|
||||
0x16C8, 0x1116, 0x0CD0, 0x099C, 0x0735,
|
||||
};
|
||||
|
||||
|
||||
int32_t L_RxPNSeed; /* DTX mode */
|
||||
int16_t swRxDtxGsIndex; /* DTX mode */
|
||||
|
||||
// From dtx.c
|
||||
int16_t swVadFrmCnt = 0; /* Indicates the number of sequential
|
||||
* frames where VAD == 0 */
|
||||
|
||||
short int siUpdPointer = 0;
|
||||
int16_t swNElapsed = 50;
|
||||
|
||||
int32_t pL_GsHist[N_SUB * (OVERHANG - 1)];
|
||||
|
||||
/* history of unquantized parameters */
|
||||
int32_t pL_R0Hist[OVERHANG];
|
||||
int32_t ppL_CorrHist[OVERHANG][NP + 1];
|
||||
|
||||
/* quantized reference parameters */
|
||||
int16_t swQntRefR0,
|
||||
swRefGsIndex;
|
||||
int piRefVqCodewds[3];
|
||||
|
||||
/* handling of short speech bursts */
|
||||
int16_t swShortBurst;
|
||||
|
||||
/* state value of random generator */
|
||||
int32_t L_TxPNSeed;
|
||||
|
||||
int16_t swR0OldCN;
|
||||
int32_t pL_OldCorrSeq[NP + 1],
|
||||
pL_NewCorrSeq[NP + 1],
|
||||
pL_CorrSeq[NP + 1];
|
||||
|
||||
// From sp_enc.c
|
||||
int16_t swTxGsHistPtr = 0;
|
||||
|
||||
int16_t pswCNVSCode1[N_SUB],
|
||||
pswCNVSCode2[N_SUB],
|
||||
pswCNGsp0Code[N_SUB],
|
||||
pswCNLpc[3],
|
||||
swCNR0;
|
||||
|
||||
int16_t pswAnalysisState[NP];
|
||||
|
||||
int16_t pswWStateNum[NP],
|
||||
pswWStateDenom[NP];
|
||||
|
||||
int16_t swLastLag;
|
||||
/*_________________________________________________________________________
|
||||
| |
|
||||
| Other External Variables |
|
||||
|_________________________________________________________________________|
|
||||
*/
|
||||
|
||||
int16_tRom *psrTable; /* points to correct table of
|
||||
* vectors */
|
||||
int iLimit; /* accessible to all in this file
|
||||
* and to lpcCorrQntz() in dtx.c */
|
||||
int iLow; /* the low element in this segment */
|
||||
int iThree; /* boolean, is this a three element
|
||||
* vector */
|
||||
int iWordHalfPtr; /* points to the next byte */
|
||||
int iWordPtr; /* points to the next word to be */
|
||||
|
||||
// from vad.c
|
||||
|
||||
int16_t
|
||||
pswRvad[9],
|
||||
swNormRvad,
|
||||
swPt_sacf,
|
||||
swPt_sav0,
|
||||
swE_thvad,
|
||||
swM_thvad,
|
||||
swAdaptCount,
|
||||
swBurstCount,
|
||||
swHangCount,
|
||||
swOldLagCount,
|
||||
swVeryOldLagCount,
|
||||
swOldLag;
|
||||
|
||||
int32_t
|
||||
pL_sacf[27],
|
||||
pL_sav0[36],
|
||||
L_lastdm;
|
||||
|
||||
public:
|
||||
|
||||
// From VAD
|
||||
void vad_reset(void);
|
||||
|
||||
void vad_algorithm
|
||||
(
|
||||
int32_t pL_acf[9],
|
||||
int16_t swScaleAcf,
|
||||
int16_t pswRc[4],
|
||||
int16_t swPtch,
|
||||
int16_t *pswVadFlag
|
||||
);
|
||||
|
||||
void energy_computation
|
||||
(
|
||||
int32_t pL_acf[],
|
||||
int16_t swScaleAcf,
|
||||
int16_t pswRvad[],
|
||||
int16_t swNormRvad,
|
||||
int16_t *pswM_pvad,
|
||||
int16_t *pswE_pvad,
|
||||
int16_t *pswM_acf0,
|
||||
int16_t *pswE_acf0
|
||||
);
|
||||
|
||||
|
||||
void average_acf
|
||||
(
|
||||
int32_t pL_acf[],
|
||||
int16_t swScaleAcf,
|
||||
int32_t pL_av0[],
|
||||
int32_t pL_av1[]
|
||||
);
|
||||
|
||||
void predictor_values
|
||||
(
|
||||
int32_t pL_av1[],
|
||||
int16_t pswRav1[],
|
||||
int16_t *pswNormRav1
|
||||
);
|
||||
|
||||
void schur_recursion
|
||||
(
|
||||
int32_t pL_av1[],
|
||||
int16_t pswVpar[]
|
||||
);
|
||||
|
||||
void step_up
|
||||
(
|
||||
int16_t swNp,
|
||||
int16_t pswVpar[],
|
||||
int16_t pswAav1[]
|
||||
);
|
||||
|
||||
void compute_rav1
|
||||
(
|
||||
int16_t pswAav1[],
|
||||
int16_t pswRav1[],
|
||||
int16_t *pswNormRav1
|
||||
);
|
||||
|
||||
void spectral_comparison
|
||||
(
|
||||
int16_t pswRav1[],
|
||||
int16_t swNormRav1,
|
||||
int32_t pL_av0[],
|
||||
int16_t *pswStat
|
||||
);
|
||||
|
||||
void tone_detection
|
||||
(
|
||||
int16_t pswRc[4],
|
||||
int16_t *pswTone
|
||||
);
|
||||
|
||||
|
||||
void threshold_adaptation
|
||||
(
|
||||
int16_t swStat,
|
||||
int16_t swPtch,
|
||||
int16_t swTone,
|
||||
int16_t pswRav1[],
|
||||
int16_t swNormRav1,
|
||||
int16_t swM_pvad,
|
||||
int16_t swE_pvad,
|
||||
int16_t swM_acf0,
|
||||
int16_t swE_acf0,
|
||||
int16_t pswRvad[],
|
||||
int16_t *pswNormRvad,
|
||||
int16_t *pswM_thvad,
|
||||
int16_t *pswE_thvad
|
||||
);
|
||||
|
||||
void vad_decision
|
||||
(
|
||||
int16_t swM_pvad,
|
||||
int16_t swE_pvad,
|
||||
int16_t swM_thvad,
|
||||
int16_t swE_thvad,
|
||||
int16_t *pswVvad
|
||||
);
|
||||
|
||||
void vad_hangover
|
||||
(
|
||||
int16_t swVvad,
|
||||
int16_t *pswVadFlag
|
||||
);
|
||||
|
||||
void periodicity_update
|
||||
(
|
||||
int16_t pswLags[4],
|
||||
int16_t *pswPtch
|
||||
);
|
||||
|
||||
|
||||
// From err_conc.h
|
||||
|
||||
void para_conceal_speech_decoder(int16_t pswErrorFlag[],
|
||||
int16_t pswSpeechPara[], int16_t *pswMutePermit);
|
||||
|
||||
int16_t level_calc(int16_t swInd, int32_t *pl_en);
|
||||
|
||||
void level_estimator(int16_t update, int16_t *pswLevelMean,
|
||||
int16_t *pswLevelMax,
|
||||
int16_t pswDecodedSpeechFrame[]);
|
||||
|
||||
void signal_conceal_sub(int16_t pswPPFExcit[],
|
||||
int16_t ppswSynthAs[], int16_t pswSynthFiltState[],
|
||||
int16_t pswLtpStateOut[], int16_t pswPPreState[],
|
||||
int16_t swLevelMean, int16_t swLevelMax,
|
||||
int16_t swErrorFlag1, int16_t swMuteFlagOld,
|
||||
int16_t *pswMuteFlag, int16_t swMutePermit);
|
||||
|
||||
|
||||
|
||||
void speechDecoder(int16_t pswParameters[],
|
||||
int16_t pswDecodedSpeechFrame[]);
|
||||
|
||||
void aFlatRcDp(int32_t *pL_R, int16_t *pswRc);
|
||||
|
||||
void b_con(int16_t swCodeWord, short siNumBits,
|
||||
int16_t pswVectOut[]);
|
||||
|
||||
void fp_ex(int16_t swOrigLagIn, int16_t pswLTPState[]);
|
||||
|
||||
int16_t g_corr1(int16_t *pswIn, int32_t *pL_out);
|
||||
|
||||
int16_t g_corr1s(int16_t pswIn[], int16_t swEngyRShft,
|
||||
int32_t *pL_out);
|
||||
|
||||
void getSfrmLpc(short int siSoftInterpolation,
|
||||
int16_t swPrevR0, int16_t swNewR0,
|
||||
int16_t pswPrevFrmKs[],
|
||||
int16_t pswPrevFrmAs[],
|
||||
int16_t pswPrevFrmPFNum[],
|
||||
int16_t pswPrevFrmPFDenom[],
|
||||
int16_t pswNewFrmKs[],
|
||||
int16_t pswNewFrmAs[],
|
||||
int16_t pswNewFrmPFNum[],
|
||||
int16_t pswNewFrmPFDenom[],
|
||||
struct NormSw *psnsSqrtRs,
|
||||
int16_t *ppswSynthAs[],
|
||||
int16_t *ppswPFNumAs[],
|
||||
int16_t *ppswPFDenomAs[]);
|
||||
|
||||
void get_ipjj(int16_t swLagIn,
|
||||
int16_t *pswIp, int16_t *pswJj);
|
||||
|
||||
short int interpolateCheck(int16_t pswRefKs[],
|
||||
int16_t pswRefCoefsA[],
|
||||
int16_t pswOldCoefsA[],
|
||||
int16_t pswNewCoefsA[],
|
||||
int16_t swOldPer,
|
||||
int16_t swNewPer,
|
||||
int16_t swRq,
|
||||
struct NormSw *psnsSqrtRsOut,
|
||||
int16_t pswCoefOutA[]);
|
||||
|
||||
void lpcFir(int16_t pswInput[], int16_t pswCoef[],
|
||||
int16_t pswState[], int16_t pswFiltOut[]);
|
||||
|
||||
void lpcIir(int16_t pswInput[], int16_t pswCoef[],
|
||||
int16_t pswState[], int16_t pswFiltOut[]);
|
||||
|
||||
void lpcIrZsIir(int16_t pswCoef[], int16_t pswFiltOut[]);
|
||||
|
||||
void lpcZiIir(int16_t pswCoef[], int16_t pswState[],
|
||||
int16_t pswFiltOut[]);
|
||||
|
||||
void lpcZsFir(int16_t pswInput[], int16_t pswCoef[],
|
||||
int16_t pswFiltOut[]);
|
||||
|
||||
void lpcZsIir(int16_t pswInput[], int16_t pswCoef[],
|
||||
int16_t pswFiltOut[]);
|
||||
|
||||
void lpcZsIirP(int16_t pswCommonIO[], int16_t pswCoef[]);
|
||||
|
||||
int16_t r0BasedEnergyShft(int16_t swR0Index);
|
||||
|
||||
short rcToADp(int16_t swAscale, int16_t pswRc[],
|
||||
int16_t pswA[]);
|
||||
|
||||
void rcToCorrDpL(int16_t swAshift, int16_t swAscale,
|
||||
int16_t pswRc[], int32_t pL_R[]);
|
||||
|
||||
void res_eng(int16_t pswReflecCoefIn[], int16_t swRq,
|
||||
struct NormSw *psnsSqrtRsOut);
|
||||
|
||||
void rs_rr(int16_t pswExcitation[], struct NormSw snsSqrtRs,
|
||||
struct NormSw *snsSqrtRsRr);
|
||||
|
||||
void rs_rrNs(int16_t pswExcitation[], struct NormSw snsSqrtRs,
|
||||
struct NormSw *snsSqrtRsRr);
|
||||
|
||||
int16_t scaleExcite(int16_t pswVect[],
|
||||
int16_t swErrTerm, struct NormSw snsRS,
|
||||
int16_t pswScldVect[]);
|
||||
|
||||
int16_t sqroot(int32_t L_SqrtIn);
|
||||
|
||||
void v_con(int16_t pswBVects[], int16_t pswOutVect[],
|
||||
int16_t pswBitArray[], short int siNumBVctrs);
|
||||
|
||||
void a_sst(int16_t swAshift, int16_t swAscale,
|
||||
int16_t pswDirectFormCoefIn[],
|
||||
int16_t pswDirectFormCoefOut[]);
|
||||
|
||||
int16_t agcGain(int16_t pswStateCurr[],
|
||||
struct NormSw snsInSigEnergy, int16_t swEngyRShft);
|
||||
|
||||
void pitchPreFilt(int16_t pswExcite[],
|
||||
int16_t swRxGsp0,
|
||||
int16_t swRxLag, int16_t swUvCode,
|
||||
int16_t swSemiBeta, struct NormSw snsSqrtRs,
|
||||
int16_t pswExciteOut[],
|
||||
int16_t pswPPreState[]);
|
||||
|
||||
void spectralPostFilter(int16_t pswSPFIn[],
|
||||
int16_t pswNumCoef[],
|
||||
int16_t pswDenomCoef[], int16_t pswSPFOut[]);
|
||||
// From dtx.c
|
||||
void avgCNHist(int32_t pL_R0History[],
|
||||
int32_t ppL_CorrHistory[OVERHANG][NP + 1],
|
||||
int32_t *pL_AvgdR0,
|
||||
int32_t pL_AvgdCorrSeq[]);
|
||||
|
||||
void avgGsHistQntz(int32_t pL_GsHistory[], int32_t *pL_GsAvgd);
|
||||
|
||||
int16_t swComfortNoise(int16_t swVadFlag,
|
||||
int32_t L_UnqntzdR0, int32_t *pL_UnqntzdCorr);
|
||||
|
||||
int16_t getPnBits(int iBits, int32_t *L_PnSeed);
|
||||
|
||||
int16_t gsQuant(int32_t L_GsIn, int16_t swVoicingMode);
|
||||
|
||||
void updateCNHist(int32_t L_UnqntzdR0,
|
||||
int32_t *pL_UnqntzdCorr,
|
||||
int32_t pL_R0Hist[],
|
||||
int32_t ppL_CorrHist[OVERHANG][NP + 1]);
|
||||
|
||||
void lpcCorrQntz(int32_t pL_CorrelSeq[],
|
||||
int16_t pswFinalRc[],
|
||||
int piVQCodewds[]);
|
||||
|
||||
int32_t linInterpSid(int32_t L_New, int32_t L_Old, int16_t swDtxState);
|
||||
|
||||
int16_t linInterpSidShort(int16_t swNew,
|
||||
int16_t swOld,
|
||||
int16_t swDtxState);
|
||||
|
||||
void rxInterpR0Lpc(int16_t *pswOldKs, int16_t *pswNewKs,
|
||||
int16_t swRxDTXState,
|
||||
int16_t swDecoMode, int16_t swFrameType);
|
||||
|
||||
// From sp_frm.c
|
||||
void iir_d(int16_t pswCoeff[], int16_t pswIn[],
|
||||
int16_t pswXstate[],
|
||||
int16_t pswYstate[],
|
||||
int npts, int shifts,
|
||||
int16_t swPreFirDownSh,
|
||||
int16_t swFinalUpShift);
|
||||
|
||||
|
||||
void filt4_2nd(int16_t pswCoeff[],
|
||||
int16_t pswIn[],
|
||||
int16_t pswXstate[],
|
||||
int16_t pswYstate[],
|
||||
int npts,
|
||||
int shifts);
|
||||
|
||||
void initPBarVBarL(int32_t pL_PBarFull[],
|
||||
int16_t pswPBar[],
|
||||
int16_t pswVBar[]);
|
||||
|
||||
void initPBarFullVBarFullL(int32_t pL_CorrelSeq[],
|
||||
int32_t pL_PBarFull[],
|
||||
int32_t pL_VBarFull[]);
|
||||
|
||||
int16_t aflatRecursion(int16_t pswQntRc[],
|
||||
int16_t pswPBar[],
|
||||
int16_t pswVBar[],
|
||||
int16_t *ppswPAddrs[],
|
||||
int16_t *ppswVAddrs[],
|
||||
int16_t swSegmentOrder);
|
||||
|
||||
void aflatNewBarRecursionL(int16_t pswQntRc[],
|
||||
int iSegment,
|
||||
int32_t pL_PBar[],
|
||||
int32_t pL_VBar[],
|
||||
int16_t pswPBar[],
|
||||
int16_t pswVBar[]);
|
||||
|
||||
|
||||
void setupPreQ(int iSeg, int iVector);
|
||||
|
||||
void setupQuant(int iSeg, int iVector);
|
||||
|
||||
void getNextVec(int16_t pswRc[]);
|
||||
|
||||
void aflat(int16_t pswSpeechToLPC[],
|
||||
int piR0Index[],
|
||||
int16_t pswFinalRc[],
|
||||
int piVQCodewds[],
|
||||
int16_t swPtch,
|
||||
int16_t *pswVadFlag,
|
||||
int16_t *pswSP);
|
||||
|
||||
|
||||
int16_t fnExp2(int32_t L_Input);
|
||||
|
||||
int16_t fnLog2(int32_t L_Input);
|
||||
|
||||
void weightSpeechFrame(int16_t pswSpeechFrm[],
|
||||
int16_t pswWNumSpace[],
|
||||
int16_t pswWDenomSpace[],
|
||||
int16_t pswWSpeechBuffBase[]);
|
||||
|
||||
void getSfrmLpcTx(int16_t swPrevR0, int16_t swNewR0,
|
||||
int16_t pswPrevFrmKs[],
|
||||
int16_t pswPrevFrmAs[],
|
||||
int16_t pswPrevFrmSNWCoef[],
|
||||
int16_t pswNewFrmKs[],
|
||||
int16_t pswNewFrmAs[],
|
||||
int16_t pswNewFrmSNWCoef[],
|
||||
int16_t pswHPFSpeech[],
|
||||
short *pswSoftInterp,
|
||||
struct NormSw *psnsSqrtRs,
|
||||
int16_t ppswSynthAs[][NP],
|
||||
int16_t ppswSNWCoefAs[][NP]);
|
||||
|
||||
short int fnBest_CG(int16_t pswCframe[],
|
||||
int16_t pswGframe[],
|
||||
int16_t *pswCmaxSqr,
|
||||
int16_t *pswGmax,
|
||||
short int siNumPairs);
|
||||
|
||||
short compResidEnergy(int16_t pswSpeech[],
|
||||
int16_t ppswInterpCoef[][NP],
|
||||
int16_t pswPreviousCoef[],
|
||||
int16_t pswCurrentCoef[],
|
||||
struct NormSw psnsSqrtRs[]);
|
||||
|
||||
int16_t r0Quant(int32_t L_UnqntzdR0);
|
||||
|
||||
int16_t cov32(int16_t pswIn[],
|
||||
int32_t pppL_B[NP][NP][2],
|
||||
int32_t pppL_F[NP][NP][2],
|
||||
int32_t pppL_C[NP][NP][2],
|
||||
int32_t *pL_R0,
|
||||
int32_t pL_VadAcf[],
|
||||
int16_t *pswVadScalAuto);
|
||||
|
||||
int32_t flat(int16_t pswSpeechIn[],
|
||||
int16_t pswRc[],
|
||||
int *piR0Inx,
|
||||
int32_t pL_VadAcf[],
|
||||
int16_t *pswVadScalAuto);
|
||||
|
||||
|
||||
|
||||
void openLoopLagSearch(int16_t pswWSpeech[],
|
||||
int16_t swPrevR0Index,
|
||||
int16_t swCurrR0Index,
|
||||
int16_t *psiUVCode,
|
||||
int16_t pswLagList[],
|
||||
int16_t pswNumLagList[],
|
||||
int16_t pswPitchBuf[],
|
||||
int16_t pswHNWCoefBuf[],
|
||||
struct NormSw psnsWSfrmEng[],
|
||||
int16_t pswVadLags[],
|
||||
int16_t swSP);
|
||||
|
||||
int16_t getCCThreshold(int16_t swRp0,
|
||||
int16_t swCC,
|
||||
int16_t swG);
|
||||
|
||||
void pitchLags(int16_t swBestIntLag,
|
||||
int16_t pswIntCs[],
|
||||
int16_t pswIntGs[],
|
||||
int16_t swCCThreshold,
|
||||
int16_t pswLPeaksSorted[],
|
||||
int16_t pswCPeaksSorted[],
|
||||
int16_t pswGPeaksSorted[],
|
||||
int16_t *psiNumSorted,
|
||||
int16_t *pswPitch,
|
||||
int16_t *pswHNWCoef);
|
||||
|
||||
short CGInterpValid(int16_t swFullResLag,
|
||||
int16_t pswCIn[],
|
||||
int16_t pswGIn[],
|
||||
int16_t pswLOut[],
|
||||
int16_t pswCOut[],
|
||||
int16_t pswGOut[]);
|
||||
|
||||
void CGInterp(int16_t pswLIn[],
|
||||
short siNum,
|
||||
int16_t pswCIn[],
|
||||
int16_t pswGIn[],
|
||||
short siLoIntLag,
|
||||
int16_t pswCOut[],
|
||||
int16_t pswGOut[]);
|
||||
|
||||
int16_t quantLag(int16_t swRawLag,
|
||||
int16_t *psiCode);
|
||||
|
||||
void findBestInQuantList(struct QuantList psqlInList,
|
||||
int iNumVectOut,
|
||||
struct QuantList psqlBestOutList[]);
|
||||
|
||||
int16_t findPeak(int16_t swSingleResLag,
|
||||
int16_t pswCIn[],
|
||||
int16_t pswGIn[]);
|
||||
|
||||
void bestDelta(int16_t pswLagList[],
|
||||
int16_t pswCSfrm[],
|
||||
int16_t pswGSfrm[],
|
||||
short int siNumLags,
|
||||
short int siSfrmIndex,
|
||||
int16_t pswLTraj[],
|
||||
int16_t pswCCTraj[],
|
||||
int16_t pswGTraj[]);
|
||||
|
||||
int16_t
|
||||
maxCCOverGWithSign(int16_t pswCIn[],
|
||||
int16_t pswGIn[],
|
||||
int16_t *pswCCMax,
|
||||
int16_t *pswGMax,
|
||||
int16_t swNum);
|
||||
|
||||
void getNWCoefs(int16_t pswACoefs[],
|
||||
int16_t pswHCoefs[]);
|
||||
|
||||
int16_t lagDecode(int16_t swDeltaLag);
|
||||
|
||||
};
|
||||
|
||||
// From mathdp31
|
||||
extern int32_t L_mpy_ls(int32_t L_var2, int16_t var1);
|
||||
extern int32_t L_mpy_ll(int32_t L_var1, int32_t L_var2);
|
||||
extern short isSwLimit(int16_t swIn);
|
||||
extern short isLwLimit(int32_t L_In);
|
||||
|
||||
// From mathhalf
|
||||
/* addition */
|
||||
/************/
|
||||
|
||||
extern int16_t add(int16_t var1, int16_t var2); /* 1 ops */
|
||||
extern int16_t sub(int16_t var1, int16_t var2); /* 1 ops */
|
||||
extern int32_t L_add(int32_t L_var1, int32_t L_var2); /* 2 ops */
|
||||
extern int32_t L_sub(int32_t L_var1, int32_t L_var2); /* 2 ops */
|
||||
|
||||
/* multiplication */
|
||||
/******************/
|
||||
|
||||
extern int16_t mult(int16_t var1, int16_t var2); /* 1 ops */
|
||||
extern int32_t L_mult(int16_t var1, int16_t var2); /* 1 ops */
|
||||
extern int16_t mult_r(int16_t var1, int16_t var2); /* 2 ops */
|
||||
|
||||
|
||||
/* arithmetic shifts */
|
||||
/*********************/
|
||||
|
||||
extern int16_t shr(int16_t var1, int16_t var2); /* 1 ops */
|
||||
extern int16_t shl(int16_t var1, int16_t var2); /* 1 ops */
|
||||
extern int32_t L_shr(int32_t L_var1, int16_t var2); /* 2 ops */
|
||||
extern int32_t L_shl(int32_t L_var1, int16_t var2); /* 2 ops */
|
||||
extern int16_t shift_r(int16_t var, int16_t var2); /* 2 ops */
|
||||
extern int32_t L_shift_r(int32_t L_var, int16_t var2); /* 3 ops */
|
||||
|
||||
/* absolute value */
|
||||
/*******************/
|
||||
|
||||
extern int16_t abs_s(int16_t var1); /* 1 ops */
|
||||
extern int32_t L_abs(int32_t var1); /* 3 ops */
|
||||
|
||||
|
||||
/* multiply accumulate */
|
||||
/************************/
|
||||
|
||||
extern int32_t L_mac(int32_t L_var3,
|
||||
int16_t var1, int16_t var2); /* 1 op */
|
||||
extern int16_t mac_r(int32_t L_var3,
|
||||
int16_t var1, int16_t var2); /* 2 op */
|
||||
extern int32_t L_msu(int32_t L_var3,
|
||||
int16_t var1, int16_t var2); /* 1 op */
|
||||
extern int16_t msu_r(int32_t L_var3,
|
||||
int16_t var1, int16_t var2); /* 2 op */
|
||||
|
||||
/* negation */
|
||||
/*************/
|
||||
|
||||
extern int16_t negate(int16_t var1); /* 1 ops */
|
||||
extern int32_t L_negate(int32_t L_var1); /* 2 ops */
|
||||
|
||||
|
||||
/* Accumulator manipulation */
|
||||
/****************************/
|
||||
|
||||
extern int32_t L_deposit_l(int16_t var1); /* 1 ops */
|
||||
extern int32_t L_deposit_h(int16_t var1); /* 1 ops */
|
||||
extern int16_t extract_l(int32_t L_var1); /* 1 ops */
|
||||
extern int16_t extract_h(int32_t L_var1); /* 1 ops */
|
||||
|
||||
/* Round */
|
||||
/*********/
|
||||
|
||||
extern int16_t round(int32_t L_var1); /* 1 ops */
|
||||
|
||||
/* Normalization */
|
||||
/*****************/
|
||||
|
||||
extern int16_t norm_l(int32_t L_var1); /* 30 ops */
|
||||
extern int16_t norm_s(int16_t var1); /* 15 ops */
|
||||
|
||||
/* Division */
|
||||
/************/
|
||||
extern int16_t divide_s(int16_t var1, int16_t var2); /* 18 ops */
|
||||
|
||||
/* Non-saturating instructions */
|
||||
/*******************************/
|
||||
extern int32_t L_add_c(int32_t L_Var1, int32_t L_Var2); /* 2 ops */
|
||||
extern int32_t L_sub_c(int32_t L_Var1, int32_t L_Var2); /* 2 ops */
|
||||
extern int32_t L_sat(int32_t L_var1); /* 4 ops */
|
||||
extern int32_t L_macNs(int32_t L_var3,
|
||||
int16_t var1, int16_t var2); /* 1 ops */
|
||||
extern int32_t L_msuNs(int32_t L_var3,
|
||||
int16_t var1, int16_t var2); /* 1 ops */
|
||||
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
1341
src/libs/gsmhr/gsmhr_dtx.c
Normal file
1341
src/libs/gsmhr/gsmhr_dtx.c
Normal file
File diff suppressed because it is too large
Load Diff
1334
src/libs/gsmhr/gsmhr_dtx.cpp
Normal file
1334
src/libs/gsmhr/gsmhr_dtx.cpp
Normal file
File diff suppressed because it is too large
Load Diff
62
src/libs/gsmhr/gsmhr_dtx.h
Normal file
62
src/libs/gsmhr/gsmhr_dtx.h
Normal file
@@ -0,0 +1,62 @@
|
||||
#ifndef __DTX
|
||||
#define __DTX
|
||||
|
||||
#include "typedefs.h"
|
||||
|
||||
|
||||
#define PN_INIT_SEED (int32_t)0x1091988L /* initial seed for Comfort
|
||||
* noise pn-generator */
|
||||
|
||||
#define CNINTPER 12 /* inperpolation period of CN
|
||||
* parameters */
|
||||
|
||||
#define SPEECH 1
|
||||
#define CNIFIRSTSID 2
|
||||
#define CNICONT 3
|
||||
#define CNIBFI 4
|
||||
|
||||
#define VALIDSID 11
|
||||
#define INVALIDSID 22
|
||||
#define GOODSPEECH 33
|
||||
#define UNUSABLE 44
|
||||
|
||||
/*________________________________________________________________________
|
||||
| |
|
||||
| Function Prototypes |
|
||||
|________________________________________________________________________|
|
||||
*/
|
||||
|
||||
void avgCNHist(int32_t pL_R0History[],
|
||||
int32_t ppL_CorrHistory[OVERHANG][NP + 1],
|
||||
int32_t *pL_AvgdR0,
|
||||
int32_t pL_AvgdCorrSeq[]);
|
||||
|
||||
void avgGsHistQntz(int32_t pL_GsHistory[], int32_t *pL_GsAvgd);
|
||||
|
||||
int16_t swComfortNoise(int16_t swVadFlag,
|
||||
int32_t L_UnqntzdR0, int32_t *pL_UnqntzdCorr);
|
||||
|
||||
int16_t getPnBits(int iBits, int32_t *L_PnSeed);
|
||||
|
||||
int16_t gsQuant(int32_t L_GsIn, int16_t swVoicingMode);
|
||||
|
||||
void updateCNHist(int32_t L_UnqntzdR0,
|
||||
int32_t *pL_UnqntzdCorr,
|
||||
int32_t pL_R0Hist[],
|
||||
int32_t ppL_CorrHist[OVERHANG][NP + 1]);
|
||||
|
||||
void lpcCorrQntz(int32_t pL_CorrelSeq[],
|
||||
int16_t pswFinalRc[],
|
||||
int piVQCodewds[]);
|
||||
|
||||
int32_t linInterpSid(int32_t L_New, int32_t L_Old, int16_t swDtxState);
|
||||
|
||||
int16_t linInterpSidShort(int16_t swNew,
|
||||
int16_t swOld,
|
||||
int16_t swDtxState);
|
||||
|
||||
void rxInterpR0Lpc(int16_t *pswOldKs, int16_t *pswNewKs,
|
||||
int16_t swRxDTXState,
|
||||
int16_t swDecoMode, int16_t swFrameType);
|
||||
|
||||
#endif
|
||||
480
src/libs/gsmhr/gsmhr_gsm_hr.c
Normal file
480
src/libs/gsmhr/gsmhr_gsm_hr.c
Normal file
@@ -0,0 +1,480 @@
|
||||
/**************************************************************************
|
||||
*
|
||||
* File Name: gsm_hr.c
|
||||
*
|
||||
* Purpose:
|
||||
*
|
||||
* This file contains the main routine for the GSM Half Rate speech
|
||||
* codec. The code for the speech coder, including the VAD, DTX,
|
||||
* Comfort Noise, bad frame handling (error concealment), and codec
|
||||
* homing functions is in the files listed below:
|
||||
*
|
||||
* gsm_hr.c globdefs.c homing.c host.c
|
||||
* mathdp31.c mathhalf.c sp_dec.c sp_enc.c
|
||||
* sp_frm.c sp_rom.c sp_sfrm.c vad.c
|
||||
* dtx.c err_conc.c
|
||||
*
|
||||
* This particular file only has the level 0, main(), and all level
|
||||
* 1, main()'s daughter functions, in it.
|
||||
*
|
||||
* Details on how to run gsm_hr are in the readme.txt file.
|
||||
*
|
||||
* Below is a listing of all the functions appearing in the file.
|
||||
* The ordering is hierarchical.
|
||||
*
|
||||
* main() "gsm_hr", main program.
|
||||
* encode() - encodes a speech file, outputs an encoded parameter file
|
||||
* decode() - decodes a parameter file, outputs a decoded speech file
|
||||
*
|
||||
**************************************************************************/
|
||||
|
||||
/*_________________________________________________________________________
|
||||
| |
|
||||
| Include Files |
|
||||
|_________________________________________________________________________|
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#include "gsmhr_gsm_hr.h"
|
||||
#include "gsmhr_homing.h"
|
||||
#include "gsmhr_host.h"
|
||||
#include "gsmhr_sp_dec.h"
|
||||
#include "gsmhr_sp_enc.h"
|
||||
#include "gsmhr_typedefs.h"
|
||||
|
||||
/****************************************************************************
|
||||
*
|
||||
* PROGRAM NAME: gsm_hr
|
||||
*
|
||||
* PURPOSE:
|
||||
* gsm_hr - main program for the GSM Half-Rate speech coder.
|
||||
* Allows running one of the following operational modes:
|
||||
* 0. Encoder only with speech input / encoded parameter data output.
|
||||
* 1. Decoder only with speech parameter data input / speech output.
|
||||
*
|
||||
* INPUT:
|
||||
* inputFileName 0. speech file in 8 kHz, pcm format.
|
||||
* 1. speech parameter file in decoder input format.
|
||||
* <number of frames> - number of frames to be processed (optional).
|
||||
* <dtx|nodtx> - switch to enable/disable the DTX functions.
|
||||
*
|
||||
* OUTPUT:
|
||||
* outputFileName 0. encoded paramter output file.
|
||||
* 1. synthesized speech file in 8 kHz, pcm format.
|
||||
*
|
||||
* RETURN:
|
||||
* none
|
||||
*
|
||||
* REFERENCES: Sub-clause 4.0 of GSM Recomendation 06.20
|
||||
*
|
||||
* KEYWORDS: main, gsm_hr, speech codec, top level
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
|
||||
/*_________________________________________________________________________
|
||||
| |
|
||||
| Local Constants |
|
||||
|_________________________________________________________________________|
|
||||
*/
|
||||
|
||||
#define DEFAULT_NUMFRAMES 32766
|
||||
|
||||
/*_________________________________________________________________________
|
||||
| |
|
||||
| Automatic Variables |
|
||||
|_________________________________________________________________________|
|
||||
*/
|
||||
|
||||
int iDoneFrm,
|
||||
iMaxNumFrms,
|
||||
option,
|
||||
i;
|
||||
|
||||
FILE *pfileInFile,
|
||||
*pfileOutFile;
|
||||
|
||||
/*_________________________________________________________________________
|
||||
| |
|
||||
| Executable Code |
|
||||
|_________________________________________________________________________|
|
||||
*/
|
||||
|
||||
/* check command line arguments */
|
||||
/* ---------------------------- */
|
||||
|
||||
iMaxNumFrms = DEFAULT_NUMFRAMES;
|
||||
giDTXon = 1;
|
||||
|
||||
/* check command line arguments */
|
||||
/* ---------------------------- */
|
||||
|
||||
switch (argc)
|
||||
{
|
||||
case 4:
|
||||
|
||||
break;
|
||||
|
||||
case 5:
|
||||
case 6:
|
||||
|
||||
for (i = 4; i < argc; i++)
|
||||
{
|
||||
if (!strcmp(argv[i], "dtx"))
|
||||
giDTXon = 1;
|
||||
else if (!strcmp(argv[i], "nodtx"))
|
||||
giDTXon = 0;
|
||||
else if ((iMaxNumFrms = atoi(argv[i])) <= 0)
|
||||
{
|
||||
printf("invalid number of frames or wrong DTX switch, %s", argv[i]);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
printf("\n\nUsage:\n\n");
|
||||
printf("gsm_hr option inputFileName outputFileName ");
|
||||
printf("<number of frames> <dtx|nodtx>\n");
|
||||
printf(" or\n");
|
||||
printf("gsm_hr option inputFileName outputFileName ");
|
||||
printf("<dtx|nodtx> <number of frames>\n");
|
||||
printf("\nOptions: ");
|
||||
printf("enc ");
|
||||
puts("inputFileName: speech --> outputFileName: encoder output");
|
||||
printf(" ");
|
||||
printf("dec ");
|
||||
puts("inputFileName: decoder input --> outputFileName: speech");
|
||||
printf("\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* check encoding and decoding options */
|
||||
/* ----------------------------------- */
|
||||
|
||||
if (!strcmp(argv[1], "enc"))
|
||||
option = 0;
|
||||
else if (!strcmp(argv[1], "dec"))
|
||||
option = 1;
|
||||
else
|
||||
{
|
||||
printf("error in option selection\n");
|
||||
printf(" Your entry : %s \n", argv[1]);
|
||||
printf("\n\nUsage:\n\n");
|
||||
printf("gsm_hr option inputFileName outputFileName ");
|
||||
printf("<number of frames> <dtx|nodtx>\n");
|
||||
printf(" or\n");
|
||||
printf("gsm_hr option inputFileName outputFileName ");
|
||||
printf("<dtx|nodtx> <number of frames>\n");
|
||||
printf("\nOptions: ");
|
||||
printf("enc ");
|
||||
puts("inputFileName: speech --> outputFileName: encoder output");
|
||||
printf(" ");
|
||||
printf("dec ");
|
||||
puts("inputFileName: decoder input --> outputFileName: speech");
|
||||
printf("\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
/* open the input and output files */
|
||||
/* ------------------------------- */
|
||||
|
||||
#ifdef VAX
|
||||
pfileInFile = fopen(argv[2], "rb", "mrs=2", "rfm=fix", "ctx=stm");
|
||||
pfileOutFile = fopen(argv[3], "wb", "mrs=2", "rfm=fix", "ctx=stm");
|
||||
#else
|
||||
pfileInFile = fopen(argv[2], "rb");
|
||||
pfileOutFile = fopen(argv[3], "wb");
|
||||
#endif
|
||||
|
||||
if (pfileInFile == NULL)
|
||||
{
|
||||
printf("error: can not open file %s\n", argv[2]);
|
||||
exit(1);
|
||||
}
|
||||
if (pfileOutFile == NULL)
|
||||
{
|
||||
printf("error: can not open file %s\n", argv[3]);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
puts("\n\n");
|
||||
puts(" ****************************************");
|
||||
puts(" * *");
|
||||
puts(" * GSM Half-Rate Speech Coder *");
|
||||
puts(" * *");
|
||||
puts(" * *");
|
||||
printf(" * %s *\n", VERSION);
|
||||
printf(" * %s *\n", DATE);
|
||||
puts(" * *");
|
||||
puts(" ****************************************");
|
||||
puts("\n");
|
||||
|
||||
|
||||
printf("option: ");
|
||||
|
||||
switch (option)
|
||||
{
|
||||
case 0:
|
||||
puts("enc (speech encoder)");
|
||||
break;
|
||||
case 1:
|
||||
puts("dec (speech decoder)");
|
||||
break;
|
||||
default:
|
||||
puts("invalid option");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (giDTXon)
|
||||
printf("DTX mode: enabled\n");
|
||||
else
|
||||
printf("DTX mode: disabled\n");
|
||||
|
||||
printf("input file: %s\n", argv[2]);
|
||||
printf("output file: %s\n\n", argv[3]);
|
||||
|
||||
|
||||
switch (option)
|
||||
{
|
||||
case 0: /* encode */
|
||||
|
||||
/* start the encoder, VAD, and transmit DTX in the home state */
|
||||
/* ---------------------------------------------------------- */
|
||||
|
||||
resetEnc();
|
||||
|
||||
/* encode: analyze 8 kHz speech and output encoded parameter file */
|
||||
/* --------------------------------------------------------------- */
|
||||
|
||||
for (giFrmCnt = 1, iDoneFrm = 0;
|
||||
!iDoneFrm && giFrmCnt <= iMaxNumFrms;
|
||||
giFrmCnt++)
|
||||
{
|
||||
|
||||
#ifndef SILENT
|
||||
printf("encoding frame %d \r", giFrmCnt);
|
||||
#endif
|
||||
|
||||
if (encode(pfileInFile, pfileOutFile))
|
||||
iDoneFrm = 1;
|
||||
}
|
||||
|
||||
if (iDoneFrm)
|
||||
giFrmCnt--;
|
||||
|
||||
printf(" %d speech frames encoded\n", giFrmCnt - 1);
|
||||
break;
|
||||
|
||||
case 1: /* decode */
|
||||
|
||||
/* start the decoder and receive DTX in the home state */
|
||||
/* --------------------------------------------------- */
|
||||
|
||||
resetDec();
|
||||
|
||||
/* decode: synthesize speech */
|
||||
/* -------------------------- */
|
||||
|
||||
for (giFrmCnt = 1, iDoneFrm = 0;
|
||||
!iDoneFrm && giFrmCnt <= iMaxNumFrms;
|
||||
giFrmCnt++)
|
||||
{
|
||||
|
||||
#ifndef SILENT
|
||||
printf("decoding frame %d \r", giFrmCnt);
|
||||
#endif
|
||||
|
||||
if (decode(pfileInFile, pfileOutFile))
|
||||
iDoneFrm = 1;
|
||||
}
|
||||
|
||||
if (iDoneFrm)
|
||||
giFrmCnt--;
|
||||
|
||||
printf(" %d speech frames decoded\n", giFrmCnt - 1);
|
||||
break;
|
||||
}
|
||||
|
||||
fclose(pfileInFile);
|
||||
fclose(pfileOutFile);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* FUNCTION NAME: decode
|
||||
*
|
||||
* PURPOSE:
|
||||
* Reads in one frame of speech parameters and outputs one frame of
|
||||
* synthesized speech. Resets the decoder to the home state if the
|
||||
* Decoder Homing Frame pattern is detected.
|
||||
*
|
||||
* INPUT:
|
||||
* pfileDec speech parameter input file.
|
||||
*
|
||||
* OUTPUT:
|
||||
* pfileSpeechOut synthesized speech file
|
||||
*
|
||||
* RETURN:
|
||||
* 0 successfully synthesized a complete frame of speech
|
||||
* 1 failed to synthesize a complete frame of speech
|
||||
*
|
||||
* REFERENCES: Sub-clause 4.2 of GSM Recomendation 06.20
|
||||
*
|
||||
* KEYWORDS:
|
||||
* pfileDec, pfileSpeechOut
|
||||
**************************************************************************/
|
||||
|
||||
int decode(FILE *pfileDec, FILE *pfileSpeechOut)
|
||||
{
|
||||
|
||||
/*_________________________________________________________________________
|
||||
| |
|
||||
| Local Constants |
|
||||
|_________________________________________________________________________|
|
||||
*/
|
||||
|
||||
/* These constants define the number of consecutive */
|
||||
/* parameters that decoderHomingFrameTest checks. */
|
||||
/* -------------------------------------------------*/
|
||||
|
||||
#define WHOLE_FRAME 18
|
||||
#define TO_FIRST_SUBFRAME 9
|
||||
|
||||
/*_________________________________________________________________________
|
||||
| |
|
||||
| Static Variables |
|
||||
|_________________________________________________________________________|
|
||||
*/
|
||||
static int16_t pswSpeechPara[22],
|
||||
pswDecodedSpeechFrame[F_LEN];
|
||||
|
||||
static int reset_flag_decoder_old = 1;
|
||||
|
||||
/*_________________________________________________________________________
|
||||
| |
|
||||
| Automatic Variables |
|
||||
|_________________________________________________________________________|
|
||||
*/
|
||||
int i,
|
||||
reset_flag_decoder;
|
||||
|
||||
/*_________________________________________________________________________
|
||||
| |
|
||||
| Executable Code |
|
||||
|_________________________________________________________________________|
|
||||
*/
|
||||
|
||||
if (readDecfile(pfileDec, pswSpeechPara))
|
||||
return (1);
|
||||
|
||||
if(reset_flag_decoder_old)
|
||||
reset_flag_decoder=decoderHomingFrameTest(pswSpeechPara,
|
||||
TO_FIRST_SUBFRAME);
|
||||
else
|
||||
reset_flag_decoder=0;
|
||||
|
||||
if (reset_flag_decoder && reset_flag_decoder_old)
|
||||
{
|
||||
/* force the output to be the encoder homing frame pattern */
|
||||
|
||||
for (i = 0; i < F_LEN; i++)
|
||||
pswDecodedSpeechFrame[i] = EHF_MASK;
|
||||
}
|
||||
else
|
||||
{
|
||||
speechDecoder(pswSpeechPara, pswDecodedSpeechFrame);
|
||||
}
|
||||
|
||||
speechDecoderHostInterface(pswDecodedSpeechFrame, pfileSpeechOut);
|
||||
|
||||
if(!reset_flag_decoder_old)
|
||||
reset_flag_decoder=decoderHomingFrameTest(pswSpeechPara, WHOLE_FRAME);
|
||||
|
||||
if (reset_flag_decoder)
|
||||
resetDec(); /* bring the decoder and receive DTX
|
||||
* to the home state */
|
||||
|
||||
reset_flag_decoder_old = reset_flag_decoder;
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* FUNCTION NAME: encode
|
||||
*
|
||||
* PURPOSE:
|
||||
* Reads in one frame of speech samples and outputs one frame of
|
||||
* speech parameters. Resets the encoder to the home state if the
|
||||
* Encoder Homing Frame pattern is detected.
|
||||
*
|
||||
* INPUT:
|
||||
* pfileSpeechIn speech file
|
||||
*
|
||||
* OUTPUT:
|
||||
* pfileEnc speech, encoded paramater data
|
||||
*
|
||||
* RETURN:
|
||||
* 0 successfully wrote a complete frame of data
|
||||
* 1 failed to write a complete frame of data
|
||||
*
|
||||
* REFERENCES: Sub-clause 4.1 of GSM Recomendation 06.20
|
||||
*
|
||||
* KEYWORDS:
|
||||
* pfileSpeechIn, pfileEnc
|
||||
**************************************************************************/
|
||||
|
||||
int encode(FILE *pfileSpeechIn, FILE *pfileEnc)
|
||||
{
|
||||
|
||||
/*_________________________________________________________________________
|
||||
| |
|
||||
| Static Variables |
|
||||
|_________________________________________________________________________|
|
||||
*/
|
||||
static int16_t pswSpeechPara[20];
|
||||
static int16_t pswSpeechBuff[F_LEN];
|
||||
|
||||
/*_________________________________________________________________________
|
||||
| |
|
||||
| Automatic Variables |
|
||||
|_________________________________________________________________________|
|
||||
*/
|
||||
int iNumRead,
|
||||
reset_flag;
|
||||
|
||||
/*_________________________________________________________________________
|
||||
| |
|
||||
| Executable Code |
|
||||
|_________________________________________________________________________|
|
||||
*/
|
||||
|
||||
iNumRead = hostEncoderInterface(pfileSpeechIn, F_LEN, &pswSpeechBuff[0]);
|
||||
|
||||
if (iNumRead < F_LEN)
|
||||
return (1);
|
||||
|
||||
reset_flag = encoderHomingFrameTest(&pswSpeechBuff[0]);
|
||||
|
||||
speechEncoder(&pswSpeechBuff[0], pswSpeechPara);
|
||||
|
||||
if (writeEncfile(pswSpeechPara, pfileEnc) != 20)
|
||||
return (1);
|
||||
|
||||
if (reset_flag)
|
||||
resetEnc(); /* Bring the encoder, VAD, and DTX to
|
||||
* the home state */
|
||||
|
||||
return (0);
|
||||
}
|
||||
15
src/libs/gsmhr/gsmhr_gsm_hr.h
Normal file
15
src/libs/gsmhr/gsmhr_gsm_hr.h
Normal file
@@ -0,0 +1,15 @@
|
||||
#ifndef __GSM_HR
|
||||
#define __GSM_HR
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
/*_________________________________________________________________________
|
||||
| |
|
||||
| Function Prototypes |
|
||||
|_________________________________________________________________________|
|
||||
*/
|
||||
|
||||
int encode(FILE *pfileSpeechIn, FILE *pfileEnc);
|
||||
int decode(FILE *pfileDec, FILE *pfileSpeechOut);
|
||||
|
||||
#endif
|
||||
648
src/libs/gsmhr/gsmhr_homing.c
Normal file
648
src/libs/gsmhr/gsmhr_homing.c
Normal file
@@ -0,0 +1,648 @@
|
||||
/**************************************************************************
|
||||
*
|
||||
* File Name: homing.c
|
||||
*
|
||||
* Purpose:
|
||||
* This file contains the following functions:
|
||||
*
|
||||
* decoderHomingFrameTest() - checks if a frame of input speech
|
||||
* parameters matches the Decoder Homing
|
||||
* Frame pattern.
|
||||
*
|
||||
* decoderReset() - called by resetDec() to reset all of the state
|
||||
* variables for the decoder
|
||||
*
|
||||
* encoderHomingFrameTest() - checks if a frame of input samples
|
||||
* matches the Encoder Homing Frame pattern.
|
||||
*
|
||||
* encoderReset() - called by resetEnc() to reset all the state
|
||||
* variables for the encoder.
|
||||
*
|
||||
* resetDec() - calls functions to reset the state variables for the
|
||||
* decoder, and for the receive DTX and Comfort Noise.
|
||||
*
|
||||
* resetEnc() - calls functions to reset the state variables for the
|
||||
* encoder and VAD, and for the transmit DTX and
|
||||
* Comfort Noise.
|
||||
*
|
||||
* dtxResetTx() - called by resetEnc() to reset all of the transmit
|
||||
* DTX and Comfort Noise state variables
|
||||
*
|
||||
* dtxResetRx() - called by resetDec() to reset all of the receive
|
||||
* DTX and Comfort Noise state variables
|
||||
*
|
||||
**************************************************************************/
|
||||
|
||||
/*_________________________________________________________________________
|
||||
| |
|
||||
| Include Files |
|
||||
|_________________________________________________________________________|
|
||||
*/
|
||||
|
||||
#include "typedefs.h"
|
||||
#include "vad.h"
|
||||
#include "dtx.h"
|
||||
#include "homing.h"
|
||||
|
||||
/*_________________________________________________________________________
|
||||
| |
|
||||
| Local Defines |
|
||||
|_________________________________________________________________________|
|
||||
*/
|
||||
|
||||
#define EHF_MASK 0x0008 /* Encoder Homing Frame pattern */
|
||||
#define LMAX 142 /* largest lag (integer sense) */
|
||||
#define CG_INT_MACS 6 /* Number of multiply-accumulates in
|
||||
* one interpolation */
|
||||
#define NUM_CLOSED 3 /* maximum number of lags searched */
|
||||
#define LPCSTARTINDEX 25 /* where the LPC analysis window
|
||||
* starts */
|
||||
#define INBUFFSZ LPCSTARTINDEX + A_LEN /* input buffer size */
|
||||
|
||||
|
||||
#define LTP_LEN 147 /* maximum ltp lag */
|
||||
#define LSMAX (LMAX + CG_INT_MACS/2)
|
||||
#define HNW_BUFF_LEN LSMAX
|
||||
|
||||
|
||||
/***************************************************************************
|
||||
*
|
||||
* FUNCTION NAME: decoderHomingFrameTest
|
||||
*
|
||||
* PURPOSE:
|
||||
* Checks if a frame of input speech parameters matches the Decoder
|
||||
* Homing Frame pattern, which is:
|
||||
*
|
||||
* parameter decimal value hexidecimal value
|
||||
* --------- ------------- -----------------
|
||||
* R0 0 0x0000
|
||||
* LPC1 881 0x0371
|
||||
* LPC2 350 0x015E
|
||||
* LPC3 195 0x00c3
|
||||
* INT_LPC 1 0x0001
|
||||
* MODE 0 0x0000
|
||||
* CODE1_1 71 0x0047
|
||||
* CODE2_1 74 0x004a
|
||||
* GSP0_1 0 0x0000
|
||||
* CODE1_2 9 0x0009
|
||||
* CODE2_2 38 0x0026
|
||||
* GSP0_2 7 0x0007
|
||||
* CODE1_3 0 0x0000
|
||||
* CODE2_3 0 0x0000
|
||||
* GSP0_3 0 0x0000
|
||||
* CODE1_4 0 0x0000
|
||||
* CODE2_4 0 0x0000
|
||||
* GSP0_4 0 0x0000
|
||||
*
|
||||
* INPUT:
|
||||
* pswSpeechPara[] - one frame of speech parameters
|
||||
* in decoder input format
|
||||
*
|
||||
* iLastPara - the number of consecutive parameters in
|
||||
* pswSpeechPara[] to match.
|
||||
*
|
||||
* OUTPUT:
|
||||
* None
|
||||
*
|
||||
* RETURN:
|
||||
* 0 input frame does not match the Decoder Homing Frame pattern.
|
||||
* 1 input frame matches the Decoder Homing Frame pattern.
|
||||
*
|
||||
* REFERENCES: Sub-clause 10 of GSM Recomendation 06.02
|
||||
*
|
||||
* KEYWORDS:
|
||||
* pswSpeechPara
|
||||
**************************************************************************/
|
||||
|
||||
int decoderHomingFrameTest(Shortword pswSpeechPara[], int iLastPara)
|
||||
{
|
||||
/* the n[] array contains the number of bits in each speech parameter */
|
||||
static int n[] = {5, 11, 9, 8, 1, 2, 7, 7, 5, 7, 7, 5, 7, 7, 5, 7, 7, 5};
|
||||
|
||||
static Shortword dhf_mask[] =
|
||||
{
|
||||
0x0000, /* R0 */
|
||||
0x0371, /* LPC1 */
|
||||
0x015E, /* LPC2 */
|
||||
0x00c3, /* LPC3 */
|
||||
0x0001, /* INT_LPC */
|
||||
0x0000, /* MODE */
|
||||
0x0047, /* CODE1_1 */
|
||||
0x004a, /* CODE2_1 */
|
||||
0x0000, /* GSP0_1 */
|
||||
0x0009, /* CODE1_2 */
|
||||
0x0026, /* CODE2_2 */
|
||||
0x0007, /* GSP0_2 */
|
||||
0x0000, /* CODE1_3 */
|
||||
0x0000, /* CODE2_3 */
|
||||
0x0000, /* GSP0_3 */
|
||||
0x0000, /* CODE1_4 */
|
||||
0x0000, /* CODE2_4 */
|
||||
0x0000 /* GSP0_4 */
|
||||
};
|
||||
|
||||
int i;
|
||||
int j;
|
||||
|
||||
for (i = 0; i < iLastPara; i++)
|
||||
{
|
||||
j = ((pswSpeechPara[i] & ~(~0 << n[i])) ^ dhf_mask[i]);
|
||||
if (j)
|
||||
break;
|
||||
}
|
||||
|
||||
return !j;
|
||||
}
|
||||
|
||||
|
||||
/***************************************************************************
|
||||
*
|
||||
* FUNCTION NAME: decoderReset
|
||||
*
|
||||
* PURPOSE:
|
||||
* resets all of the state variables for the decoder
|
||||
*
|
||||
* INPUT:
|
||||
* None
|
||||
*
|
||||
* OUTPUT:
|
||||
* None
|
||||
*
|
||||
* RETURN:
|
||||
* None
|
||||
*
|
||||
* REFERENCES: Sub-clause 10 of GSM Recomendation 06.02
|
||||
*
|
||||
* KEYWORDS:
|
||||
**************************************************************************/
|
||||
|
||||
void decoderReset(void)
|
||||
{
|
||||
/*_________________________________________________________________________
|
||||
| |
|
||||
| External declarations for decoder variables which need to be reset |
|
||||
|_________________________________________________________________________|
|
||||
*/
|
||||
|
||||
/* variables defined in sp_dec.c */
|
||||
/* ----------------------------- */
|
||||
|
||||
extern Shortword gswPostFiltAgcGain,
|
||||
gpswPostFiltStateNum[NP],
|
||||
gpswPostFiltStateDenom[NP],
|
||||
swPostEmphasisState,
|
||||
pswSynthFiltState[NP],
|
||||
pswOldFrmKsDec[NP],
|
||||
pswOldFrmAsDec[NP],
|
||||
pswOldFrmPFNum[NP],
|
||||
pswOldFrmPFDenom[NP],
|
||||
swOldR0Dec,
|
||||
pswLtpStateBaseDec[LTP_LEN + S_LEN],
|
||||
pswPPreState[LTP_LEN + S_LEN];
|
||||
|
||||
extern Shortword swMuteFlagOld; /* error concealment */
|
||||
|
||||
|
||||
/* variables defined in err_conc.c *//* error concealment */
|
||||
/* ------------------------------- *//* error concealment */
|
||||
|
||||
extern Longword plSubfrEnergyMem[4]; /* error concealment */
|
||||
extern Shortword swLevelMem[4],
|
||||
lastR0, /* error concealment */
|
||||
pswLastGood[18], /* error concealment */
|
||||
swState,
|
||||
swLastFlag; /* error concealment */
|
||||
|
||||
/*_________________________________________________________________________
|
||||
| |
|
||||
| Automatic Variables |
|
||||
|_________________________________________________________________________|
|
||||
*/
|
||||
|
||||
int i;
|
||||
|
||||
/*_________________________________________________________________________
|
||||
| |
|
||||
| Executable code |
|
||||
|_________________________________________________________________________|
|
||||
*/
|
||||
|
||||
/* reset all the decoder state variables */
|
||||
/* ------------------------------------- */
|
||||
|
||||
swOldR0Dec = 0;
|
||||
|
||||
gswPostFiltAgcGain = 0;
|
||||
|
||||
swPostEmphasisState = 0;
|
||||
|
||||
for (i = 0; i < NP; i++)
|
||||
{
|
||||
gpswPostFiltStateNum[i] = 0;
|
||||
gpswPostFiltStateDenom[i] = 0;
|
||||
pswSynthFiltState[i] = 0;
|
||||
pswOldFrmKsDec[i] = 0;
|
||||
pswOldFrmAsDec[i] = 0;
|
||||
pswOldFrmPFNum[i] = 0;
|
||||
pswOldFrmPFDenom[i] = 0;
|
||||
}
|
||||
|
||||
for (i = 0; i < (LTP_LEN + S_LEN); i++)
|
||||
{
|
||||
pswLtpStateBaseDec[i] = 0;
|
||||
pswPPreState[i] = 0;
|
||||
}
|
||||
|
||||
|
||||
/* reset all the error concealment state variables */
|
||||
/* ----------------------------------------------- */
|
||||
|
||||
swMuteFlagOld = 0;
|
||||
|
||||
lastR0 = 0;
|
||||
swState = 7;
|
||||
swLastFlag = 0;
|
||||
for (i = 0; i < 3; i++)
|
||||
{
|
||||
plSubfrEnergyMem[i] = 80;
|
||||
swLevelMem[i] = -72;
|
||||
}
|
||||
for (i = 0; i < 18; i++)
|
||||
{
|
||||
pswLastGood[i] = 0;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/***************************************************************************
|
||||
*
|
||||
* FUNCTION NAME: encoderHomingFrameTest
|
||||
*
|
||||
* PURPOSE:
|
||||
* Checks if a frame of input samples matches the Encoder Homing Frame
|
||||
* pattern, which is 0x0008 for all 160 samples in the frame.
|
||||
*
|
||||
* INPUT:
|
||||
* pswSpeech[] one frame of speech samples
|
||||
*
|
||||
* OUTPUT:
|
||||
* None
|
||||
*
|
||||
* RETURN:
|
||||
* 0 input frame does not match the Encoder Homing Frame pattern.
|
||||
* 1 input frame matches the Encoder Homing Frame pattern.
|
||||
*
|
||||
* REFERENCES: Sub-clause 10 of GSM Recomendation 06.02
|
||||
*
|
||||
* KEYWORDS:
|
||||
* pswSpeech
|
||||
**************************************************************************/
|
||||
|
||||
int encoderHomingFrameTest(Shortword pswSpeech[])
|
||||
{
|
||||
int i;
|
||||
Shortword j;
|
||||
|
||||
for (i = 0; i < F_LEN; i++)
|
||||
{
|
||||
j = pswSpeech[i] ^ EHF_MASK;
|
||||
if (j)
|
||||
break;
|
||||
}
|
||||
|
||||
return !j;
|
||||
}
|
||||
|
||||
/***************************************************************************
|
||||
*
|
||||
* FUNCTION NAME: encoderReset
|
||||
*
|
||||
* PURPOSE:
|
||||
* resets all of the state variables for the encoder
|
||||
*
|
||||
* INPUT:
|
||||
* None
|
||||
*
|
||||
* OUTPUT:
|
||||
* None
|
||||
*
|
||||
* RETURN:
|
||||
* None
|
||||
*
|
||||
* REFERENCES: Sub-clause 10 of GSM Recomendation 06.02
|
||||
*
|
||||
* KEYWORDS:
|
||||
**************************************************************************/
|
||||
|
||||
void encoderReset(void)
|
||||
{
|
||||
|
||||
/*_________________________________________________________________________
|
||||
| |
|
||||
| External declarations for encoder variables which need to be reset |
|
||||
|_________________________________________________________________________|
|
||||
*/
|
||||
|
||||
/* variables defined in sp_enc.c */
|
||||
/* ----------------------------- */
|
||||
|
||||
extern Shortword swOldR0;
|
||||
extern Shortword swOldR0Index;
|
||||
|
||||
extern struct NormSw psnsWSfrmEngSpace[];
|
||||
|
||||
extern Shortword pswHPFXState[];
|
||||
extern Shortword pswHPFYState[];
|
||||
extern Shortword pswOldFrmKs[];
|
||||
extern Shortword pswOldFrmAs[];
|
||||
extern Shortword pswOldFrmSNWCoefs[];
|
||||
extern Shortword pswWgtSpeechSpace[];
|
||||
|
||||
extern Shortword pswSpeech[]; /* input speech */
|
||||
|
||||
extern Shortword swPtch;
|
||||
|
||||
|
||||
/* variables defined in sp_frm.c */
|
||||
/* ----------------------------- */
|
||||
|
||||
extern Shortword pswAnalysisState[NP];
|
||||
|
||||
extern Shortword pswWStateNum[NP],
|
||||
pswWStateDenom[NP];
|
||||
|
||||
|
||||
/* variables defined in sp_sfrm.c */
|
||||
/* ------------------------------ */
|
||||
|
||||
extern Shortword pswLtpStateBase[LTP_LEN + S_LEN];
|
||||
extern Shortword pswHState[NP];
|
||||
extern Shortword pswHNWState[HNW_BUFF_LEN];
|
||||
|
||||
/*_________________________________________________________________________
|
||||
| |
|
||||
| Automatic Variables |
|
||||
|_________________________________________________________________________|
|
||||
*/
|
||||
|
||||
int i;
|
||||
|
||||
/*_________________________________________________________________________
|
||||
| |
|
||||
| Executable code |
|
||||
|_________________________________________________________________________|
|
||||
*/
|
||||
|
||||
/* reset all the encoder state variables */
|
||||
/* ------------------------------------- */
|
||||
|
||||
swOldR0Index = 0;
|
||||
swOldR0 = 0;
|
||||
|
||||
for (i = 0; i < 2 * N_SUB; i++)
|
||||
{
|
||||
psnsWSfrmEngSpace[i].man = 0;
|
||||
psnsWSfrmEngSpace[i].sh = 0;
|
||||
}
|
||||
|
||||
for (i = 0; i < 4; i++)
|
||||
pswHPFXState[i] = 0;
|
||||
|
||||
for (i = 0; i < 8; i++)
|
||||
pswHPFYState[i] = 0;
|
||||
|
||||
for (i = 0; i < NP; i++)
|
||||
{
|
||||
pswOldFrmKs[i] = 0;
|
||||
pswOldFrmAs[i] = 0;
|
||||
pswOldFrmSNWCoefs[i] = 0;
|
||||
pswAnalysisState[i] = 0;
|
||||
pswWStateNum[i] = 0;
|
||||
pswWStateDenom[i] = 0;
|
||||
pswHState[i] = 0;
|
||||
}
|
||||
|
||||
for (i = 0; i < (F_LEN + LMAX + CG_INT_MACS / 2); i++)
|
||||
pswWgtSpeechSpace[i] = 0;
|
||||
|
||||
for (i = 0; i < INBUFFSZ; i++)
|
||||
pswSpeech[i] = 0;
|
||||
|
||||
for (i = 0; i < (LTP_LEN + S_LEN); i++)
|
||||
pswLtpStateBase[i] = 0;
|
||||
|
||||
for (i = 0; i < HNW_BUFF_LEN; i++)
|
||||
pswHNWState[i] = 0;
|
||||
|
||||
swPtch = 1;
|
||||
}
|
||||
|
||||
/***************************************************************************
|
||||
*
|
||||
* FUNCTION NAME: resetDec
|
||||
*
|
||||
* PURPOSE:
|
||||
* resets all of the state variables for the decoder, and for the
|
||||
* receive DTX and Comfort Noise.
|
||||
*
|
||||
* INPUT:
|
||||
* None
|
||||
*
|
||||
* OUTPUT:
|
||||
* None
|
||||
*
|
||||
* RETURN:
|
||||
* None
|
||||
*
|
||||
* REFERENCES: Sub-clause 10 of GSM Recomendation 06.02
|
||||
*
|
||||
* KEYWORDS:
|
||||
**************************************************************************/
|
||||
|
||||
void resetDec(void)
|
||||
{
|
||||
decoderReset(); /* reset all the state variables in
|
||||
* the speech decoder */
|
||||
dtxResetRx(); /* reset all the receive DTX and CN
|
||||
* state variables */
|
||||
}
|
||||
|
||||
/***************************************************************************
|
||||
*
|
||||
* FUNCTION NAME: resetEnc
|
||||
*
|
||||
* PURPOSE:
|
||||
* resets all of the state variables for the encoder and VAD, and for
|
||||
* the transmit DTX and Comfort Noise.
|
||||
*
|
||||
* INPUT:
|
||||
* None
|
||||
*
|
||||
* OUTPUT:
|
||||
* None
|
||||
*
|
||||
* RETURN:
|
||||
* None
|
||||
*
|
||||
* REFERENCES: Sub-clause 10 of GSM Recomendation 06.02
|
||||
*
|
||||
* KEYWORDS:
|
||||
**************************************************************************/
|
||||
|
||||
void resetEnc(void)
|
||||
{
|
||||
|
||||
encoderReset(); /* reset all the state variables in
|
||||
* the speech encoder */
|
||||
vad_reset(); /* reset all the VAD state variables */
|
||||
|
||||
dtxResetTx(); /* reset all the transmit DTX and CN
|
||||
* state variables */
|
||||
}
|
||||
|
||||
/***************************************************************************
|
||||
*
|
||||
* FUNCTION NAME: dtxResetTx
|
||||
*
|
||||
* PURPOSE:
|
||||
* reset all the transmit DTX and CN state variables
|
||||
*
|
||||
* INPUT:
|
||||
* None
|
||||
*
|
||||
* OUTPUT:
|
||||
* None
|
||||
*
|
||||
* RETURN:
|
||||
* None
|
||||
*
|
||||
* REFERENCES: Sub-clause 10 of GSM Recomendation 06.02
|
||||
*
|
||||
* KEYWORDS:
|
||||
**************************************************************************/
|
||||
|
||||
void dtxResetTx(void)
|
||||
{
|
||||
|
||||
/*_________________________________________________________________________
|
||||
| |
|
||||
| External declarations for encoder variables which need to be reset |
|
||||
|_________________________________________________________________________|
|
||||
*/
|
||||
|
||||
/* variables defined in sp_enc.c */
|
||||
/* ----------------------------- */
|
||||
|
||||
extern Shortword swTxGsHistPtr;
|
||||
|
||||
|
||||
/* variables defined in dtx.c */
|
||||
/* -------------------------- */
|
||||
|
||||
extern Shortword swVadFrmCnt; /* Indicates the number of sequential
|
||||
* frames where VAD == 0 */
|
||||
extern short int siUpdPointer;
|
||||
extern Shortword swNElapsed;
|
||||
|
||||
/*_________________________________________________________________________
|
||||
| |
|
||||
| Automatic Variables |
|
||||
|_________________________________________________________________________|
|
||||
*/
|
||||
|
||||
|
||||
/*_________________________________________________________________________
|
||||
| |
|
||||
| Executable code |
|
||||
|_________________________________________________________________________|
|
||||
*/
|
||||
|
||||
/* reset all the transmit DTX and CN state variables */
|
||||
/* ------------------------------------------------- */
|
||||
|
||||
swTxGsHistPtr = 0;
|
||||
|
||||
swVadFrmCnt = 0;
|
||||
|
||||
siUpdPointer = 0;
|
||||
|
||||
swNElapsed = 50;
|
||||
|
||||
}
|
||||
|
||||
/***************************************************************************
|
||||
*
|
||||
* FUNCTION NAME: dtxResetRx
|
||||
*
|
||||
* PURPOSE:
|
||||
* reset all the receive DTX and CN state variables
|
||||
*
|
||||
* INPUT:
|
||||
* None
|
||||
*
|
||||
* OUTPUT:
|
||||
* None
|
||||
*
|
||||
* RETURN:
|
||||
* None
|
||||
*
|
||||
* REFERENCES: Sub-clause 10 of GSM Recomendation 06.02
|
||||
*
|
||||
* KEYWORDS:
|
||||
**************************************************************************/
|
||||
|
||||
void dtxResetRx(void)
|
||||
{
|
||||
|
||||
/*_________________________________________________________________________
|
||||
| |
|
||||
| External declarations for encoder variables which need to be reset |
|
||||
|_________________________________________________________________________|
|
||||
*/
|
||||
|
||||
/* variables defined in sp_dec.c */
|
||||
/* ----------------------------- */
|
||||
|
||||
extern Shortword swRxDTXState;
|
||||
extern Shortword swDecoMode;
|
||||
extern Shortword swDtxMuting;
|
||||
extern Shortword swDtxBfiCnt;
|
||||
|
||||
extern Shortword swOldR0IndexDec;
|
||||
|
||||
extern Shortword swRxGsHistPtr;
|
||||
extern Longword pL_RxGsHist[(OVERHANG - 1) * N_SUB];
|
||||
|
||||
|
||||
/*_________________________________________________________________________
|
||||
| |
|
||||
| Automatic Variables |
|
||||
|_________________________________________________________________________|
|
||||
*/
|
||||
|
||||
int i;
|
||||
|
||||
|
||||
/*_________________________________________________________________________
|
||||
| |
|
||||
| Executable code |
|
||||
|_________________________________________________________________________|
|
||||
*/
|
||||
|
||||
/* reset all the receive DTX and CN state variables */
|
||||
/* ------------------------------------------------ */
|
||||
|
||||
swRxDTXState = CNINTPER - 1;
|
||||
swDecoMode = SPEECH;
|
||||
swDtxMuting = 0;
|
||||
swDtxBfiCnt = 0;
|
||||
|
||||
swOldR0IndexDec = 0;
|
||||
|
||||
swRxGsHistPtr = 0;
|
||||
|
||||
for (i = 0; i < (OVERHANG - 1) * N_SUB; i++)
|
||||
pL_RxGsHist[i] = 0;
|
||||
|
||||
}
|
||||
648
src/libs/gsmhr/gsmhr_homing.cpp
Normal file
648
src/libs/gsmhr/gsmhr_homing.cpp
Normal file
@@ -0,0 +1,648 @@
|
||||
/**************************************************************************
|
||||
*
|
||||
* File Name: homing.c
|
||||
*
|
||||
* Purpose:
|
||||
* This file contains the following functions:
|
||||
*
|
||||
* decoderHomingFrameTest() - checks if a frame of input speech
|
||||
* parameters matches the Decoder Homing
|
||||
* Frame pattern.
|
||||
*
|
||||
* decoderReset() - called by resetDec() to reset all of the state
|
||||
* variables for the decoder
|
||||
*
|
||||
* encoderHomingFrameTest() - checks if a frame of input samples
|
||||
* matches the Encoder Homing Frame pattern.
|
||||
*
|
||||
* encoderReset() - called by resetEnc() to reset all the state
|
||||
* variables for the encoder.
|
||||
*
|
||||
* resetDec() - calls functions to reset the state variables for the
|
||||
* decoder, and for the receive DTX and Comfort Noise.
|
||||
*
|
||||
* resetEnc() - calls functions to reset the state variables for the
|
||||
* encoder and VAD, and for the transmit DTX and
|
||||
* Comfort Noise.
|
||||
*
|
||||
* dtxResetTx() - called by resetEnc() to reset all of the transmit
|
||||
* DTX and Comfort Noise state variables
|
||||
*
|
||||
* dtxResetRx() - called by resetDec() to reset all of the receive
|
||||
* DTX and Comfort Noise state variables
|
||||
*
|
||||
**************************************************************************/
|
||||
|
||||
/*_________________________________________________________________________
|
||||
| |
|
||||
| Include Files |
|
||||
|_________________________________________________________________________|
|
||||
*/
|
||||
|
||||
#include "gsmhr_typedefs.h"
|
||||
#include "gsmhr_vad.h"
|
||||
#include "gsmhr_dtx.h"
|
||||
#include "gsmhr_homing.h"
|
||||
|
||||
/*_________________________________________________________________________
|
||||
| |
|
||||
| Local Defines |
|
||||
|_________________________________________________________________________|
|
||||
*/
|
||||
|
||||
#define EHF_MASK 0x0008 /* Encoder Homing Frame pattern */
|
||||
#define LMAX 142 /* largest lag (integer sense) */
|
||||
#define CG_INT_MACS 6 /* Number of multiply-accumulates in
|
||||
* one interpolation */
|
||||
#define NUM_CLOSED 3 /* maximum number of lags searched */
|
||||
#define LPCSTARTINDEX 25 /* where the LPC analysis window
|
||||
* starts */
|
||||
#define INBUFFSZ LPCSTARTINDEX + A_LEN /* input buffer size */
|
||||
|
||||
|
||||
#define LTP_LEN 147 /* maximum ltp lag */
|
||||
#define LSMAX (LMAX + CG_INT_MACS/2)
|
||||
#define HNW_BUFF_LEN LSMAX
|
||||
|
||||
|
||||
/***************************************************************************
|
||||
*
|
||||
* FUNCTION NAME: decoderHomingFrameTest
|
||||
*
|
||||
* PURPOSE:
|
||||
* Checks if a frame of input speech parameters matches the Decoder
|
||||
* Homing Frame pattern, which is:
|
||||
*
|
||||
* parameter decimal value hexidecimal value
|
||||
* --------- ------------- -----------------
|
||||
* R0 0 0x0000
|
||||
* LPC1 881 0x0371
|
||||
* LPC2 350 0x015E
|
||||
* LPC3 195 0x00c3
|
||||
* INT_LPC 1 0x0001
|
||||
* MODE 0 0x0000
|
||||
* CODE1_1 71 0x0047
|
||||
* CODE2_1 74 0x004a
|
||||
* GSP0_1 0 0x0000
|
||||
* CODE1_2 9 0x0009
|
||||
* CODE2_2 38 0x0026
|
||||
* GSP0_2 7 0x0007
|
||||
* CODE1_3 0 0x0000
|
||||
* CODE2_3 0 0x0000
|
||||
* GSP0_3 0 0x0000
|
||||
* CODE1_4 0 0x0000
|
||||
* CODE2_4 0 0x0000
|
||||
* GSP0_4 0 0x0000
|
||||
*
|
||||
* INPUT:
|
||||
* pswSpeechPara[] - one frame of speech parameters
|
||||
* in decoder input format
|
||||
*
|
||||
* iLastPara - the number of consecutive parameters in
|
||||
* pswSpeechPara[] to match.
|
||||
*
|
||||
* OUTPUT:
|
||||
* None
|
||||
*
|
||||
* RETURN:
|
||||
* 0 input frame does not match the Decoder Homing Frame pattern.
|
||||
* 1 input frame matches the Decoder Homing Frame pattern.
|
||||
*
|
||||
* REFERENCES: Sub-clause 10 of GSM Recomendation 06.02
|
||||
*
|
||||
* KEYWORDS:
|
||||
* pswSpeechPara
|
||||
**************************************************************************/
|
||||
|
||||
int GsmHrCodec::decoderHomingFrameTest(int16_t pswSpeechPara[], int iLastPara)
|
||||
{
|
||||
/* the n[] array contains the number of bits in each speech parameter */
|
||||
static int n[] = {5, 11, 9, 8, 1, 2, 7, 7, 5, 7, 7, 5, 7, 7, 5, 7, 7, 5};
|
||||
|
||||
static int16_t dhf_mask[] =
|
||||
{
|
||||
0x0000, /* R0 */
|
||||
0x0371, /* LPC1 */
|
||||
0x015E, /* LPC2 */
|
||||
0x00c3, /* LPC3 */
|
||||
0x0001, /* INT_LPC */
|
||||
0x0000, /* MODE */
|
||||
0x0047, /* CODE1_1 */
|
||||
0x004a, /* CODE2_1 */
|
||||
0x0000, /* GSP0_1 */
|
||||
0x0009, /* CODE1_2 */
|
||||
0x0026, /* CODE2_2 */
|
||||
0x0007, /* GSP0_2 */
|
||||
0x0000, /* CODE1_3 */
|
||||
0x0000, /* CODE2_3 */
|
||||
0x0000, /* GSP0_3 */
|
||||
0x0000, /* CODE1_4 */
|
||||
0x0000, /* CODE2_4 */
|
||||
0x0000 /* GSP0_4 */
|
||||
};
|
||||
|
||||
int i;
|
||||
int j;
|
||||
|
||||
for (i = 0; i < iLastPara; i++)
|
||||
{
|
||||
j = ((pswSpeechPara[i] & ~(~0 << n[i])) ^ dhf_mask[i]);
|
||||
if (j)
|
||||
break;
|
||||
}
|
||||
|
||||
return !j;
|
||||
}
|
||||
|
||||
|
||||
/***************************************************************************
|
||||
*
|
||||
* FUNCTION NAME: decoderReset
|
||||
*
|
||||
* PURPOSE:
|
||||
* resets all of the state variables for the decoder
|
||||
*
|
||||
* INPUT:
|
||||
* None
|
||||
*
|
||||
* OUTPUT:
|
||||
* None
|
||||
*
|
||||
* RETURN:
|
||||
* None
|
||||
*
|
||||
* REFERENCES: Sub-clause 10 of GSM Recomendation 06.02
|
||||
*
|
||||
* KEYWORDS:
|
||||
**************************************************************************/
|
||||
|
||||
void GsmHrCodec::decoderReset(void)
|
||||
{
|
||||
/*_________________________________________________________________________
|
||||
| |
|
||||
| External declarations for decoder variables which need to be reset |
|
||||
|_________________________________________________________________________|
|
||||
*/
|
||||
|
||||
/* variables defined in sp_dec.c */
|
||||
/* ----------------------------- */
|
||||
|
||||
extern int16_t gswPostFiltAgcGain,
|
||||
gpswPostFiltStateNum[NP],
|
||||
gpswPostFiltStateDenom[NP],
|
||||
swPostEmphasisState,
|
||||
pswSynthFiltState[NP],
|
||||
pswOldFrmKsDec[NP],
|
||||
pswOldFrmAsDec[NP],
|
||||
pswOldFrmPFNum[NP],
|
||||
pswOldFrmPFDenom[NP],
|
||||
swOldR0Dec,
|
||||
pswLtpStateBaseDec[LTP_LEN + S_LEN],
|
||||
pswPPreState[LTP_LEN + S_LEN];
|
||||
|
||||
extern int16_t swMuteFlagOld; /* error concealment */
|
||||
|
||||
|
||||
/* variables defined in err_conc.c *//* error concealment */
|
||||
/* ------------------------------- *//* error concealment */
|
||||
|
||||
extern int32_t plSubfrEnergyMem[4]; /* error concealment */
|
||||
extern int16_t swLevelMem[4],
|
||||
lastR0, /* error concealment */
|
||||
pswLastGood[18], /* error concealment */
|
||||
swState,
|
||||
swLastFlag; /* error concealment */
|
||||
|
||||
/*_________________________________________________________________________
|
||||
| |
|
||||
| Automatic Variables |
|
||||
|_________________________________________________________________________|
|
||||
*/
|
||||
|
||||
int i;
|
||||
|
||||
/*_________________________________________________________________________
|
||||
| |
|
||||
| Executable code |
|
||||
|_________________________________________________________________________|
|
||||
*/
|
||||
|
||||
/* reset all the decoder state variables */
|
||||
/* ------------------------------------- */
|
||||
|
||||
swOldR0Dec = 0;
|
||||
|
||||
gswPostFiltAgcGain = 0;
|
||||
|
||||
swPostEmphasisState = 0;
|
||||
|
||||
for (i = 0; i < NP; i++)
|
||||
{
|
||||
gpswPostFiltStateNum[i] = 0;
|
||||
gpswPostFiltStateDenom[i] = 0;
|
||||
pswSynthFiltState[i] = 0;
|
||||
pswOldFrmKsDec[i] = 0;
|
||||
pswOldFrmAsDec[i] = 0;
|
||||
pswOldFrmPFNum[i] = 0;
|
||||
pswOldFrmPFDenom[i] = 0;
|
||||
}
|
||||
|
||||
for (i = 0; i < (LTP_LEN + S_LEN); i++)
|
||||
{
|
||||
pswLtpStateBaseDec[i] = 0;
|
||||
pswPPreState[i] = 0;
|
||||
}
|
||||
|
||||
|
||||
/* reset all the error concealment state variables */
|
||||
/* ----------------------------------------------- */
|
||||
|
||||
swMuteFlagOld = 0;
|
||||
|
||||
lastR0 = 0;
|
||||
swState = 7;
|
||||
swLastFlag = 0;
|
||||
for (i = 0; i < 3; i++)
|
||||
{
|
||||
plSubfrEnergyMem[i] = 80;
|
||||
swLevelMem[i] = -72;
|
||||
}
|
||||
for (i = 0; i < 18; i++)
|
||||
{
|
||||
pswLastGood[i] = 0;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/***************************************************************************
|
||||
*
|
||||
* FUNCTION NAME: encoderHomingFrameTest
|
||||
*
|
||||
* PURPOSE:
|
||||
* Checks if a frame of input samples matches the Encoder Homing Frame
|
||||
* pattern, which is 0x0008 for all 160 samples in the frame.
|
||||
*
|
||||
* INPUT:
|
||||
* pswSpeech[] one frame of speech samples
|
||||
*
|
||||
* OUTPUT:
|
||||
* None
|
||||
*
|
||||
* RETURN:
|
||||
* 0 input frame does not match the Encoder Homing Frame pattern.
|
||||
* 1 input frame matches the Encoder Homing Frame pattern.
|
||||
*
|
||||
* REFERENCES: Sub-clause 10 of GSM Recomendation 06.02
|
||||
*
|
||||
* KEYWORDS:
|
||||
* pswSpeech
|
||||
**************************************************************************/
|
||||
|
||||
int encoderHomingFrameTest(int16_t pswSpeech[])
|
||||
{
|
||||
int i;
|
||||
int16_t j;
|
||||
|
||||
for (i = 0; i < F_LEN; i++)
|
||||
{
|
||||
j = pswSpeech[i] ^ EHF_MASK;
|
||||
if (j)
|
||||
break;
|
||||
}
|
||||
|
||||
return !j;
|
||||
}
|
||||
|
||||
/***************************************************************************
|
||||
*
|
||||
* FUNCTION NAME: encoderReset
|
||||
*
|
||||
* PURPOSE:
|
||||
* resets all of the state variables for the encoder
|
||||
*
|
||||
* INPUT:
|
||||
* None
|
||||
*
|
||||
* OUTPUT:
|
||||
* None
|
||||
*
|
||||
* RETURN:
|
||||
* None
|
||||
*
|
||||
* REFERENCES: Sub-clause 10 of GSM Recomendation 06.02
|
||||
*
|
||||
* KEYWORDS:
|
||||
**************************************************************************/
|
||||
|
||||
void encoderReset(void)
|
||||
{
|
||||
|
||||
/*_________________________________________________________________________
|
||||
| |
|
||||
| External declarations for encoder variables which need to be reset |
|
||||
|_________________________________________________________________________|
|
||||
*/
|
||||
|
||||
/* variables defined in sp_enc.c */
|
||||
/* ----------------------------- */
|
||||
|
||||
extern int16_t swOldR0;
|
||||
extern int16_t swOldR0Index;
|
||||
|
||||
extern struct NormSw psnsWSfrmEngSpace[];
|
||||
|
||||
extern int16_t pswHPFXState[];
|
||||
extern int16_t pswHPFYState[];
|
||||
extern int16_t pswOldFrmKs[];
|
||||
extern int16_t pswOldFrmAs[];
|
||||
extern int16_t pswOldFrmSNWCoefs[];
|
||||
extern int16_t pswWgtSpeechSpace[];
|
||||
|
||||
extern int16_t pswSpeech[]; /* input speech */
|
||||
|
||||
extern int16_t swPtch;
|
||||
|
||||
|
||||
/* variables defined in sp_frm.c */
|
||||
/* ----------------------------- */
|
||||
|
||||
extern int16_t pswAnalysisState[NP];
|
||||
|
||||
extern int16_t pswWStateNum[NP],
|
||||
pswWStateDenom[NP];
|
||||
|
||||
|
||||
/* variables defined in sp_sfrm.c */
|
||||
/* ------------------------------ */
|
||||
|
||||
extern int16_t pswLtpStateBase[LTP_LEN + S_LEN];
|
||||
extern int16_t pswHState[NP];
|
||||
extern int16_t pswHNWState[HNW_BUFF_LEN];
|
||||
|
||||
/*_________________________________________________________________________
|
||||
| |
|
||||
| Automatic Variables |
|
||||
|_________________________________________________________________________|
|
||||
*/
|
||||
|
||||
int i;
|
||||
|
||||
/*_________________________________________________________________________
|
||||
| |
|
||||
| Executable code |
|
||||
|_________________________________________________________________________|
|
||||
*/
|
||||
|
||||
/* reset all the encoder state variables */
|
||||
/* ------------------------------------- */
|
||||
|
||||
swOldR0Index = 0;
|
||||
swOldR0 = 0;
|
||||
|
||||
for (i = 0; i < 2 * N_SUB; i++)
|
||||
{
|
||||
psnsWSfrmEngSpace[i].man = 0;
|
||||
psnsWSfrmEngSpace[i].sh = 0;
|
||||
}
|
||||
|
||||
for (i = 0; i < 4; i++)
|
||||
pswHPFXState[i] = 0;
|
||||
|
||||
for (i = 0; i < 8; i++)
|
||||
pswHPFYState[i] = 0;
|
||||
|
||||
for (i = 0; i < NP; i++)
|
||||
{
|
||||
pswOldFrmKs[i] = 0;
|
||||
pswOldFrmAs[i] = 0;
|
||||
pswOldFrmSNWCoefs[i] = 0;
|
||||
pswAnalysisState[i] = 0;
|
||||
pswWStateNum[i] = 0;
|
||||
pswWStateDenom[i] = 0;
|
||||
pswHState[i] = 0;
|
||||
}
|
||||
|
||||
for (i = 0; i < (F_LEN + LMAX + CG_INT_MACS / 2); i++)
|
||||
pswWgtSpeechSpace[i] = 0;
|
||||
|
||||
for (i = 0; i < INBUFFSZ; i++)
|
||||
pswSpeech[i] = 0;
|
||||
|
||||
for (i = 0; i < (LTP_LEN + S_LEN); i++)
|
||||
pswLtpStateBase[i] = 0;
|
||||
|
||||
for (i = 0; i < HNW_BUFF_LEN; i++)
|
||||
pswHNWState[i] = 0;
|
||||
|
||||
swPtch = 1;
|
||||
}
|
||||
|
||||
/***************************************************************************
|
||||
*
|
||||
* FUNCTION NAME: resetDec
|
||||
*
|
||||
* PURPOSE:
|
||||
* resets all of the state variables for the decoder, and for the
|
||||
* receive DTX and Comfort Noise.
|
||||
*
|
||||
* INPUT:
|
||||
* None
|
||||
*
|
||||
* OUTPUT:
|
||||
* None
|
||||
*
|
||||
* RETURN:
|
||||
* None
|
||||
*
|
||||
* REFERENCES: Sub-clause 10 of GSM Recomendation 06.02
|
||||
*
|
||||
* KEYWORDS:
|
||||
**************************************************************************/
|
||||
|
||||
void resetDec(void)
|
||||
{
|
||||
decoderReset(); /* reset all the state variables in
|
||||
* the speech decoder */
|
||||
dtxResetRx(); /* reset all the receive DTX and CN
|
||||
* state variables */
|
||||
}
|
||||
|
||||
/***************************************************************************
|
||||
*
|
||||
* FUNCTION NAME: resetEnc
|
||||
*
|
||||
* PURPOSE:
|
||||
* resets all of the state variables for the encoder and VAD, and for
|
||||
* the transmit DTX and Comfort Noise.
|
||||
*
|
||||
* INPUT:
|
||||
* None
|
||||
*
|
||||
* OUTPUT:
|
||||
* None
|
||||
*
|
||||
* RETURN:
|
||||
* None
|
||||
*
|
||||
* REFERENCES: Sub-clause 10 of GSM Recomendation 06.02
|
||||
*
|
||||
* KEYWORDS:
|
||||
**************************************************************************/
|
||||
|
||||
void resetEnc(void)
|
||||
{
|
||||
|
||||
encoderReset(); /* reset all the state variables in
|
||||
* the speech encoder */
|
||||
vad_reset(); /* reset all the VAD state variables */
|
||||
|
||||
dtxResetTx(); /* reset all the transmit DTX and CN
|
||||
* state variables */
|
||||
}
|
||||
|
||||
/***************************************************************************
|
||||
*
|
||||
* FUNCTION NAME: dtxResetTx
|
||||
*
|
||||
* PURPOSE:
|
||||
* reset all the transmit DTX and CN state variables
|
||||
*
|
||||
* INPUT:
|
||||
* None
|
||||
*
|
||||
* OUTPUT:
|
||||
* None
|
||||
*
|
||||
* RETURN:
|
||||
* None
|
||||
*
|
||||
* REFERENCES: Sub-clause 10 of GSM Recomendation 06.02
|
||||
*
|
||||
* KEYWORDS:
|
||||
**************************************************************************/
|
||||
|
||||
void dtxResetTx(void)
|
||||
{
|
||||
|
||||
/*_________________________________________________________________________
|
||||
| |
|
||||
| External declarations for encoder variables which need to be reset |
|
||||
|_________________________________________________________________________|
|
||||
*/
|
||||
|
||||
/* variables defined in sp_enc.c */
|
||||
/* ----------------------------- */
|
||||
|
||||
extern int16_t swTxGsHistPtr;
|
||||
|
||||
|
||||
/* variables defined in dtx.c */
|
||||
/* -------------------------- */
|
||||
|
||||
extern int16_t swVadFrmCnt; /* Indicates the number of sequential
|
||||
* frames where VAD == 0 */
|
||||
extern short int siUpdPointer;
|
||||
extern int16_t swNElapsed;
|
||||
|
||||
/*_________________________________________________________________________
|
||||
| |
|
||||
| Automatic Variables |
|
||||
|_________________________________________________________________________|
|
||||
*/
|
||||
|
||||
|
||||
/*_________________________________________________________________________
|
||||
| |
|
||||
| Executable code |
|
||||
|_________________________________________________________________________|
|
||||
*/
|
||||
|
||||
/* reset all the transmit DTX and CN state variables */
|
||||
/* ------------------------------------------------- */
|
||||
|
||||
swTxGsHistPtr = 0;
|
||||
|
||||
swVadFrmCnt = 0;
|
||||
|
||||
siUpdPointer = 0;
|
||||
|
||||
swNElapsed = 50;
|
||||
|
||||
}
|
||||
|
||||
/***************************************************************************
|
||||
*
|
||||
* FUNCTION NAME: dtxResetRx
|
||||
*
|
||||
* PURPOSE:
|
||||
* reset all the receive DTX and CN state variables
|
||||
*
|
||||
* INPUT:
|
||||
* None
|
||||
*
|
||||
* OUTPUT:
|
||||
* None
|
||||
*
|
||||
* RETURN:
|
||||
* None
|
||||
*
|
||||
* REFERENCES: Sub-clause 10 of GSM Recomendation 06.02
|
||||
*
|
||||
* KEYWORDS:
|
||||
**************************************************************************/
|
||||
|
||||
void dtxResetRx(void)
|
||||
{
|
||||
|
||||
/*_________________________________________________________________________
|
||||
| |
|
||||
| External declarations for encoder variables which need to be reset |
|
||||
|_________________________________________________________________________|
|
||||
*/
|
||||
|
||||
/* variables defined in sp_dec.c */
|
||||
/* ----------------------------- */
|
||||
|
||||
extern int16_t swRxDTXState;
|
||||
extern int16_t swDecoMode;
|
||||
extern int16_t swDtxMuting;
|
||||
extern int16_t swDtxBfiCnt;
|
||||
|
||||
extern int16_t swOldR0IndexDec;
|
||||
|
||||
extern int16_t swRxGsHistPtr;
|
||||
extern int32_t pL_RxGsHist[(OVERHANG - 1) * N_SUB];
|
||||
|
||||
|
||||
/*_________________________________________________________________________
|
||||
| |
|
||||
| Automatic Variables |
|
||||
|_________________________________________________________________________|
|
||||
*/
|
||||
|
||||
int i;
|
||||
|
||||
|
||||
/*_________________________________________________________________________
|
||||
| |
|
||||
| Executable code |
|
||||
|_________________________________________________________________________|
|
||||
*/
|
||||
|
||||
/* reset all the receive DTX and CN state variables */
|
||||
/* ------------------------------------------------ */
|
||||
|
||||
swRxDTXState = CNINTPER - 1;
|
||||
swDecoMode = SPEECH;
|
||||
swDtxMuting = 0;
|
||||
swDtxBfiCnt = 0;
|
||||
|
||||
swOldR0IndexDec = 0;
|
||||
|
||||
swRxGsHistPtr = 0;
|
||||
|
||||
for (i = 0; i < (OVERHANG - 1) * N_SUB; i++)
|
||||
pL_RxGsHist[i] = 0;
|
||||
|
||||
}
|
||||
30
src/libs/gsmhr/gsmhr_homing.h
Normal file
30
src/libs/gsmhr/gsmhr_homing.h
Normal file
@@ -0,0 +1,30 @@
|
||||
#ifndef __HOMING
|
||||
#define __HOMING
|
||||
|
||||
#include "typedefs.h"
|
||||
|
||||
#define EHF_MASK 0x0008 /* Encoder Homing Frame pattern */
|
||||
|
||||
/*_________________________________________________________________________
|
||||
| |
|
||||
| Function Prototypes |
|
||||
|_________________________________________________________________________|
|
||||
*/
|
||||
|
||||
int decoderHomingFrameTest(Shortword pswSpeechPara[], int iLastPara);
|
||||
|
||||
void decoderReset(void);
|
||||
|
||||
int encoderHomingFrameTest(Shortword pswSpeech[]);
|
||||
|
||||
void encoderReset(void);
|
||||
|
||||
void resetDec(void);
|
||||
|
||||
void resetEnc(void);
|
||||
|
||||
void dtxResetTx(void);
|
||||
|
||||
void dtxResetRx(void);
|
||||
|
||||
#endif
|
||||
347
src/libs/gsmhr/gsmhr_host.c
Normal file
347
src/libs/gsmhr/gsmhr_host.c
Normal file
@@ -0,0 +1,347 @@
|
||||
/***************************************************************************
|
||||
*
|
||||
* File Name: host.c
|
||||
*
|
||||
* Purpose: Contains functions for file I/O and formatting, no signal
|
||||
* processing.
|
||||
*
|
||||
* The functions in this file are listed below. All are level 2
|
||||
* fuctions, where level 0 is main(), except for fillBitAlloc() which
|
||||
* is level 3. The two "Interface" routines perform truncation of the
|
||||
* three least significant bits of the 16 bit linear input. The others
|
||||
* are simply file I/O functions and data reformatters.
|
||||
*
|
||||
* fillBitAlloc()
|
||||
* hostEncoderInterface()
|
||||
* readDecfile()
|
||||
* speechDecoderHostInterface()
|
||||
* writeEncfile()
|
||||
*
|
||||
**************************************************************************/
|
||||
|
||||
/*_________________________________________________________________________
|
||||
| |
|
||||
| Include Files |
|
||||
|_________________________________________________________________________|
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include "gsmhr_typedefs.h"
|
||||
|
||||
/***************************************************************************
|
||||
*
|
||||
* FUNCTION NAME: fillBitAlloc
|
||||
*
|
||||
* PURPOSE:
|
||||
*
|
||||
* Arrange speech parameters for encoder output
|
||||
*
|
||||
* INPUTS:
|
||||
*
|
||||
* The speechcoders codewords:
|
||||
* iR0 - Frame energy
|
||||
* piVqIndeces[0:2] - LPC vector quantizer codewords
|
||||
* iSoftInterp - Soft interpolation bit 1 or 0
|
||||
* iVoicing - voicing mode 0,1,2,3
|
||||
* piLags[0:3] - Frame and delta lag codewords
|
||||
* piCodeWrdsA[0:3] - VSELP codevector 1
|
||||
* piCodeWrdsB[0:3] - VSELP codevector 2 (n/a for voiced modes)
|
||||
* piGsp0s[0:3] - GSP0 codewords
|
||||
* swVadFlag - voice activity detection flag
|
||||
* swSP - Speech flag
|
||||
*
|
||||
* OUTPUTS:
|
||||
*
|
||||
* pswBAlloc[0:20] - an array into which the coded data is moved
|
||||
*
|
||||
* RETURN VALUE:
|
||||
*
|
||||
* none
|
||||
*
|
||||
* REFERENCES: Sub-clause 2.1 and 4.1.12 of GSM Recomendation 06.20
|
||||
*
|
||||
**************************************************************************/
|
||||
|
||||
void fillBitAlloc(int iVoicing, int iR0, int *piVqIndeces,
|
||||
int iSoftInterp, int *piLags,
|
||||
int *piCodeWrdsA, int *piCodeWrdsB,
|
||||
int *piGsp0s, int16_t swVadFlag,
|
||||
int16_t swSP, int16_t *pswBAlloc)
|
||||
{
|
||||
|
||||
/*_________________________________________________________________________
|
||||
| |
|
||||
| Automatic Variables |
|
||||
|_________________________________________________________________________|
|
||||
*/
|
||||
|
||||
int i;
|
||||
int16_t *pswNxt;
|
||||
|
||||
/*_________________________________________________________________________
|
||||
| |
|
||||
| Executable Code |
|
||||
|_________________________________________________________________________|
|
||||
*/
|
||||
|
||||
pswNxt = pswBAlloc;
|
||||
*pswNxt++ = iR0;
|
||||
for (i = 0; i < 3; i++)
|
||||
*pswNxt++ = *piVqIndeces++;
|
||||
*pswNxt++ = iSoftInterp;
|
||||
*pswNxt++ = iVoicing;
|
||||
|
||||
/* check voicing mode */
|
||||
if (iVoicing)
|
||||
{
|
||||
/* voiced mode */
|
||||
for (i = 0; i < N_SUB; i++)
|
||||
{
|
||||
*pswNxt++ = *piLags++;
|
||||
*pswNxt++ = *piCodeWrdsA++;
|
||||
*pswNxt++ = *piGsp0s++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{ /* unvoiced frame */
|
||||
for (i = 0; i < N_SUB; i++)
|
||||
{
|
||||
*pswNxt++ = *piCodeWrdsA++;
|
||||
*pswNxt++ = *piCodeWrdsB++;
|
||||
*pswNxt++ = *piGsp0s++;
|
||||
}
|
||||
}
|
||||
*pswNxt++ = swVadFlag;
|
||||
*pswNxt++ = swSP;
|
||||
}
|
||||
|
||||
/***************************************************************************
|
||||
*
|
||||
* FUNCTION NAME: hostEncoderInterface
|
||||
*
|
||||
* PURPOSE:
|
||||
*
|
||||
* Read in speech data from a file. Zero the least significant 3 bits.
|
||||
*
|
||||
*
|
||||
* INPUTS:
|
||||
*
|
||||
* pfileInSpeech
|
||||
* FILE pointer to the binary input file
|
||||
*
|
||||
* iNumToRead
|
||||
* Number of samples to read from the file, typically
|
||||
* 160 (20 ms of speech).
|
||||
*
|
||||
*
|
||||
* OUTPUTS:
|
||||
*
|
||||
* pswSamplesRead[]
|
||||
* The speech samples read in from the file.
|
||||
*
|
||||
*
|
||||
* RETURN VALUE:
|
||||
*
|
||||
* iNumRead
|
||||
* The number of samples actually read.
|
||||
*
|
||||
* IMPLEMENTATION:
|
||||
*
|
||||
* The input speech file should be in "native" format. This means that
|
||||
* the file is to be read (by this program) and written (by another
|
||||
* program) as short ints (not chars).
|
||||
*
|
||||
* If not enough samples are available in the file, the number actually
|
||||
* read is returned. If the read fails to fill the requested iNumToRead
|
||||
* samples, then the rest are zeroed.
|
||||
*
|
||||
* In all cases the least significant 3 bits of all speech samples are
|
||||
* zeroed.
|
||||
*
|
||||
* REFERENCES: Sub-clause 4.1 of GSM Recomendation 06.20
|
||||
*
|
||||
* KEYWORDS: read, read speech, get speech data
|
||||
*
|
||||
**************************************************************************/
|
||||
|
||||
int hostEncoderInterface(FILE *pfileInSpeech, int iNumToRead,
|
||||
int16_t pswSamplesRead[])
|
||||
{
|
||||
|
||||
/*_________________________________________________________________________
|
||||
| |
|
||||
| Automatic Variables |
|
||||
|_________________________________________________________________________|
|
||||
*/
|
||||
int iNumRead,
|
||||
i;
|
||||
|
||||
/*_________________________________________________________________________
|
||||
| |
|
||||
| Executable Code |
|
||||
|_________________________________________________________________________|
|
||||
*/
|
||||
|
||||
iNumRead = fread((char *) pswSamplesRead, sizeof (int16_t),
|
||||
iNumToRead, pfileInSpeech);
|
||||
|
||||
/* Delete the 3 LSB's - 13 bit speech input */
|
||||
/*------------------------------------------*/
|
||||
|
||||
for (i = 0; i < iNumRead; i++)
|
||||
{
|
||||
pswSamplesRead[i] &= 0xfff8;
|
||||
}
|
||||
|
||||
|
||||
/* Fill out the iNumToRead buffer with zeroes */
|
||||
/*--------------------------------------------*/
|
||||
|
||||
if (iNumRead != iNumToRead)
|
||||
{
|
||||
for (i = iNumRead; i < iNumToRead; i++)
|
||||
{
|
||||
pswSamplesRead[i] = 0;
|
||||
}
|
||||
}
|
||||
return (iNumRead);
|
||||
}
|
||||
|
||||
/***************************************************************************
|
||||
*
|
||||
* FUNCTION NAME: readDecfile
|
||||
*
|
||||
* PURPOSE:
|
||||
* Reads decoder parameter input file
|
||||
*
|
||||
* INPUT:
|
||||
* infile decoder parameter input file.
|
||||
*
|
||||
* OUTPUT:
|
||||
* pswSpeechPara array of received 16-bit values
|
||||
*
|
||||
* RETURN:
|
||||
* 0 successfully read a complete frame of data
|
||||
*
|
||||
* REFERENCES: Sub-clause 4.2 of GSM Recomendation 06.20
|
||||
*
|
||||
* KEYWORDS: pswSpeechPara
|
||||
*
|
||||
**************************************************************************/
|
||||
|
||||
int readDecfile(FILE *infile, int16_t pswSpeechPara[])
|
||||
{
|
||||
if (fread((char *) pswSpeechPara, sizeof (int16_t), 22, infile) == 0)
|
||||
return (1);
|
||||
else
|
||||
return (0);
|
||||
}
|
||||
|
||||
/***************************************************************************
|
||||
*
|
||||
* FUNCTION NAME: speechDecoderHostInterface
|
||||
*
|
||||
* PURPOSE:
|
||||
* The purpose of this function is to truncate the linear pcm and write
|
||||
* it into the output file
|
||||
*
|
||||
* INPUTS:
|
||||
*
|
||||
* F_LEN
|
||||
*
|
||||
* 160 = linear pcm output frame size
|
||||
*
|
||||
* pswDecodedSpeechFrame[0:F_LEN-1]
|
||||
*
|
||||
* 16 bit linear pcm
|
||||
*
|
||||
* OUTPUTS:
|
||||
*
|
||||
* fpfileSpeechOut
|
||||
*
|
||||
* 13 bit linear pcm stored to file given by this pointer
|
||||
*
|
||||
* RETURN VALUE:
|
||||
*
|
||||
* none
|
||||
*
|
||||
* IMPLEMENTATION:
|
||||
*
|
||||
* REFERENCES: Sub-clause 4.2 of GSM Recomendation 06.20
|
||||
*
|
||||
* KEYWORDS: synthesis, speechdecoder, decoding, truncation
|
||||
*
|
||||
**************************************************************************/
|
||||
|
||||
void speechDecoderHostInterface(int16_t pswDecodedSpeechFrame[],
|
||||
FILE *fpfileSpeechOut)
|
||||
{
|
||||
|
||||
/*_________________________________________________________________________
|
||||
| |
|
||||
| Local Constants |
|
||||
|_________________________________________________________________________|
|
||||
*/
|
||||
|
||||
#define PCM_MASK 0xfff8 /* 16 to 13 bit linear PCM mask */
|
||||
|
||||
/*_________________________________________________________________________
|
||||
| |
|
||||
| Automatic Variables |
|
||||
|_________________________________________________________________________|
|
||||
*/
|
||||
|
||||
short int i;
|
||||
|
||||
/*_________________________________________________________________________
|
||||
| |
|
||||
| Executable Code |
|
||||
|_________________________________________________________________________|
|
||||
*/
|
||||
|
||||
/* truncate the 16 bit linear pcm to 13 bits */
|
||||
/* ----------------------------------------- */
|
||||
|
||||
for (i = 0; i < F_LEN; i++)
|
||||
{
|
||||
pswDecodedSpeechFrame[i] = pswDecodedSpeechFrame[i] & PCM_MASK;
|
||||
}
|
||||
|
||||
/* F_LEN samples of linear pcm to output file */
|
||||
/* ------------------------------------------ */
|
||||
|
||||
fwrite((char *) pswDecodedSpeechFrame, sizeof (int16_t),
|
||||
F_LEN, fpfileSpeechOut);
|
||||
}
|
||||
|
||||
/***************************************************************************
|
||||
*
|
||||
* FUNCTION NAME: writeEncfile
|
||||
*
|
||||
* PURPOSE:
|
||||
* Writes encoded parameters to ouput file
|
||||
*
|
||||
* INPUT:
|
||||
* pswSpeechPara array of encoded parameter words.
|
||||
*
|
||||
* OUTPUT:
|
||||
* fpfileEnc 16-bit encoded values.
|
||||
*
|
||||
* RETURN:
|
||||
* i number of bytes written
|
||||
*
|
||||
* REFERENCES: Sub-clause 4.1 of GSM Recomendation 06.20
|
||||
*
|
||||
* KEYWORDS: pswSpeechPara, fpfileEnc
|
||||
*
|
||||
**************************************************************************
|
||||
*/
|
||||
|
||||
int writeEncfile(int16_t pswSpeechPara[], FILE *fpfileEnc)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = fwrite((char *) pswSpeechPara, sizeof (int16_t), 20, fpfileEnc);
|
||||
|
||||
return (i);
|
||||
}
|
||||
29
src/libs/gsmhr/gsmhr_host.h
Normal file
29
src/libs/gsmhr/gsmhr_host.h
Normal file
@@ -0,0 +1,29 @@
|
||||
#ifndef __HOSTGSM
|
||||
#define __HOSTGSM
|
||||
|
||||
#include <stdio.h>
|
||||
#include "typedefs.h"
|
||||
|
||||
/*_________________________________________________________________________
|
||||
| |
|
||||
| Function Prototypes |
|
||||
|_________________________________________________________________________|
|
||||
*/
|
||||
|
||||
void fillBitAlloc(int iVoicing, int iR0, int *piVqIndeces,
|
||||
int iSoftInterp, int *piLags,
|
||||
int *piCodeWrdsA, int *piCodeWrdsB,
|
||||
int *piGsp0s, int16_t swVadFlag,
|
||||
int16_t swSP, int16_t *pswBAlloc);
|
||||
|
||||
int hostEncoderInterface(FILE *pfileInSpeech, int iNumToRead,
|
||||
int16_t pswSamplesRead[]);
|
||||
|
||||
int readDecfile(FILE *infile, int16_t pswSpeechPara[]);
|
||||
|
||||
void speechDecoderHostInterface(int16_t pswDecodedSpeechFrame[],
|
||||
FILE *fpfileSpeechOut);
|
||||
|
||||
int writeEncfile(int16_t pswOutBit[], FILE *fpfileEnc);
|
||||
|
||||
#endif
|
||||
5471
src/libs/gsmhr/gsmhr_sp_dec.c
Normal file
5471
src/libs/gsmhr/gsmhr_sp_dec.c
Normal file
File diff suppressed because it is too large
Load Diff
100
src/libs/gsmhr/gsmhr_sp_dec.h
Normal file
100
src/libs/gsmhr/gsmhr_sp_dec.h
Normal file
@@ -0,0 +1,100 @@
|
||||
#ifndef __SP_DEC
|
||||
#define __SP_DEC
|
||||
|
||||
#include "typedefs.h"
|
||||
|
||||
/*_________________________________________________________________________
|
||||
| |
|
||||
| Function Prototypes |
|
||||
|_________________________________________________________________________|
|
||||
*/
|
||||
|
||||
void speechDecoder(int16_t pswParameters[],
|
||||
int16_t pswDecodedSpeechFrame[]);
|
||||
|
||||
void aFlatRcDp(int32_t *pL_R, int16_t *pswRc);
|
||||
|
||||
void b_con(int16_t swCodeWord, short siNumBits,
|
||||
int16_t pswVectOut[]);
|
||||
|
||||
void fp_ex(int16_t swOrigLagIn, int16_t pswLTPState[]);
|
||||
|
||||
int16_t g_corr1(int16_t *pswIn, int32_t *pL_out);
|
||||
|
||||
int16_t g_corr1s(int16_t pswIn[], int16_t swEngyRShft,
|
||||
int32_t *pL_out);
|
||||
|
||||
void getSfrmLpc(short int siSoftInterpolation,
|
||||
int16_t swPrevR0, int16_t swNewR0,
|
||||
int16_t pswPrevFrmKs[],
|
||||
int16_t pswPrevFrmAs[],
|
||||
int16_t pswPrevFrmPFNum[],
|
||||
int16_t pswPrevFrmPFDenom[],
|
||||
int16_t pswNewFrmKs[],
|
||||
int16_t pswNewFrmAs[],
|
||||
int16_t pswNewFrmPFNum[],
|
||||
int16_t pswNewFrmPFDenom[],
|
||||
struct NormSw *psnsSqrtRs,
|
||||
int16_t *ppswSynthAs[],
|
||||
int16_t *ppswPFNumAs[],
|
||||
int16_t *ppswPFDenomAs[]);
|
||||
|
||||
void get_ipjj(int16_t swLagIn,
|
||||
int16_t *pswIp, int16_t *pswJj);
|
||||
|
||||
short int interpolateCheck(int16_t pswRefKs[],
|
||||
int16_t pswRefCoefsA[],
|
||||
int16_t pswOldCoefsA[],
|
||||
int16_t pswNewCoefsA[],
|
||||
int16_t swOldPer,
|
||||
int16_t swNewPer,
|
||||
int16_t swRq,
|
||||
struct NormSw *psnsSqrtRsOut,
|
||||
int16_t pswCoefOutA[]);
|
||||
|
||||
void lpcFir(int16_t pswInput[], int16_t pswCoef[],
|
||||
int16_t pswState[], int16_t pswFiltOut[]);
|
||||
|
||||
void lpcIir(int16_t pswInput[], int16_t pswCoef[],
|
||||
int16_t pswState[], int16_t pswFiltOut[]);
|
||||
|
||||
void lpcIrZsIir(int16_t pswCoef[], int16_t pswFiltOut[]);
|
||||
|
||||
void lpcZiIir(int16_t pswCoef[], int16_t pswState[],
|
||||
int16_t pswFiltOut[]);
|
||||
|
||||
void lpcZsFir(int16_t pswInput[], int16_t pswCoef[],
|
||||
int16_t pswFiltOut[]);
|
||||
|
||||
void lpcZsIir(int16_t pswInput[], int16_t pswCoef[],
|
||||
int16_t pswFiltOut[]);
|
||||
|
||||
void lpcZsIirP(int16_t pswCommonIO[], int16_t pswCoef[]);
|
||||
|
||||
int16_t r0BasedEnergyShft(int16_t swR0Index);
|
||||
|
||||
short rcToADp(int16_t swAscale, int16_t pswRc[],
|
||||
int16_t pswA[]);
|
||||
|
||||
void rcToCorrDpL(int16_t swAshift, int16_t swAscale,
|
||||
int16_t pswRc[], int32_t pL_R[]);
|
||||
|
||||
void res_eng(int16_t pswReflecCoefIn[], int16_t swRq,
|
||||
struct NormSw *psnsSqrtRsOut);
|
||||
|
||||
void rs_rr(int16_t pswExcitation[], struct NormSw snsSqrtRs,
|
||||
struct NormSw *snsSqrtRsRr);
|
||||
|
||||
void rs_rrNs(int16_t pswExcitation[], struct NormSw snsSqrtRs,
|
||||
struct NormSw *snsSqrtRsRr);
|
||||
|
||||
int16_t scaleExcite(int16_t pswVect[],
|
||||
int16_t swErrTerm, struct NormSw snsRS,
|
||||
int16_t pswScldVect[]);
|
||||
|
||||
int16_t sqroot(int32_t L_SqrtIn);
|
||||
|
||||
void v_con(int16_t pswBVects[], int16_t pswOutVect[],
|
||||
int16_t pswBitArray[], short int siNumBVctrs);
|
||||
|
||||
#endif
|
||||
406
src/libs/gsmhr/gsmhr_sp_enc.c
Normal file
406
src/libs/gsmhr/gsmhr_sp_enc.c
Normal file
@@ -0,0 +1,406 @@
|
||||
/***************************************************************************
|
||||
*
|
||||
* File Name: sp_enc.c
|
||||
*
|
||||
* Purpose: Contains speech encoder function. Calls are made to the
|
||||
* frame-based encoding functions (see sp_frm.c), and the subframe-
|
||||
* based encoding function (see sp_sfrm.c)
|
||||
*
|
||||
* Functions in this file (only 1)
|
||||
* speechEncoder()
|
||||
*
|
||||
**************************************************************************/
|
||||
/*_________________________________________________________________________
|
||||
| |
|
||||
| Include Files |
|
||||
|_________________________________________________________________________|
|
||||
*/
|
||||
|
||||
#include "gsmhr_mathhalf.h"
|
||||
#include "gsmhr_mathdp31.h"
|
||||
#include "gsmhr_sp_rom.h"
|
||||
#include "gsmhr_sp_dec.h"
|
||||
#include "gsmhr_sp_frm.h"
|
||||
#include "gsmhr_sp_sfrm.h"
|
||||
#include "gsmhr_sp_enc.h"
|
||||
#include "gsmhr_host.h"
|
||||
#include "gsmhr_vad.h"
|
||||
|
||||
/*_________________________________________________________________________
|
||||
| |
|
||||
| Local Defines |
|
||||
|_________________________________________________________________________|
|
||||
*/
|
||||
|
||||
#define CG_INT_MACS 6 /* Number of Multiply-Accumulates in */
|
||||
/* one interpolation */
|
||||
#define ASCALE 0x0800
|
||||
#define LMAX 142 /* largest lag (integer sense) */
|
||||
#define LSMAX (LMAX+ CG_INT_MACS/2) /* Lag Search Array Length */
|
||||
#define NUM_CLOSED 3 /* Maximum number of lags searched */
|
||||
/* in closed loop. */
|
||||
|
||||
#define LPCSTARTINDEX 25 /* Where the LPC analysis window
|
||||
* starts */
|
||||
#define INBUFFSZ LPCSTARTINDEX + A_LEN /* Input buffer size */
|
||||
#define NUMSTARTUPSMP INBUFFSZ - F_LEN /* Number of samples needed */
|
||||
/* at start up */
|
||||
#define NUMSTARTUPSMP_P1 INBUFFSZ - F_LEN + 1
|
||||
#define HPFSHIFT 1 /* no right shifts high pass shifts
|
||||
* speech */
|
||||
|
||||
/*_________________________________________________________________________
|
||||
| |
|
||||
| State variables (globals) |
|
||||
|_________________________________________________________________________|
|
||||
*/
|
||||
|
||||
int16_t swOldR0;
|
||||
int16_t swOldR0Index;
|
||||
|
||||
struct NormSw psnsWSfrmEngSpace[2 * N_SUB];
|
||||
|
||||
int16_t pswHPFXState[4];
|
||||
int16_t pswHPFYState[8];
|
||||
int16_t pswOldFrmKs[NP];
|
||||
int16_t pswOldFrmAs[NP];
|
||||
int16_t pswOldFrmSNWCoefs[NP];
|
||||
int16_t pswWgtSpeechSpace[F_LEN + LMAX + CG_INT_MACS / 2];
|
||||
|
||||
int16_t pswSpeech[INBUFFSZ]; /* input speech */
|
||||
|
||||
int16_t swPtch = 1;
|
||||
|
||||
/*_________________________________________________________________________
|
||||
| |
|
||||
| Global DTX variables |
|
||||
|_________________________________________________________________________|
|
||||
*/
|
||||
|
||||
int16_t swTxGsHistPtr = 0;
|
||||
|
||||
int16_t pswCNVSCode1[N_SUB],
|
||||
pswCNVSCode2[N_SUB],
|
||||
pswCNGsp0Code[N_SUB],
|
||||
pswCNLpc[3],
|
||||
swCNR0;
|
||||
|
||||
|
||||
extern int32_t pL_GsHist[];
|
||||
extern int32_tRom ppLr_gsTable[4][32];
|
||||
|
||||
/***************************************************************************
|
||||
*
|
||||
* FUNCTION NAME: speechEncoder
|
||||
*
|
||||
* PURPOSE:
|
||||
*
|
||||
* Performs GSM half-rate speech encoding on frame basis (160 samples).
|
||||
*
|
||||
* INPUTS:
|
||||
*
|
||||
* pswSpeechIn[0:159] - input speech samples, 160 new samples per frame
|
||||
*
|
||||
* OUTPUTS:
|
||||
*
|
||||
* pswFrmCodes[0:19] - output parameters, 18 speech parameters plus
|
||||
* VAD and SP flags
|
||||
*
|
||||
* RETURN VALUE:
|
||||
*
|
||||
* None
|
||||
*
|
||||
* IMPLEMENTATION:
|
||||
*
|
||||
* n/a
|
||||
*
|
||||
* REFERENCES: Sub-clause 4.1 of GSM Recomendation 06.20
|
||||
*
|
||||
* KEYWORDS: speechcoder, analysis
|
||||
*
|
||||
*************************************************************************/
|
||||
|
||||
void speechEncoder(int16_t pswSpeechIn[], int16_t pswFrmCodes[])
|
||||
{
|
||||
|
||||
/*_________________________________________________________________________
|
||||
| |
|
||||
| Static Variables |
|
||||
|_________________________________________________________________________|
|
||||
*/
|
||||
|
||||
/* 1st point in analysis window */
|
||||
static int16_t *pswLpcStart = &pswSpeech[LPCSTARTINDEX];
|
||||
|
||||
/* 1st point of new frame other than 1st */
|
||||
static int16_t *pswNewSpeech = &pswSpeech[NUMSTARTUPSMP];
|
||||
|
||||
/* sample 0 of weighted speech */
|
||||
static int16_t *pswWgtSpeech = &pswWgtSpeechSpace[LSMAX];
|
||||
|
||||
static struct NormSw *psnsWSfrmEng = &psnsWSfrmEngSpace[N_SUB];
|
||||
|
||||
/*_________________________________________________________________________
|
||||
| |
|
||||
| Automatic Variables |
|
||||
|_________________________________________________________________________|
|
||||
*/
|
||||
|
||||
int iVoicing, /* bitAlloc */
|
||||
iR0, /* bitAlloc and aflat */
|
||||
piVq[3], /* bitAlloc */
|
||||
iSi, /* bitAlloc */
|
||||
piLagCode[N_SUB], /* bitAlloc */
|
||||
piVSCode1[N_SUB], /* bitAlloc */
|
||||
piVSCode2[N_SUB], /* bitAlloc */
|
||||
piGsp0Code[N_SUB]; /* bitAlloc */
|
||||
|
||||
short int siUVCode,
|
||||
siSi,
|
||||
i,
|
||||
j;
|
||||
|
||||
int16_t swR0,
|
||||
pswLagCode[N_SUB],
|
||||
pswVSCode1[N_SUB],
|
||||
pswVSCode2[N_SUB],
|
||||
pswGsp0Code[N_SUB],
|
||||
*pswLagListPtr,
|
||||
pswFrmKs[NP],
|
||||
pswFrmAs[NP],
|
||||
pswFrmSNWCoefs[NP],
|
||||
pswLagList[N_SUB * NUM_CLOSED],
|
||||
pswNumLagList[N_SUB],
|
||||
pswPitchBuf[N_SUB],
|
||||
pswHNWCoefBuf[N_SUB],
|
||||
ppswSNWCoefAs[N_SUB][NP],
|
||||
ppswSynthAs[N_SUB][NP];
|
||||
|
||||
int16_t swSP,
|
||||
pswVadLags[4], /* VAD Parameters */
|
||||
swVadFlag; /* flag indicating voice activity
|
||||
* detector state. 1 = speech or
|
||||
* speech/signal present */
|
||||
struct NormSw
|
||||
psnsSqrtRs[N_SUB];
|
||||
|
||||
/*_________________________________________________________________________
|
||||
| |
|
||||
| Executable Code |
|
||||
|_________________________________________________________________________|
|
||||
*/
|
||||
|
||||
/* Speech frame processing */
|
||||
/* High pass filter the speech */
|
||||
/* ---------------------------- */
|
||||
|
||||
filt4_2nd(psrHPFCoefs, pswSpeechIn,
|
||||
pswHPFXState, pswHPFYState, F_LEN, HPFSHIFT);
|
||||
|
||||
/* copy high passed filtered speech into encoder's speech buff */
|
||||
/*-------------------------------------------------------------*/
|
||||
|
||||
for (i = 0; i < F_LEN; i++)
|
||||
pswNewSpeech[i] = pswSpeechIn[i];
|
||||
|
||||
|
||||
|
||||
|
||||
/* Calculate and quantize LPC coefficients */
|
||||
/* --------------------------------------- */
|
||||
|
||||
aflat(pswLpcStart, &iR0, pswFrmKs, piVq,
|
||||
swPtch, &swVadFlag, &swSP);
|
||||
|
||||
|
||||
/* Lookup frame energy r0 */
|
||||
/* ---------------------- */
|
||||
|
||||
swR0 = psrR0DecTbl[iR0 * 2]; /* lookupR0 */
|
||||
|
||||
/* Generate the direct form coefs */
|
||||
/* ------------------------------ */
|
||||
|
||||
if (!rcToADp(ASCALE, pswFrmKs, pswFrmAs))
|
||||
{
|
||||
|
||||
getNWCoefs(pswFrmAs, pswFrmSNWCoefs);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
for (i = 0; i < NP; i++)
|
||||
{
|
||||
pswFrmKs[i] = pswOldFrmKs[i];
|
||||
pswFrmAs[i] = pswOldFrmAs[i];
|
||||
pswFrmSNWCoefs[i] = pswOldFrmSNWCoefs[i];
|
||||
}
|
||||
}
|
||||
|
||||
/* Interpolate, or otherwise get sfrm reflection coefs */
|
||||
/* --------------------------------------------------- */
|
||||
|
||||
getSfrmLpcTx(swOldR0, swR0,
|
||||
pswOldFrmKs, pswOldFrmAs,
|
||||
pswOldFrmSNWCoefs,
|
||||
pswFrmKs, pswFrmAs,
|
||||
pswFrmSNWCoefs,
|
||||
pswSpeech,
|
||||
&siSi,
|
||||
psnsSqrtRs,
|
||||
ppswSynthAs, ppswSNWCoefAs);
|
||||
|
||||
/* loose once bitAlloc done */
|
||||
iSi = siSi;
|
||||
|
||||
/* Weight the entire speech frame */
|
||||
/* ------------------------------ */
|
||||
|
||||
weightSpeechFrame(pswSpeech, ppswSynthAs[0], ppswSNWCoefAs[0],
|
||||
pswWgtSpeechSpace);
|
||||
|
||||
/* Perform open-loop lag search, get harmonic-noise-weighting parameters */
|
||||
/* --------------------------------------------------------------------- */
|
||||
|
||||
openLoopLagSearch(&pswWgtSpeechSpace[LSMAX],
|
||||
swOldR0Index,
|
||||
(int16_t) iR0,
|
||||
&siUVCode,
|
||||
pswLagList,
|
||||
pswNumLagList,
|
||||
pswPitchBuf,
|
||||
pswHNWCoefBuf,
|
||||
&psnsWSfrmEng[0],
|
||||
pswVadLags,
|
||||
swSP);
|
||||
|
||||
iVoicing = siUVCode;
|
||||
|
||||
|
||||
/* Using open loop LTP data to calculate swPtch */ /* DTX mode */
|
||||
/* parameter */ /* DTX mode */
|
||||
/* -------------------------------------------- */ /* DTX mode */
|
||||
|
||||
periodicity_update(pswVadLags, &swPtch); /* DTX mode */
|
||||
|
||||
|
||||
/* Subframe processing loop */
|
||||
/* ------------------------ */
|
||||
|
||||
pswLagListPtr = pswLagList;
|
||||
|
||||
for (giSfrmCnt = 0; giSfrmCnt < N_SUB; giSfrmCnt++)
|
||||
{
|
||||
|
||||
if (swSP == 0) /* DTX mode */
|
||||
{ /* DTX mode */
|
||||
pswVSCode1[giSfrmCnt] = pswCNVSCode1[giSfrmCnt]; /* DTX mode */
|
||||
pswVSCode2[giSfrmCnt] = pswCNVSCode2[giSfrmCnt]; /* DTX mode */
|
||||
pswGsp0Code[giSfrmCnt] = pswCNGsp0Code[giSfrmCnt]; /* DTX mode */
|
||||
} /* DTX mode */
|
||||
|
||||
sfrmAnalysis(&pswWgtSpeech[giSfrmCnt * S_LEN],
|
||||
siUVCode,
|
||||
psnsSqrtRs[giSfrmCnt],
|
||||
ppswSNWCoefAs[giSfrmCnt],
|
||||
pswLagListPtr,
|
||||
pswNumLagList[giSfrmCnt],
|
||||
pswPitchBuf[giSfrmCnt],
|
||||
pswHNWCoefBuf[giSfrmCnt],
|
||||
&pswLagCode[giSfrmCnt], &pswVSCode1[giSfrmCnt],
|
||||
&pswVSCode2[giSfrmCnt], &pswGsp0Code[giSfrmCnt],
|
||||
swSP);
|
||||
|
||||
pswLagListPtr = &pswLagListPtr[pswNumLagList[giSfrmCnt]];
|
||||
|
||||
}
|
||||
|
||||
|
||||
/* copy comfort noise parameters, */ /* DTX mode */
|
||||
/* update GS history */ /* DTX mode */
|
||||
/* ------------------------------ */ /* DTX mode */
|
||||
|
||||
if (swSP == 0) /* DTX mode */
|
||||
{ /* DTX mode */
|
||||
|
||||
/* copy comfort noise frame parameter */ /* DTX mode */
|
||||
/* ---------------------------------- */ /* DTX mode */
|
||||
|
||||
iR0 = swCNR0; /* quantized R0 index */ /* DTX mode */
|
||||
for (i=0; i < 3; i++) /* DTX mode */
|
||||
piVq[i] = pswCNLpc[i]; /* DTX mode */
|
||||
|
||||
} /* DTX mode */
|
||||
else /* DTX mode */
|
||||
{ /* DTX mode */
|
||||
|
||||
/* if swSP != 0, then update the GS history */ /* DTX mode */
|
||||
/* -----------------------------------------*/ /* DTX mode */
|
||||
|
||||
for (i=0; i < N_SUB; i++){ /* DTX mode */
|
||||
pL_GsHist[swTxGsHistPtr] = /* DTX mode */
|
||||
ppLr_gsTable[siUVCode][pswGsp0Code[i]]; /* DTX mode */
|
||||
swTxGsHistPtr++; /* DTX mode */
|
||||
if (swTxGsHistPtr > ((OVERHANG-1)*N_SUB)-1) /* DTX mode */
|
||||
swTxGsHistPtr=0; /* DTX mode */
|
||||
} /* DTX mode */
|
||||
|
||||
} /* DTX mode */
|
||||
|
||||
|
||||
/* End of frame processing, update frame based parameters */
|
||||
/* ------------------------------------------------------ */
|
||||
|
||||
for (i = 0; i < N_SUB; i++)
|
||||
{
|
||||
piLagCode[i] = pswLagCode[i];
|
||||
piVSCode1[i] = pswVSCode1[i];
|
||||
piVSCode2[i] = pswVSCode2[i];
|
||||
piGsp0Code[i] = pswGsp0Code[i];
|
||||
}
|
||||
|
||||
swOldR0Index = (int16_t) iR0;
|
||||
swOldR0 = swR0;
|
||||
|
||||
for (i = 0; i < NP; i++)
|
||||
{
|
||||
pswOldFrmKs[i] = pswFrmKs[i];
|
||||
pswOldFrmAs[i] = pswFrmAs[i];
|
||||
pswOldFrmSNWCoefs[i] = pswFrmSNWCoefs[i];
|
||||
}
|
||||
|
||||
/* Insert SID Codeword */ /* DTX mode */
|
||||
/* ------------------- */ /* DTX mode */
|
||||
|
||||
if (swSP == 0) /* DTX mode */
|
||||
{ /* DTX mode */
|
||||
iVoicing = 0x0003; /* 2 bits */ /* DTX mode */
|
||||
iSi = 0x0001; /* 1 bit */ /* DTX mode */
|
||||
for (i=0; i < N_SUB; i++) /* DTX mode */
|
||||
{ /* DTX mode */
|
||||
piVSCode1[i] = 0x01ff; /* 9 bits */ /* DTX mode */
|
||||
piGsp0Code[i] = 0x001f; /* 5 bits */ /* DTX mode */
|
||||
}
|
||||
piLagCode[0] = 0x00ff; /* 8 bits */ /* DTX mode */
|
||||
piLagCode[1] = 0x000f; /* 4 bits */ /* DTX mode */
|
||||
piLagCode[2] = 0x000f; /* 4 bits */ /* DTX mode */
|
||||
piLagCode[3] = 0x000f; /* 4 bits */ /* DTX mode */
|
||||
} /* DTX mode */
|
||||
|
||||
|
||||
/* Generate encoded parameter array */
|
||||
/* -------------------------------- */
|
||||
|
||||
fillBitAlloc(iVoicing, iR0, piVq, iSi, piLagCode,
|
||||
piVSCode1, piVSCode2,
|
||||
piGsp0Code, swVadFlag, swSP, pswFrmCodes);
|
||||
|
||||
|
||||
/* delay the input speech by 1 frame */
|
||||
/*-----------------------------------*/
|
||||
|
||||
for (i = 0, j = F_LEN; j < INBUFFSZ; i++, j++)
|
||||
{
|
||||
pswSpeech[i] = pswSpeech[j];
|
||||
}
|
||||
}
|
||||
14
src/libs/gsmhr/gsmhr_sp_enc.h
Normal file
14
src/libs/gsmhr/gsmhr_sp_enc.h
Normal file
@@ -0,0 +1,14 @@
|
||||
#ifndef __SP_ENC
|
||||
#define __SP_ENC
|
||||
|
||||
#include "typedefs.h"
|
||||
|
||||
/*_________________________________________________________________________
|
||||
| |
|
||||
| Function Prototypes |
|
||||
|_________________________________________________________________________|
|
||||
*/
|
||||
|
||||
void speechEncoder(int16_t pswSpeechIn[], int16_t pswFrmCodes[]);
|
||||
|
||||
#endif
|
||||
5908
src/libs/gsmhr/gsmhr_sp_frm.c
Normal file
5908
src/libs/gsmhr/gsmhr_sp_frm.c
Normal file
File diff suppressed because it is too large
Load Diff
201
src/libs/gsmhr/gsmhr_sp_frm.h
Normal file
201
src/libs/gsmhr/gsmhr_sp_frm.h
Normal file
@@ -0,0 +1,201 @@
|
||||
#ifndef __SP_FRM
|
||||
#define __SP_FRM
|
||||
|
||||
#include "gsmhr_typedefs.h"
|
||||
#include "gsmhr_sp_rom.h"
|
||||
|
||||
|
||||
struct QuantList
|
||||
{
|
||||
/* structure which points to the beginning of a block of candidate vq
|
||||
* vectors. It also stores the residual error for each vector. */
|
||||
int iNum; /* total number in list */
|
||||
int iRCIndex; /* an index to the first vector of the
|
||||
* block */
|
||||
int16_t pswPredErr[PREQ1_NUM_OF_ROWS]; /* PREQ1 is the biggest block */
|
||||
};
|
||||
|
||||
/*_________________________________________________________________________
|
||||
| |
|
||||
| Function Prototypes |
|
||||
|_________________________________________________________________________|
|
||||
*/
|
||||
|
||||
void iir_d(int16_t pswCoeff[], int16_t pswIn[],
|
||||
int16_t pswXstate[],
|
||||
int16_t pswYstate[],
|
||||
int npts, int shifts,
|
||||
int16_t swPreFirDownSh,
|
||||
int16_t swFinalUpShift);
|
||||
|
||||
|
||||
void filt4_2nd(int16_t pswCoeff[],
|
||||
int16_t pswIn[],
|
||||
int16_t pswXstate[],
|
||||
int16_t pswYstate[],
|
||||
int npts,
|
||||
int shifts);
|
||||
|
||||
void initPBarVBarL(int32_t pL_PBarFull[],
|
||||
int16_t pswPBar[],
|
||||
int16_t pswVBar[]);
|
||||
|
||||
void initPBarFullVBarFullL(int32_t pL_CorrelSeq[],
|
||||
int32_t pL_PBarFull[],
|
||||
int32_t pL_VBarFull[]);
|
||||
|
||||
int16_t aflatRecursion(int16_t pswQntRc[],
|
||||
int16_t pswPBar[],
|
||||
int16_t pswVBar[],
|
||||
int16_t *ppswPAddrs[],
|
||||
int16_t *ppswVAddrs[],
|
||||
int16_t swSegmentOrder);
|
||||
|
||||
void aflatNewBarRecursionL(int16_t pswQntRc[],
|
||||
int iSegment,
|
||||
int32_t pL_PBar[],
|
||||
int32_t pL_VBar[],
|
||||
int16_t pswPBar[],
|
||||
int16_t pswVBar[]);
|
||||
|
||||
|
||||
void setupPreQ(int iSeg, int iVector);
|
||||
|
||||
void setupQuant(int iSeg, int iVector);
|
||||
|
||||
void getNextVec(int16_t pswRc[]);
|
||||
|
||||
void aflat(int16_t pswSpeechToLPC[],
|
||||
int piR0Index[],
|
||||
int16_t pswFinalRc[],
|
||||
int piVQCodewds[],
|
||||
int16_t swPtch,
|
||||
int16_t *pswVadFlag,
|
||||
int16_t *pswSP);
|
||||
|
||||
|
||||
int16_t fnExp2(int32_t L_Input);
|
||||
|
||||
int16_t fnLog2(int32_t L_Input);
|
||||
|
||||
void weightSpeechFrame(int16_t pswSpeechFrm[],
|
||||
int16_t pswWNumSpace[],
|
||||
int16_t pswWDenomSpace[],
|
||||
int16_t pswWSpeechBuffBase[]);
|
||||
|
||||
void getSfrmLpcTx(int16_t swPrevR0, int16_t swNewR0,
|
||||
int16_t pswPrevFrmKs[],
|
||||
int16_t pswPrevFrmAs[],
|
||||
int16_t pswPrevFrmSNWCoef[],
|
||||
int16_t pswNewFrmKs[],
|
||||
int16_t pswNewFrmAs[],
|
||||
int16_t pswNewFrmSNWCoef[],
|
||||
int16_t pswHPFSpeech[],
|
||||
short *pswSoftInterp,
|
||||
struct NormSw *psnsSqrtRs,
|
||||
int16_t ppswSynthAs[][NP],
|
||||
int16_t ppswSNWCoefAs[][NP]);
|
||||
|
||||
short int fnBest_CG(int16_t pswCframe[],
|
||||
int16_t pswGframe[],
|
||||
int16_t *pswCmaxSqr,
|
||||
int16_t *pswGmax,
|
||||
short int siNumPairs);
|
||||
|
||||
short compResidEnergy(int16_t pswSpeech[],
|
||||
int16_t ppswInterpCoef[][NP],
|
||||
int16_t pswPreviousCoef[],
|
||||
int16_t pswCurrentCoef[],
|
||||
struct NormSw psnsSqrtRs[]);
|
||||
|
||||
int16_t r0Quant(int32_t L_UnqntzdR0);
|
||||
|
||||
int16_t cov32(int16_t pswIn[],
|
||||
int32_t pppL_B[NP][NP][2],
|
||||
int32_t pppL_F[NP][NP][2],
|
||||
int32_t pppL_C[NP][NP][2],
|
||||
int32_t *pL_R0,
|
||||
int32_t pL_VadAcf[],
|
||||
int16_t *pswVadScalAuto);
|
||||
|
||||
int32_t flat(int16_t pswSpeechIn[],
|
||||
int16_t pswRc[],
|
||||
int *piR0Inx,
|
||||
int32_t pL_VadAcf[],
|
||||
int16_t *pswVadScalAuto);
|
||||
|
||||
|
||||
|
||||
void openLoopLagSearch(int16_t pswWSpeech[],
|
||||
int16_t swPrevR0Index,
|
||||
int16_t swCurrR0Index,
|
||||
int16_t *psiUVCode,
|
||||
int16_t pswLagList[],
|
||||
int16_t pswNumLagList[],
|
||||
int16_t pswPitchBuf[],
|
||||
int16_t pswHNWCoefBuf[],
|
||||
struct NormSw psnsWSfrmEng[],
|
||||
int16_t pswVadLags[],
|
||||
int16_t swSP);
|
||||
|
||||
int16_t getCCThreshold(int16_t swRp0,
|
||||
int16_t swCC,
|
||||
int16_t swG);
|
||||
|
||||
void pitchLags(int16_t swBestIntLag,
|
||||
int16_t pswIntCs[],
|
||||
int16_t pswIntGs[],
|
||||
int16_t swCCThreshold,
|
||||
int16_t pswLPeaksSorted[],
|
||||
int16_t pswCPeaksSorted[],
|
||||
int16_t pswGPeaksSorted[],
|
||||
int16_t *psiNumSorted,
|
||||
int16_t *pswPitch,
|
||||
int16_t *pswHNWCoef);
|
||||
|
||||
short CGInterpValid(int16_t swFullResLag,
|
||||
int16_t pswCIn[],
|
||||
int16_t pswGIn[],
|
||||
int16_t pswLOut[],
|
||||
int16_t pswCOut[],
|
||||
int16_t pswGOut[]);
|
||||
|
||||
void CGInterp(int16_t pswLIn[],
|
||||
short siNum,
|
||||
int16_t pswCIn[],
|
||||
int16_t pswGIn[],
|
||||
short siLoIntLag,
|
||||
int16_t pswCOut[],
|
||||
int16_t pswGOut[]);
|
||||
|
||||
int16_t quantLag(int16_t swRawLag,
|
||||
int16_t *psiCode);
|
||||
|
||||
void findBestInQuantList(struct QuantList psqlInList,
|
||||
int iNumVectOut,
|
||||
struct QuantList psqlBestOutList[]);
|
||||
|
||||
int16_t findPeak(int16_t swSingleResLag,
|
||||
int16_t pswCIn[],
|
||||
int16_t pswGIn[]);
|
||||
|
||||
void bestDelta(int16_t pswLagList[],
|
||||
int16_t pswCSfrm[],
|
||||
int16_t pswGSfrm[],
|
||||
short int siNumLags,
|
||||
short int siSfrmIndex,
|
||||
int16_t pswLTraj[],
|
||||
int16_t pswCCTraj[],
|
||||
int16_t pswGTraj[]);
|
||||
|
||||
int16_t
|
||||
maxCCOverGWithSign(int16_t pswCIn[],
|
||||
int16_t pswGIn[],
|
||||
int16_t *pswCCMax,
|
||||
int16_t *pswGMax,
|
||||
int16_t swNum);
|
||||
|
||||
void getNWCoefs(int16_t pswACoefs[],
|
||||
int16_t pswHCoefs[]);
|
||||
|
||||
#endif
|
||||
6592
src/libs/gsmhr/gsmhr_sp_rom.c
Normal file
6592
src/libs/gsmhr/gsmhr_sp_rom.c
Normal file
File diff suppressed because it is too large
Load Diff
193
src/libs/gsmhr/gsmhr_sp_rom.h
Normal file
193
src/libs/gsmhr/gsmhr_sp_rom.h
Normal file
@@ -0,0 +1,193 @@
|
||||
/***************************************************************************
|
||||
*
|
||||
* Purpose: Define the structure of the Global Constants
|
||||
*
|
||||
**************************************************************************/
|
||||
|
||||
#ifndef ___ROM
|
||||
#define ___ROM
|
||||
|
||||
#include "gsmhr_typedefs.h"
|
||||
//#include "gsmhr_mathhalf.h"
|
||||
//#include "gsmhr_mathdp31.h"
|
||||
|
||||
/*_________________________________________________________________________
|
||||
| |
|
||||
| Data Types |
|
||||
|_________________________________________________________________________|
|
||||
*/
|
||||
|
||||
/* gsp0 vector quantizer */
|
||||
/*-----------------------*/
|
||||
#define GSP0_NUM_OF_TABLES 4
|
||||
#define GSP0_NUM 32
|
||||
#define GSP0_VECTOR_SIZE 5
|
||||
|
||||
extern int16_tRom pppsrGsp0
|
||||
[GSP0_NUM_OF_TABLES][GSP0_NUM][GSP0_VECTOR_SIZE];
|
||||
|
||||
|
||||
/* unvoiced code vectors */
|
||||
/*-----------------------*/
|
||||
#define UVCODEVEC_NUM_OF_CODE_BOOKS 2
|
||||
#define UVCODEVEC_NUM_OF_CODE_BITS 7
|
||||
|
||||
extern int16_tRom pppsrUvCodeVec
|
||||
[UVCODEVEC_NUM_OF_CODE_BOOKS][UVCODEVEC_NUM_OF_CODE_BITS][S_LEN];
|
||||
|
||||
|
||||
/* voiced code vectors */
|
||||
/*---------------------*/
|
||||
#define VCDCODEVEC_NUM_OF_CODE_BOOKS 1
|
||||
#define VCDCODEVEC_NUM_OF_CODE_BITS 9
|
||||
|
||||
extern int16_tRom pppsrVcdCodeVec
|
||||
[VCDCODEVEC_NUM_OF_CODE_BOOKS][VCDCODEVEC_NUM_OF_CODE_BITS][S_LEN];
|
||||
|
||||
|
||||
/* vector quantizer tables */
|
||||
/*-------------------------*/
|
||||
#define QUANT_NUM_OF_TABLES 3
|
||||
|
||||
#define QUANT1_NUM_OF_BITS 11
|
||||
#define QUANT1_NUM_OF_ROWS (1 << QUANT1_NUM_OF_BITS)
|
||||
#define QUANT1_NUM_OF_STAGES 3
|
||||
#define QUANT1_NUM_OF_WORDS (QUANT1_NUM_OF_ROWS*QUANT1_NUM_OF_STAGES/2)
|
||||
|
||||
#define QUANT2_NUM_OF_BITS 9
|
||||
#define QUANT2_NUM_OF_ROWS (1 << QUANT2_NUM_OF_BITS)
|
||||
#define QUANT2_NUM_OF_STAGES 3
|
||||
#define QUANT2_NUM_OF_WORDS (QUANT2_NUM_OF_ROWS*QUANT2_NUM_OF_STAGES/2)
|
||||
|
||||
#define QUANT3_NUM_OF_BITS 8
|
||||
#define QUANT3_NUM_OF_ROWS (1 << QUANT3_NUM_OF_BITS)
|
||||
#define QUANT3_NUM_OF_STAGES 4
|
||||
#define QUANT3_NUM_OF_WORDS (QUANT3_NUM_OF_ROWS*QUANT3_NUM_OF_STAGES/2)
|
||||
|
||||
extern int16_tRom psrQuant1[QUANT1_NUM_OF_WORDS];
|
||||
|
||||
extern int16_tRom psrQuant2[QUANT2_NUM_OF_WORDS];
|
||||
|
||||
extern int16_tRom psrQuant3[QUANT3_NUM_OF_WORDS];
|
||||
|
||||
|
||||
/* lpc pre-quantizer */
|
||||
/*-------------------*/
|
||||
#define PREQ1_NUM_OF_BITS 6
|
||||
#define PREQ1_NUM_OF_ROWS (1 << PREQ1_NUM_OF_BITS)
|
||||
#define PREQ1_NUM_OF_STAGES 3
|
||||
#define PREQ1_NUM_OF_WORDS (PREQ1_NUM_OF_ROWS*PREQ1_NUM_OF_STAGES/2)
|
||||
|
||||
#define PREQ2_NUM_OF_BITS 5
|
||||
#define PREQ2_NUM_OF_ROWS (1 << PREQ2_NUM_OF_BITS)
|
||||
#define PREQ2_NUM_OF_STAGES 3
|
||||
#define PREQ2_NUM_OF_WORDS (PREQ2_NUM_OF_ROWS*PREQ2_NUM_OF_STAGES/2)
|
||||
|
||||
#define PREQ3_NUM_OF_BITS 4
|
||||
#define PREQ3_NUM_OF_ROWS (1 << PREQ3_NUM_OF_BITS)
|
||||
#define PREQ3_NUM_OF_STAGES 4
|
||||
#define PREQ3_NUM_OF_WORDS (PREQ3_NUM_OF_ROWS*PREQ3_NUM_OF_STAGES/2)
|
||||
|
||||
extern int16_tRom psrPreQ1[PREQ1_NUM_OF_WORDS];
|
||||
|
||||
extern int16_tRom psrPreQ2[PREQ2_NUM_OF_WORDS];
|
||||
|
||||
extern int16_tRom psrPreQ3[PREQ3_NUM_OF_WORDS];
|
||||
|
||||
|
||||
/* size of the vq subset in the kth segment */
|
||||
/*------------------------------------------*/
|
||||
extern int16_tRom psrQuantSz[QUANT_NUM_OF_TABLES];
|
||||
|
||||
|
||||
/* pre-quantizer size */
|
||||
/*--------------------*/
|
||||
extern int16_tRom psrPreQSz[QUANT_NUM_OF_TABLES];
|
||||
|
||||
|
||||
/* reflection coeff scalar quantizer */
|
||||
/*-----------------------------------*/
|
||||
#define SQUANT_NUM_OF_BITS 8
|
||||
#define SQUANT_NUM_OF_ROWS (1 << SQUANT_NUM_OF_BITS)
|
||||
|
||||
extern int16_tRom psrSQuant[SQUANT_NUM_OF_ROWS];
|
||||
|
||||
|
||||
/* index structure for LPC Vector Quantizer */
|
||||
/*------------------------------------------*/
|
||||
struct IsubLHn
|
||||
{ /* index structure for LPC Vector
|
||||
* Quantizer */
|
||||
int16_tRom l; /* lowest index index range
|
||||
* from 1..NP */
|
||||
int16_tRom h; /* highest index */
|
||||
int16_tRom len; /* h-l+1 */
|
||||
};
|
||||
|
||||
|
||||
extern struct IsubLHn psvqIndex[QUANT_NUM_OF_TABLES];
|
||||
|
||||
|
||||
/* square root of p0 table */
|
||||
/*-------------------------*/
|
||||
#define SQRTP0_NUM_OF_BITS 5
|
||||
#define SQRTP0_NUM_OF_ROWS (1 << SQRTP0_NUM_OF_BITS)
|
||||
#define SQRTP0_NUM_OF_MODES 3
|
||||
|
||||
extern int16_tRom ppsrSqrtP0[SQRTP0_NUM_OF_MODES][SQRTP0_NUM_OF_ROWS];
|
||||
|
||||
|
||||
/* interpolation filter used for C and G */
|
||||
/*---------------------------------------*/
|
||||
#define CGINTFILT_MACS 6
|
||||
|
||||
extern int16_tRom ppsrCGIntFilt[CGINTFILT_MACS][OS_FCTR];
|
||||
|
||||
|
||||
/* interpolation filter used pitch */
|
||||
/*---------------------------------*/
|
||||
#define PVECINTFILT_MACS 10
|
||||
|
||||
extern int16_tRom ppsrPVecIntFilt[PVECINTFILT_MACS][OS_FCTR];
|
||||
|
||||
|
||||
/* fractional pitch lag table lag*OS_FCTR */
|
||||
/*----------------------------------------*/
|
||||
#define LAGTBL_NUM_OF_ROWS 256
|
||||
|
||||
extern int16_tRom psrLagTbl[LAGTBL_NUM_OF_ROWS];
|
||||
|
||||
|
||||
/* R0 decision value table defines range (not the levels themselves */
|
||||
/*------------------------------------------------------------------*/
|
||||
|
||||
#define R0DECTBL_NUM_OF_R0BITS 5
|
||||
#define R0DECTBL_NUM_OF_ROWS ((1 << R0DECTBL_NUM_OF_R0BITS)*2 - 1)
|
||||
|
||||
extern int16_tRom psrR0DecTbl[R0DECTBL_NUM_OF_ROWS];
|
||||
|
||||
|
||||
/* high pass filter coefficients */
|
||||
/*-------------------------------*/
|
||||
#define HPFCOEFS_NUM_OF_CODES 10
|
||||
|
||||
extern int16_tRom psrHPFCoefs[HPFCOEFS_NUM_OF_CODES];
|
||||
|
||||
|
||||
/* spectral smoothing coefficients */
|
||||
/*---------------------------------*/
|
||||
#define NWCOEFS_NUM_OF_CODES 20
|
||||
|
||||
extern int16_tRom psrNWCoefs[NWCOEFS_NUM_OF_CODES];
|
||||
|
||||
|
||||
/* spectral smoothing coefficients for FLAT */
|
||||
/*------------------------------------------*/
|
||||
#define FLATSSTCOEFS_NUM_OF_CODES 10
|
||||
|
||||
extern int32_tRom pL_rFlatSstCoefs[FLATSSTCOEFS_NUM_OF_CODES];
|
||||
|
||||
extern int16_tRom psrOldCont[4];
|
||||
extern int16_tRom psrNewCont[4];
|
||||
|
||||
#endif
|
||||
2360
src/libs/gsmhr/gsmhr_sp_sfrm.c
Normal file
2360
src/libs/gsmhr/gsmhr_sp_sfrm.c
Normal file
File diff suppressed because it is too large
Load Diff
65
src/libs/gsmhr/gsmhr_sp_sfrm.h
Normal file
65
src/libs/gsmhr/gsmhr_sp_sfrm.h
Normal file
@@ -0,0 +1,65 @@
|
||||
#ifndef __SP_SFRM
|
||||
#define __SP_SFRM
|
||||
|
||||
#include "gsmfr_typedefs.h"
|
||||
|
||||
/*_________________________________________________________________________
|
||||
| |
|
||||
| Function Prototypes |
|
||||
|_________________________________________________________________________|
|
||||
*/
|
||||
|
||||
int16_t g_corr2(int16_t *pswIn, int16_t *pswIn2,
|
||||
int32_t *pL_out);
|
||||
|
||||
int closedLoopLagSearch(int16_t pswLagList[],
|
||||
int iNumLags,
|
||||
int16_t pswLtpState[],
|
||||
int16_t pswHCoefs[],
|
||||
int16_t pswPVect[],
|
||||
int16_t *pswLag,
|
||||
int16_t *pswLtpShift);
|
||||
|
||||
void decorr(int iNumVects,
|
||||
int16_t pswGivenVect[],
|
||||
int16_t pswVects[]);
|
||||
|
||||
int16_t g_quant_vl(int16_t swUVCode,
|
||||
int16_t pswWInput[],
|
||||
int16_t swWIShift,
|
||||
int16_t pswWLTPVec[],
|
||||
int16_t pswWVSVec1[],
|
||||
int16_t pswWVSVec2[],
|
||||
struct NormSw snsRs00,
|
||||
struct NormSw snsRs11,
|
||||
struct NormSw snsRs22);
|
||||
|
||||
void gainTweak(struct NormSw *psErrorTerm);
|
||||
|
||||
void hnwFilt(int16_t pswInSample[],
|
||||
int16_t pswOutSample[],
|
||||
int16_t pswState[],
|
||||
int16_t pswInCoef[],
|
||||
int iStateOffset,
|
||||
int16_t swZeroState,
|
||||
int iNumSamples);
|
||||
|
||||
void sfrmAnalysis(int16_t *pswWSpeech,
|
||||
int16_t swVoicingMode,
|
||||
struct NormSw snsSqrtRs,
|
||||
int16_t *pswHCoefs,
|
||||
int16_t *pswLagList,
|
||||
short siNumLags,
|
||||
int16_t swPitch,
|
||||
int16_t swHNWCoef,
|
||||
short *psiLagCode,
|
||||
short *psiVSCode1,
|
||||
short *psiVSCode2,
|
||||
short *psiGsp0Code,
|
||||
int16_t swSP);
|
||||
|
||||
int16_t v_srch(int16_t pswWInput[],
|
||||
int16_t pswWBasisVecs[],
|
||||
short int siNumBasis);
|
||||
|
||||
#endif
|
||||
63
src/libs/gsmhr/gsmhr_typedefs.h
Normal file
63
src/libs/gsmhr/gsmhr_typedefs.h
Normal file
@@ -0,0 +1,63 @@
|
||||
/*******************************************************************
|
||||
*
|
||||
* typedef statements of types used in all half-rate GSM routines
|
||||
*
|
||||
******************************************************************/
|
||||
|
||||
#ifndef __GSM_HR_TYPEDEFS
|
||||
#define __GSM_HR_TYPEDEFS
|
||||
|
||||
#define DATE "August 8, 1996 "
|
||||
#define VERSION "Version 4.2 "
|
||||
|
||||
#define LW_SIGN (long)0x80000000 /* sign bit */
|
||||
#define LW_MIN (long)0x80000000
|
||||
#define LW_MAX (long)0x7fffffff
|
||||
|
||||
#define SW_SIGN (short)0x8000 /* sign bit for int16_t type */
|
||||
#define SW_MIN (short)0x8000 /* smallest Ram */
|
||||
#define SW_MAX (short)0x7fff /* largest Ram */
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
/* Definition of Types *
|
||||
***********************/
|
||||
|
||||
/* 32 bit "accumulator" (L_*) */
|
||||
/* 16 bit "register" (sw*) */
|
||||
typedef short int int16_tRom; /* 16 bit ROM data (sr*) */
|
||||
typedef long int int32_tRom; /* 32 bit ROM data (L_r*) */
|
||||
|
||||
struct NormSw
|
||||
{ /* normalized int16_t fractional
|
||||
* number snr.man precedes snr.sh (the
|
||||
* shift count)i */
|
||||
int16_t man; /* "mantissa" stored in 16 bit
|
||||
* location */
|
||||
int16_t sh; /* the shift count, stored in 16 bit
|
||||
* location */
|
||||
};
|
||||
|
||||
/* Global constants *
|
||||
********************/
|
||||
|
||||
#define NP 10 /* order of the lpc filter */
|
||||
#define N_SUB 4 /* number of subframes */
|
||||
#define F_LEN 160 /* number of samples in a frame */
|
||||
#define S_LEN 40 /* number of samples in a subframe */
|
||||
#define A_LEN 170 /* LPC analysis length */
|
||||
#define OS_FCTR 6 /* maximum LTP lag oversampling
|
||||
* factor */
|
||||
|
||||
#define OVERHANG 8 /* vad parameter */
|
||||
#define strStr strStr16
|
||||
|
||||
/* global variables */
|
||||
/********************/
|
||||
|
||||
extern int giFrmCnt; /* 0,1,2,3,4..... */
|
||||
extern int giSfrmCnt; /* 0,1,2,3 */
|
||||
|
||||
extern int giDTXon; /* DTX Mode on/off */
|
||||
|
||||
#endif
|
||||
1106
src/libs/gsmhr/gsmhr_utils.c
Normal file
1106
src/libs/gsmhr/gsmhr_utils.c
Normal file
File diff suppressed because it is too large
Load Diff
1363
src/libs/gsmhr/gsmhr_vad.c
Normal file
1363
src/libs/gsmhr/gsmhr_vad.c
Normal file
File diff suppressed because it is too large
Load Diff
1331
src/libs/gsmhr/gsmhr_vad.cpp
Normal file
1331
src/libs/gsmhr/gsmhr_vad.cpp
Normal file
File diff suppressed because it is too large
Load Diff
125
src/libs/gsmhr/gsmhr_vad.h
Normal file
125
src/libs/gsmhr/gsmhr_vad.h
Normal file
@@ -0,0 +1,125 @@
|
||||
#ifndef __VAD
|
||||
#define __VAD
|
||||
|
||||
#include "typedefs.h"
|
||||
|
||||
|
||||
/*_________________________________________________________________________
|
||||
| |
|
||||
| Function Prototypes |
|
||||
|_________________________________________________________________________|
|
||||
*/
|
||||
|
||||
void vad_reset(void);
|
||||
|
||||
void vad_algorithm
|
||||
(
|
||||
int32_t pL_acf[9],
|
||||
int16_t swScaleAcf,
|
||||
int16_t pswRc[4],
|
||||
int16_t swPtch,
|
||||
int16_t *pswVadFlag
|
||||
);
|
||||
|
||||
void energy_computation
|
||||
(
|
||||
int32_t pL_acf[],
|
||||
int16_t swScaleAcf,
|
||||
int16_t pswRvad[],
|
||||
int16_t swNormRvad,
|
||||
int16_t *pswM_pvad,
|
||||
int16_t *pswE_pvad,
|
||||
int16_t *pswM_acf0,
|
||||
int16_t *pswE_acf0
|
||||
);
|
||||
|
||||
|
||||
void average_acf
|
||||
(
|
||||
int32_t pL_acf[],
|
||||
int16_t swScaleAcf,
|
||||
int32_t pL_av0[],
|
||||
int32_t pL_av1[]
|
||||
);
|
||||
|
||||
void predictor_values
|
||||
(
|
||||
int32_t pL_av1[],
|
||||
int16_t pswRav1[],
|
||||
int16_t *pswNormRav1
|
||||
);
|
||||
|
||||
void schur_recursion
|
||||
(
|
||||
int32_t pL_av1[],
|
||||
int16_t pswVpar[]
|
||||
);
|
||||
|
||||
void step_up
|
||||
(
|
||||
int16_t swNp,
|
||||
int16_t pswVpar[],
|
||||
int16_t pswAav1[]
|
||||
);
|
||||
|
||||
void compute_rav1
|
||||
(
|
||||
int16_t pswAav1[],
|
||||
int16_t pswRav1[],
|
||||
int16_t *pswNormRav1
|
||||
);
|
||||
|
||||
void spectral_comparison
|
||||
(
|
||||
int16_t pswRav1[],
|
||||
int16_t swNormRav1,
|
||||
int32_t pL_av0[],
|
||||
int16_t *pswStat
|
||||
);
|
||||
|
||||
void tone_detection
|
||||
(
|
||||
int16_t pswRc[4],
|
||||
int16_t *pswTone
|
||||
);
|
||||
|
||||
|
||||
void threshold_adaptation
|
||||
(
|
||||
int16_t swStat,
|
||||
int16_t swPtch,
|
||||
int16_t swTone,
|
||||
int16_t pswRav1[],
|
||||
int16_t swNormRav1,
|
||||
int16_t swM_pvad,
|
||||
int16_t swE_pvad,
|
||||
int16_t swM_acf0,
|
||||
int16_t swE_acf0,
|
||||
int16_t pswRvad[],
|
||||
int16_t *pswNormRvad,
|
||||
int16_t *pswM_thvad,
|
||||
int16_t *pswE_thvad
|
||||
);
|
||||
|
||||
void vad_decision
|
||||
(
|
||||
int16_t swM_pvad,
|
||||
int16_t swE_pvad,
|
||||
int16_t swM_thvad,
|
||||
int16_t swE_thvad,
|
||||
int16_t *pswVvad
|
||||
);
|
||||
|
||||
void vad_hangover
|
||||
(
|
||||
int16_t swVvad,
|
||||
int16_t *pswVadFlag
|
||||
);
|
||||
|
||||
void periodicity_update
|
||||
(
|
||||
int16_t pswLags[4],
|
||||
int16_t *pswPtch
|
||||
);
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user