Hey, I am currently trying to get the FFT parameterData, but following all examples I can find online, the fft response has a numchannels of 0 always.
Am I thinking about this wrong? Or is something up with my code maybe?
// This is defined outside the loop
FMOD::DSP* dsp;
system->createDSPByType(FMOD_DSP_TYPE::FMOD_DSP_TYPE_FFT, &dsp);
channel->addDSP(FMOD_DSP_PARAMETER_DATA_TYPE_FFT, dsp);
dsp->setActive(true);
// This is in the loop
FMOD_DSP_PARAMETER_FFT *fft; // FMOD_DSP_FFT_DOMINANT_FREQ
dsp->getParameterData(FMOD_DSP_FFT_SPECTRUMDATA, (void **)&fft, 0, 0, 0);
Common_Draw("Channels %d", fft->numchannels);
for (int channelz = 0; channelz < fft->numchannels; channelz++)
{
Common_Draw("count %f", channelz);
for (int bin = 0; bin < fft->length; bin++)
{
float val = fft->spectrum[channelz][bin];
Common_Draw("FFT %f", val);
}
}
I am using the record.cpp example for the low-level api.
Hi ,
I put this code into the recording example and it seemed to work fine.
The key would be where to put your âoutside the loopâ code though.
The playsound only happens after a few updates, so it has to go after the playSound call so that channel is valid.
Are you checking error return values? I have a feeling you would be getting errors. (ie FMOD_ERR_INVALID_HANDLE in addDSP).
Hey Brett, thanks for your feedback. Can you tell me where you put the code? I just tried moving it around, and i t seems to still be coming back with 0 channels on the fft.
The playSound is inside the loop, so confused on where to put things.
Where should I put the dps variable declaration? I tried having it in there, but then the code that grabs the fft cant access the variable. I tried declaring it up top but then it says the dsp var is not there when it hits the call right after playSound.
Thanks again, and sorry if this is some obvious thingâŚI just started in c++ in the last few months, still figuring it out.
Hi Scott,
The issue youâre having is to do with âscopeâ (you can google that in regards to C++). You need to make dsp accessible from both places, so just put it at the top of main if you want. Any time a variable is declared in {} braces the code in the level above it cannot access it.
Your second case should be the right one, what actual error did it give you?
error C4703: potentially uninitialized local pointer variable âdspâ used
I tried putting FMOD::DSP* dsp; at the very top outside of the int FMOD_Main() and also inside. Outside up top had some read access violation, and inside had the error above.
thats more of a warning. Do you have warnings set as errors in your project settings.
Just set dsp = 0, and put it in main, you donât need to make it global.
I think I messed some other stuff up in the file, because Iâm getting some weird unrelated errors now that its running. (I messed with it for a while).
Is there any way I can get you to pastebin.com the contents of your record.cpp file so I donât have to uninstall/reinstall? I cant seem to find the files anywhere except thru the api installer.
can you use the debugger to inspect the variables? I dont think length being null is a good check. For a start it should not be NULL but 0 (null is typically only used for pointers) and also if fft->length was 0 then length would be -1 anyway.
The for loop wouldnt execute if length was 0 or -1 anyway.
Have you determined thatâs why it has the problem? Where is the read, and what variable is it talking about?