0
0

Hello,
me and many others have problems with getting Spectrum Analysis to work. The documents included in [i:frxd8uw0]fmod[/i:frxd8uw0] doesn’t help very much.
Maybe it would be a good idea if someone wrote a tutorial how to use Spectrum.
It would be good if the tutorial could describe how to write the code in different programming-languages.

Some of the most common questions are:[list:frxd8uw0][:frxd8uw0]How to creat a float-vector to store FSOUND_DSP_GetSpectrum()[/:m:frxd8uw0]
[:frxd8uw0]Why return of FSOUND_DSP_GetSpectrum only contains zeroes (0)[/:m:frxd8uw0]
[:frxd8uw0]What does the 512 values returned bo FSOUND_DSP_GetSpectrum() really mean. Describe how FSOUND_DSP_GetSpectrum() works “under the hood”.[/:m:frxd8uw0]
[:frxd8uw0]How to use FSOUND_DSP_GetSpectrum() with real- and non-realtime playback. Eg if you do a Spectrum Analysis of a file which is playing, or scanning the file in non-realtime (faster/slower).[/:m:frxd8uw0]
[:frxd8uw0]The use of FSOUND_Update() and what it really does. How to use it together with FSOUND_DSP_GetSpectrum() to scan a file in non-realtime.[/:m:frxd8uw0]
[:frxd8uw0]Using FSOUND_DSP_GetSpectrum() with file in memory or streamed from disk.[/:m:frxd8uw0]
[:frxd8uw0]Using FSOUND_DSP_GetSpectrum() together with FX.[/:m:frxd8uw0]
[:frxd8uw0]Sample of code written in different languages. [b:frxd8uw0]This is really important.[/b:frxd8uw0][/:m:frxd8uw0][/list:u:frxd8uw0]Feel free to add more questions to the list.

If I had the knowledge about [i:frxd8uw0]fmod[/i:frxd8uw0], the use of Spectrum Analysis, and knowledge about how to write correct english (which is not my native language), I could write the tutorial by my self.

My question is if anyone with some knowledge in [i:frxd8uw0]fmod[/i:frxd8uw0] (developer ?) could write a detailed tutorial about how FSOUND_DSP_GetSpectrum() works and how to use it.
I am sure such tutorial will spare this forum many posts about Spectrum Analysis.

  • You must to post comments
0
0

[b:xgs3mw8e]Here you are[/b:xgs3mw8e]

[size=150:xgs3mw8e][u:xgs3mw8e][b:xgs3mw8e]The Simple Guide to FSOUND_DSP_GetSpectrum[/b:xgs3mw8e][/u:xgs3mw8e][/size:xgs3mw8e]

[b:xgs3mw8e]What does it do:[/b:xgs3mw8e]
FSound_DSP_GetSpectrum() returns a POINTER to an array of 512 floating point values between 0.0 and 1.0. It does not return an array.

[b:xgs3mw8e]What do the values mean:[/b:xgs3mw8e]
The values represent what the current sound is doing at various frequencies. The first value is the lowest frequency and the last is the highest frequency. So a drum beat might be found in the first 5 elements of the array.

[b:xgs3mw8e]How do I use it:[/b:xgs3mw8e]
Assuming you have a means of playing a stream such as:
[code:xgs3mw8e]
main()
{

FSOUND_STREAM *my_stream;

FSOUND_Init(44100,2,0);

my_stream = FSOUND_Stream_Open( “song.mp3”, 0, 0, 0);
FSOUND_Stream_Play( 0, my_stream);

while(1)
{
/ / your loop

            if(!FSOUND_GetChannelsPlaying()) break;

}
}
[/code:xgs3mw8e]
You will need a pointer to float to access the return values from FSOUND_DSP_GetSpectrum:
float *spectrum_buffer_ptr;

You will need to activate the DSP unit like so:
FSOUND_DSP_SetActive(FSOUND_DSP_GetFFTUnit(), TRUE);

And finally you will need to use FSOUND_DSP_GetSpectrum() in your main loop:
spectrum_buffer_ptr = FSOUND_DSP_GetSpectrum();

All together it would look like this:

[code:xgs3mw8e]
main()
{

FSOUND_STREAM *my_stream;
float *spectrum_buffer_ptr;

FSOUND_Init(44100,2,0);
FSOUND_DSP_SetActive(FSOUND_DSP_GetFFTUnit(), TRUE);

my_stream = FSOUND_Stream_Open( “song.mp3”, 0, 0, 0);
FSOUND_Stream_Play( 0, my_stream);

while(1)
{
spectrum_buffer_ptr = FSOUND_DSP_GetSpectrum();
/ / your loop
if(!FSOUND_GetChannelsPlaying()) break;

}
}
[/code:xgs3mw8e]
To access the array use this in main
[code:xgs3mw8e]
while(1)
{
spectrum_buffer_ptr = FSOUND_DSP_GetSpectrum();
/ / your loop
for(int dunno=0; dunno<512; dunno++)
{
if( spectrum_buffer_ptr==1.0)
printf(“Man burp”);
if(
spectrum_buffer_ptr<0.5)
printf(“Lady Burp”);
spectrum_buffer_ptr++;
}
if(!FSOUND_GetChannelsPlaying()) break;

}
[/code:xgs3mw8e]

[b:xgs3mw8e]Super fast analyses[/b:xgs3mw8e]
To analyse at full speed rather than realtime you will need to tell FMOD so before you use FSOUND_Init() with:
FSOUND_SetOutput(FSOUND_OUTPUT_NOSOUND_NONREALTIME);

And in your main loop you will need to update the playing with:
FSOUND_update();

All together it looks like so:

[code:xgs3mw8e]
main()
{

FSOUND_STREAM *my_stream;
float *spectrum_buffer_ptr;

FSOUND_SetOutput(FSOUND_OUTPUT_NOSOUND_NONREALTIME);
FSOUND_Init(44100,2,0);
FSOUND_DSP_SetActive(FSOUND_DSP_GetFFTUnit(), TRUE);

my_stream = FSOUND_Stream_Open( “song.mp3”, 0, 0, 0);
FSOUND_Stream_Play( 0, my_stream);

while(1)
{
FSOUND_Update();
spectrum_buffer_ptr = FSOUND_DSP_GetSpectrum();
/ / your loop
for(int dunno=0; dunno<512; dunno++)
{
if( spectrum_buffer_ptr==1.0)
printf(“Man burp”);
if(
spectrum_buffer_ptr<0.5)
printf(“Lady Burp”);
spectrum_buffer_ptr++;
}
if(!FSOUND_GetChannelsPlaying()) break;
}
}
[/code:xgs3mw8e]

  • You must to post comments
0
0

An enormous thank for the great tutorial. 😛

But i do have one more question.
I don’t really understand the returned values by FSOUND_DSP_GetSpectrum(). Does the 512 elements represent an frequency each?
Is it like this:[code:18k2zkhd]44100 Hz / 512 = 86.1 Hz/element.
Element 368 = 31684.8 Hz ??[/code:18k2zkhd]And what does the values (0.0 – 1.0) in each element represent?

Please answer very detailed and mayby give som examples like in the tutorial. Keep in mind that I have almost no knowledge about how sound works.

And again, great thanks !
😀

  • You must to post comments
0
0

Despite using 44100 in FSOUND_Init() halve that value would be used to calculate the scope of each element. So each element would be 22050/512 and if you used 22050 in FSOUND_Init it would be 110025/512.

I admit I don’t know for certain but I think that each element represents a range of frequencies rather than just one so the first element in my example would 0-42hz the second would be 42.x hz to 84hz.

Each element represents sound at specific frequnecy or pitch so the higher the array subscript the higher the pitch.

The value you get in each element is the amplitude or volume of the sound at the specified frequency range with 0.0 being no sound at that frequency and 1.0 being maximum sound at that frequency.

A lot of this is assumptions perhaps one of the FMOD crew could verify.

  • You must to post comments
0
0

Thanks.

What you said does seem to make sense, but it would be fun if any [i:2gn8z99u]fmod[/i:2gn8z99u]-developer could comment.

  • You must to post comments
0
0

Thanks for the answer.

What about moving this thread to the FAQ-forum ??
I think many more people will find this thread useful.

  • You must to post comments
0
0

[quote="Warwolf":258rkhkm]
[*]Why return of FSOUND_DSP_GetSpectrum only contains zeroes (0).[/quote:258rkhkm]
trager, I exactly did what you said and i still got my array full of 0 !
please heeelp !

GOD DAMN IT ! you made a mistake !!!! you wrote FALSE instead of TRUUUUUUUUUUEEE !!!

  • You must to post comments
0
0

Lol. Damn it. I missed that one 3 times.

Fixed now.

  • You must to post comments
Showing 7 results
Your Answer

Please first to submit.