Skip to content

Commit

Permalink
Use sincos instead of sine and cosine separately
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremysalwen committed Jun 5, 2011
1 parent e5e9b32 commit 21b9607
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
13 changes: 12 additions & 1 deletion QuickTrig.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,19 @@ class CQuickTrig
{
return QuickCosQ((int)(dAngle*(kMsTableSize*kLsTableSize/(2*PI))) );
}
inline void QuickSinCos(double dAngle,float * cos, float* sin) const // Returns cos with 20 bits of precision.
{
return QuickSinCosQ((int)(dAngle*(kMsTableSize*kLsTableSize/(2*PI))),cos,sin );
}


inline void QuickSinCosQ(int nIndex, float* cos, float*sin) const {
// Based on the identity sin(u+v) = sinu cosv + cosu sinv
// based on the identity cos(u+v) = cosu cosv + sinu sinv
TSinCos *pscu = mMsBitsTable +( (nIndex >> kLSBits) & (kMsTableSize-1));
TSinCos *pscv = mLsBitsTable + ( (nIndex) & (kLsTableSize-1));
*cos= pscu->mcos * pscv->mcos - pscu->msin * pscv->msin;
*sin= pscu->msin * pscv->mcos + pscu->mcos * pscv->msin;
}


};
7 changes: 4 additions & 3 deletions kn0ck0ut6.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -368,9 +368,10 @@ void AKnockout::do_rebuild(long numSampsToProcess, long fftFrameSize, long osamp
tmp *= dFreqfactor;
tmp += (double)k*expct;

/* get real and imag part and re-interleave */
gFFTworksp[k][0] = magn*myQT.QuickCos(tmp);
gFFTworksp[k][1] = magn*myQT.QuickSin(tmp);
/* get real and imag part and re-interleave */
myQT.QuickSinCos(tmp,gFFTworksp[k],gFFTworksp[k]+1);
gFFTworksp[k][0] *=magn;
gFFTworksp[k][1] *=magn;

}

Expand Down

0 comments on commit 21b9607

Please sign in to comment.