0

I'm using the below code in Unreal Engine 4 to capture microphone input and get the resulting FFT.

I'm having trouble calculating the frequency based on this data.

I've tried finding the max amplitude and taking that as the frequency, but that doesn't seem to be correct.

// Additional includes:
#include "Voice.h"
#include "OnlineSubsystemUtils.h"

// New class member:
TSharedPtr<class IVoiceCapture> voiceCapture;

// Initialisation:
voiceCapture = FVoiceModule::Get().CreateVoiceCapture();
voiceCapture->Start();

// Capturing samples:
uint32 bytesAvailable = 0;
EVoiceCaptureState::Type captureState = voiceCapture->GetCaptureState(bytesAvailable);
if (captureState == EVoiceCaptureState::Ok && bytesAvailable > 0)
{
    uint8 buf[maxBytes];
    memset(buf, 0, maxBytes);
    uint32 readBytes = 0;
    voiceCapture->GetVoiceData(buf, maxBytes, readBytes);

    uint32 samples = readBytes / 2;
    float* sampleBuf = new float[samples];

    int16_t sample;
    for (uint32 i = 0; i < samples; i++)
    {
        sample = (buf[i * 2 + 1] << 8) | buf[i * 2];
        sampleBuf[i] = float(sample) / 32768.0f;
    }

    // Do fun stuff here

    delete[] sampleBuf;
}
4

1 回答 1

1

我没有在您的代码片段中看到要执行的傅立叶变换。无论如何,使用以平均采样频率R给定N个样本的 DFT ,对应于 bin k的频率为k·R/2N

于 2015-05-18T00:17:10.897 回答