Boolean	FFTBufferManager::ComputeFFT(int32_t *outFFTData, float_t *outMajorPitch)
{
	if (HasNewAudioData())
	{
		SpectrumAnalysisProcess(mSpectrumAnalysis, mAudioBuffer, outFFTData, outMajorPitch, true);		
		OSAtomicDecrement32Barrier(&mHasAudioData);
		OSAtomicIncrement32Barrier(&mNeedsAudioData);
		mAudioBufferCurrentIndex = 0;
		return true;
	}
	else if (mNeedsAudioData == 0)
		OSAtomicIncrement32Barrier(&mNeedsAudioData);
	
	return false;
}
Exemplo n.º 2
0
Boolean	FFTBufferManager::ComputeFFT(int32_t *outFFTData)
{
	if (HasNewAudioData())
	{
//        for(int i=0;i<mFFTLength;i++)
//        {
//            if(mAudioBuffer[i]>0.15)
//            printf("%f\n",mAudioBuffer[i]);
//        }
        //Generate a split complex vector from the real data
# define NOISE_FILTER 0.01;
        for(int i=0;i<4096;i++)
        {
            
            //DENOISE
            if(mAudioBuffer[i]>0)
            {
                mAudioBuffer[i] -= NOISE_FILTER;
                if(mAudioBuffer[i] < 0)
                {
                    mAudioBuffer[i] = 0;
                }
            }
            else if(mAudioBuffer[i]<0)
            {
                mAudioBuffer[i] += NOISE_FILTER;
                if(mAudioBuffer[i]>0)
                {
                    mAudioBuffer[i] = 0;
                }
            }
            else
            {
                mAudioBuffer[i] = 0;         
            }
            
        }

        
        
        
        vDSP_ctoz((COMPLEX *)mAudioBuffer, 2, &mDspSplitComplex, 1, mFFTLength);
        
        //Take the fft and scale appropriately
        vDSP_fft_zrip(mSpectrumAnalysis, &mDspSplitComplex, 1, mLog2N, kFFTDirection_Forward);
        vDSP_vsmul(mDspSplitComplex.realp, 1, &mFFTNormFactor, mDspSplitComplex.realp, 1, mFFTLength);
        vDSP_vsmul(mDspSplitComplex.imagp, 1, &mFFTNormFactor, mDspSplitComplex.imagp, 1, mFFTLength);
        
        //Zero out the nyquist value
        mDspSplitComplex.imagp[0] = 0.0;
        
        //Convert the fft data to dB
        Float32 tmpData[mFFTLength];
        vDSP_zvmags(&mDspSplitComplex, 1, tmpData, 1, mFFTLength);
        
        //In order to avoid taking log10 of zero, an adjusting factor is added in to make the minimum value equal -128dB
        vDSP_vsadd(tmpData, 1, &mAdjust0DB, tmpData, 1, mFFTLength);
        Float32 one = 1;
        vDSP_vdbcon(tmpData, 1, &one, tmpData, 1, mFFTLength, 0);
        
        //Convert floating point data to integer (Q7.24)
        vDSP_vsmul(tmpData, 1, &m24BitFracScale, tmpData, 1, mFFTLength);
        for(UInt32 i=0; i<mFFTLength; ++i)
            outFFTData[i] = (SInt32) tmpData[i];
        
        for(int i=0;i<mFFTLength/4;i++)
        {
            
                printf("%i:::%i\n",i,outFFTData[i]/16777216+120);
        }
        OSAtomicDecrement32Barrier(&mHasAudioData);
		OSAtomicIncrement32Barrier(&mNeedsAudioData);
		mAudioBufferCurrentIndex = 0;
		return true;
	}
	else if (mNeedsAudioData == 0)
		OSAtomicIncrement32Barrier(&mNeedsAudioData);
	
	return false;
}