Hi, I’ve been trying to do spectrum analysis, or something of the sort, and I’ve been hitting dead-ends for the past couple of days, namely FMOD seems to be the only library that has a built-in function that supports getting the spectrum, but the problem "invalid object handle was used" seems to haunt me every time I try to use it, if anyone would be so kind as to give me an example of it’s usage I’d be very grateful.
Sorry, I forgot to include the platform I’m coding on, it’s Windows x64 (OS, I’m not compiling a 64-bit application).
As for IDE, I’m using Visual Studio 2010.
Thanks in advance for any future replies.
- Mind Calamity asked 5 years ago
The functions are documented, and examples provided.
Maybe you could give an example what you wrote?
[i:2gkybidh]"invalid object handle was used"[/i:2gkybidh]: Guess you use the wrong handle / parameter;
Retrieves the spectrum from the currently playing output signal;
handle of the system (e.g. via System_Create)
Retrieves the spectrum from the currently playing output signal for the current channel only;
handle of the channel (e.g. via FMOD_System_PlaySound)
Retrieves the spectrum from the currently playing channels assigned to this channel group;
handle of the channel group (e.g. via FMOD_System_CreateChannelGroup)
Sorry about that, but at the time of posting I was unable to provide more information, as I wasn’t at my working computer, and now I’m going to fill in more information on what I’m doing:
[code:23yqz44w] FMOD_RESULT res;
mSoundSystem->init(100, FMOD_INIT_NORMAL, 0);
res = mSoundSystem->createSound("D:\song.mp3", FMOD_2D, 0, &mSound);
res = mSoundSystem->playSound(FMOD_CHANNEL_FREE, mSound, false, &mPrimaryChannel); check(res); res = mPrimaryChannel->getSpectrum(mSpectrum, 512, 0, FMOD_DSP_FFT_WINDOW_BLACKMAN); check(res);[/code:23yqz44w]
This is all I have, and the corresponding variable and function declarations:
[code:23yqz44w] FMOD::System* mSoundSystem;
void check(FMOD_RESULT result)
if (result != FMOD_OK)
printf("FMOD error! (%d) %s\n", result, FMOD_ErrorString(result));
That’s all related to FMOD.
Also, after I tried it again now, this line:
[code:23yqz44w]res = mPrimaryChannel->getSpectrum(mSpectrum, 512, 0, FMOD_DSP_FFT_WINDOW_BLACKMAN);[/code:23yqz44w]
Seems to crash my application, and the check() part does not report any errors, this is why I asked for a working example, as I wasn’t able to find anything using the get spectrum function (or did I miss it maybe ?).
And obviously removing the said line removes the crash too.
Thanks for the quick reply Controller.
As far as I understand, you’re passing a single float, instead of an array of floats.
Excerpt from [b:2qkfprov]examples_csharp\vs2005\spectrum[/b:2qkfprov]:
[code:2qkfprov]private const int SPECTRUMSIZE = 512;
private float spectrum = new float[SPECTRUMSIZE];
system.getSpectrum(spectrum, SPECTRUMSIZE, count, FMOD.DSP_FFT_WINDOW.TRIANGLE);[/code:2qkfprov]
Alternatively from the example in [b:2qkfprov]examples\pitchdetection[/b:2qkfprov]:
[code:2qkfprov]#define SPECTRUMSIZE 8192
static float spectrum[SPECTRUMSIZE];
result = channel->getSpectrum(spectrum, SPECTRUMSIZE, 0, FMOD_DSP_FFT_WINDOW_TRIANGLE);[/code:2qkfprov]
Should work. Or at least fix the crash issue.
I’ve always thought that float* was the same as float, I haven’t really used float pointers, so this proved to be a good lesson for me.
I changed this:
define SPECTRUMSIZE 1024
And that removed the crash, and now mSpectrum is filled with some values, for which I’m yet to find out what their value represents.
[quote="Mind Calamity":3c9yhwe3]I’ve always thought that float* was the same as float, I haven’t really used float pointers, so this proved to be a good lesson for me.[/quote:3c9yhwe3]
Not so familiar with C etc, but float* may be something like pointer to an array / memory block of floats. In that case you’d have to allocate the memory first. But better ask someone who knows C/C++/C# better than me.
[quote="Mind Calamity":3c9yhwe3]…, and now mSpectrum is filled with some values, for which I’m yet to find out what their value represents.[/quote:3c9yhwe3]
Documented, in case that helps you. Or just try around. Try different windowtypes.
Note that FMOD_Channel_GetSpectrum receives from a specific channel ("song") and channeloffset ("mono") only. For stereo, you’d have to call this function twice. To get the spectrum of everything playing, switch to FMOD_System_GetSpectrum (Works pretty similar).
Please login first to submit.