UE4 - Microphone Spectrum always return 0 Length

I’m working on the same thing but for unreal engine, I did everything possible as I’ve researched, but the results always zero

void UMyActorComponent::getSpectrum_Linear()
if (fft != NULL)
GEngine->AddOnScreenDebugMessage(-1, 0.05f, FColor::Red, “FFT”);
GEngine->AddOnScreenDebugMessage(-1, 0.05f, FColor::Red, FString::FromInt(fft->length));
GEngine->AddOnScreenDebugMessage(-1, 0.05f, FColor::Red, FString::FromInt(fft->numchannels));
for (int channels = 0; channels < fft->numchannels; ++channels)
for (int bin = 0; bin < fft->length; ++bin)
float freVal = fft->spectrum[channels][bin];
GEngine->AddOnScreenDebugMessage(-1, 0.1f, FColor::Green, FString::SanitizeFloat(freVal));

void UMyActorComponent::StartRecording()
result = lowlevel->createSound(0, FMOD_LOOP_NORMAL | FMOD_OPENUSER, &exinfo, &sound);
result = lowlevel->recordStart(DEVICE_INDEX, sound, true);
result = lowlevel->playSound(sound, 0, false, &channel);
lowlevel->createDSPByType(FMOD_DSP_TYPE::FMOD_DSP_TYPE_FFT, &dsp);
dsp->getParameterData(FMOD_DSP_FFT_SPECTRUMDATA, (void **)&fft, 0, 0, 0);
GEngine->AddOnScreenDebugMessage(-1, 2.f, FColor::Red, TEXT(“Start Recording!”));

I’ve been told to use lock and unlock sound, but i couldn’t understand or find any example how to use those functions to get what I want.

I really need help in this. any advice?

You will need to call dsp->getParameterData every time you want new data, as it will only get a snapshot of the data at that exact frame.

1 Like