How do I get most accurate audio frequency data possible from real time FFT on Tizen?

帅比萌擦擦* 提交于 2019-12-11 20:40:48

问题


currently i m working on the Tizen IDE.

I had read the input data from the microPhone and apply the FFT on it... but everytime i gets the nan output.

here is my code..

 ShortBuffer *pBuffer1 = pData->AsShortBufferN();

fft = new KissFFT(BUFFER_SIZE);

std::vector<short> input(pBuffer1->GetPointer(),
        pBuffer1->GetPointer() + BUFFER_SIZE); // this contains audio data
std::vector<float> specturm(BUFFER_SIZE);

fft->spectrum(input, specturm);

applying FFT..

   void KissFFT::spectrum(KissFFTO* fft, std::vector<short>& samples2,
        std::vector<float>& spectrum) {


    int len = fft->numSamples / 2 + 1;

    kiss_fft_scalar* samples = (kiss_fft_scalar*) &samples2[0];

    kiss_fftr(fft->config, samples, fft->spectrum);

    for (int i = 0; i < len; i++) {

        float re = scale(fft->spectrum[i].r) * fft->numSamples;
        float im = scale(fft->spectrum[i].i) * fft->numSamples;

         if (i > 0)
         spectrum[i] = sqrtf(re * re + im * im) / (fft->numSamples / 2);
         else
         spectrum[i] = sqrtf(re * re + im * im) / (fft->numSamples);
         AppLog("specturm %d",spectrum[i]); // everytime returns returns nan output
    }

}



 KissFFTO* KissFFT::create(int numSamples) {

    KissFFTO* fft = new KissFFTO();
    fft->config = kiss_fftr_alloc(numSamples/2, 0, NULL, NULL);
    fft->spectrum = new kiss_fft_cpx[numSamples / 2 + 1];
    fft->numSamples = numSamples;

    return fft;
}

回答1:


In fft->config there should be some parameters about the size of FFT like 2048, 4096, i.e. powers of 2. If you increase this value, you can get more resolution in frequency.



来源:https://stackoverflow.com/questions/16931570/how-do-i-get-most-accurate-audio-frequency-data-possible-from-real-time-fft-on-t

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!