📄 stdafx.cpp
字号:
//stdafx.cpp : source file that includes just the standard includes
//TestFilter.pch will be the pre-compiled header
//stdafx.obj will contain the pre-compiled type information
#include "stdafx.h"
void GetResult(float *pfRealBuffer,float *pfImagBuffer,float *pfResBuffer,int iNum)
{
//返回复数的模
//abs(z)=sqrt(Re(z)^2+Im(z)^2);
//I needed fast scaling,so I placed a /10 in here
//I will have a control for this plus log Scale
//later. I have no time now
//(isn't that funny,I have read that excuse in thousands
//of sourcecodes?)
int i;
for(i=0;i<iNum;i++)
{
pfResBuffer[i]=(float)sqrt(pfRealBuffer[i]*pfRealBuffer[i]+pfImagBuffer[i]*pfImagBuffer[i])/10;
}
}
void FourieTrans(float *pfReal,float *pfImag,unsigned int iNumOfSamples)
{
//公式直接方法求傅立叶转换,速度慢.
//ianliu
float pfTemp[4096*2];
unsigned int k,n;
memcpy(pfTemp,pfReal,iNumOfSamples*2*sizeof(float));
for(k=0;k<iNumOfSamples;k++)
{
pfReal[k]=0;
}
for(k=0;k<iNumOfSamples;k++)
{
for(n=0;n<iNumOfSamples;n++)
{
pfReal[k]=(float)(pfReal[k]+(pfTemp[n]*cos((TWO_PI/iNumOfSamples)*k*n)));
pfImag[k]=(float)(pfImag[k]-(pfTemp[n]*sin((TWO_PI/iNumOfSamples)*k*n)));
}
}
}
void GetReal(float *pfReal,float *pfRes,unsigned int iNumOfSamples)
{
//从复数pfRes中取实部
//ianliu
unsigned int k,n;
for(k=0;k<iNumOfSamples;k++)
{
{
pfReal[k]=(float)(pfRes[k]*cos((TWO_PI/iNumOfSamples)));
}
}
}
void GetImag(float *pfImag,float *pfRes,unsigned int iNumOfSamples)
{
//从复数pfRes中取虚部
//ianliu
unsigned int k,n;
for(k=0;k<iNumOfSamples;k++)
{
{
pfImag[k]=(float)(pfRes[k]*sin((TWO_PI/iNumOfSamples)));
}
}
}
void IFourieTrans(float *pfReal,float *pfImag,unsigned int iNumOfSamples)
{
//公式直接方法求傅立叶转换,速度慢.
//ianliu
float pfTemp[4096*2];
unsigned int k,n;
memcpy(pfTemp,pfReal,iNumOfSamples*2*sizeof(float));
for(k=0;k<iNumOfSamples;k++)
{
pfReal[k]=0;
}
for(k=0;k<iNumOfSamples;k++)
{
for(n=0;n<iNumOfSamples;n++)
{
pfReal[k]=((float)(pfReal[k]+(pfTemp[n]*cos((TWO_PI/iNumOfSamples)*k*n))));
pfImag[k]=((float)(pfImag[k]+(pfTemp[n]*sin((TWO_PI/iNumOfSamples)*k*n))));
}
}
}
void CopyAudioData(PBYTE pbAudioBuffer,float *pfRealBuffer,float *pfImagBuffer,int iNumBytes)
{
int i,n;
short sAudioSample;
for(i=0,n=0;i<iNumBytes;i+=2,n++)
{
//we need to align the data,because it has the wrong byte order
sAudioSample=((pbAudioBuffer[i+1]<<8)&0xFF00)|(pbAudioBuffer[i]&0x00FF);
pfImagBuffer[n]=0;
pfRealBuffer[n]=sAudioSample; //this is the correct 16bit SampleValue
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -