1
0

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. :)

  • You must to post comments
0
0

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;

FMOD_System_GetSpectrum
Retrieves the spectrum from the currently playing output signal;
handle of the system (e.g. via System_Create)

FMOD_Channel_GetSpectrum
Retrieves the spectrum from the currently playing output signal for the current channel only;
handle of the channel (e.g. via FMOD_System_PlaySound)

FMOD_ChannelGroup_GetSpectrum
Retrieves the spectrum from the currently playing channels assigned to this channel group;
handle of the channel group (e.g. via FMOD_System_CreateChannelGroup)

  • You must to post comments
0
0

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;
FMOD::System_Create(&mSoundSystem);
mSoundSystem->init(100, FMOD_INIT_NORMAL, 0);
res = mSoundSystem->createSound("D:\song.mp3", FMOD_2D, 0, &mSound);
check(res);

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;
FMOD::Channel* mPrimaryChannel;
FMOD::Sound* mSound;
float* mSpectrum;
void check(FMOD_RESULT result)
{
if (result != FMOD_OK)
{
printf("FMOD error! (%d) %s\n", result, FMOD_ErrorString(result));
system("pause");
}
}[/code:23yqz44w]

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. :)

  • You must to post comments
0
0

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.

  • You must to post comments
0
0

Thanks, Controller.

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:
[code:2mcrehj1]float* mSpectrum;[/code:2mcrehj1]
to this:

[code:2mcrehj1]

define SPECTRUMSIZE 1024

float mSpectrum[SPECTRUMSIZE];[/code:2mcrehj1]

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.

  • You must to post comments
0
0

[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).

  • You must to post comments
0
0

Thanks for all your help, Controller, I really appreciate it.

And thus my problem is solved and I can now continue with my experiments. :)

  • You must to post comments
Showing 6 results
Your Answer

Please first to submit.