?? tfr16.c
字號(hào):
if (ax >= ay)
{
temp16 = div_s(ay,ax);
}
else
{
temp16 = div_s(ax,ay); /* temp = x/y i.e. 1/(y/x) */
div_flag = 1;
}
}
z = tfr16AtanOverPI(temp16);
if (div_flag == 1) /* atan(x)/pi = (0.5-(atan(1/x))/pi) */
{
z = sub(CFF(0.5),z);
}
if (sign_flag ==1)
{
z = negate(z);
}
return z;
}
typedef struct{
Frac16 PreviousAlpha;
Frac16 Delta;
Frac16 NextAlpha;
Frac16 Amplitude;
}sSineGenPAM;
/*******************************************************************************/
tfr16_tSineWaveGenPAM * tfr16SineWaveGenPAMCreate(Int16 SineFreq,
Int16 SampleFreq,
Frac16 InitialPhasePIx,
Frac16 Amplitude)
{
tfr16_tSineWaveGenPAM * pPrivateData = memMallocEM(sizeof(tfr16_tSineWaveGenPAM));
tfr16SineWaveGenPAMInit(pPrivateData, SineFreq, SampleFreq, InitialPhasePIx, Amplitude);
return(pPrivateData);
}
/*******************************************************************************/
void tfr16SineWaveGenPAMDestroy(tfr16_tSineWaveGenPAM * pSWG)
{
if (pSWG != NULL)
{
memFreeEM(pSWG);
}
}
/*******************************************************************************/
void tfr16SineWaveGenPAMInit(tfr16_tSineWaveGenPAM * pSWG,
Int16 SineFreq,
Int16 SampleFreq,
Frac16 InitialPhasePIx,
Frac16 Amplitude)
{
sSineGenPAM * pState = (sSineGenPAM *) pSWG;
pState -> PreviousAlpha = InitialPhasePIx;
pState -> Delta = div_s((Frac16)(2 * SineFreq),(Frac16)SampleFreq);
pState -> Amplitude = Amplitude;
}
/*******************************************************************************/
void tfr16SineWaveGenPAMC(tfr16_tSineWaveGenPAM * pSWG, Frac16 * pValues, UInt16 Nsamples)
{
sSineGenPAM * pState = (sSineGenPAM *) pSWG;
Frac16 NextAlpha;
UInt16 I;
for(I = 0; I < Nsamples; I++)
{
NextAlpha = add(pState -> PreviousAlpha, pState -> Delta);
if(NextAlpha >= MAX_16)
{
NextAlpha = sub(pState -> PreviousAlpha, MAX_16);
NextAlpha = add(NextAlpha, pState -> Delta);
NextAlpha = add(NextAlpha, MIN_16);
}
* pValues = mult(pState -> Amplitude,tfr16SinPIx(pState -> PreviousAlpha));
pValues += 1;
pState -> PreviousAlpha = NextAlpha;
}
}
typedef struct{
UInt16 * pIndex;
Frac16 * pEndTable;
bool bAligned;
UInt16 Delta;
UInt16 SineTableLength;
}sSineGenIDTL;
/*******************************************************************************/
tfr16_tSineWaveGenIDTL * tfr16SineWaveGenIDTLCreate(Frac16 * pSineTable,
UInt16 SineTableLength,
Int16 SineFreq,
Int16 SampleFreq,
Frac16 InitialPhasePIx)
{
tfr16_tSineWaveGenIDTL * pPrivateData = memMallocEM(sizeof(tfr16_tSineWaveGenIDTL));
tfr16SineWaveGenIDTLInit(pPrivateData, pSineTable, SineTableLength, SineFreq, SampleFreq, InitialPhasePIx);
return(pPrivateData);
}
/*******************************************************************************/
void tfr16SineWaveGenIDTLDestroy(tfr16_tSineWaveGenIDTL * pSWG)
{
if (pSWG != NULL)
{
memFreeEM(pSWG);
}
}
/*******************************************************************************/
void tfr16SineWaveGenIDTLInit(tfr16_tSineWaveGenIDTL * pSWG,
Frac16 * pSineTable,
UInt16 SineTableLength,
Int16 SineFreq,
Int16 SampleFreq,
Frac16 InitialPhasePIx)
{
sSineGenIDTL * pState = (sSineGenIDTL *) pSWG;
Frac16 NormFreq = div_s((Frac16)SineFreq,(Frac16)SampleFreq);
/* Frac16 NormFreq = add(div_s((Frac16)SineFreq,(Frac16)SampleFreq), CFF(.001)); */
Frac16 InitialPhase;
UInt16 FirstIndex;
pState -> bAligned = memIsAligned (pSineTable, SineTableLength*sizeof(Frac16));
pState -> SineTableLength = SineTableLength;
pState -> Delta = (UInt16) mult((Frac16)SineTableLength, NormFreq);
InitialPhase = mult(InitialPhasePIx, 0x4000);
if(InitialPhasePIx < 0)
{
InitialPhasePIx = add(InitialPhasePIx, MAX_16);
InitialPhase = add(-InitialPhase, InitialPhasePIx);
}
FirstIndex = (UInt16) mult((Frac16)SineTableLength, InitialPhase);
pState -> pEndTable = pSineTable + SineTableLength;
pState -> pIndex = (UInt16 *) pSineTable + FirstIndex;
}
/*******************************************************************************/
void tfr16SineWaveGenIDTLC(tfr16_tSineWaveGenIDTL * pSWG, Frac16 * pValues, UInt16 Nsamples)
{
sSineGenIDTL * pState = (sSineGenIDTL *) pSWG;
UInt16 I;
for(I = 0; I < Nsamples; I++)
{
* pValues = (Frac16) *(pState -> pIndex);
pValues += 1;
pState -> pIndex = (pState -> pIndex + pState -> Delta);
if((pState -> pIndex) >= (UInt16 *)(pState -> pEndTable))
{
pState -> pIndex -= pState -> SineTableLength;
}
}
}
typedef struct{
Frac16 * pSineTable;
Frac16 Phase;
Frac16 Delta;
UInt16 SineTableLength;
}sSineGenRDTL;
/*******************************************************************************/
tfr16_tSineWaveGenRDTL * tfr16SineWaveGenRDTLCreate(Frac16 * pSineTable,
UInt16 SineTableLength,
Int16 SineFreq,
Int16 SampleFreq,
Frac16 InitialPhasePIx)
{
tfr16_tSineWaveGenRDTL * pPrivateData = memMallocEM(sizeof(tfr16_tSineWaveGenRDTL));
tfr16SineWaveGenRDTLInit(pPrivateData, pSineTable, SineTableLength, SineFreq, SampleFreq, InitialPhasePIx);
return(pPrivateData);
}
/*******************************************************************************/
void tfr16SineWaveGenRDTLDestroy(tfr16_tSineWaveGenRDTL * pSWG)
{
if (pSWG != NULL)
{
memFreeEM(pSWG);
}
}
/*******************************************************************************/
void tfr16SineWaveGenRDTLInit(tfr16_tSineWaveGenRDTL * pSWG,
Frac16 * pSineTable,
UInt16 SineTableLength,
Int16 SineFreq,
Int16 SampleFreq,
Frac16 InitialPhasePIx)
{
sSineGenRDTL * pState = (sSineGenRDTL *) pSWG;
Frac16 InitialPhase;
pState -> pSineTable = pSineTable;
pState -> SineTableLength = SineTableLength;
pState -> Delta = div_s((Frac16)SineFreq,(Frac16)SampleFreq);
InitialPhase = mult(InitialPhasePIx, SWG_ONEHALF);
if(InitialPhasePIx < 0)
{
InitialPhasePIx = add(InitialPhasePIx, MAX_16);
InitialPhase = add(-InitialPhase, InitialPhasePIx);
}
pState -> Phase = InitialPhase;
}
/*******************************************************************************/
void tfr16SineWaveGenRDTLC(tfr16_tSineWaveGenRDTL * pSWG, Frac16 * pValues, UInt16 Nsamples)
{
sSineGenRDTL * pState = (sSineGenRDTL *) pSWG;
UInt16 Index;
UInt16 I;
for(I = 0; I < Nsamples; I++)
{
Index = (UInt16) mult((Frac16)(pState -> SineTableLength), pState -> Phase);
* pValues = *(pState -> pSineTable + Index);
pValues += 1;
if((pState -> Phase + pState -> Delta) >= MAX_16)
{
pState -> Phase = sub(MAX_16, pState -> Phase);
pState -> Phase = sub(pState -> Delta, pState -> Phase);
}
else
{
pState -> Phase = (pState -> Phase + pState -> Delta);
}
}
}
typedef struct{
Frac16 * pSineTable;
Frac16 Phase;
Frac16 Delta;
UInt16 SineTableLength;
UInt16 Shift;
}sSineGenRDITL;
/*******************************************************************************/
tfr16_tSineWaveGenRDITL * tfr16SineWaveGenRDITLCreate(Frac16 * pSineTable,
UInt16 SineTableLength,
Int16 SineFreq,
Int16 SampleFreq,
Frac16 InitialPhasePIx)
{
tfr16_tSineWaveGenRDITL * pPrivateData = memMallocEM(sizeof(tfr16_tSineWaveGenRDITL));
tfr16SineWaveGenRDITLInit(pPrivateData, pSineTable, SineTableLength, SineFreq, SampleFreq, InitialPhasePIx);
return(pPrivateData);
}
/*******************************************************************************/
void tfr16SineWaveGenRDITLDestroy(tfr16_tSineWaveGenRDITL * pSWG)
{
if (pSWG != NULL)
{
memFreeEM(pSWG);
}
}
/*******************************************************************************/
void tfr16SineWaveGenRDITLInit(tfr16_tSineWaveGenRDITL * pSWG,
Frac16 * pSineTable,
UInt16 SineTableLength,
Int16 SineFreq,
Int16 SampleFreq,
Frac16 InitialPhasePIx)
{
sSineGenRDITL * pState = (sSineGenRDITL *) pSWG;
pState -> pSineTable = pSineTable;
pState -> SineTableLength = SineTableLength;
pState -> Delta = div_s((Frac16)SineFreq,(Frac16)SampleFreq);
pState -> Phase = InitialPhasePIx;
pState -> Shift = (UInt16) (2 * div_s((Frac16)SineTableLength,(Frac16)SWG_180_DEGREES));
pState -> Shift = pState -> Shift / 4;
/* pState -> Shift = (norm_s(pState -> Shift)) + 1; */
pState -> Shift = (UInt16) norm_s((Word16) pState -> Shift);
pState -> Shift = (pState -> Shift) + 1;
}
/*******************************************************************************/
void tfr16SineWaveGenRDITLC(tfr16_tSineWaveGenRDITL * pSWG, Frac16 * pValues, UInt16 Nsamples)
{
sSineGenRDITL * pState = (sSineGenRDITL *) pSWG;
Frac16 SineAngle;
Frac16 SineValue1;
Frac16 SineValue2;
Frac16 SineDelta;
Frac16 Sign;
UInt16 I;
UInt16 Samples = Nsamples;
for(I = 0; I < Samples; I++)
{
if((pState -> Phase) >= 0)
{
if((pState -> Phase) < PI_HALF_PLUS) /* 0 <= Angle < PI/2 */
{
SineAngle = (Frac16) shr_r((Word16) pState -> Phase, (Word16) pState -> Shift);
SineDelta = ((pState -> Phase) & 0x003F);
Sign = SWG_SIGN_POSITIVE;
}
else /* PI/2 <= Angle < PI */
{
SineAngle = (Frac16) shr_r((Word16) (PI_PLUS - (pState -> Phase)), (Word16) pState -> Shift);
SineDelta = (Frac16) ((PI_PLUS - (pState -> Phase)) & 0x003F);
Sign = SWG_SIGN_POSITIVE;
}
}
else /* (*Angle) < 0 */
{
if((pState -> Phase) < PI_HALF_MINUS) /* -PI <= Angle < -PI/2 */
{
SineAngle = (Frac16) shr_r((Word16) (PI_PLUS + (pState -> Phase)), (Word16) pState -> Shift);
SineDelta = (Frac16) ((PI_PLUS + (pState -> Phase)) & 0x003F);
Sign = SWG_SIGN_NEGATIVE;
}
else /* -PI/2 <= Angle < 0 */
{
SineAngle = (Frac16) shr_r((Word16) (abs_s((pState -> Phase))), (Word16) pState -> Shift);
SineDelta = (abs_s((pState -> Phase)) & 0x003F);
Sign = SWG_SIGN_NEGATIVE;
}
}
SineValue1 = pState -> pSineTable[SineAngle];
SineValue2 = pState -> pSineTable[SineAngle + 1];
* pValues = Sign * ((((SineValue2 - SineValue1) * SineDelta) >> pState -> Shift) + SineValue1);
pValues += 1;
if((pState -> Phase + pState -> Delta) >= MAX_16)
{
pState -> Phase = sub(MAX_16, pState -> Phase);
pState -> Phase = sub(pState -> Delta, pState -> Phase);
pState -> Phase = add(pState -> Phase, SWG_NEG_MAX);
}
else
{
pState -> Phase = (pState -> Phase + pState -> Delta);
}
}
}
typedef struct{
Frac16 * pSineTable;
Frac16 Phase;
Frac16 Delta;
UInt16 SineTableLength;
UInt16 Shift;
}sSineGenRDITLQ;
/*******************************************************************************/
tfr16_tSineWaveGenRDITLQ * tfr16SineWaveGenRDITLQCreate(Frac16 * pSineTable,
UInt16 SineTableLength,
Int16 SineFreq,
Int16 SampleFreq,
Frac16 InitialPhasePIx)
{
tfr16_tSineWaveGenRDITLQ * pPrivateData = memMallocEM(sizeof(tfr16_tSineWaveGenRDITLQ));
tfr16SineWaveGenRDITLQInit(pPrivateData, pSineTable, SineTableLength, SineFreq, SampleFreq, InitialPhasePIx);
return(pPrivateData);
}
/*******************************************************************************/
void tfr16SineWaveGenRDITLQDestroy(tfr16_tSineWaveGenRDITLQ * pSWG)
{
if (pSWG != NULL)
{
memFreeEM(pSWG);
}
}
/*******************************************************************************/
void tfr16SineWaveGenRDITLQInit(tfr16_tSineWaveGenRDITLQ * pSWG,
Frac16 * pSineTable,
UInt16 SineTableLength,
Int16 SineFreq,
Int16 SampleFreq,
Frac16 InitialPhasePIx)
{
sSineGenRDITLQ * pState = (sSineGenRDITLQ *) pSWG;
pState -> pSineTable = pSineTable;
pState -> SineTableLength = SineTableLength;
pState -> Delta = 2 * div_s((Frac16)SineFreq,(Frac16)SampleFreq);
pState -> Phase = InitialPhasePIx;
pState -> Shift = (UInt16) div_s((Frac16)SineTableLength,(Frac16)SWG_180_DEGREES);
/* pState -> Shift = (norm_s(pState -> Shift)) + 1; */
pState -> Shift = (UInt16) norm_s((Word16) pState -> Shift);
pState -> Shift = (pState -> Shift) + 1;
}
/*******************************************************************************/
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -